Skip to content

Commit

Permalink
Handle freezing tests. Fixes mesonbuild#10752.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpakkane committed Nov 21, 2022
1 parent e5ce7f0 commit 3ae89a7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mesonbuild/mtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,14 +1265,14 @@ async def _kill(self) -> T.Optional[str]:

# Make sure the termination signal actually kills the process
# group, otherwise retry with a SIGKILL.
with suppress(TimeoutError):
with suppress(asyncio.TimeoutError):
await asyncio.wait_for(p.wait(), timeout=0.5)
if p.returncode is not None:
return None

os.killpg(p.pid, signal.SIGKILL)

with suppress(TimeoutError):
with suppress(asyncio.TimeoutError):
await asyncio.wait_for(p.wait(), timeout=1)
if p.returncode is not None:
return None
Expand All @@ -1281,7 +1281,7 @@ async def _kill(self) -> T.Optional[str]:
# Try to kill it one last time with a direct call.
# If the process has spawned children, they will remain around.
p.kill()
with suppress(TimeoutError):
with suppress(asyncio.TimeoutError):
await asyncio.wait_for(p.wait(), timeout=1)
if p.returncode is not None:
return None
Expand Down
21 changes: 21 additions & 0 deletions test cases/unit/109 freeze/freeze.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<stdio.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>

static void do_nothing(int signo, siginfo_t *info, void *context) {
}

int main(int argc, char **argv) {
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_sigaction = do_nothing;
if (sigaction(SIGTERM, &sa, NULL) == -1) {
printf("Could not set up signal handler.\n");
return 1;
}
printf("Freezing forever.\n");
while(1) {
}
return 0;
}
4 changes: 4 additions & 0 deletions test cases/unit/109 freeze/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project('freeze', 'c')

e = executable('freeze', 'freeze.c')
test('freeze', e, timeout: 1)
8 changes: 8 additions & 0 deletions unittests/linuxliketests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,3 +1820,11 @@ def test_isystem_default_removal_with_symlink(self):
default_symlinks.append(symlink)
os.symlink(default_dirs[i], symlink)
self.assertFalse(cpp.compiler_args([f'-isystem{symlink}' for symlink in default_symlinks]).to_native())

def test_freezing(self):
testdir = os.path.join(self.unit_test_dir, '109 freeze')
self.init(testdir)
self.build()
with self.assertRaises(subprocess.CalledProcessError) as e:
self.run_tests()
self.assertNotIn('Traceback', e.exception.output)

0 comments on commit 3ae89a7

Please sign in to comment.