[systemd-commits] 2 commits - src/test

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Thu Dec 25 08:55:35 PST 2014


 src/test/test-util.c |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

New commits:
commit 0289a5bcb5eec84783f771e634ccafe5a2e4936c
Author: Filipe Brandenburger <filbranden at google.com>
Date:   Thu Dec 25 11:40:46 2014 -0500

    test: wait for cloned thread to exit
    
    In test_raw_clone, make sure the cloned thread calls _exit() and in the parent
    thread call waitpid(..., __WCLONE) to wait for the child thread to terminate,
    otherwise there is a race condition where the child thread will log to the
    console after the test process has already exited and the assertion from the
    child thread might not be enforced.
    
    The absence of this patch might also create problems for other tests that would
    be added after this one, since potentially both parent and child would run
    those tests as the child would continue running.
    
    Tested by confirming that the logs from the child are printed before the test
    terminates and that a false assertion in the child aborts the test with a core
    dump.
    
    [zj: also add check for the return value.]

diff --git a/src/test/test-util.c b/src/test/test-util.c
index 57fd19b..93f11eb 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -1336,10 +1336,16 @@ static void test_raw_clone(void) {
         pid2 = raw_getpid();
         log_info("raw_clone: "PID_FMT" getpid()→"PID_FMT" raw_getpid()→"PID_FMT,
                  pid, getpid(), pid2);
-        if (pid == 0)
+        if (pid == 0) {
                 assert_se(pid2 != parent);
-        else
+                _exit(EXIT_SUCCESS);
+        } else {
+                int status;
+
                 assert_se(pid2 == parent);
+                waitpid(pid, &status, __WCLONE);
+                assert_se(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
+        }
 }
 
 int main(int argc, char *argv[]) {

commit e50221bf1ae8bc8e14f242efa4c9d26b7a47639b
Author: Filipe Brandenburger <filbranden at google.com>
Date:   Tue Dec 23 10:14:46 2014 -0800

    test: only use assert_se in test_raw_clone
    
    The asserts used in the tests should never be allowed to be optimized away.

diff --git a/src/test/test-util.c b/src/test/test-util.c
index 222af9a..57fd19b 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -420,7 +420,7 @@ static void check(const char *test, char** expected, bool trailing) {
                 printf("<%s>\n", t);
         }
         printf("<<<%s>>>\n", state);
-        assert(expected[i] == NULL);
+        assert_se(expected[i] == NULL);
         assert_se(isempty(state) == !trailing);
 }
 
@@ -1331,15 +1331,15 @@ static void test_raw_clone(void) {
         assert_se(raw_getpid() == parent);
 
         pid = raw_clone(0, NULL);
-        assert(pid >= 0);
+        assert_se(pid >= 0);
 
         pid2 = raw_getpid();
         log_info("raw_clone: "PID_FMT" getpid()→"PID_FMT" raw_getpid()→"PID_FMT,
                  pid, getpid(), pid2);
         if (pid == 0)
-                assert(pid2 != parent);
+                assert_se(pid2 != parent);
         else
-                assert(pid2 == parent);
+                assert_se(pid2 == parent);
 }
 
 int main(int argc, char *argv[]) {



More information about the systemd-commits mailing list