[DTrace-devel] [PATCH] test: Add test for modpath

eugene.loh at oracle.com eugene.loh at oracle.com
Tue Jan 31 22:57:05 UTC 2023


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

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 .../options/err.D_PRAGMA_OPTSET.modpath.d     | 19 ++++++++
 .../options/err.D_PRAGMA_OPTSET.modpath.r     |  2 +
 test/unittest/options/tst.modpath.r           | 14 ++++++
 test/unittest/options/tst.modpath.sh          | 47 +++++++++++++++++++
 4 files changed, 82 insertions(+)
 create mode 100644 test/unittest/options/err.D_PRAGMA_OPTSET.modpath.d
 create mode 100644 test/unittest/options/err.D_PRAGMA_OPTSET.modpath.r
 create mode 100644 test/unittest/options/tst.modpath.r
 create mode 100755 test/unittest/options/tst.modpath.sh

diff --git a/test/unittest/options/err.D_PRAGMA_OPTSET.modpath.d b/test/unittest/options/err.D_PRAGMA_OPTSET.modpath.d
new file mode 100644
index 00000000..741c3e83
--- /dev/null
+++ b/test/unittest/options/err.D_PRAGMA_OPTSET.modpath.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 modpath cannot be used from within a D program.
+ *
+ * SECTION: Options and Tunables/Consumer Options
+ */
+
+#pragma D option modpath=/nonexistent/directory
+
+BEGIN
+{
+	exit(0);
+}
diff --git a/test/unittest/options/err.D_PRAGMA_OPTSET.modpath.r b/test/unittest/options/err.D_PRAGMA_OPTSET.modpath.r
new file mode 100644
index 00000000..1a4ac7a1
--- /dev/null
+++ b/test/unittest/options/err.D_PRAGMA_OPTSET.modpath.r
@@ -0,0 +1,2 @@
+-- @@stderr --
+dtrace: failed to compile script test/unittest/options/err.D_PRAGMA_OPTSET.modpath.d: [D_PRAGMA_OPTSET] line 14: failed to set option 'modpath' to '/nonexistent/directory': Option cannot be used from within a D program
diff --git a/test/unittest/options/tst.modpath.r b/test/unittest/options/tst.modpath.r
new file mode 100644
index 00000000..464a19be
--- /dev/null
+++ b/test/unittest/options/tst.modpath.r
@@ -0,0 +1,14 @@
+                   FUNCTION:NAME
+                          :BEGIN 
+
+sanity check on DTrace passed
+DTrace correctly fails when modpath is an empty directory
+                   FUNCTION:NAME
+                          :BEGIN 
+
+DTrace works with modpath and a linked CTF archive
+-- @@stderr --
+dtrace: description 'BEGIN ' matched 1 probe
+dtrace: description 'BEGIN ' matched 1 probe
+dtrace: could not enable tracing: Module does not contain any CTF data
+dtrace: description 'BEGIN ' matched 1 probe
diff --git a/test/unittest/options/tst.modpath.sh b/test/unittest/options/tst.modpath.sh
new file mode 100755
index 00000000..cd26114f
--- /dev/null
+++ b/test/unittest/options/tst.modpath.sh
@@ -0,0 +1,47 @@
+#!/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/modpath.$$.$RANDOM"
+mkdir -p $DIRNAME
+cd $DIRNAME
+
+# create the directory where the CTF archive will end up
+mkdir -p mydirectory/kernel
+
+# sanity check that DTrace works
+$dtrace $dt_flags -n 'BEGIN {exit(0)}'
+if [ $? -ne 0 ]; then
+	echo ERROR: sanity check on DTrace failed
+	exit 1
+else
+	echo sanity check on DTrace passed
+fi
+
+# verify that modpath directs us to the (empty) directory
+$dtrace $dt_flags -xmodpath=mydirectory -n 'BEGIN {exit(0)}'
+if [ $? -ne 0 ]; then
+	echo DTrace correctly fails when modpath is an empty directory
+else
+	echo ERROR: DTrace unexpectedly passes with modpath set to empty directory
+	exit 1
+fi
+
+# link a CTF archive to our directory
+ln -s /lib/modules/$(uname -r)/kernel/vmlinux.ctfa mydirectory/kernel/vmlinux.ctfa
+
+# verify that modpath now works
+$dtrace $dt_flags -xmodpath=mydirectory -n 'BEGIN {exit(0)}'
+if [ $? -ne 0 ]; then
+	echo ERROR: DTrace somehow fails
+	exit 1
+else
+	echo DTrace works with modpath and a linked CTF archive
+	exit 0
+fi
-- 
2.18.4




More information about the DTrace-devel mailing list