diff options
author | davidot <davidot@serenityos.org> | 2022-09-11 10:13:58 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-09-11 20:25:51 +0100 |
commit | 3b020c6fb466a98e44e8c32759cc0e5a615b965e (patch) | |
tree | e21ec908d80b594fec27dc86bd466f53027b794a /Tests/LibJS | |
parent | 7948897688f84f4aa85adf3c1f9f96b07f27ddec (diff) | |
download | serenity-3b020c6fb466a98e44e8c32759cc0e5a615b965e.zip |
test262-runner: Use alarm instead of setitimer
Since setitimer is not implemented in Serenity we use alarm which
triggers SIGALRM after the timeout. We also don't use a signal handler
as we are doing things that serenity doesn't like/doesn't allow.
Linux dealt with allocating and writing in a signal handler but it is
undefined, so instead we just let the process die by SIGALRM.
This means we instead of reading the output can detect timeouts by
checking how the process died.
Diffstat (limited to 'Tests/LibJS')
-rw-r--r-- | Tests/LibJS/test262-runner.cpp | 59 |
1 files changed, 4 insertions, 55 deletions
diff --git a/Tests/LibJS/test262-runner.cpp b/Tests/LibJS/test262-runner.cpp index 0b4e3e595a..1329d94c12 100644 --- a/Tests/LibJS/test262-runner.cpp +++ b/Tests/LibJS/test262-runner.cpp @@ -23,8 +23,6 @@ #include <LibJS/Script.h> #include <fcntl.h> #include <signal.h> -#include <stdio.h> -#include <time.h> #include <unistd.h> static String s_current_test = ""; @@ -505,20 +503,6 @@ static bool verify_test(Result<void, TestError>& result, TestMetadata const& met static FILE* saved_stdout_fd; -static void timer_handler(int signum) -{ - JsonObject timeout_result; - timeout_result.set("test", s_current_test); - timeout_result.set("timeout", true); - timeout_result.set("result", "timeout"); - outln(saved_stdout_fd, "RESULT {}{}", timeout_result.to_string(), '\0'); - // Make sure this message gets out and just die like the default action would be. - fflush(saved_stdout_fd); - - signal(signum, SIG_DFL); - raise(signum); -} - void __assert_fail(char const* assertion, char const* file, unsigned int line, char const* function) { JsonObject assert_fail_result; @@ -618,46 +602,11 @@ int main(int argc, char** argv) return value; }; - if (signal(SIGVTALRM, timer_handler) == SIG_ERR) { - perror("signal"); - return 1; - } +#define ARM_TIMER() \ + alarm(timeout) - timer_t timer_id; - struct sigevent timer_settings; - timer_settings.sigev_notify = SIGEV_SIGNAL; - timer_settings.sigev_signo = SIGVTALRM; - timer_settings.sigev_value.sival_ptr = &timer_id; - - if (timer_create(CLOCK_PROCESS_CPUTIME_ID, &timer_settings, &timer_id) < 0) { - perror("timer_create"); - return 1; - } - ScopeGuard destroy_timer = [timer_id] { timer_delete(timer_id); }; - - struct itimerspec timeout_timer; - timeout_timer.it_value.tv_sec = timeout; - timeout_timer.it_value.tv_nsec = 0; - timeout_timer.it_interval.tv_sec = 0; - timeout_timer.it_interval.tv_nsec = 0; - - struct itimerspec disarm; - disarm.it_value.tv_sec = 0; - disarm.it_value.tv_nsec = 0; - disarm.it_interval.tv_sec = 0; - disarm.it_interval.tv_nsec = 0; - -#define ARM_TIMER() \ - if (timer_settime(timer_id, 0, &timeout_timer, nullptr) < 0) { \ - perror("timer_settime"); \ - return 1; \ - } - -#define DISARM_TIMER() \ - if (timer_settime(timer_id, 0, &disarm, nullptr) < 0) { \ - perror("timer_settime"); \ - return 1; \ - } +#define DISARM_TIMER() \ + alarm(0) auto stdin = Core::File::standard_input(); size_t count = 0; |