fix: resolve coverage profile symbol at runtime

This commit is contained in:
Peter Steinberger
2025-12-24 21:43:36 +01:00
parent f7c5eff35e
commit 4d4308af78

View File

@@ -6,13 +6,19 @@ import Testing
struct CoverageDumpTests {
@Test func periodicallyFlushCoverage() async {
guard ProcessInfo.processInfo.environment["LLVM_PROFILE_FILE"] != nil else { return }
guard let writeProfile = resolveProfileWriteFile() else { return }
let deadline = Date().addingTimeInterval(4)
while Date() < deadline {
_ = llvmProfileWriteFile()
_ = writeProfile()
try? await Task.sleep(nanoseconds: 250_000_000)
}
}
}
@_silgen_name("__llvm_profile_write_file")
private func llvmProfileWriteFile() -> Int32
private typealias ProfileWriteFn = @convention(c) () -> Int32
private func resolveProfileWriteFile() -> ProfileWriteFn? {
let symbol = dlsym(UnsafeMutableRawPointer(bitPattern: -2), "__llvm_profile_write_file")
guard let symbol else { return nil }
return unsafeBitCast(symbol, to: ProfileWriteFn.self)
}