Commit cf57f25f authored by Philip Chimento's avatar Philip Chimento 🚮

tests: Don't time-limit the unit tests

Previously there was code that would intentionally crash if more than 7
minutes elapsed, in case the tests got stuck on autobuilders. This code
is more harmful than helpful, see the following table:

  Times it has killed a stuck test on GitLab: . . . . . . . . 0
  Times it has killed a JS_GC_ZEAL test:  . . . . . . . . .  34
  Times it has killed my GDB session because I forgot
    to add the stupid environment variable: . . . . . . . . 478
parent 284586e6
......@@ -88,91 +88,3 @@ gjs_unit_test_exception_message(GjsUnitTestFixture *fx)
JS_ClearPendingException(fx->cx);
return retval;
}
/* Fork a process that waits the given time then
* sends us ABRT
*/
void
gjs_crash_after_timeout(int seconds)
{
pid_t parent_pid;
int pipe_fds[2];
fd_set read_fds;
struct timeval term_time;
struct timeval remaining;
struct timeval now;
int old_flags;
/* We use a pipe to know in the child when the parent exited */
if (pipe(pipe_fds) != 0) {
fprintf(stderr, "Failed to create pipe to crash-in-timeout process: %s\n",
strerror(errno));
return;
}
/* We want pipe_fds[1] to only be open in the parent process; when it closes
* the child will see an EOF. Setting FD_CLOEXEC is protection in case the
* parent spawns off some process without properly closing fds.
*/
old_flags = fcntl(pipe_fds[1], F_GETFD);
if (old_flags == -1 ||
fcntl(pipe_fds[1], F_SETFD, old_flags | FD_CLOEXEC) != 0) {
fprintf(stderr, "Couldn't make crash-timeout pipe FD_CLOEXEC: %s\n",
strerror(errno));
return;
}
parent_pid = getpid();
switch (fork()) {
case -1:
fprintf(stderr, "Failed to fork crash-in-timeout process: %s\n",
strerror(errno));
return;
case 0:
/* child */
break;
default:
/* parent */
close(pipe_fds[0]);
return;
}
close (pipe_fds[1]);
gettimeofday (&now, NULL);
term_time = now;
term_time.tv_sec += seconds;
FD_ZERO(&read_fds);
FD_SET(pipe_fds[0], &read_fds);
while (true) {
remaining.tv_sec = term_time.tv_sec - now.tv_sec;
remaining.tv_usec = term_time.tv_usec - now.tv_usec;
if (remaining.tv_usec < 0) {
remaining.tv_usec += 1000;
remaining.tv_sec -= 1;
}
if (remaining.tv_sec < 0) /* expired */
break;
select(pipe_fds[0] + 1, &read_fds, NULL, NULL, &remaining);
if (FD_ISSET(pipe_fds[0], &read_fds)) {
/* The parent exited */
_exit(0);
}
gettimeofday(&now, NULL);
}
if (kill(parent_pid, 0) == 0) {
fprintf(stderr, "Timeout of %d seconds expired; aborting process %d\n",
seconds, (int) parent_pid);
kill(parent_pid, SIGABRT);
}
_exit(1);
}
......@@ -46,8 +46,6 @@ void gjs_unit_test_fixture_teardown(GjsUnitTestFixture *fx,
char *gjs_unit_test_exception_message(GjsUnitTestFixture *fx);
void gjs_crash_after_timeout(int seconds);
void gjs_test_add_tests_for_coverage ();
void gjs_test_add_tests_for_parse_call_args(void);
......
......@@ -406,11 +406,6 @@ int
main(int argc,
char **argv)
{
/* give the unit tests 7 minutes to complete, unless an environment variable
* is set; use this when running under GDB, for example */
if (!g_getenv("GJS_TEST_SKIP_TIMEOUT"))
gjs_crash_after_timeout(60 * 7);
/* Avoid interference in the tests from stray environment variable */
g_unsetenv("GJS_ENABLE_PROFILER");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment