[DTrace-devel] [PATCH v2] test: Add tests for ldpath

Kris Van Hees kris.van.hees at oracle.com
Mon Feb 20 19:27:59 UTC 2023


On Fri, Feb 17, 2023 at 01:49:02PM -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>
> ---
>  .../options/err.D_PRAGMA_OPTSET.ldpath.d      | 19 +++++++++++++++++++
>  .../options/err.D_PRAGMA_OPTSET.ldpath.r      |  2 ++
>  test/unittest/options/err.ldpath.d            | 19 +++++++++++++++++++
>  test/unittest/options/err.ldpath.r            |  3 +++
>  test/unittest/options/err.ldpath.r.p          |  3 +++
>  test/unittest/options/tst.ldpath.sh           | 17 +++++++++++++++++
>  6 files changed, 63 insertions(+)
>  create mode 100644 test/unittest/options/err.D_PRAGMA_OPTSET.ldpath.d
>  create mode 100644 test/unittest/options/err.D_PRAGMA_OPTSET.ldpath.r
>  create mode 100644 test/unittest/options/err.ldpath.d
>  create mode 100644 test/unittest/options/err.ldpath.r
>  create mode 100755 test/unittest/options/err.ldpath.r.p
>  create mode 100755 test/unittest/options/tst.ldpath.sh
> 
> diff --git a/test/unittest/options/err.D_PRAGMA_OPTSET.ldpath.d b/test/unittest/options/err.D_PRAGMA_OPTSET.ldpath.d
> new file mode 100644
> index 00000000..d5457593
> --- /dev/null
> +++ b/test/unittest/options/err.D_PRAGMA_OPTSET.ldpath.d
> @@ -0,0 +1,19 @@
> +/*
> + * 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.
> + */
> +
> +/*
> + * ASSERTION: Option ldpath cannot be used from within a D program.
> + *
> + * SECTION: Options and Tunables/Consumer Options
> + */
> +
> +#pragma D option ldpath=/nonexistent/directory
> +
> +BEGIN
> +{
> +	exit(0);
> +}
> diff --git a/test/unittest/options/err.D_PRAGMA_OPTSET.ldpath.r b/test/unittest/options/err.D_PRAGMA_OPTSET.ldpath.r
> new file mode 100644
> index 00000000..a717f859
> --- /dev/null
> +++ b/test/unittest/options/err.D_PRAGMA_OPTSET.ldpath.r
> @@ -0,0 +1,2 @@
> +-- @@stderr --
> +dtrace: failed to compile script test/unittest/options/err.D_PRAGMA_OPTSET.ldpath.d: [D_PRAGMA_OPTSET] line 14: failed to set option 'ldpath' to '/nonexistent/directory': Option cannot be used from within a D program
> diff --git a/test/unittest/options/err.ldpath.d b/test/unittest/options/err.ldpath.d
> new file mode 100644
> index 00000000..576e22e6
> --- /dev/null
> +++ b/test/unittest/options/err.ldpath.d
> @@ -0,0 +1,19 @@
> +/*
> + * 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.
> + */
> +
> +/*
> + * ASSERTION: The ldpath option changes the ld path.
> + *
> + * SECTION: Options and Tunables/Consumer Options
> + */
> +
> +/* @@runtest-opts: -G -xldpath=/nonexistent/ld */
> +
> +BEGIN
> +{
> +	exit(0);
> +}
> diff --git a/test/unittest/options/err.ldpath.r b/test/unittest/options/err.ldpath.r
> new file mode 100644
> index 00000000..87725469
> --- /dev/null
> +++ b/test/unittest/options/err.ldpath.r
> @@ -0,0 +1,3 @@
> +-- @@stderr --
> +sh: /nonexistent/ld: No such file or directory
> +dtrace: failed to link script test/unittest/options/err.ldpath: failed to link err.ldpath.o: /nonexistent/ld exited with status 127
> diff --git a/test/unittest/options/err.ldpath.r.p b/test/unittest/options/err.ldpath.r.p
> new file mode 100755
> index 00000000..61a5d637
> --- /dev/null
> +++ b/test/unittest/options/err.ldpath.r.p
> @@ -0,0 +1,3 @@
> +#!/usr/bin/gawk -f
> +
> +{ sub("line 1: ", ""); print }

This does not work for all cases, i.e. Debian's default /usr/bin/sh is dash
which outputs a different error message:

sh: 1: /nonexistent/ld: not found

And actually, bash gives us:

sh: /nonexistent/ld: No such file or directory

So, consistency is really lacking.  Just checking for the string
": /nonexistent/ld:" should be sufficient though.

> diff --git a/test/unittest/options/tst.ldpath.sh b/test/unittest/options/tst.ldpath.sh
> new file mode 100755
> index 00000000..96d12871
> --- /dev/null
> +++ b/test/unittest/options/tst.ldpath.sh
> @@ -0,0 +1,17 @@
> +#!/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.
> +#
> +
> +dtrace=$1
> +
> +DIRNAME="$tmpdir/ldpath.$$.$RANDOM"
> +mkdir -p $DIRNAME
> +cd $DIRNAME
> +
> +# ldpath=ld does nothing remarkable, but this test complements err.ldpath.d
> +$dtrace $dt_flags -G -xldpath=ld -n 'BEGIN {exit(0)}'
> +exit $?
> -- 
> 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