|
23 | 23 |
|
24 | 24 | try: |
25 | 25 | from _remote_debugging import PROCESS_VM_READV_SUPPORTED |
| 26 | + import _remote_debugging |
26 | 27 | except ImportError: |
27 | 28 | raise unittest.SkipTest( |
28 | 29 | "Test only runs when _remote_debugging is available" |
29 | 30 | ) |
30 | 31 | else: |
31 | 32 | import profile.sample |
| 33 | + from profile.sample import SampleProfiler |
| 34 | + |
32 | 35 |
|
33 | 36 |
|
34 | 37 | class MockFrameInfo: |
@@ -1600,6 +1603,30 @@ def test_invalid_output_format_with_mocked_profiler(self): |
1600 | 1603 | "Invalid output format: unknown_format", str(cm.exception) |
1601 | 1604 | ) |
1602 | 1605 |
|
| 1606 | + def test_is_process_running(self): |
| 1607 | + with (test_subprocess("import time; time.sleep(0.2)") as proc, |
| 1608 | + mock.patch("_remote_debugging.RemoteUnwinder") as mock_unwinder_class): |
| 1609 | + mock_unwinder_class.return_value = mock.MagicMock() |
| 1610 | + profiler = SampleProfiler(pid=proc.pid, sample_interval_usec=1000, all_threads=False) |
| 1611 | + |
| 1612 | + self.assertTrue(profiler._is_process_running()) |
| 1613 | + proc.wait() |
| 1614 | + self.assertFalse(profiler._is_process_running()) |
| 1615 | + |
| 1616 | + @unittest.skipUnless(sys.platform == "linux", "Only valid on Linux") |
| 1617 | + def test_esrch_signal_handling(self): |
| 1618 | + with test_subprocess("import time; time.sleep(0.1)") as proc: |
| 1619 | + unwinder = _remote_debugging.RemoteUnwinder(proc.pid) |
| 1620 | + initial_trace = unwinder.get_stack_trace() |
| 1621 | + self.assertIsNotNone(initial_trace) |
| 1622 | + |
| 1623 | + # Wait for the process to die and try to get another trace |
| 1624 | + proc.wait() |
| 1625 | + |
| 1626 | + with self.assertRaises(ProcessLookupError): |
| 1627 | + unwinder.get_stack_trace() |
| 1628 | + |
| 1629 | + |
1603 | 1630 |
|
1604 | 1631 | class TestSampleProfilerCLI(unittest.TestCase): |
1605 | 1632 | def test_cli_collapsed_format_validation(self): |
|
0 commit comments