xref: /llvm-project/llvm/test/Support/interrupts.test (revision 83368191a21340a6c3a8f88b01ecae6433640957)
1## Show that SIGINT and similar signals don't cause crash messages to be
2## reported.
3# RUN: %python %s wrapper llvm-symbolizer 2> %t.err
4# RUN: FileCheck -DMSG=%errc_ENOENT --input-file=%t.err %s
5
6# CHECK: {{.*}} error: 'foo': [[MSG]]
7# CHECK-NOT: {{.+}}
8
9import os
10import signal
11import subprocess
12import sys
13import time
14
15def run_symbolizer():
16    proc = subprocess.Popen([sys.argv[2]], stdout=subprocess.PIPE,
17                            stdin=subprocess.PIPE, stderr=sys.stderr)
18    # Write then read some output to ensure the process has started fully.
19    proc.stdin.write(b'foo bar\n')
20    proc.stdin.flush()
21    proc.stdout.readline()
22    # Windows handles signals differently.
23    if os.name == 'nt':
24        os.kill(0, signal.CTRL_BREAK_EVENT)
25    else:
26        proc.send_signal(signal.SIGINT)
27
28# On Windows, this function spawns the subprocess in its own (hidden) console,
29# so that signals do not interfere with the calling test. This isn't necessary
30# on other systems.
31def run_wrapper():
32    args = [sys.executable, __file__, 'symbolizer'] + sys.argv[2:]
33    if os.name == 'nt':
34        startupinfo = subprocess.STARTUPINFO()
35        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
36        subprocess.run(args, stderr=sys.stderr, startupinfo=startupinfo,
37                       creationflags=subprocess.CREATE_NEW_CONSOLE)
38    else:
39        subprocess.run(args, stderr=sys.stderr)
40
41if sys.argv[1] == 'wrapper':
42    run_wrapper()
43else:
44    run_symbolizer()
45