From: eugene.loh@oracle.com
To: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: [PATCH v2 4/4] test: Add test for predefined preprocessor definitions
Date: Wed, 25 Jun 2025 02:03:03 -0400 [thread overview]
Message-ID: <20250625060305.15707-3-eugene.loh@oracle.com> (raw)
In-Reply-To: <20250625060305.15707-1-eugene.loh@oracle.com>
From: Eugene Loh <eugene.loh@oracle.com>
Orabug: 28763074
Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
---
COMMANDLINE-OPTIONS | 10 +-
test/unittest/preprocessor/tst.predefined.r | 1 +
test/unittest/preprocessor/tst.predefined.sh | 119 +++++++++++++++++++
3 files changed, 125 insertions(+), 5 deletions(-)
create mode 100644 test/unittest/preprocessor/tst.predefined.r
create mode 100755 test/unittest/preprocessor/tst.predefined.sh
diff --git a/COMMANDLINE-OPTIONS b/COMMANDLINE-OPTIONS
index 40561af91..73be89b1f 100644
--- a/COMMANDLINE-OPTIONS
+++ b/COMMANDLINE-OPTIONS
@@ -321,12 +321,12 @@ definitions are always specified and valid in all modes:
* __sparcv9 (on SPARC® systems only when 64–bit programs are compiled)
* __i386 (on x86 systems only when 32–bit programs are compiled)
* __amd64 (on x86 systems only when 64–bit programs are compiled)
- * _`uname -s` (for example, __Linux)
+ * __`uname -s` (for example, __Linux)
* __SUNW_D=1
- * _SUNW_D_VERSION=0x_MMmmmuuu (where MM is the Major release value
- in hexadecimal, mmm is the Minor release value in hexadecimal,
- and uuu is the Micro release value in hexadecimal; see Chapter
- 41, Versioning for more information about DTrace versioning)
+ * _SUNW_D_VERSION=(MM << 24 | mmm << 12 | uuu), where
+ MM is the Major release value
+ mmm is the Minor release value
+ uuu is the Micro release value
-Z
Permit probe descriptions that match zero probes. If the -Z option is
diff --git a/test/unittest/preprocessor/tst.predefined.r b/test/unittest/preprocessor/tst.predefined.r
new file mode 100644
index 000000000..2e9ba477f
--- /dev/null
+++ b/test/unittest/preprocessor/tst.predefined.r
@@ -0,0 +1 @@
+success
diff --git a/test/unittest/preprocessor/tst.predefined.sh b/test/unittest/preprocessor/tst.predefined.sh
new file mode 100755
index 000000000..47e35d9c6
--- /dev/null
+++ b/test/unittest/preprocessor/tst.predefined.sh
@@ -0,0 +1,119 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2025, 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.
+#
+# Confirm preprocessor pre-definitions.
+
+dtrace=$1
+
+DIRNAME=$tmpdir/predefined.$$.$RANDOM
+mkdir -p $DIRNAME
+cd $DIRNAME
+
+# Arg 1 is macro that we check is defined.
+
+function check_defined() {
+ # Add to script: #ifdef is okay, else is ERROR.
+ echo '#ifdef' $1 >> D.d
+ echo 'printf("'$1' okay\n");' >> D.d
+ echo '#else' >> D.d
+ echo 'printf("ERROR! missing '$1'\n");' >> D.d
+ echo '#endif' >> D.d
+
+ # Add to check file: expect "okay" message.
+ echo $1 okay >> chk.txt
+}
+
+# Arg 1 is macro whose value we check to be arg 2.
+
+function check_value() {
+ # Add to script: print value.
+ echo 'printf("'$1'=%x\n", '$1');' >> D.d
+
+ # Add to check file: expected value.
+ echo $1=$2 >> chk.txt
+}
+
+# Arg 1 is macro that we check is not defined.
+
+function check_undef() {
+ # Add to script: #ifdef is ERROR, else is okay.
+ echo '#ifdef' $1 >> D.d
+ echo 'printf("ERROR! found '$1'\n");' >> D.d
+ echo '#else' >> D.d
+ echo 'printf("missing '$1' is okay\n");' >> D.d
+ echo '#endif' >> D.d
+
+ # Add to check file: expect "okay" message.
+ echo missing $1 is okay >> chk.txt
+}
+
+# Construct version string (major, minor, micro).
+
+read MM mmm uuu <<< `$dtrace -vV | awk '/^This is DTrace / { gsub("\\\.", " "); print $(NF-2), $(NF-1), $NF }'`
+vers=`printf "%x" $(($MM << 24 | $mmm << 12 | $uuu))`
+
+# Start setting up the D script.
+
+echo 'BEGIN {' > D.d
+
+# Check for the preprocessor definitions of COMMANDLINE-OPTIONS.
+
+check_defined __linux
+check_defined __unix
+check_defined __SVR4
+if [ `uname -m` == x86_64 ]; then
+check_defined __amd64
+else
+check_undef __amd64
+fi
+check_defined __`uname -s`
+check_value __SUNW_D 1
+check_value __SUNW_D_VERSION $vers
+
+# Confirm other preprocessor definitions.
+
+check_defined __SUNW_D_64
+
+# Confirm that __GNUC__ is not present.
+
+check_undef __GNUC__
+
+# Finish setting up the D script.
+
+echo 'exit(0); }' >> D.d
+echo >> chk.txt
+
+# Run the D script.
+
+$dtrace $dt_flags -qCs D.d -o out.txt
+if [ $? -ne 0 ]; then
+ echo ERROR: DTrace failed
+ echo "==== D.d"
+ cat D.d
+ echo "==== out.txt"
+ cat out.txt
+ exit 1
+fi
+
+# Check.
+
+if ! diff -q chk.txt out.txt; then
+ echo ERROR output disagrees
+ echo === expect ===
+ cat chk.txt
+ echo === actual ===
+ cat out.txt
+ echo === diff ===
+ diff chk.txt out.txt
+ exit 1
+fi
+
+# Indicate success.
+
+echo success
+
+exit 0
--
2.43.5
next prev parent reply other threads:[~2025-06-25 6:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-25 6:03 [PATCH v2] Optimize USDT discovery a little eugene.loh
2025-06-25 6:03 ` [PATCH v2 3/4] Sync up the version numbers eugene.loh
2025-07-22 10:51 ` [DTrace-devel] " Nick Alcock
2025-06-25 6:03 ` eugene.loh [this message]
2025-06-25 6:03 ` [PATCH v2 2/2] Extend the USDT bit mask to multiple words eugene.loh
2025-07-22 12:34 ` Nick Alcock
2025-07-23 0:47 ` Eugene Loh
2025-06-25 6:03 ` [PATCH] test: Extend timeout for many-pids test eugene.loh
2025-07-22 12:44 ` Nick Alcock
2025-07-22 10:45 ` [PATCH v2] Optimize USDT discovery a little Nick Alcock
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250625060305.15707-3-eugene.loh@oracle.com \
--to=eugene.loh@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox