mirror-llvm-project/lldb/test/API/macosx/unregistered-macho/TestUnregisteredMacho.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

62 lines
2.3 KiB
Python

"""Test that debugserver will parse a mach-o in inferior memory even if it's not loaded."""
import os
import re
import subprocess
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class TestUnregisteredMacho(TestBase):
# newer debugserver required for jGetLoadedDynamicLibrariesInfos
# to support this
@no_debug_info_test
@requireDarwin
def test(self):
self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.c")
)
frame = thread.GetFrameAtIndex(0)
macho_buf = frame.GetValueForVariablePath("macho_buf")
macho_addr = macho_buf.GetValueAsUnsigned()
invalid_macho_addr = macho_buf.GetValueAsUnsigned() + 4
gdb_packet = (
"process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d]}]'"
% macho_addr
)
# Send the jGetLoadedDynamicLibrariesInfos packet
# to debugserver, asking it to parse the mach-o binary
# at this address and give us the UUID etc, even though
# dyld doesn't think there is a binary at that address.
# We won't get a pathname for the binary (from dyld), but
# we will get to the LC_UUID and include that.
self.expect(
gdb_packet,
substrs=['"pathname":""', '"uuid":"1B4E28BA-2FA1-11D2-883F-B9A761BDE3FB"'],
)
no_macho_gdb_packet = (
"process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d]}]'"
% invalid_macho_addr
)
self.expect(no_macho_gdb_packet, substrs=['response: {"images":[]}'])
# Test that we get back the information for the properly
# formatted Mach-O binary in memory, but do not get an
# entry for the invalid Mach-O address.
both_gdb_packet = (
"process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d,%d]}]'"
% (macho_addr, invalid_macho_addr)
)
self.expect(both_gdb_packet, substrs=['"load_address":%d,' % macho_addr])
self.expect(
both_gdb_packet,
substrs=['"load_address":%d,' % invalid_macho_addr],
matching=False,
)