selftests/harness: Add 30 second timeout per test
authorKees Cook <keescook@chromium.org>
Fri, 12 Apr 2019 00:11:08 +0000 (17:11 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 16 Apr 2019 23:04:34 +0000 (17:04 -0600)
In order to keep tests from hanging forever, this adds an alarm signal
to each test run. This assumes an individual test doesn't take longer
than 30 seconds.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/kselftest_harness.h

index 2d90c98..941d939 100644 (file)
@@ -696,6 +696,7 @@ void __run_test(struct __test_metadata *t)
        t->passed = 1;
        t->trigger = 0;
        printf("[ RUN      ] %s\n", t->name);
+       alarm(30);
        child_pid = fork();
        if (child_pid < 0) {
                printf("ERROR SPAWNING TEST CHILD\n");
@@ -744,6 +745,7 @@ void __run_test(struct __test_metadata *t)
                }
        }
        printf("[     %4s ] %s\n", (t->passed ? "OK" : "FAIL"), t->name);
+       alarm(0);
 }
 
 static int test_harness_run(int __attribute__((unused)) argc,