[DTrace-devel] [PATCH] test: Add test for incdir option

eugene.loh at oracle.com eugene.loh at oracle.com
Thu Jan 19 20:41:34 UTC 2023


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

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 test/unittest/options/tst.incdir.r  |  8 +++++
 test/unittest/options/tst.incdir.sh | 52 +++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)
 create mode 100644 test/unittest/options/tst.incdir.r
 create mode 100755 test/unittest/options/tst.incdir.sh

diff --git a/test/unittest/options/tst.incdir.r b/test/unittest/options/tst.incdir.r
new file mode 100644
index 00000000..5db641a8
--- /dev/null
+++ b/test/unittest/options/tst.incdir.r
@@ -0,0 +1,8 @@
+script fails by default as expected
+good
+
+script runs with incdir
+-- @@stderr --
+/dev/stdin:1: fatal error: D.h: No such file or directory
+compilation terminated.
+dtrace: failed to compile script D.d: Preprocessor failed to process input program
diff --git a/test/unittest/options/tst.incdir.sh b/test/unittest/options/tst.incdir.sh
new file mode 100755
index 00000000..3193a016
--- /dev/null
+++ b/test/unittest/options/tst.incdir.sh
@@ -0,0 +1,52 @@
+#!/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/incdir.$$.$RANDOM"
+mkdir -p $DIRNAME
+cd $DIRNAME
+
+# form a D script that relies on a header file
+
+cat << EOF > D.d
+#include "D.h"
+BEGIN
+{
+	printf("%c%c%c%c\n", (foo) 0x67, (foo) 0x6f, (foo) 0x6f, (foo) 0x64);
+	exit(0);
+}
+EOF
+
+# hide the header file in a subdirectory
+
+mkdir mysubdir
+cat << EOF > mysubdir/D.h
+typedef char foo;
+EOF
+
+# confirm we do not find the subdirectory by default
+
+$dtrace $dt_flags -Cqs D.d
+if [ $? -eq 0 ]; then
+	echo ERROR: script should not pass by default
+	exit 1
+else
+	echo script fails by default as expected
+fi
+
+# confirm that -xincdir fixes the problem
+
+$dtrace $dt_flags -xincdir=mysubdir -Cqs D.d
+if [ $? -eq 0 ]; then
+	echo script runs with incdir
+	exit 0
+else
+	echo ERROR: script fails even with incdir
+	exit 1
+fi
-- 
2.18.4




More information about the DTrace-devel mailing list