1
|
|
|
import os |
2
|
|
|
import signal |
3
|
|
|
import sys |
4
|
|
|
|
5
|
|
|
import platform |
6
|
|
|
import process_tests |
7
|
|
|
import pytest |
8
|
|
|
|
9
|
|
|
TIMEOUT = int(os.getenv('HUNTER_TEST_TIMEOUT', 10)) |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
@pytest.mark.skipif('platform.system() == "Windows"') |
13
|
|
|
def test_manhole(): |
14
|
|
|
with process_tests.TestProcess(sys.executable, '-mtarget', 'manhole') as target, \ |
15
|
|
|
process_tests.dump_on_error(target.read): |
16
|
|
|
|
17
|
|
|
process_tests.wait_for_strings(target.read, TIMEOUT, 'Oneshot activation is done by signal Signals.SIGURG') |
18
|
|
|
|
19
|
|
|
with process_tests.TestProcess('hunter-trace', '-p', str(target.proc.pid), 'stdlib=False') as tracer,\ |
20
|
|
|
process_tests.dump_on_error(tracer.read): |
21
|
|
|
|
22
|
|
|
process_tests.wait_for_strings( |
23
|
|
|
tracer.read, TIMEOUT, |
24
|
|
|
'Output stream active. Starting tracer', |
25
|
|
|
'call => stuff()', |
26
|
|
|
'line time.sleep(1)', |
27
|
|
|
'return <= stuff: None', |
28
|
|
|
) |
29
|
|
|
process_tests.wait_for_strings(target.read, TIMEOUT, 'Broken pipe. Stopping tracer.') |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
@pytest.mark.skipif('platform.system() == "Windows"') |
33
|
|
|
def test_manhole_clean_exit(): |
34
|
|
|
with process_tests.TestProcess(sys.executable, '-mtarget', 'manhole') as target, \ |
35
|
|
|
process_tests.dump_on_error(target.read): |
36
|
|
|
|
37
|
|
|
process_tests.wait_for_strings(target.read, TIMEOUT, 'Oneshot activation is done by signal Signals.SIGURG') |
38
|
|
|
|
39
|
|
|
with process_tests.TestProcess('hunter-trace', '-p', str(target.proc.pid), 'stdlib=False') as tracer,\ |
40
|
|
|
process_tests.dump_on_error(tracer.read): |
41
|
|
|
|
42
|
|
|
process_tests.wait_for_strings( |
43
|
|
|
tracer.read, TIMEOUT, |
44
|
|
|
'Output stream active. Starting tracer', |
45
|
|
|
'call => stuff()', |
46
|
|
|
'line time.sleep(1)', |
47
|
|
|
'return <= stuff: None', |
48
|
|
|
) |
49
|
|
|
target.reset() |
50
|
|
|
tracer.proc.send_signal(signal.SIGINT) |
51
|
|
|
process_tests.wait_for_strings(target.read, TIMEOUT, |
52
|
|
|
'remote.deactivate()', |
53
|
|
|
'Doing stuff', |
54
|
|
|
'Doing stuff', |
55
|
|
|
'Doing stuff') |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
@pytest.mark.skipif('platform.system() == "Windows"') |
59
|
|
|
def test_gdb(): |
60
|
|
|
with process_tests.TestProcess(sys.executable, '-mtarget', 'manhole') as target, \ |
61
|
|
|
process_tests.dump_on_error(target.read): |
62
|
|
|
with process_tests.TestProcess('hunter-trace', '-p', str(target.proc.pid), |
63
|
|
|
'--gdb', 'stdlib=False') as tracer,\ |
64
|
|
|
process_tests.dump_on_error(tracer.read): |
65
|
|
|
|
66
|
|
|
process_tests.wait_for_strings( |
67
|
|
|
tracer.read, TIMEOUT, |
68
|
|
|
'WARNING: Using GDB may deadlock the process or create unpredictable results!', |
69
|
|
|
'Output stream active. Starting tracer', |
70
|
|
|
'call => stuff()', |
71
|
|
|
'line time.sleep(1)', |
72
|
|
|
'return <= stuff: None', |
73
|
|
|
) |
74
|
|
|
process_tests.wait_for_strings(target.read, TIMEOUT, 'Broken pipe. Stopping tracer.') |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
@pytest.mark.skipif('platform.system() == "Windows"') |
78
|
|
|
def test_gdb_clean_exit(): |
79
|
|
|
with process_tests.TestProcess(sys.executable, '-mtarget', 'manhole') as target, \ |
80
|
|
|
process_tests.dump_on_error(target.read): |
81
|
|
|
|
82
|
|
|
with process_tests.TestProcess('hunter-trace', '-p', str(target.proc.pid), |
83
|
|
|
'stdlib=False', '--gdb') as tracer,\ |
84
|
|
|
process_tests.dump_on_error(tracer.read): |
85
|
|
|
|
86
|
|
|
process_tests.wait_for_strings( |
87
|
|
|
tracer.read, TIMEOUT, |
88
|
|
|
'WARNING: Using GDB may deadlock the process or create unpredictable results!', |
89
|
|
|
'Output stream active. Starting tracer', |
90
|
|
|
'call => stuff()', |
91
|
|
|
'line time.sleep(1)', |
92
|
|
|
'return <= stuff: None', |
93
|
|
|
) |
94
|
|
|
target.reset() |
95
|
|
|
tracer.proc.send_signal(signal.SIGINT) |
96
|
|
|
process_tests.wait_for_strings(target.read, TIMEOUT, |
97
|
|
|
'Doing stuff', |
98
|
|
|
'Doing stuff', |
99
|
|
|
'Doing stuff') |
100
|
|
|
|
101
|
|
|
|