mirror-llvm-project/lldb/test/API/windows/launch/replace-dll/TestReplaceDLL.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

64 lines
1.7 KiB
Python

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
import gc
import os
class ReplaceDllTestCase(TestBase):
SHARED_BUILD_TESTCASE = False
@requireWindows
def test(self):
"""
Test that LLDB unlocks module files once all references are released.
"""
exe = self.getBuildArtifact("a.out")
foo = self.getBuildArtifact("foo.dll")
bar = self.getBuildArtifact("bar.dll")
self.build(
dictionary={
"DYLIB_NAME": "foo",
"DYLIB_C_SOURCES": "foo.c",
"C_SOURCES": "test.c",
}
)
self.build(
dictionary={
"DYLIB_ONLY": "YES",
"DYLIB_NAME": "bar",
"DYLIB_C_SOURCES": "bar.c",
}
)
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
shlib_names = ["foo"]
environment = self.registerSharedLibrariesWithTarget(target, shlib_names)
process = target.LaunchSimple(
None, environment, self.get_process_working_directory()
)
self.assertEqual(process.GetExitStatus(), 42)
module = next((m for m in target.modules if "foo" in m.file.basename), None)
self.assertIsNotNone(module)
self.assertEqual(module.file.fullpath, foo)
target.RemoveModule(module)
del module
gc.collect()
self.dbg.MemoryPressureDetected()
os.remove(foo)
os.rename(bar, foo)
process = target.LaunchSimple(
None, environment, self.get_process_working_directory()
)
self.assertEqual(process.GetExitStatus(), 43)