Skip to content

Commit 3935eba

Browse files
committed
add multiple test runs, one with and one without the address sanitizer
1 parent b2b9d45 commit 3935eba

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

.github/workflows/swift.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,26 @@ jobs:
9797
LDK_C_BINDINGS_BASE: /home/runner/work/ldk-swift/ldk-swift/ldk-c-bindings
9898
LLVM_CLANG_ASAN_PATH: /usr/lib/llvm-11/lib/clang/11.0.0/lib/linux/libclang_rt.asan-x86_64.a
9999
RUST_BACKTRACE: 1
100-
- name: Test Swift bindings package
100+
- name: Test Swift bindings package without address sanitizer
101101
run: |
102+
python ci/toggle_address_sanitation_library.py off
102103
cd ci/LDKSwift
103104
../../swift-5.6-RELEASE-ubuntu20.04/usr/bin/swift test -v
105+
cd ../../
104106
env:
105107
LDK_C_BINDINGS_BASE: /home/runner/work/ldk-swift/ldk-swift/ldk-c-bindings
106108
LLVM_CLANG_ASAN_PATH: /usr/lib/llvm-11/lib/clang/11.0.0/lib/linux/libclang_rt.asan-x86_64.a
107109
RUST_BACKTRACE: 1
110+
- name: Test Swift bindings package with address sanitizer
111+
run: |
112+
python ci/toggle_address_sanitation_library.py on
113+
cd ci/LDKSwift
114+
../../swift-5.6-RELEASE-ubuntu20.04/usr/bin/swift test -v
115+
env:
116+
LDK_C_BINDINGS_BASE: /home/runner/work/ldk-swift/ldk-swift/ldk-c-bindings
117+
LLVM_CLANG_ASAN_PATH: /usr/lib/llvm-11/lib/clang/11.0.0/lib/linux/libclang_rt.asan-x86_64.a
118+
RUST_BACKTRACE: 1
119+
108120
- name: Check that the latest headers are in the swift repo
109121
run: |
110122
git diff --exit-code

ci/LDKSwift/Package.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let package = Package(
1313
// .library(name: "LDKSwift", type: .dynamic, targets: ["LDKSwift"])
1414
],
1515
dependencies: [
16-
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0")
16+
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0"..<"3.0.0")
1717
],
1818
targets: [
1919
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
@@ -46,17 +46,15 @@ let package = Package(
4646
swiftSettings: nil,
4747
linkerSettings: [
4848
.linkedLibrary(String(utf8String: getenv("LDK_C_BINDINGS_BASE")!)! + "/lightning-c-bindings/target/debug/libldk.a"),
49-
// .linkedLibrary(String(utf8String: getenv("LDK_C_BINDINGS_BASE") ?? "~/Developer/ldk-c-bindings")! + "/lightning-c-bindings/target/debug/libldk.a"),
50-
// .linkedLibrary("/usr/lib/llvm-11/lib/clang/11.0.0/lib/linux/libclang_rt.asan-x86_64.a")
51-
.linkedLibrary(String(utf8String: getenv("LLVM_CLANG_ASAN_PATH")!)!)
49+
.linkedLibrary(String(utf8String: getenv("LLVM_CLANG_ASAN_PATH")!)!),
5250
]),
5351
.testTarget(
5452
name: "LDKSwiftTests",
5553
dependencies: [
56-
"LDKSwift",
57-
"LDKHeaders",
58-
.product(name: "Crypto", package: "swift-crypto")
59-
],
54+
"LDKSwift",
55+
"LDKHeaders",
56+
.product(name: "Crypto", package: "swift-crypto")
57+
],
6058
path: nil,
6159
exclude: [],
6260
// exclude: ["SampleTest.swift"],
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import re
2+
import os
3+
import sys
4+
5+
directory_path = os.path.dirname(os.path.realpath(__file__))
6+
file_path = f'{directory_path}/LDKSwift/Package.swift'
7+
if len(sys.argv) != 2:
8+
sys.exit('Usage: python3 toggle_address_sanitation_library.py [on/off]')
9+
10+
if not os.path.isfile(file_path):
11+
sys.exit(f'Package.swift file is missing')
12+
13+
should_enable_string = sys.argv[1]
14+
if not should_enable_string.lower() in ['on', 'off']:
15+
sys.exit(f'{should_enable_string} is not a valid on/off value')
16+
17+
should_enable = True if should_enable_string.lower() == 'on' else False
18+
19+
file_in = open(file_path, 'rt', encoding='utf-8')
20+
original_contents = file_in.read()
21+
file_in.close()
22+
23+
regex = re.compile("(\/\/)?([^\S\r\n]*)(\.linkedLibrary\(String\(utf8String: getenv\(\"LLVM_CLANG_ASAN_PATH\"\)!\)!\))", re.MULTILINE)
24+
matches = regex.search(original_contents)
25+
26+
comment_prefix = ''
27+
if not should_enable:
28+
comment_prefix = '//'
29+
30+
toggle_result = regex.sub(f'\g<2>{comment_prefix}\g<3>', original_contents)
31+
32+
file_out = open(file_path, 'wt', encoding='utf-8')
33+
file_out.write(toggle_result)
34+
file_out.close()

0 commit comments

Comments
 (0)