Debian Codegraph @

tests/test_coverup_125.py

raw symbols SCIP
1 # file scalene/scalene_profiler.py:1629-1645
2 # lines [1643, 1644, 1645]
3 # branches ['1643->1644', '1643->1645']
4
5 import os
6 import signal
7 import pytest
8 from scalene.scalene_profiler import Scalene
9
10
11 @pytest.fixture
12 def scalene_setup_and_teardown():
13 # Setup code
14 Scalene.start = lambda: None
15 Scalene.__orig_kill = os.kill
16 Scalene.__signals = type("Signals", (), {"start_profiling_signal": signal.SIGCONT})
17 Scalene.child_pids = set()
18 # Create a child process and add its PID to the set
19 pid = os.fork()
20 if pid == 0:
21 # Child process: wait for a signal
22 signal.pause()
23 else:
24 # Parent process: add child PID to the set
25 Scalene.child_pids.add(pid)
26 yield
27 # Teardown code
28 if pid > 0:
29 os.kill(pid, signal.SIGKILL) # Terminate the child process
30 Scalene.child_pids.remove(pid)
31 Scalene.child_pids.clear()
32
33
34 def test_start_signal_handler(scalene_setup_and_teardown):
35 # Test that the signal handler sends the start_profiling_signal to child processes
36 Scalene.start_signal_handler(None, None)
37 # No direct postconditions to assert; the test is for coverage of the signal sending