mirror-llvm-project/lldb/test/API/macosx/dsym_modules/TestdSYMModuleInit.py
Charles Zablit 67a20745d6
[lldb] Introduce the require decorator (#212753)
Currently, it is unclear if a test that is skipped is either:
- Unsupported because it will never run (macosx tests should not run on
Windows).
- Skipped because it's supposed to work but does not yet.
`@expectedFailure` is not always an option because a test might be
timing out and waiting 600s for it to fail is not acceptable.

This patch introduces 2 new decorators to differentiate those tests:
- `@requireX` meaning the tests require X to run (e.g `@requireDarwin`).
- `@requireNotX` meaning the tests requires anything but `X` to run (e.g
`@requireNotDarwin`).

In the tests results summary, this introduces a new category: `skipped`
tests:
- `@requireX` -> `UNSUPPORTED`
- `@skipIfX` -> `SKIPPED`

Here is how they can and cannot be stacked:

This will never run:
```py3
@requireDarwin
@requireWindows
def test():
    ...
```

This will not run on Linux, because `@requireWindows` is not satisfied.
```py3
@requireNotDarwin
@requireWindows
def test():
    ...
```

For "require Darwin or Windows", you need:
```py3
@requirePlatform(["darwin", "windows"])
def test():
    ...
```

For "require Darwin on ARM64 or Windows on ARM64", you need:
```py3
@requireARM64
@requirePlatform(["darwin", "windows"])
def test():
    ...
```

This patch also converts the tests in
`lldb/tests/API/{macosx,linux,windows}` to use these decorators. Patches
to convert the rest of the tests will follow.
2026-08-01 18:03:29 +02:00

65 lines
2.5 KiB
Python

"""
Test that we read in the Python module from a dSYM, and run the
init in debugger and the init in target routines.
"""
import os, shutil
import lldb
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
@requireDarwin
class TestdSYMModuleInit(TestBase):
SHARED_BUILD_TESTCASE = False
@no_debug_info_test
def test_add_module(self):
"""This loads a file into a target and ensures that the python module was
correctly added and the two initialization functions are called."""
self.exe_name = "has_dsym"
self.py_name = self.exe_name + ".py"
# Now load the target the first time into the debugger:
self.runCmd("settings set target.load-script-from-symbol-file true")
self.interp = self.dbg.GetCommandInterpreter()
executable = self.build_dsym(self.exe_name + "_1")
target = self.createTestTarget(file_path=executable)
self.check_answers(executable, ["1", "1", "has_dsym_1"])
# Now make a second target and make sure both get called:
executable_2 = self.build_dsym(self.exe_name + "_2")
target_2 = self.createTestTarget(file_path=executable_2)
self.check_answers(executable_2, ["2", "2", "has_dsym_2"])
def check_answers(self, name, answers):
result = lldb.SBCommandReturnObject()
self.interp.HandleCommand("report_command", result)
self.assertTrue(
result.Succeeded(), f"report_command succeeded {result.GetError()}"
)
cmd_results = result.GetOutput().split()
self.assertEqual(answers[0], cmd_results[0], "Right number of module imports")
self.assertEqual(answers[1], cmd_results[1], "Right number of target notices")
self.assertIn(answers[2], name, "Right target name")
def build_dsym(self, name):
self.build(debug_info="dsym", dictionary={"EXE": name})
executable = self.getBuildArtifact(name)
dsym_path = self.getBuildArtifact(name + ".dSYM")
python_dir_path = dsym_path
python_dir_path = os.path.join(dsym_path, "Contents", "Resources", "Python")
if not os.path.exists(python_dir_path):
os.mkdir(python_dir_path)
python_file_name = name + ".py"
module_dest_path = os.path.join(python_dir_path, python_file_name)
module_origin_path = os.path.join(self.getSourceDir(), self.py_name)
shutil.copy(module_origin_path, module_dest_path)
return executable