summaryrefslogtreecommitdiff
path: root/tests/platform_checks/check.py
blob: b41755a9635c805290fc3a2f1cbd0dc24810161d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
import signal
import os
import time
import pty

def signal_handler (signum, frame):
    print 'Signal handler called with signal:', signum
    print 'signal.SIGCHLD=', signal.SIGKILL

# First thing we do is set up a handler for SIGCHLD.
signal.signal (signal.SIGCHLD, signal.SIG_IGN)

print 'PART 1 -- Test signal handling with empty pipe.'
# Create a child process for us to kill.
try:
    pid, fd = pty.fork()
except Exception as e:
    print str(e)

if pid == 0:
#    os.write (sys.stdout.fileno(), 'This is a test.\n This is a test.')
    time.sleep(10000)

print 'Sending SIGKILL to child pid:', pid
os.kill (pid, signal.SIGKILL)

# SIGCHLD should interrupt sleep.
# Note that this is a race.
# It is possible that the signal handler will get called
# before we try to sleep, but this has not happened yet.
# But in that case we can only tell by order of printed output.
print 'Entering sleep...'
try:
    time.sleep(10)
except:
    print 'sleep was interrupted by signal.'

# Just for fun let's see if the process is alive.
try:
    os.kill(pid, 0)
    print 'Child is alive. This is ambiguous because it may be a Zombie.'
except OSError as e:
    print 'Child appears to be dead.'

print 'PART 2 -- Test signal handling with full pipe.'
# Create a child process for us to kill.
try:
    pid, fd = pty.fork()
except Exception as e:
    print str(e)

if pid == 0:
    os.write (sys.stdout.fileno(), 'This is a test.\n This is a test.')
    time.sleep(10000)

print 'Sending SIGKILL to child pid:', pid
os.kill (pid, signal.SIGKILL)

# SIGCHLD should interrupt sleep.
# Note that this is a race.
# It is possible that the signal handler will get called
# before we try to sleep, but this has not happened yet.
# But in that case we can only tell by order of printed output.
print 'Entering sleep...'
try:
    time.sleep(10)
except:
    print 'sleep was interrupted by signal.'

# Just for fun let's see if the process is alive.
try:
    os.kill(pid, 0)
    print 'Child is alive. This is ambiguous because it may be a Zombie.'
except OSError as e:
    print 'Child appears to be dead.'