[DTrace-devel] [PATCH] test: Convert tick-* probes to write:entry probes for clear() tests
eugene.loh at oracle.com
eugene.loh at oracle.com
Sat Mar 4 23:54:23 UTC 2023
From: Eugene Loh <eugene.loh at oracle.com>
Tests for the clear() function rely on some interactions between the
producer and consumer. Specifically, we want to make sure the producer
waits amply after sending a clear() action to the consumer before taking
further action. Arguably, a tick-* probe could be used for such timing
purposes, but we find tick-* probes to be unreliable on many systems and
their robustness is not the subject of these tests.
Introduce a trigger that emits messages at most once a second. The
D test scripts can then probe system::write:entry to fire after delays.
Also, add @@nosort options to these tests.
Finally, remove some .r.p files. The output is deterministic anyhow.
So it's easier and more stringent to supply a verbatim .r results file.
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
test/triggers/Build | 3 +-
test/triggers/periodic_output.c | 29 +++++++++++
test/unittest/aggs/tst.clear.d | 53 +++++++++++--------
test/unittest/aggs/tst.clear.r | 23 ++++++++-
test/unittest/aggs/tst.clear.r.p | 46 -----------------
test/unittest/aggs/tst.clearavg.d | 27 +++++-----
test/unittest/aggs/tst.clearavg2.d | 24 +++++----
test/unittest/aggs/tst.clearavg2.r | 13 -----
test/unittest/aggs/tst.cleardenormalize.d | 57 ++++++++++++---------
test/unittest/aggs/tst.cleardenormalize.r | 23 ++++++++-
test/unittest/aggs/tst.cleardenormalize.r.p | 1 -
test/unittest/aggs/tst.clearlquantize.d | 30 +++++------
test/unittest/aggs/tst.clearnormalize.d | 53 +++++++++++--------
test/unittest/aggs/tst.clearnormalize.r | 23 ++++++++-
test/unittest/aggs/tst.clearnormalize.r.p | 1 -
15 files changed, 232 insertions(+), 174 deletions(-)
create mode 100644 test/triggers/periodic_output.c
delete mode 100755 test/unittest/aggs/tst.clear.r.p
delete mode 120000 test/unittest/aggs/tst.cleardenormalize.r.p
delete mode 120000 test/unittest/aggs/tst.clearnormalize.r.p
diff --git a/test/triggers/Build b/test/triggers/Build
index 4538a5c1..7363e420 100644
--- a/test/triggers/Build
+++ b/test/triggers/Build
@@ -1,9 +1,10 @@
# Oracle Linux DTrace.
-# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 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.
EXTERNAL_64BIT_TRIGGERS = testprobe readwholedir mmap bogus-ioctl open delaydie futex \
+ periodic_output \
pid-tst-args1 pid-tst-float pid-tst-fork pid-tst-gcc \
pid-tst-ret1 pid-tst-ret2 pid-tst-vfork pid-tst-weak1 pid-tst-weak2 \
proc-tst-sigwait proc-tst-omp proc-tst-pthread-exec profile-tst-ufuncsort \
diff --git a/test/triggers/periodic_output.c b/test/triggers/periodic_output.c
new file mode 100644
index 00000000..7b131fda
--- /dev/null
+++ b/test/triggers/periodic_output.c
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+/* emit periodic output */
+
+#include <stdio.h>
+#include <time.h>
+
+int main (void)
+{
+ struct timespec t;
+ int i = 0;
+ FILE *fp = fopen("/dev/null", "a");
+
+ t.tv_sec = 1;
+ t.tv_nsec = 0;
+
+ while (1) {
+ fprintf(fp, "periodic output %4.4d\n", i++);
+ fflush(fp);
+ nanosleep(&t, NULL);
+ }
+
+ return 0;
+}
diff --git a/test/unittest/aggs/tst.clear.d b/test/unittest/aggs/tst.clear.d
index f574b5d2..07d3a7e8 100644
--- a/test/unittest/aggs/tst.clear.d
+++ b/test/unittest/aggs/tst.clear.d
@@ -1,18 +1,17 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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:
- * Positive test for clearing aggregations
+ * ASSERTION: Positive test for clearing aggregations
*
* SECTION: Aggregations/Clearing aggregations
- *
- *
*/
+/* @@nosort */
+/* @@trigger: periodic_output */
#pragma D option quiet
#pragma D option aggrate=1ms
@@ -21,32 +20,42 @@
BEGIN
{
i = 0;
- start = timestamp;
-}
-
-tick-100ms
-/i < 20/
-{
- @func[i%5] = sum(i * 100);
- i++;
-}
-
-tick-100ms
-/i == 10/
-{
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
printf("Aggregation data before clear():\n");
printa(@func);
-
clear(@func);
+ n = 0;
+}
+syscall::write:entry
+/pid == $target && n == 2/
+{
printf("Aggregation data after clear():\n");
printa(@func);
- i++;
+ i++;
}
-tick-100ms
-/i == 20/
+syscall::write:entry
+/pid == $target && n++ == 4/
{
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
+ @func[i%5] = sum(i * 100); i++;
printf("Final aggregation data:\n");
printa(@func);
diff --git a/test/unittest/aggs/tst.clear.r b/test/unittest/aggs/tst.clear.r
index 1fa2c752..486e4ac0 100644
--- a/test/unittest/aggs/tst.clear.r
+++ b/test/unittest/aggs/tst.clear.r
@@ -1 +1,22 @@
-All sums as expected.
+Aggregation data before clear():
+
+ 0 500
+ 1 700
+ 2 900
+ 3 1100
+ 4 1300
+Aggregation data after clear():
+
+ 0 0
+ 1 0
+ 2 0
+ 3 0
+ 4 0
+Final aggregation data:
+
+ 0 1500
+ 1 2700
+ 2 2900
+ 3 3100
+ 4 3300
+
diff --git a/test/unittest/aggs/tst.clear.r.p b/test/unittest/aggs/tst.clear.r.p
deleted file mode 100755
index f12022b8..00000000
--- a/test/unittest/aggs/tst.clear.r.p
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/usr/bin/gawk -f
-# Oracle Linux DTrace.
-# Copyright (c) 2016, 2022, 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.
-# Check that the sum of all 'before clear' values is nonzero,
-# the sum of all 'after clear' values is zero, and the sum of
-# all 'final' values are nonzero again.
-
-BEGIN {
- inafter = 0;
- sum = 0;
- fail = 0;
-}
-
-$2 ~ /^[0-9]+$/ { sum += $2; }
-
-function checksums(zerop) {
- if (zerop && sum != 0) {
- printf "FAIL: sum %i is nonzero.\n", sum;
- fail = 1;
- }
- else if (!zerop && sum == 0) {
- fail = 1;
- printf "FAIL: sum %i is zero.\n", sum;
- }
-}
-
-/after clear/ {
- checksums(inafter);
- inafter = 1;
- sum = 0;
-}
-
-/Final / {
- checksums(inafter);
- inafter = 0;
- sum = 0;
-}
-
-END {
- checksums(inafter);
-
- if (!fail)
- printf "All sums as expected.\n";
-}
diff --git a/test/unittest/aggs/tst.clearavg.d b/test/unittest/aggs/tst.clearavg.d
index 16d18f34..60e60365 100644
--- a/test/unittest/aggs/tst.clearavg.d
+++ b/test/unittest/aggs/tst.clearavg.d
@@ -1,38 +1,37 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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:
- * Positive avg() test
+ * ASSERTION: Positive avg() test
*
* SECTION: Aggregations/Aggregations
*
* NOTES:
* Verifies that printing a clear()'d aggregation with an avg()
* aggregation function doesn't cause problems.
- *
*/
+/* @@nosort */
+/* @@trigger: periodic_output */
#pragma D option quiet
-tick-10ms
-/i++ < 5/
+BEGIN
{
@a = avg(timestamp);
+ @a = avg(timestamp);
+ @a = avg(timestamp);
+ @a = avg(timestamp);
+ @a = avg(timestamp);
+ clear(@a);
+ n = 0;
}
-tick-10ms
-/i == 5/
-{
- exit(2);
-}
-
-END
+syscall::write:entry
+/pid == $target && n++ == 2/
{
- clear(@a);
exit(0);
}
diff --git a/test/unittest/aggs/tst.clearavg2.d b/test/unittest/aggs/tst.clearavg2.d
index 984ce82c..cd022e14 100644
--- a/test/unittest/aggs/tst.clearavg2.d
+++ b/test/unittest/aggs/tst.clearavg2.d
@@ -1,41 +1,43 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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:
- * Positive avg() test
+ * ASSERTION: Positive avg() test
*
* SECTION: Aggregations/Aggregations
*
* NOTES:
* Verifies that printing a clear()'d aggregation with an avg()
* aggregation function of 0 doesn't cause divide-by-zero problems.
- *
*/
+/* @@nosort */
+/* @@trigger: periodic_output */
#pragma D option quiet
#pragma D option switchrate=50ms
#pragma D option aggrate=1ms
-tick-100ms
-/(x++ % 5) == 0/
+BEGIN
{
@time = avg(0);
+ printa(" %@d\n", @time);
+ clear(@time);
+ n = 0;
}
-tick-100ms
-/x > 5 && x <= 20/
+syscall::write:entry
+/pid == $target && n == 2/
{
printa(" %@d\n", @time);
- clear(@time);
}
-tick-100ms
-/x > 20/
+syscall::write:entry
+/pid == $target && n++ == 4/
{
+ @time = avg(0);
exit(0);
}
diff --git a/test/unittest/aggs/tst.clearavg2.r b/test/unittest/aggs/tst.clearavg2.r
index 7cceedda..aa2f0233 100644
--- a/test/unittest/aggs/tst.clearavg2.r
+++ b/test/unittest/aggs/tst.clearavg2.r
@@ -1,16 +1,3 @@
0
0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
diff --git a/test/unittest/aggs/tst.cleardenormalize.d b/test/unittest/aggs/tst.cleardenormalize.d
index 191ecad7..bdc8ae96 100644
--- a/test/unittest/aggs/tst.cleardenormalize.d
+++ b/test/unittest/aggs/tst.cleardenormalize.d
@@ -1,18 +1,18 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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:
- * Denormalized aggregations can be cleared
+ * ASSERTION: Denormalized aggregations can be cleared
*
* SECTION: Aggregations/Normalization;
- * Aggregations/Clearing aggregations
- *
+ * Aggregations/Clearing aggregations
*/
+/* @@nosort */
+/* @@trigger: periodic_output */
#pragma D option quiet
#pragma D option aggrate=1ms
@@ -21,33 +21,44 @@
BEGIN
{
i = 0;
- start = timestamp;
-}
-
-tick-100ms
-/i != 10 || i != 20/
-{
- @func[i%5] = sum(i * 100);
- i++;
-}
-
-tick-100ms
-/i == 10/
-{
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
printf("Denormalized data before clear:\n");
denormalize(@func);
printa(@func);
-
clear(@func);
+ n = 0;
+}
- printf("Aggregation data after clear:\n");
+syscall::write:entry
+/pid == $target && n == 2/
+{
+ printf("Aggregation data after clear():\n");
printa(@func);
- i++
+ i++;
}
-tick-100ms
-/i == 20/
+syscall::write:entry
+/pid == $target && n++ == 4/
{
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+
printf("Final (denormalized) aggregation data:\n");
denormalize(@func);
printa(@func);
diff --git a/test/unittest/aggs/tst.cleardenormalize.r b/test/unittest/aggs/tst.cleardenormalize.r
index 1fa2c752..186fcdd5 100644
--- a/test/unittest/aggs/tst.cleardenormalize.r
+++ b/test/unittest/aggs/tst.cleardenormalize.r
@@ -1 +1,22 @@
-All sums as expected.
+Denormalized data before clear:
+
+ 0 500
+ 1 700
+ 2 900
+ 3 1100
+ 4 1300
+Aggregation data after clear():
+
+ 0 0
+ 1 0
+ 2 0
+ 3 0
+ 4 0
+Final (denormalized) aggregation data:
+
+ 0 1500
+ 1 2700
+ 2 2900
+ 3 3100
+ 4 3300
+
diff --git a/test/unittest/aggs/tst.cleardenormalize.r.p b/test/unittest/aggs/tst.cleardenormalize.r.p
deleted file mode 120000
index 91ba6415..00000000
--- a/test/unittest/aggs/tst.cleardenormalize.r.p
+++ /dev/null
@@ -1 +0,0 @@
-tst.clear.r.p
\ No newline at end of file
diff --git a/test/unittest/aggs/tst.clearlquantize.d b/test/unittest/aggs/tst.clearlquantize.d
index dbd987db..40146b24 100644
--- a/test/unittest/aggs/tst.clearlquantize.d
+++ b/test/unittest/aggs/tst.clearlquantize.d
@@ -6,8 +6,7 @@
*/
/*
- * ASSERTION:
- * Positive quantize()/lquantize()/clear() test
+ * ASSERTION: Positive quantize()/lquantize()/clear() test
*
* SECTION: Aggregations/Aggregations
*
@@ -17,6 +16,7 @@
*/
/* @@nosort */
+/* @@trigger: periodic_output */
#pragma D option switchrate=20ms
#pragma D option aggrate=1ms
@@ -24,30 +24,26 @@
BEGIN
{
- z = 0;
+ i = 0;
+ n = 0;
}
-tick-500ms
-/(z % 2) == 0/
+syscall::write:entry
+/pid == $target && (n % 2) == 0/
{
- x++; @a["linear"] = lquantize(x, 0, 100, 1); @b["exp"] = quantize(x);
- x++; @a["linear"] = lquantize(x, 0, 100, 1); @b["exp"] = quantize(x);
- x++; @a["linear"] = lquantize(x, 0, 100, 1); @b["exp"] = quantize(x);
- x++; @a["linear"] = lquantize(x, 0, 100, 1); @b["exp"] = quantize(x);
- x++; @a["linear"] = lquantize(x, 0, 100, 1); @b["exp"] = quantize(x);
+ i++; @a["linear"] = lquantize(i, 0, 100, 1); @b["exp"] = quantize(i);
+ i++; @a["linear"] = lquantize(i, 0, 100, 1); @b["exp"] = quantize(i);
+ i++; @a["linear"] = lquantize(i, 0, 100, 1); @b["exp"] = quantize(i);
+ i++; @a["linear"] = lquantize(i, 0, 100, 1); @b["exp"] = quantize(i);
+ i++; @a["linear"] = lquantize(i, 0, 100, 1); @b["exp"] = quantize(i);
printa(@a);
printa(@b);
-}
-
-tick-500ms
-/(z % 2) == 1/
-{
clear(@a);
clear(@b);
}
-tick-500ms
-/z++ >= 9/
+syscall::write:entry
+/pid == $target && n++ >= 8/
{
exit(0);
}
diff --git a/test/unittest/aggs/tst.clearnormalize.d b/test/unittest/aggs/tst.clearnormalize.d
index 34d225f0..66f81b81 100644
--- a/test/unittest/aggs/tst.clearnormalize.d
+++ b/test/unittest/aggs/tst.clearnormalize.d
@@ -1,18 +1,18 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 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:
- * Normalized aggregation data can be cleared
+ * ASSERTION: Normalized aggregation data can be cleared
*
* SECTION: Aggregations/Normalization;
* Aggregations/Clearing aggregations
- *
*/
+/* @@nosort */
+/* @@trigger: periodic_output */
#pragma D option quiet
#pragma D option aggrate=1ms
@@ -21,36 +21,45 @@
BEGIN
{
i = 0;
- start = timestamp;
-}
-
-tick-100ms
-/i < 20/
-{
- @func[i % 5] = sum(i * 100);
- i++;
-}
-
-tick-100ms
-/i == 10/
-{
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
printf("Normalized data before clear:\n");
normalize(@func, 5);
printa(@func);
-
clear(@func);
+ n = 0;
+}
+syscall::write:entry
+/pid == $target && n == 2/
+{
printf("Aggregation data after clear:\n");
printa(@func);
- i++
+ i++;
}
-tick-100ms
-/i == 20/
+syscall::write:entry
+/pid == $target && n++ == 4/
{
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
+ @func[i % 5] = sum(i * 100); i++;
printf("Final (normalized) aggregation data:\n");
normalize(@func, 5);
printa(@func);
-
exit(0);
}
diff --git a/test/unittest/aggs/tst.clearnormalize.r b/test/unittest/aggs/tst.clearnormalize.r
index 1fa2c752..e568427e 100644
--- a/test/unittest/aggs/tst.clearnormalize.r
+++ b/test/unittest/aggs/tst.clearnormalize.r
@@ -1 +1,22 @@
-All sums as expected.
+Normalized data before clear:
+
+ 0 100
+ 1 140
+ 2 180
+ 3 220
+ 4 260
+Aggregation data after clear:
+
+ 0 0
+ 1 0
+ 2 0
+ 3 0
+ 4 0
+Final (normalized) aggregation data:
+
+ 0 300
+ 1 540
+ 2 580
+ 3 620
+ 4 660
+
diff --git a/test/unittest/aggs/tst.clearnormalize.r.p b/test/unittest/aggs/tst.clearnormalize.r.p
deleted file mode 120000
index 91ba6415..00000000
--- a/test/unittest/aggs/tst.clearnormalize.r.p
+++ /dev/null
@@ -1 +0,0 @@
-tst.clear.r.p
\ No newline at end of file
--
2.18.4
More information about the DTrace-devel
mailing list