1#!/usr/bin/python
2
3import os
4import signal
5import subprocess
6import sys
7import time
8
9"""
10This test runs the underlying 'platform-interrupt-test' binary,
11sends it a SIGINT/CTRL_C_EVENT, and then propogates the return
12code that the underlying binary gave.
13"""
14
15if len(sys.argv) != 2:
16    exit(1)
17
18print sys.argv[1]
19proc = subprocess.Popen(sys.argv[1],stderr=subprocess.PIPE)
20
21# Let the underlying process register the signal handler
22while True:
23    line = proc.stderr.readline()
24    if 'Busy waiting for signal' in line:
25        break
26
27if os.name == 'nt':
28    # The most consistent way to detect ctrl+c on Windows
29    # is via the specific CTRL_C_EVENT rather than SIGINT
30    os.kill(proc.pid, signal.CTRL_C_EVENT)
31else:
32    os.kill(proc.pid, signal.SIGINT)
33
34# Propogate the returncode of the underlying test
35exit(proc.wait())
36