Skip to content

Commit 564e946

Browse files
committed
fix 'CheckDtraceProbes' tests by reading '.SUNW_dof' ELF section
1 parent c7b9a13 commit 564e946

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

‎Lib/test/test_dtrace.py‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def run_readelf(cmd):
8383
stdout=subprocess.PIPE,
8484
stderr=subprocess.PIPE,
8585
text=True,
86+
errors='replace',
8687
env=env,
8788
)
8889
except OSError:
@@ -476,37 +477,47 @@ def get_readelf_output(self):
476477
binary = libpython_path
477478
break
478479

480+
if sys.platform == "sunos5":
481+
# Solaris keeps the tracing metadata in a special
482+
# ELF section called .SUNW_dof
483+
return run_readelf(["readelf", "-p", ".SUNW_dof", binary])
479484
return run_readelf(["readelf", "-n", binary])
480485

486+
def assert_probe_present(self, probe_name, readelf_output):
487+
if sys.platform == "sunos5":
488+
self.assertIn(probe_name.replace("__", "-"), readelf_output)
489+
else:
490+
self.assertIn(f"Name: {probe_name}", readelf_output)
491+
481492
def test_check_probes(self):
482493
readelf_output = self.get_readelf_output()
483494

484495
available_probe_names = [
485-
"Name: import__find__load__done",
486-
"Name: import__find__load__start",
487-
"Name: audit",
488-
"Name: gc__start",
489-
"Name: gc__done",
490-
"Name: function__entry",
491-
"Name: function__return",
496+
"import__find__load__done",
497+
"import__find__load__start",
498+
"audit",
499+
"gc__start",
500+
"gc__done",
501+
"function__entry",
502+
"function__return",
492503
]
493504

494505
for probe_name in available_probe_names:
495506
with self.subTest(probe_name=probe_name):
496-
self.assertIn(probe_name, readelf_output)
507+
self.assert_probe_present(probe_name, readelf_output)
497508

498509
@unittest.expectedFailure
499510
def test_missing_probes(self):
500511
readelf_output = self.get_readelf_output()
501512

502513
# Missing probes will be added in the future.
503514
missing_probe_names = [
504-
"Name: line",
515+
"line",
505516
]
506517

507518
for probe_name in missing_probe_names:
508519
with self.subTest(probe_name=probe_name):
509-
self.assertIn(probe_name, readelf_output)
520+
self.assert_probe_present(probe_name, readelf_output)
510521

511522

512523
if __name__ == '__main__':

0 commit comments

Comments
 (0)