[DTrace-devel] [PATCH] test: Improve tst.dlclose1.sh test for USDT probes

Eugene Loh eugene.loh at oracle.com
Fri Apr 8 16:57:10 UTC 2022


On 4/8/22 12:15 PM, Kris Van Hees wrote:

> On Fri, Apr 08, 2022 at 11:58:47AM -0400, Eugene Loh via DTrace-devel wrote:
>> On 4/8/22 10:35 AM, Kris Van Hees wrote:
>>
>>> I would prefer to put this test on hold until we actually have USDT support in
>>> this version.
>> Meanwhile, the test is failing on OL8/ARM.  The motivation was to deal with
>> test failures we see every release.
> If it is giving inconsistent behaviour between architectures and/or UEK or OL
> versions, I'd say "skip it" with an annotation that it needs USDT.
Sounds reasonable.

There is that other issue, though, that the test is just weak:  it's 
happy if no USDT probes are found and clearly there are lots of reasons 
that could be the case.  (E.g. USDT probes have not been implemented.)  
So since I've gone through the trouble of cleaning the test up and 
checking it, I think it'd be nice to push the test so it's available 
once USDT is working.
>
>>> I agree witg your approach but there simply is not way for us
>>> to test right now whether this conclusively works or not.
>> I checked the new test on legacy DTrace.
> Yes, but the imolementation will be quite different for DTrace using BPF.  It
> defintely should behave the same way once we implement it, but wuthout a way
> to verify the changes on the new implementation.
Sorry, I don't follow.  I get that the implementation will be different, 
and I get that that doesn't matter since we're targeting the same 
behavior.  I just don't understand the last part.  We cannot check the 
test on the new implementation until the new implementation exists, but 
the cleaned up test -- vetted on an implementation that works -- gives 
us a leg up on testing the new USDT implementation once it is available.
> As an aside, does the old version of the test succeed or fail on the legacy
> version?
Succeed.  Note:

*)  The old test started failing on ARM/OL8 because no probes were 
firing in pause().  That is the subject of a separate email.  I think 
legacy DTrace is not available on OL8 and therefore does not see this issue.

*)  Its success was unrelated to the legacy version having USDT 
support.  In fact, the test has been passing on the new implementation 
precisely because there are no USDT probes.
>>> On Tue, Apr 05, 2022 at 04:40:13PM -0400, eugene.loh--- via DTrace-devel wrote:
>>>> From: Eugene Loh <eugene.loh at oracle.com>
>>>>
>>>> This test has been failing on aarch64/OL8 ever since its XFAIL was removed
>>>> in 8359ab81fa5e "tests: fix usdt/tst.dlclose1.sh".
>>>>
>>>> That patch changed the problematic bufsize setting in the test, but it
>>>> could have removed the unnecessary bufsize setting altogether.
>>>>
>>>> The test was then passing gratuitously.  As expected, it failed to find
>>>> USDT probes after the dlclose() call, but the reason was that there were
>>>> no USDT probes at all simply because they are not yet supported in DTrace
>>>> on BPF.
>>>>
>>>> Meanwhile, the test was failing on aarch64/OL8 because no probes were
>>>> firing in the pause() call.
>>>>
>>>> Fix the test so that it first confirms there are USDT probes before the
>>>> dlclose() call and second that there are no such probes after the call.
>>>>
>>>> Use a different mechanism to synchronize between user program and test
>>>> script given the increased synchronization.
>>>>
>>>> Eliminate the unnecessary bufsize setting.
>>>>
>>>> When checking for USDT probes, make sure they are for the expected
>>>> process and not for any other test_prov* (e.g. an orphaned process from
>>>> an earlier test run).
>>>>
>>>> Set @@xfail since USDT probes are not yet fully implemented.  (This new
>>>> version of the test has been checked on legacy DTrace.)
>>>>
>>>> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
>>>> ---
>>>>    test/unittest/usdt/tst.dlclose1.r   |   8 +-
>>>>    test/unittest/usdt/tst.dlclose1.r.p |  12 +++
>>>>    test/unittest/usdt/tst.dlclose1.sh  | 141 +++++++++++++++++++++-------
>>>>    3 files changed, 126 insertions(+), 35 deletions(-)
>>>>    create mode 100755 test/unittest/usdt/tst.dlclose1.r.p
>>>>
>>>> diff --git a/test/unittest/usdt/tst.dlclose1.r b/test/unittest/usdt/tst.dlclose1.r
>>>> index 91cf962d..7873cb51 100644
>>>> --- a/test/unittest/usdt/tst.dlclose1.r
>>>> +++ b/test/unittest/usdt/tst.dlclose1.r
>>>> @@ -1,4 +1,6 @@
>>>> -   ID   PROVIDER            MODULE                          FUNCTION NAME
>>>> -
>>>> +started pid NNN
>>>> + ID PROVIDER MODULE FUNCTION NAME
>>>> +NNN test_provNNN livelib.so go go
>>>> + ID PROVIDER MODULE FUNCTION NAME
>>>>    -- @@stderr --
>>>> -dtrace: failed to match test_prov*:::: No probe matches description
>>>> +dtrace: failed to match test_provNNN:::: No probe matches description
>>>> diff --git a/test/unittest/usdt/tst.dlclose1.r.p b/test/unittest/usdt/tst.dlclose1.r.p
>>>> new file mode 100755
>>>> index 00000000..da4a2cbc
>>>> --- /dev/null
>>>> +++ b/test/unittest/usdt/tst.dlclose1.r.p
>>>> @@ -0,0 +1,12 @@
>>>> +#!/bin/awk -f
>>>> +{
>>>> +	# ignore the specific probe ID or process ID
>>>> +	# (the script ensures the process ID is consistent)
>>>> +	gsub(/[0-9]+/, "NNN");
>>>> +
>>>> +	# ignore the numbers of spaces for alignment
>>>> +	# (they depend on the ID widths)
>>>> +	gsub(/ +/, " ");
>>>> +
>>>> +	print;
>>>> +}
>>>> diff --git a/test/unittest/usdt/tst.dlclose1.sh b/test/unittest/usdt/tst.dlclose1.sh
>>>> index b33ca4cf..81fa2415 100755
>>>> --- a/test/unittest/usdt/tst.dlclose1.sh
>>>> +++ b/test/unittest/usdt/tst.dlclose1.sh
>>>> @@ -1,19 +1,34 @@
>>>>    #!/bin/bash
>>>>    #
>>>>    # Oracle Linux DTrace.
>>>> -# Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
>>>> +# Copyright (c) 2007, 2022, 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.
>>>>    #
>>>> -# This test verifies that USDT providers are removed when its associated
>>>> +# This test verifies that USDT providers are removed when the associated
>>>>    # load object is closed via dlclose(3dl).
>>>> -
>>>> -PATH=/usr/bin:/usr/sbin:$PATH
>>>> -
>>>> -if [ $# != 1 ]; then
>>>> -	echo expected one argument: '<'dtrace-path'>'
>>>> -	exit 2
>>>> -fi
>>>> +#
>>>> +# The expected sequence of events is:
>>>> +#
>>>> +#     main.c                                 script
>>>> +#     ==============================         =================================
>>>> +#
>>>> +#     load livelib.so
>>>> +#     write "started" to myfile.txt
>>>> +#                                            see "started" in myfile.txt
>>>> +#                                            check USDT provider test_prov$pid
>>>> +#                                            signal USR1
>>>> +#     get USR1
>>>> +#     run dlclose()
>>>> +#     write  "dlclosed" to myfile.txt
>>>> +#                                            see "dlclosed" in myfile.txt
>>>> +#                                            check USDT provider test_prov$pid
>>>> +#                                            kill main.c
>>>> +#
>>>> +# The first USDT provider check should find test_prov$pid.
>>>> +# The second should not.
>>>> +#
>>>> +# @@xfail: dtv2 (USDT probes)
>>>>    dtrace=$1
>>>>    CC=/usr/bin/gcc
>>>> @@ -23,6 +38,10 @@ DIRNAME="$tmpdir/usdt-dlclose1.$$.$RANDOM"
>>>>    mkdir -p $DIRNAME
>>>>    cd $DIRNAME
>>>> +#
>>>> +# set up Makefile
>>>> +#
>>>> +
>>>>    cat > Makefile <<EOF
>>>>    all: main livelib.so deadlib.so
>>>> @@ -59,6 +78,10 @@ clobber: clean
>>>>    	rm -f main livelib.so deadlib.so
>>>>    EOF
>>>> +#
>>>> +# set up some small files
>>>> +#
>>>> +
>>>>    cat > prov.d <<EOF
>>>>    provider test_prov {
>>>>    	probe go();
>>>> @@ -67,7 +90,6 @@ EOF
>>>>    cat > livelib.c <<EOF
>>>>    #include "prov.h"
>>>> -
>>>>    void
>>>>    go(void)
>>>>    {
>>>> @@ -82,57 +104,112 @@ go(void)
>>>>    }
>>>>    EOF
>>>> +#
>>>> +# set up main.c
>>>> +#
>>>>    cat > main.c <<EOF
>>>>    #include <dlfcn.h>
>>>> +#include <signal.h>
>>>>    #include <unistd.h>
>>>>    #include <stdio.h>
>>>> +void *live;
>>>> +
>>>> +static void
>>>> +interrupt(int sig)
>>>> +{
>>>> +	/* close livelib.so to remove USDT probes */
>>>> +	dlclose(live);
>>>> +
>>>> +	/* notification */
>>>> +	printf("dlclosed\n");
>>>> +	fflush(stdout);
>>>> +}
>>>> +
>>>>    int
>>>>    main(int argc, char **argv)
>>>>    {
>>>> -	void *live;
>>>> +	struct sigaction act;
>>>> +	/* open livelib.so to make USDT probes visible */
>>>>    	if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
>>>>    		printf("dlopen of livelib.so failed: %s\n", dlerror());
>>>>    		return 1;
>>>>    	}
>>>> -	dlclose(live);
>>>> +	/* set the handler to listen for SIGUSR1 */
>>>> +	act.sa_handler = interrupt;
>>>> +	act.sa_flags = 0;
>>>> +	if (sigaction(SIGUSR1, &act, NULL)) {
>>>> +		printf("set handler failed\n");
>>>> +		return 1;
>>>> +	}
>>>> +
>>>> +	/* notification */
>>>> +	printf("started\n");
>>>> +	fflush(stdout);
>>>> +	/* wait for SIGUSR1 to execute handler */
>>>> +	pause();
>>>> +
>>>> +	/* wait for SIGKILL to terminate */
>>>>    	pause();
>>>>    	return 0;
>>>>    }
>>>>    EOF
>>>> +#
>>>> +# make
>>>> +#
>>>> +
>>>>    make > /dev/null
>>>>    if [ $? -ne 0 ]; then
>>>>    	echo "failed to build" >& 2
>>>>    	exit 1
>>>>    fi
>>>> -script() {
>>>> -	$dtrace -Zw -x bufsize=64k -c ./main -qs /dev/stdin <<EOF
>>>> -	syscall::pause:entry,
>>>> -	syscall::rt_sig*:entry
>>>> -	/pid == \$target/
>>>> -	{
>>>> -		system("$dtrace -l -P test_prov*");
>>>> -		system("kill %d", \$target);
>>>> -		exit(0);
>>>> -	}
>>>> +#
>>>> +# set up a wait mechanism
>>>> +#
>>>> -	tick-1s
>>>> -	/i++ == 5/
>>>> -	{
>>>> -		printf("failed\n");
>>>> -		exit(1);
>>>> -	}
>>>> -EOF
>>>> +# args:
>>>> +#   1: number of seconds to wait
>>>> +#   2: string to watch for
>>>> +#   3: file to watch
>>>> +function mywait() {
>>>> +	for iter in `seq $1`; do
>>>> +		sleep 1
>>>> +		if grep -q "$2" $3; then
>>>> +			iter=0
>>>> +			break
>>>> +		fi
>>>> +	done
>>>> +	if [[ $iter -ne 0 ]]; then
>>>> +		echo did not see message: $2
>>>> +		echo "==================== start of messages"
>>>> +		cat $3
>>>> +		echo "==================== end of messages"
>>>> +		kill -s KILL $pid
>>>> +		exit 1
>>>> +	fi
>>>>    }
>>>> -script
>>>> -status=$?
>>>> +#
>>>> +# run the process in the background and check USDT probes
>>>> +#
>>>> +
>>>> +./main > myfile.txt &
>>>> +pid=$!
>>>> +echo started pid $pid
>>>> +
>>>> +mywait 6 "started"  myfile.txt # wait for process to start
>>>> +$dtrace -lP test_prov$pid      # check USDT probes
>>>> +kill -s USR1 $pid              # signal process
>>>> +
>>>> +mywait 6 "dlclosed" myfile.txt # wait for process to dlclose
>>>> +$dtrace -lP test_prov$pid      # check USDT probes
>>>> +kill -s KILL $pid              # kill process
>>>> -exit $status
>>>> +exit 0
>>>> -- 
>>>> 2.18.4
>>>>
>>>>
>>>> _______________________________________________
>>>> DTrace-devel mailing list
>>>> DTrace-devel at oss.oracle.com
>>>> https://oss.oracle.com/mailman/listinfo/dtrace-devel
>> _______________________________________________
>> 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