[DTrace-devel] [PATCH v2] test: Add test for option "linktype"

Kris Van Hees kris.van.hees at oracle.com
Fri Apr 28 05:24:59 UTC 2023


On Sat, Mar 11, 2023 at 12:29:14PM -0500, eugene.loh--- via DTrace-devel wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>

Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>

> ---
>  test/unittest/options/tst.linktype.r  | 10 ++++
>  test/unittest/options/tst.linktype.sh | 80 +++++++++++++++++++++++++++
>  2 files changed, 90 insertions(+)
>  create mode 100644 test/unittest/options/tst.linktype.r
>  create mode 100755 test/unittest/options/tst.linktype.sh
> 
> diff --git a/test/unittest/options/tst.linktype.r b/test/unittest/options/tst.linktype.r
> new file mode 100644
> index 00000000..2a2b1c99
> --- /dev/null
> +++ b/test/unittest/options/tst.linktype.r
> @@ -0,0 +1,10 @@
> +link pass:
> +objdump recognizes elf
> +link pass: -xlinktype=elf
> +objdump recognizes elf
> +link pass: -xlinktype=dof
> +objdump does NOT recognize file format
> +link FAIL: -xlinktype=foo
> +objdump does NOT recognize file format
> +-- @@stderr --
> +dtrace: failed to set -x linktype: Invalid value for specified option
> diff --git a/test/unittest/options/tst.linktype.sh b/test/unittest/options/tst.linktype.sh
> new file mode 100755
> index 00000000..25bcaae0
> --- /dev/null
> +++ b/test/unittest/options/tst.linktype.sh
> @@ -0,0 +1,80 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
> +# Licensed under the Universal Permissive License v 1.0 as shown at
> +# http://oss.oracle.com/licenses/upl.
> +#
> +
> +# @@nosort
> +
> +dtrace=$1
> +CC=/usr/bin/gcc
> +CFLAGS=
> +
> +DIRNAME="$tmpdir/linktype.$$.$RANDOM"
> +mkdir -p $DIRNAME
> +cd $DIRNAME
> +
> +# set up the prov.d file and compile
> +
> +cat > prov.d <<EOF
> +provider test_prov {
> +	probe go();
> +};
> +EOF
> +
> +$dtrace -h -s prov.d
> +if [ $? -ne 0 ]; then
> +	echo "failed to generate header file" >& 2
> +	exit 1
> +fi
> +
> +# set up the test.c file and compile
> +
> +cat > test.c <<EOF
> +#include <sys/types.h>
> +#include "prov.h"
> +int main(int argc, char **argv)
> +{
> +	TEST_PROV_GO();
> +	return 0;
> +}
> +EOF
> +
> +${CC} ${CFLAGS} -c test.c
> +if [ $? -ne 0 ]; then
> +	echo "failed to compile test.c" >& 2
> +	exit 1
> +fi
> +
> +# link with different -xlinktype values
> +
> +function mytest() {
> +	$dtrace -G $1 -s prov.d test.o
> +
> +	# report whether the link succeeded
> +	if [ $? -ne 0 ]; then
> +		echo "link FAIL:" $1
> +	else
> +		echo "link pass:" $1
> +	fi
> +
> +	# report whether the file format is recognized
> +	objdump --file-headers prov.o |& awk '
> +	    /format not recognized/ {
> +		print "objdump does NOT recognize file format";
> +		exit(0);
> +	    }
> +	    /file format elf/ {
> +		print "objdump recognizes elf";
> +		exit(0);
> +	    }'
> +}
> +
> +mytest " "              # link should pass, file format should be recognized
> +mytest -xlinktype=elf   # link should pass, file format should be recognized
> +mytest -xlinktype=dof   # link should pass, file format should NOT be recognized
> +mytest -xlinktype=foo   # link should FAIL, file format should NOT be recognized
> +
> +exit 0
> -- 
> 2.18.4
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list