Completed
Push — master ( 9a2fe9...d1c046 )
by Ionel Cristian
35s
created

test_gdb_clean_exit()   B

Complexity

Conditions 3

Size

Total Lines 24

Duplication

Lines 24
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
dl 24
loc 24
rs 8.9713
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
@pytest.mark.skipif('platform.python_implementation() == "PyPy"')
14
def test_manhole():
15
    with process_tests.TestProcess(sys.executable, '-mtarget', 'manhole') as target, \
16
         process_tests.dump_on_error(target.read):
17
18
            process_tests.wait_for_strings(target.read, TIMEOUT, 'Oneshot activation is done by signal')
19
20
            with process_tests.TestProcess('hunter-trace', '-p', str(target.proc.pid), 'stdlib=False') as tracer,\
21
                 process_tests.dump_on_error(tracer.read):
22
23
                process_tests.wait_for_strings(
24
                    tracer.read, TIMEOUT,
25
                    'Output stream active. Starting tracer',
26
                    'call      => stuff()',
27
                    'line         time.sleep(1)',
28
                    'return    <= stuff: None',
29
                )
30
            process_tests.wait_for_strings(target.read, TIMEOUT, 'Broken pipe. Stopping tracer.')
31
32
33 View Code Duplication
@pytest.mark.skipif('platform.system() == "Windows"')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
34
def test_manhole_clean_exit():
35
    with process_tests.TestProcess(sys.executable, '-mtarget', 'manhole') as target, \
36
         process_tests.dump_on_error(target.read):
37
38
            process_tests.wait_for_strings(target.read, TIMEOUT, 'Oneshot activation is done by signal')
39
40
            with process_tests.TestProcess('hunter-trace', '-p', str(target.proc.pid), 'stdlib=False') as tracer,\
41
                 process_tests.dump_on_error(tracer.read):
42
43
                process_tests.wait_for_strings(
44
                    tracer.read, TIMEOUT,
45
                    'Output stream active. Starting tracer',
46
                    'call      => stuff()',
47
                    'line         time.sleep(1)',
48
                    'return    <= stuff: None',
49
                )
50
                target.reset()
51
                tracer.proc.send_signal(signal.SIGINT)
52
            process_tests.wait_for_strings(target.read, TIMEOUT,
53
                                           'remote.deactivate()',
54
                                           'Doing stuff',
55
                                           'Doing stuff',
56
                                           'Doing stuff')
57
58
59
@pytest.mark.skipif('platform.system() == "Windows"')
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"')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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