[DTrace-devel] [PATCH] test: Add print() tests
eugene.loh at oracle.com
eugene.loh at oracle.com
Tue Nov 14 00:04:45 UTC 2023
From: Eugene Loh <eugene.loh at oracle.com>
This patch isn't really for review. Just an illustration of how
Alan's tests can be converted to use the runtest.sh checking mechanisms.
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
test/unittest/print/tst.print.local.d | 45 ++++++++++++++++++++
test/unittest/print/tst.print.local.r | 21 ++++++++++
test/unittest/print/tst.print.local.trunc.d | 46 +++++++++++++++++++++
test/unittest/print/tst.print.local.trunc.r | 12 ++++++
4 files changed, 124 insertions(+)
create mode 100644 test/unittest/print/tst.print.local.d
create mode 100644 test/unittest/print/tst.print.local.r
create mode 100644 test/unittest/print/tst.print.local.trunc.d
create mode 100644 test/unittest/print/tst.print.local.trunc.r
diff --git a/test/unittest/print/tst.print.local.d b/test/unittest/print/tst.print.local.d
new file mode 100644
index 00000000..ba37be7a
--- /dev/null
+++ b/test/unittest/print/tst.print.local.d
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+/* @@nosort */
+
+#pragma D option quiet
+
+enum eh { FIRSTVAL = 0, SECONDVAL = 1, THIRDVAL = 3 };
+
+/* DTrace will not parse nested anonymous structs/unions; also bitfields are not supported. */
+struct test_struct {
+ int a;
+ char b[5];
+ union {
+ __u8 c;
+ __u64 d;
+ } u;
+ struct {
+ void *e;
+ uint64_t f;
+ } s;
+ bool g;
+ enum eh h;
+};
+
+BEGIN
+{
+ t = (struct test_struct *)alloca(sizeof (struct test_struct));
+ t->a = 1;
+ t->b[0] = 't';
+ t->b[1] = 'e';
+ t->b[2] = 's';
+ t->b[3] = 't';
+ t->b[4] = '\0';
+ t->u.d = 123456789;
+ t->s.e = (void *)0xffff9b7aca7e0000,
+ t->s.f = 987654321;
+ t->g = 1;
+ t->h = SECONDVAL;
+ print(t);
+ exit(0);
+}
diff --git a/test/unittest/print/tst.print.local.r b/test/unittest/print/tst.print.local.r
new file mode 100644
index 00000000..17b81423
--- /dev/null
+++ b/test/unittest/print/tst.print.local.r
@@ -0,0 +1,21 @@
+
+ (struct test_struct) {
+ .a = (int)1,
+ .b = (char [5]) [
+ (char)'t',
+ (char)'e',
+ (char)'s',
+ (char)'t',
+ ],
+ .u = (union) {
+ .c = (__u8)21,
+ .d = (__u64)123456789,
+ },
+ .s = (struct) {
+ .e = (void *){ptr},
+ .f = (uint64_t)987654321,
+ },
+ .g = (bool)1,
+ .h = (enum eh)SECONDVAL,
+ }
+
diff --git a/test/unittest/print/tst.print.local.trunc.d b/test/unittest/print/tst.print.local.trunc.d
new file mode 100644
index 00000000..2e7beeee
--- /dev/null
+++ b/test/unittest/print/tst.print.local.trunc.d
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+/* @@nosort */
+
+#pragma D option quiet
+#pragma D option printsize=8
+
+enum eh { FIRSTVAL = 1, SECONDVAL = 2, THIRDVAL= 3 };
+
+/* DTrace will not parse nested anonymous structs/unions; also bitfields are not supported. */
+struct test_struct {
+ int a;
+ char b[5];
+ union {
+ __u8 c;
+ __u64 d;
+ } u;
+ struct {
+ void *e;
+ uint64_t f;
+ } s;
+ bool g;
+ enum eh h;
+};
+
+BEGIN
+{
+ t = (struct test_struct *)alloca(sizeof (struct test_struct));
+ t->a = 1;
+ t->b[0] = 't';
+ t->b[1] = 'e';
+ t->b[2] = 's';
+ t->b[3] = 't';
+ t->b[4] = '\0';
+ t->u.d = 12345678,
+ t->s.e = (void *)0xfeedfacefeedface;
+ t->s.f = 100,
+ t->g = 1;
+ t->h = FIRSTVAL;
+ print(t);
+ exit(0);
+}
diff --git a/test/unittest/print/tst.print.local.trunc.r b/test/unittest/print/tst.print.local.trunc.r
new file mode 100644
index 00000000..7008d286
--- /dev/null
+++ b/test/unittest/print/tst.print.local.trunc.r
@@ -0,0 +1,12 @@
+
+ (struct test_struct) {
+ .a = (int)1,
+ .b = (char [5]) [
+ (char)'t',
+ (char)'e',
+ (char)'s',
+ (char)'t',
+ ],
+ ...
+ }
+
--
2.18.4
More information about the DTrace-devel
mailing list