[DTrace-devel] [PATCH] test: Improve sync mechanism in tst.multiple.sh

eugene.loh at oracle.com eugene.loh at oracle.com
Wed Dec 11 23:09:01 UTC 2024


From: Eugene Loh <eugene.loh at oracle.com>

In this test, a USDT process is launched.  Subsequently, dtrace is
started.  To give dtrace a chance to enable the USDT probes, the
USDT process waits a few seconds.  On some systems and when the
amount of work dtrace does upon startup is high, "a few seconds"
may not be enough, causing the test to miss expected probes.

Have the USDT process loop on an is-enabled probe;  this is a
more resilient sync mechanism between it and dtrace.

That said, dtrace does not enable all probes in one instant, and
it makes no promises in what order probes will be started.  So,
we still leave a (shorter) sleep() in the target process.

Arguably, the test could be simplified by launching the USDT
process with "dtrace -c".  In this patch, we choose instead to
retain the overall character of the existing test.

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 test/unittest/usdt/tst.multiple.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/test/unittest/usdt/tst.multiple.sh b/test/unittest/usdt/tst.multiple.sh
index 1fd30dc6f..440a7d7ba 100755
--- a/test/unittest/usdt/tst.multiple.sh
+++ b/test/unittest/usdt/tst.multiple.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 #
 # Oracle Linux DTrace.
-# Copyright (c) 2006, 2023, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2006, 2024, 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.
 #
@@ -41,7 +41,12 @@ cat > test.c <<EOF
 int
 main(int argc, char **argv)
 {
-	sleep(5); /* Until proper synchronization is implemented. */
+	/* Wait for probes to be enabled. */
+	while (! TEST_PROV_GO_ENABLED());
+
+	/* Allow a generous delay. (Not all probes are enabled instantaneously.) */
+	sleep(2);
+
 	TEST_PROV_GO();
 	TEST_PROV_GO();
 	TEST_PROV_GO();
-- 
2.43.5




More information about the DTrace-devel mailing list