Skip to content

Commit

Permalink
test: Add trunc tests
Browse files Browse the repository at this point in the history
Theoretically, funny race conditions could arise between producer
and consumer, especially for functions like trunc(), which are
generated in the producer but then executed in the consumer.

Add some trunc tests that should be robust against such races.
They are patterned after similar clear() tests.  Specifically,
many aggregations are performed and then followed immediately by
the trunc() call to be tested.  Then, the test waits, protecting
it from variations in update rates, before a final aggregation is
performed and results dumped out.

Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed Aug 28, 2023
1 parent 7cf085c commit b55ea52
Show file tree
Hide file tree
Showing 12 changed files with 388 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/unittest/aggs/tst.trunc-lquantize-5.d
Original file line number Diff line number Diff line change
@@ -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.
*/
/* @@trigger: bogus-ioctl */
/* @@nosort */

#pragma D option quiet

BEGIN
{
i = 0;
nsecs = 1000000000 * (long long)3;
tstop = timestamp + nsecs;
}

syscall::ioctl:entry
/pid == $target && i < 100/
{
@[100 + i] = lquantize(i + 1, 0, 150, 1, 10000 + i);
@[100 + i] = lquantize(i + 2, 0, 150, 1, 10000 + i);
@[100 + i] = lquantize(i + 3, 0, 150, 1, 10000 + i);
@[100 + i] = lquantize(i + 4, 0, 150, 1, 10000 + i);
i++;
}

syscall::ioctl:entry
/pid == $target && i == 100/
{
trunc(@, 5);
tstop = timestamp + nsecs;
i++;
}

syscall::ioctl:entry
/pid == $target && i > 100 && timestamp > tstop/
{
@[200 + i] = lquantize(i + 1, 0, 150, 1, 20000 + i);
@[200 + i] = lquantize(i + 2, 0, 150, 1, 20000 + i);
@[200 + i] = lquantize(i + 3, 0, 150, 1, 20000 + i);
@[200 + i] = lquantize(i + 4, 0, 150, 1, 20000 + i);
exit(0);
}
55 changes: 55 additions & 0 deletions test/unittest/aggs/tst.trunc-lquantize-5.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

195
value ------------- Distribution ------------- count
95 | 0
96 |@@@@@@@@@@ 10095
97 |@@@@@@@@@@ 10095
98 |@@@@@@@@@@ 10095
99 |@@@@@@@@@@ 10095
100 | 0

196
value ------------- Distribution ------------- count
96 | 0
97 |@@@@@@@@@@ 10096
98 |@@@@@@@@@@ 10096
99 |@@@@@@@@@@ 10096
100 |@@@@@@@@@@ 10096
101 | 0

197
value ------------- Distribution ------------- count
97 | 0
98 |@@@@@@@@@@ 10097
99 |@@@@@@@@@@ 10097
100 |@@@@@@@@@@ 10097
101 |@@@@@@@@@@ 10097
102 | 0

198
value ------------- Distribution ------------- count
98 | 0
99 |@@@@@@@@@@ 10098
100 |@@@@@@@@@@ 10098
101 |@@@@@@@@@@ 10098
102 |@@@@@@@@@@ 10098
103 | 0

199
value ------------- Distribution ------------- count
99 | 0
100 |@@@@@@@@@@ 10099
101 |@@@@@@@@@@ 10099
102 |@@@@@@@@@@ 10099
103 |@@@@@@@@@@ 10099
104 | 0

301
value ------------- Distribution ------------- count
101 | 0
102 |@@@@@@@@@@ 20101
103 |@@@@@@@@@@ 20101
104 |@@@@@@@@@@ 20101
105 |@@@@@@@@@@ 20101
106 | 0

45 changes: 45 additions & 0 deletions test/unittest/aggs/tst.trunc-lquantize-default.d
Original file line number Diff line number Diff line change
@@ -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.
*/
/* @@trigger: bogus-ioctl */
/* @@nosort */

#pragma D option quiet

BEGIN
{
i = 0;
nsecs = 1000000000 * (long long)3;
tstop = timestamp + nsecs;
}

syscall::ioctl:entry
/pid == $target && i < 100/
{
@[100 + i] = lquantize(i + 1, 0, 150, 1, 10000 + i);
@[100 + i] = lquantize(i + 2, 0, 150, 1, 10000 + i);
@[100 + i] = lquantize(i + 3, 0, 150, 1, 10000 + i);
@[100 + i] = lquantize(i + 4, 0, 150, 1, 10000 + i);
i++;
}

syscall::ioctl:entry
/pid == $target && i == 100/
{
trunc(@);
tstop = timestamp + nsecs;
i++;
}

syscall::ioctl:entry
/pid == $target && i > 100 && timestamp > tstop/
{
@[200 + i] = lquantize(i + 1, 0, 150, 1, 20000 + i);
@[200 + i] = lquantize(i + 2, 0, 150, 1, 20000 + i);
@[200 + i] = lquantize(i + 3, 0, 150, 1, 20000 + i);
@[200 + i] = lquantize(i + 4, 0, 150, 1, 20000 + i);
exit(0);
}
10 changes: 10 additions & 0 deletions test/unittest/aggs/tst.trunc-lquantize-default.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

301
value ------------- Distribution ------------- count
101 | 0
102 |@@@@@@@@@@ 20101
103 |@@@@@@@@@@ 20101
104 |@@@@@@@@@@ 20101
105 |@@@@@@@@@@ 20101
106 | 0

45 changes: 45 additions & 0 deletions test/unittest/aggs/tst.trunc-lquantize-neg5.d
Original file line number Diff line number Diff line change
@@ -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.
*/
/* @@trigger: bogus-ioctl */
/* @@nosort */

