Completed
Push — master ( 0a37b1...f3b841 )
by Ionel Cristian
50s
created

tests/test_remote.py (1 issue)

1
import os
2
import platform
3
import signal
4
import sys
5
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')
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 View Code Duplication
def test_manhole_clean_exit():
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
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')
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
@pytest.mark.skipif('platform.python_implementation() == "PyPy"')
60
def test_gdb():
61
    with process_tests.TestProcess(sys.executable, '-mtarget', 'manhole') as target, \
62
         process_tests.dump_on_error(target.read):
63
            with process_tests.TestProcess('hunter-trace', '-p', str(target.proc.pid),
64
                                           '--gdb', 'stdlib=False') as tracer,\
65
                 process_tests.dump_on_error(tracer.read):
66
67
                process_tests.wait_for_strings(
68
                    tracer.read, TIMEOUT,
69
                    'WARNING: Using GDB may deadlock the process or create unpredictable results!',
70
                    'Output stream active. Starting tracer',
71
                    'call      => stuff()',
72
                    'line         time.sleep(1)',
73
                    'return    <= stuff: None',
74
                )
75
            process_tests.wait_for_strings(target.read, TIMEOUT, 'Broken pipe. Stopping tracer.')
76
77
78 View Code Duplication
@pytest.mark.skipif('platform.system() == "Windows"')
79
@pytest.mark.skipif('platform.python_implementation() == "PyPy"')
80
def test_gdb_clean_exit():
81
    with process_tests.TestProcess(sys.executable, '-mtarget', 'manhole') as target, \
82
         process_tests.dump_on_error(target.read):
83
84
            with process_tests.TestProcess('hunter-trace', '-p', str(target.proc.pid),
85
                                           'stdlib=False', '--gdb') as tracer,\
86
                 process_tests.dump_on_error(tracer.read):
87
88
                process_tests.wait_for_strings(
89
                    tracer.read, TIMEOUT,
90
                    'WARNING: Using GDB may deadlock the process or create unpredictable results!',
91
                    'Output stream active. Starting tracer',
92
                    'call      => stuff()',
93
                    'line         time.sleep(1)',
94
                    'return    <= stuff: None',
95
                )
96
                target.reset()
97
                tracer.proc.send_signal(signal.SIGINT)
98
            process_tests.wait_for_strings(target.read, TIMEOUT,
99
                                           'Doing stuff',
100
                                           'Doing stuff',
101
                                           'Doing stuff')
102