summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_monitoring.py
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-09-05 11:29:38 (GMT)
committerGitHub <noreply@github.com>2023-09-05 11:29:38 (GMT)
commit7ee021f99998690ee724d08a95dceadd2ec8a051 (patch)
tree6b1b3d3baae57c46b3a56ce0645661e0568de46e /Lib/test/test_monitoring.py
parent5121faabd1b3733a1198a18fa5df540eeb2475f6 (diff)
downloadcpython-7ee021f99998690ee724d08a95dceadd2ec8a051.zip
cpython-7ee021f99998690ee724d08a95dceadd2ec8a051.tar.gz
cpython-7ee021f99998690ee724d08a95dceadd2ec8a051.tar.bz2
[3.12] GH-108390: Prevent non-local events being set with `sys.monitoring.set_local_events()` (GH-108420) (#108899)
* GH-108390: Prevent non-local events being set with `sys.monitoring.set_local_events()` (GH-108420) * Restore generated objects * Restore size of monitoring arrays in code object for 3.12 ABI compatibility. * Update ABI file
Diffstat (limited to 'Lib/test/test_monitoring.py')
-rw-r--r--Lib/test/test_monitoring.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/Lib/test/test_monitoring.py b/Lib/test/test_monitoring.py
index 4c74389..8665c35 100644
--- a/Lib/test/test_monitoring.py
+++ b/Lib/test/test_monitoring.py
@@ -1218,9 +1218,11 @@ class TestInstallIncrementallly(MonitoringTestBase, unittest.TestCase):
self.check_events(self.func2,
recorders = recorders, must_include = self.MUST_INCLUDE_CI)
+LOCAL_RECORDERS = CallRecorder, LineRecorder, CReturnRecorder, CRaiseRecorder
+
class TestLocalEvents(MonitoringTestBase, unittest.TestCase):
- def check_events(self, func, expected, tool=TEST_TOOL, recorders=(ExceptionRecorder,)):
+ def check_events(self, func, expected, tool=TEST_TOOL, recorders=()):
try:
self.assertEqual(sys.monitoring._all_events(), {})
event_list = []
@@ -1248,7 +1250,7 @@ class TestLocalEvents(MonitoringTestBase, unittest.TestCase):
line2 = 2
line3 = 3
- self.check_events(func1, recorders = MANY_RECORDERS, expected = [
+ self.check_events(func1, recorders = LOCAL_RECORDERS, expected = [
('line', 'func1', 1),
('line', 'func1', 2),
('line', 'func1', 3)])
@@ -1260,7 +1262,7 @@ class TestLocalEvents(MonitoringTestBase, unittest.TestCase):
[].append(2)
line3 = 3
- self.check_events(func2, recorders = MANY_RECORDERS, expected = [
+ self.check_events(func2, recorders = LOCAL_RECORDERS, expected = [
('line', 'func2', 1),
('line', 'func2', 2),
('call', 'append', [2]),
@@ -1277,15 +1279,17 @@ class TestLocalEvents(MonitoringTestBase, unittest.TestCase):
line = 5
line = 6
- self.check_events(func3, recorders = MANY_RECORDERS, expected = [
+ self.check_events(func3, recorders = LOCAL_RECORDERS, expected = [
('line', 'func3', 1),
('line', 'func3', 2),
('line', 'func3', 3),
- ('raise', KeyError),
('line', 'func3', 4),
('line', 'func3', 5),
('line', 'func3', 6)])
+ def test_set_non_local_event(self):
+ with self.assertRaises(ValueError):
+ sys.monitoring.set_local_events(TEST_TOOL, just_call.__code__, E.RAISE)
def line_from_offset(code, offset):
for start, end, line in code.co_lines():
@@ -1698,3 +1702,19 @@ class TestRegressions(MonitoringTestBase, unittest.TestCase):
self.assertEqual(caught, "inner")
finally:
sys.monitoring.set_events(TEST_TOOL, 0)
+
+ def test_108390(self):
+
+ class Foo:
+ def __init__(self, set_event):
+ if set_event:
+ sys.monitoring.set_events(TEST_TOOL, E.PY_RESUME)
+
+ def make_foo_optimized_then_set_event():
+ for i in range(100):
+ Foo(i == 99)
+
+ try:
+ make_foo_optimized_then_set_event()
+ finally:
+ sys.monitoring.set_events(TEST_TOOL, 0)