[DTrace-devel] [PATCH] The stackdepth/tst.value.r.p could loop forever

Kris Van Hees kris.van.hees at oracle.com
Wed Jun 24 08:30:40 PDT 2020


When a test has a post-processor script associated with it, this post
processor is executed after the test execution completes.  It is meant
to post-process the test output, prior to comparison with expected
output.  This means that the post-processor is executed outside the
test timeout protection mechanism, and if the post-processor contains
a bug that causes it to never complete, the testsuite execution will
hang indefinitely.

The stackdepth/tst.value.r.p post-processor was not safe in this regard
because it was using getline to read from input without checking that
there was input to read (no EOF detection) or that an error might have
occurred trying to read data.  This could lead to an endless loop.  The
script now verifies the return value of getline to ensure it successfully
read a line from input.  If not, it will report failure.

This patch also adds newline characters to the printf statements in the
actual test.  While the stack() action ensures its output starts with a
newline, and that every line in the output terminates with a newline,
it is still a good idea to ensure marker strings that are looked for in
the post-processor are guaranteed to be on their own line.

Incidentally, this issue was found because DTrace v2 currently does not
have a working stack() implementation and therefore no output is
generated for this action.  This resulted in the stack start and end
marker strings to be in the same line.  The post-processor did not
allow for that.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 bpf/get_bvar.c                         |  4 ++++
 test/unittest/stackdepth/tst.value.d   |  4 ++--
 test/unittest/stackdepth/tst.value.r.p | 10 +++++++---
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/bpf/get_bvar.c b/bpf/get_bvar.c
index 5a55a495..77e7fa12 100644
--- a/bpf/get_bvar.c
+++ b/bpf/get_bvar.c
@@ -29,6 +29,10 @@ noinline uint64_t dt_get_bvar(struct dt_bpf_context *dctx, uint32_t id)
 	case DIF_VAR_ARG6: case DIF_VAR_ARG7: case DIF_VAR_ARG8:
 	case DIF_VAR_ARG9:
 		return dctx->argv[id - DIF_VAR_ARG0];
+	case DIF_VAR_STACKDEPTH: {
+		/* FIXME: no stack() yet */
+		return 0;
+	}
 	case DIF_VAR_PID: {
 		uint64_t	val = bpf_get_current_pid_tgid();
 
diff --git a/test/unittest/stackdepth/tst.value.d b/test/unittest/stackdepth/tst.value.d
index b5c06250..857728bd 100644
--- a/test/unittest/stackdepth/tst.value.d
+++ b/test/unittest/stackdepth/tst.value.d
@@ -18,8 +18,8 @@
 BEGIN
 {
 	printf("DEPTH %d\n", stackdepth);
-	printf("TRACE BEGIN");
+	printf("TRACE BEGIN\n");
 	stack();
-	printf("TRACE END");
+	printf("TRACE END\n");
 	exit(0);
 }
diff --git a/test/unittest/stackdepth/tst.value.r.p b/test/unittest/stackdepth/tst.value.r.p
index 9cf956b1..d5143e38 100755
--- a/test/unittest/stackdepth/tst.value.r.p
+++ b/test/unittest/stackdepth/tst.value.r.p
@@ -1,6 +1,6 @@
 #!/usr/bin/gawk -f
 # Oracle Linux DTrace.
-# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2016, 2020, 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.
 
@@ -12,8 +12,12 @@
 	getline;
 	count = 0;
 	while ($0 !~ /^TRACE END/) {
-		getline;
-		count++;
+		if (getline != 1) {
+			print "EOF or error while processing stack\n";
+			exit 0;
+		}
+		if (NF)
+			count++;
 	}
 }
 
-- 
2.26.0




More information about the DTrace-devel mailing list