From dedf9c50520d7be64d11ae13b957c93fd4a3ee0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Str=C3=B6mb=C3=A4ck?= Date: Fri, 13 May 2016 21:19:16 +0200 Subject: Fix for possible bug in exec-missing. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test userprog/exec-missing verifies that exec() returns -1 when starting a process for which the binary is not found. Since the failure of load() is discovered after a new process has been created, the output 'no-such-file: exit(-1)' will be visible in the output. The problem is that we do not know when this happens with respect to the thread calling exec(). Due to how the tests are designed, the time when 'no-such-file' terminates is important. Some of the cases were listed as acceptable outputs, but I found some acceptable outputs missing from there, namely if 'no-such-file' for some reason takes quite some time terminating, or even terminates after the 'exec-missing' process exits. As there is no synchronization between these processes (nor can it be), we do not know which one terminates first. Effectively, I added the following possible outputs to the test, as I find them reasonable outcomes of a correct implementation (in very unfortunate circumstances, or when printing a lot in process_cleanup): (exec-missing) begin load: no-such-file: open failed (exec-missing) exec("no-such-file"): -1 (exec-missing) end no-such-file: exit(-1) exec-missing: exit(0) (exec-missing) begin load: no-such-file: open failed (exec-missing) exec("no-such-file"): -1 (exec-missing) end exec-missing: exit(0) no-such-file: exit(-1) Signed-off-by: Filip Strömbäck --- src/tests/userprog/exec-missing.ck | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/userprog/exec-missing.ck b/src/tests/userprog/exec-missing.ck index 0ef7aaa..7f9b0cb 100644 --- a/src/tests/userprog/exec-missing.ck +++ b/src/tests/userprog/exec-missing.ck @@ -2,7 +2,7 @@ use strict; use warnings; use tests::tests; -check_expected ([<<'EOF', <<'EOF', <<'EOF', <<'EOF']); +check_expected ([<<'EOF', <<'EOF', <<'EOF', <<'EOF', <<'EOF', <<'EOF']); (exec-missing) begin load: no-such-file: open failed (exec-missing) exec("no-such-file"): -1 @@ -28,4 +28,18 @@ no-such-file: exit(-1) (exec-missing) end exec-missing: exit(0) EOF +(exec-missing) begin +load: no-such-file: open failed +(exec-missing) exec("no-such-file"): -1 +(exec-missing) end +no-such-file: exit(-1) +exec-missing: exit(0) +EOF +(exec-missing) begin +load: no-such-file: open failed +(exec-missing) exec("no-such-file"): -1 +(exec-missing) end +exec-missing: exit(0) +no-such-file: exit(-1) +EOF pass; -- cgit v1.2.1 From 3757af98040e80af075e10417179d1a82199d7cf Mon Sep 17 00:00:00 2001 From: klaar36 Date: Mon, 16 May 2016 19:51:18 +0200 Subject: explanatory comment and oredering of cases --- src/tests/userprog/exec-missing.ck | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/userprog/exec-missing.ck b/src/tests/userprog/exec-missing.ck index 7f9b0cb..749db01 100644 --- a/src/tests/userprog/exec-missing.ck +++ b/src/tests/userprog/exec-missing.ck @@ -1,15 +1,36 @@ # -*- perl -*- + +# In this test a program named "exec-missing" tries to start another +# program that do not exist. This is discovered in the thread of the +# new program, in the function load. + +# Correct handling can be done in three basic ways: + +# 1. We only know about the failure when our "exec" system call +# returns -1. The "no-such-file" thread never becomes a process and +# do not leave any messages. + +# 2. We know about the failure both when "exec" return -1 and when the +# "no-such-file" thread fails to become a process. It notify the +# failure by printing "load: no-such-file: open failed". But it +# does not become a process and will thus not leave a +# "no-such-file: exit(-1)" message. + +# 3. "exec" return -1 and "no-such-file" become a failed process. It +# will thus produce a "no-such-file: exit(-1)" message. This +# message may occur some time after "open failed". + use strict; use warnings; use tests::tests; check_expected ([<<'EOF', <<'EOF', <<'EOF', <<'EOF', <<'EOF', <<'EOF']); (exec-missing) begin -load: no-such-file: open failed (exec-missing) exec("no-such-file"): -1 (exec-missing) end exec-missing: exit(0) EOF (exec-missing) begin +load: no-such-file: open failed (exec-missing) exec("no-such-file"): -1 (exec-missing) end exec-missing: exit(0) -- cgit v1.2.1