Skip to content

Commit b1ac38f

Browse files
Add tests for llvm-objdump parsing
1 parent 323d0ae commit b1ac38f

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

Package.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,10 @@ let package = Package(
955955
name: "SwiftFixItTests",
956956
dependencies: ["SwiftFixIt", "_InternalTestSupport"]
957957
),
958+
.testTarget(
959+
name: "BinarySymbolsTests",
960+
dependencies: ["BinarySymbols", "_InternalTestSupport"]
961+
),
958962
.testTarget(
959963
name: "XCBuildSupportTests",
960964
dependencies: ["XCBuildSupport", "_InternalTestSupport", "_InternalBuildTestSupport"],
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import Testing
2+
import BinarySymbols
3+
import Basics
4+
5+
@Suite
6+
struct LLVMObjdumpSymbolProviderTests {
7+
private func getSymbols(_ dump: String) throws -> ReferencedSymbols {
8+
var symbols = ReferencedSymbols()
9+
// Placeholder executable path since we won't actually run it
10+
try LLVMObjdumpSymbolProvider(objdumpPath: AbsolutePath.root).parse(output: dump, symbols: &symbols)
11+
return symbols
12+
}
13+
14+
@Test
15+
func ignoresHeaderLines() throws {
16+
let output = try getSymbols(
17+
"""
18+
19+
/usr/lib/aarch64-linux-gnu/libc.so.6: file format elf64-littleaarch64
20+
21+
SYMBOL TABLE:
22+
23+
DYNAMIC SYMBOL TABLE:
24+
"""
25+
)
26+
27+
#expect(output.defined.isEmpty)
28+
#expect(output.undefined.isEmpty)
29+
}
30+
31+
@Test
32+
func detectsDefinedSymbol() throws {
33+
let output = try getSymbols("00000000000e0618 g DF .text 0000000000000018 GLIBC_2.17 __ppoll_chk")
34+
35+
#expect(output.defined.contains("__ppoll_chk"))
36+
#expect(output.undefined.isEmpty)
37+
}
38+
39+
@Test
40+
func detectsUndefinedSymbol() throws {
41+
let output = try getSymbols("0000000000000000 *UND* 0000000000000000 calloc")
42+
43+
#expect(output.defined.isEmpty)
44+
#expect(output.undefined.contains("calloc"))
45+
}
46+
47+
@Test
48+
func treatsCommonSymbolsAsDefined() throws {
49+
let output = try getSymbols("0000000000000004 O *COM* 0000000000000004 __libc_enable_secure_decided")
50+
51+
#expect(output.defined.contains("__libc_enable_secure_decided"))
52+
#expect(output.undefined.isEmpty)
53+
}
54+
}

0 commit comments

Comments
 (0)