mirror-llvm-project/lldb/test/API/macosx/arm-pointer-metadata-cfa-dwarf-expr/TestArmPointerMetadataCFADwarfExpr.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

35 lines
1.4 KiB
Python

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
@requireDarwin
@skipIf(archs=no_match(["arm64"]))
class TestArmPointerMetadataStripping(TestBase):
def test(self):
self.build()
target, process, thread, bkpt = lldbutil.run_to_name_breakpoint(self, "foo")
# Step over the first two instructions of foo in order to
# toggle the bit of fp and save it on the stack:
# orr x29, x29, #0x1000000000000000
# stp x29, x30, [sp, #-16]!
# This is effectively adding metadata to the CFA of the caller frame (main).
thread.StepInstruction(False)
thread.StepInstruction(False)
# The location of `argv` has been artificially made equal to the CFA of the frame.
# As such, it should have the metadata artificially set previously.
argv_addr = thread.frames[1].GetValueForVariablePath("&argv")
self.assertTrue(argv_addr.IsValid())
argv_addr_uint = argv_addr.GetValueAsUnsigned()
self.assertNotEqual((argv_addr_uint & (1 << 60)), 0)
# GetCFA strips metadata.
cfa = thread.frames[1].GetCFA()
self.assertEqual((cfa & (1 << 60)), 0)
# If the test worked correctly, the cfa and the location should be identical,
# modulo the metadata.
self.assertEqual(cfa | (1 << 60), argv_addr_uint)