Obtaining a Backtrace after swift_test failure
ed-irl opened this issue · comments
Hello, I was wondering if it is possible to obtain a backtrace (see https://github.com/apple/swift/blob/main/docs/Backtracing.rst) in the failure report of Xcode tests run via Bazel? Merely setting env = {"SWIFT_BACKTRACE":"enable=yes"}
doesn't seem to help on MacOS.
https://github.com/apple/swift/blob/main/docs/Backtracing.rst#macos I think the second part of the instructions would be required too, worth a try
I played around with this today and may come back to it.
You can indeed codesign the bundle (or binary within the bundle) by using codesign --force --sign - --entitlements get-task-allow.plist path/to/bundle.xctest
or codesign --force --sign - --entitlements get-task-allow.plist path/to/bundle.xctest/path/to/binary
. Having done so, you can cd
into the sandbox and run the test with SWIFT_BACKTRACE=enable=yes xcrun xctest libs/swift/DockerTestContainers/DockerTestContainersTests.xctest
. Unfortunately, this did not produce a stack trace in the output. Its unclear to me why this was the case; I am in the process of debugging a race condition and I suspect the signing or backtrace instrumentation may prevent the test failure in my code from happening, or it might just not work.
I think the following might be needed to make this work on MacOS:
- possibly disabling bundling
- adding an option to swift_test to add the required signature and entitlement
I assume it probably already works for swift linux users based on the docs, and the fact that the test is just a plain binary in linux.