mirror-llvm-project/lldb/test/API/macosx/ctf/TestCTF.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

97 lines
2.7 KiB
Python

import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import shutil
import os
class TestCTF(TestBase):
SHARED_BUILD_TESTCASE = False
NO_DEBUG_INFO_TESTCASE = True
def no_ctf_convert(self):
if not shutil.which("ctfconvert"):
return "ctfconvert not found in path"
return None
def no_objcopy(self):
if not "OBJCOPY" in os.environ:
return "llvm-objcopy not found in environment"
return None
@skipTestIfFn(no_ctf_convert)
@skipTestIfFn(no_objcopy)
@requireDarwin
def test(self):
self.build()
self.do_test()
@skipTestIfFn(no_ctf_convert)
@skipTestIfFn(no_objcopy)
@requireDarwin
def test_compressed(self):
self.build(dictionary={"COMPRESS_CTF": "YES"})
self.do_test()
def do_test(self):
lldbutil.run_to_name_breakpoint(self, "printf")
symbol_file = self.getBuildArtifact("a.ctf")
if self.TraceOn():
self.runCmd("log enable -v lldb symbol")
self.runCmd("target symbols add {}".format(symbol_file))
self.expect(
"target variable foo",
substrs=[
"(MyStructT) foo",
"i = 1",
"foo",
"'c'",
"[0] = 'c'",
"[1] = 'a'",
"[2] = 'b'",
"[3] = 'c'",
'u = (i = 1, s = "")',
"b = false",
"f = 0x0000000000000000",
],
)
self.expect("target variable foo.n.i", substrs=["(MyInt) foo.n.i = 1"])
self.expect(
"target variable foo.n.s", substrs=["(const char *) foo.n.s", '"foo"']
)
self.expect(
"target variable foo.n.c", substrs=["(volatile char) foo.n.c = 'c'"]
)
self.expect(
"target variable foo.n.a",
substrs=[
"(char[4]:8) foo.n.a",
"[0] = 'c'",
"[1] = 'a'",
"[2] = 'b'",
"[3] = 'c'",
],
)
self.expect(
"target variable foo.n.u", substrs=['(MyUnionT) foo.n.u = (i = 1, s = "")']
)
self.expect(
"target variable foo.f",
substrs=["(void (*)(int)) foo.f = 0x0000000000000000"],
)
self.expect(
"type lookup MyEnum",
substrs=[
"enum MyEnum {",
"eOne,",
"eTwo,",
"eThree",
"}",
],
)
self.expect("type lookup RecursiveStruct", substrs=["RecursiveStruct *n;"])