#pragma D option quiet

BEGIN
{
i = 0;
nsecs = 1000000000 * (long long)3;
tstop = timestamp + nsecs;
}

syscall::ioctl:entry
/pid == $target && i < 100/
{
@[100 + i] = lquantize(i + 1, 0, 150, 1, 10000 + i);
@[100 + i] = lquantize(i + 2, 0, 150, 1, 10000 + i);
@[100 + i] = lquantize(i + 3, 0, 150, 1, 10000 + i);
@[100 + i] = lquantize(i + 4, 0, 150, 1, 10000 + i);
i++;
}

syscall::ioctl:entry
/pid == $target && i == 100/
{
trunc(@, -5);
tstop = timestamp + nsecs;
i++;
}

syscall::ioctl:entry
/pid == $target && i > 100 && timestamp > tstop/
{
@[200 + i] = lquantize(i + 1, 0, 150, 1, 20000 + i);
@[200 + i] = lquantize(i + 2, 0, 150, 1, 20000 + i);
@[200 + i] = lquantize(i + 3, 0, 150, 1, 20000 + i);
@[200 + i] = lquantize(i + 4, 0, 150, 1, 20000 + i);
exit(0);
}
55 changes: 55 additions & 0 deletions test/unittest/aggs/tst.trunc-lquantize-neg5.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

100
value ------------- Distribution ------------- count
0 | 0
1 |@@@@@@@@@@ 10000
2 |@@@@@@@@@@ 10000
3 |@@@@@@@@@@ 10000
4 |@@@@@@@@@@ 10000
5 | 0

101
value ------------- Distribution ------------- count
1 | 0
2 |@@@@@@@@@@ 10001
3 |@@@@@@@@@@ 10001
4 |@@@@@@@@@@ 10001
5 |@@@@@@@@@@ 10001
6 | 0

102
value ------------- Distribution ------------- count
2 | 0
3 |@@@@@@@@@@ 10002
4 |@@@@@@@@@@ 10002
5 |@@@@@@@@@@ 10002
6 |@@@@@@@@@@ 10002
7 | 0

103
value ------------- Distribution ------------- count
3 | 0
4 |@@@@@@@@@@ 10003
5 |@@@@@@@@@@ 10003
6 |@@@@@@@@@@ 10003
7 |@@@@@@@@@@ 10003
8 | 0

104
value ------------- Distribution ------------- count
4 | 0
5 |@@@@@@@@@@ 10004
6 |@@@@@@@@@@ 10004
7 |@@@@@@@@@@ 10004
8 |@@@@@@@@@@ 10004
9 | 0

301
value ------------- Distribution ------------- count
101 | 0
102 |@@@@@@@@@@ 20101
103 |@@@@@@@@@@ 20101
104 |@@@@@@@@@@ 20101
105 |@@@@@@@@@@ 20101
106 | 0

39 changes: 39 additions & 0 deletions test/unittest/aggs/tst.trunc-sum-5.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.
*/
/* @@trigger: bogus-ioctl */
/* @@nosort */

#pragma D option quiet

BEGIN
{
i = 0;
nsecs = 1000000000 * (long long)3;
tstop = timestamp + nsecs;
}

syscall::ioctl:entry
/pid == $target && i < 100/
{
@[100 + i] = sum(1000 + i);
i++;
}

syscall::ioctl:entry
/pid == $target && i == 100/
{
trunc(@, 5);
tstop = timestamp + nsecs;
i++;
}

syscall::ioctl:entry
/pid == $target && i > 100 && timestamp > tstop/
{
@[200 + i] = sum(2000 + i);
exit(0);
}
7 changes: 7 additions & 0 deletions test/unittest/aggs/tst.trunc-sum-5.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

195 1095
196 1096
197 1097
198 1098
199 1099
301 2101
39 changes: 39 additions & 0 deletions test/unittest/aggs/tst.trunc-sum-default.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.
*/
/* @@trigger: bogus-ioctl */
/* @@nosort */

#pragma D option quiet

BEGIN
{
i = 0;
nsecs = 1000000000 * (long long)3;
tstop = timestamp + nsecs;
}

syscall::ioctl:entry
/pid == $target && i < 100/
{
@[100 + i] = sum(1000 + i);
i++;
}

syscall::ioctl:entry
/pid == $target && i == 100/
{
trunc(@);
tstop = timestamp + nsecs;
i++;
}

syscall::ioctl:entry
/pid == $target && i > 100 && timestamp > tstop/
{
@[200 + i] = sum(2000 + i);
exit(0);
}
2 changes: 2 additions & 0 deletions test/unittest/aggs/tst.trunc-sum-default.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

301 2101
39 changes: 39 additions & 0 deletions test/unittest/aggs/tst.trunc-sum-neg5.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.
*/
/* @@trigger: bogus-ioctl */
/* @@nosort */

#pragma D option quiet

BEGIN
{
i = 0;
nsecs = 1000000000 * (long long)3;
tstop = timestamp + nsecs;
}

syscall::ioctl:entry
/pid == $target && i < 100/
{
@[100 + i] = sum(1000 + i);
i++;
}

syscall::ioctl:entry
/pid == $target && i == 100/
{
trunc(@, -5);
tstop = timestamp + nsecs;
i++;
}

syscall::ioctl:entry
/pid == $target && i > 100 && timestamp > tstop/
{
@[200 + i] = sum(2000 + i);
exit(0);
}
7 changes: 7 additions & 0 deletions test/unittest/aggs/tst.trunc-sum-neg5.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

100 1000
101 1001
102 1002
103 1003
104 1004
301 2101

0 comments on commit b55ea52

Please sign in to comment.