Skip to content

Commit e2d3a3f

Browse files
authored
Merge pull request #3287 from kkebo/enable-wasi-test-ci
[CI] Enable Wasm SDK tests
2 parents 2afc46d + 21c59ce commit e2d3a3f

File tree

7 files changed

+73
-34
lines changed

7 files changed

+73
-34
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@0.0.7
2020
with:
2121
enable_wasm_sdk_build: true
22+
wasm_sdk_build_command: "swift test -c release --explicit-target-dependency-import-check error --toolset Toolsets/wasi-test-toolset.json"
2223
linux_build_command: "swift test --explicit-target-dependency-import-check error"
2324
windows_build_command: "Invoke-Program swift test --explicit-target-dependency-import-check error"
2425
soundness:

Sources/_InstructionCounter/include/InstructionsExecuted.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
/// On macOS returns the number of instructions the process has executed since
1616
/// it was launched, on all other platforms returns 0.
17-
uint64_t getInstructionsExecuted();
17+
uint64_t getInstructionsExecuted(void);

Tests/SwiftParserTest/Assertions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ extension ParserTestCase {
757757
}
758758

759759
if !longTestsDisabled {
760-
DispatchQueue.concurrentPerform(iterations: Array(tree.tokens(viewMode: .all)).count) { tokenIndex in
760+
performConcurrentIfPossible(iterations: Array(tree.tokens(viewMode: .all)).count) { tokenIndex in
761761
let flippedTokenTree = TokenPresenceFlipper(flipTokenAtIndex: tokenIndex).rewrite(Syntax(tree))
762762
_ = ParseDiagnosticsGenerator.diagnostics(for: flippedTokenTree)
763763
Self.assertMutationRoundTrip(
@@ -776,7 +776,7 @@ extension ParserTestCase {
776776
replacements in
777777
return replacements.map { (offset, $0) }
778778
}
779-
DispatchQueue.concurrentPerform(iterations: mutations.count) { index in
779+
performConcurrentIfPossible(iterations: mutations.count) { index in
780780
let mutation = mutations[index]
781781
let alternateSource = MutatedTreePrinter.print(
782782
tree: Syntax(tree),

Tests/SwiftParserTest/ParserTests.swift

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Dispatch
1413
import SwiftParser
1514
import SwiftParserDiagnostics
1615
import SwiftSyntax
@@ -59,8 +58,8 @@ class ParserTests: ParserTestCase {
5958
name: String,
6059
path: URL,
6160
checkDiagnostics: Bool,
62-
shouldExclude: @Sendable (URL) -> Bool = { _ in false }
63-
) {
61+
shouldExclude: @escaping @Sendable (URL) -> Bool = { _ in false }
62+
) async throws {
6463
let fileURLs = FileManager.default
6564
.enumerator(at: path, includingPropertiesForKeys: nil)!
6665
.compactMap({ $0 as? URL })
@@ -71,16 +70,15 @@ class ParserTests: ParserTestCase {
7170
}
7271

7372
print("\(name) - processing \(fileURLs.count) source files")
74-
DispatchQueue.concurrentPerform(iterations: fileURLs.count) { fileURLIndex in
75-
let fileURL = fileURLs[fileURLIndex]
76-
if shouldExclude(fileURL) {
77-
return
78-
}
79-
80-
do {
81-
try Self.runParseTest(fileURL: fileURL, checkDiagnostics: checkDiagnostics)
82-
} catch {
83-
XCTFail("\(name): \(fileURL) failed due to \(error)")
73+
await withTaskGroup(of: Void.self) { group in
74+
for fileURL in fileURLs where !shouldExclude(fileURL) {
75+
group.addTask {
76+
do {
77+
try Self.runParseTest(fileURL: fileURL, checkDiagnostics: checkDiagnostics)
78+
} catch {
79+
XCTFail("\(name): \(fileURL) failed due to \(error)")
80+
}
81+
}
8482
}
8583
}
8684
}
@@ -90,14 +88,14 @@ class ParserTests: ParserTestCase {
9088
.deletingLastPathComponent()
9189
.deletingLastPathComponent()
9290

93-
func testSelfParse() throws {
91+
func testSelfParse() async throws {
9492
// Allow skipping the self parse test in local development environments
9593
// because it takes very long compared to all the other tests.
9694
try XCTSkipIf(longTestsDisabled)
9795
let currentDir =
9896
packageDir
9997
.appendingPathComponent("Sources")
100-
runParserTests(
98+
try await runParserTests(
10199
name: "Self-parse tests",
102100
path: currentDir,
103101
checkDiagnostics: true
@@ -107,14 +105,14 @@ class ParserTests: ParserTestCase {
107105
/// Test all of the files in the "test" directory of the main Swift compiler.
108106
/// This requires the Swift compiler to have been checked out into the "swift"
109107
/// directory alongside swift-syntax.
110-
func testSwiftTestsuite() throws {
108+
func testSwiftTestsuite() async throws {
111109
try XCTSkipIf(longTestsDisabled)
112110
let testDir =
113111
packageDir
114112
.deletingLastPathComponent()
115113
.appendingPathComponent("swift")
116114
.appendingPathComponent("test")
117-
runParserTests(
115+
try await runParserTests(
118116
name: "Swift tests",
119117
path: testDir,
120118
checkDiagnostics: false
@@ -124,14 +122,14 @@ class ParserTests: ParserTestCase {
124122
/// Test all of the files in the "validation-text" directory of the main
125123
/// Swift compiler. This requires the Swift compiler to have been checked
126124
/// out into the "swift" directory alongside swift-syntax.
127-
func testSwiftValidationTestsuite() throws {
125+
func testSwiftValidationTestsuite() async throws {
128126
try XCTSkipIf(longTestsDisabled)
129127
let testDir =
130128
packageDir
131129
.deletingLastPathComponent()
132130
.appendingPathComponent("swift")
133131
.appendingPathComponent("validation-test")
134-
runParserTests(
132+
try await runParserTests(
135133
name: "Swift validation tests",
136134
path: testDir,
137135
checkDiagnostics: false

Tests/SwiftParserTest/Utils.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,24 @@
1212

1313
@_spi(Testing) import SwiftParser
1414

15+
#if !os(WASI)
16+
import Dispatch
17+
#endif
18+
1519
func withParser<T>(source: String, _ body: (inout Parser) throws -> T) rethrows -> T {
1620
var source = source
1721
return try source.withUTF8 { buffer in
1822
var parser = Parser(buffer)
1923
return try body(&parser)
2024
}
2125
}
26+
27+
func performConcurrentIfPossible(iterations: Int, execute work: @Sendable (Int) -> Void) {
28+
#if os(WASI)
29+
for i in 0..<iterations {
30+
work(i)
31+
}
32+
#else
33+
DispatchQueue.concurrentPerform(iterations: iterations, execute: work)
34+
#endif
35+
}

Tests/SwiftSyntaxTest/MultithreadingTests.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,23 @@ extension SyntaxProtocol {
2323
// Marked as `@unchecked Sendable` to work around rdar://130094927, which complains about `MultithreadingTests` not conforming to
2424
// `Sendable`.
2525
class MultithreadingTests: XCTestCase, @unchecked Sendable {
26-
public func testPathological() {
26+
public func testPathological() async {
2727
let tuple = TupleTypeSyntax(
2828
leftParen: .leftParenToken(),
2929
elements: TupleTypeElementListSyntax([]),
3030
rightParen: .rightParenToken()
3131
)
3232

33-
DispatchQueue.concurrentPerform(iterations: 100) { _ in
34-
XCTAssertEqual(tuple.leftParen, tuple.leftParen)
33+
await withTaskGroup(of: Void.self) { group in
34+
for _ in 0..<100 {
35+
group.addTask {
36+
XCTAssertEqual(tuple.leftParen, tuple.leftParen)
37+
}
38+
}
3539
}
3640
}
3741

38-
public func testConcurrentMutation() {
42+
public func testConcurrentMutation() async {
3943
// 'base.member()'
4044
let methodCall = FunctionCallExprSyntax(
4145
calledExpression: MemberAccessExprSyntax(
@@ -50,15 +54,19 @@ class MultithreadingTests: XCTestCase, @unchecked Sendable {
5054
rightParen: .rightParenToken()
5155
)
5256

53-
DispatchQueue.concurrentPerform(iterations: 100) { i in
54-
var copied = methodCall
55-
copied
56-
.calledExpression[as: MemberAccessExprSyntax.self]
57-
.base![as: DeclReferenceExprSyntax.self]
58-
.baseName = .identifier("ident\(i)")
59-
copied = copied.with(\.leadingTrivia, [.newlines(1)])
57+
await withTaskGroup(of: Void.self) { group in
58+
for i in 0..<100 {
59+
group.addTask {
60+
var copied = methodCall
61+
copied
62+
.calledExpression[as: MemberAccessExprSyntax.self]
63+
.base![as: DeclReferenceExprSyntax.self]
64+
.baseName = .identifier("ident\(i)")
65+
copied = copied.with(\.leadingTrivia, [.newlines(1)])
6066

61-
XCTAssertEqual(copied.description, "\nident\(i).member()")
67+
XCTAssertEqual(copied.description, "\nident\(i).member()")
68+
}
69+
}
6270
}
6371
}
6472

Toolsets/wasi-test-toolset.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"linker": {
4+
"extraCLIOptions": [
5+
"-z", "stack-size=16777216"
6+
]
7+
},
8+
"testRunner": {
9+
"path": "/usr/bin/env",
10+
"extraCLIOptions": [
11+
"wasmkit",
12+
"run",
13+
"--dir", ".build",
14+
"--dir", "/",
15+
"--stack-size", "16777216"
16+
]
17+
}
18+
}

0 commit comments

Comments
 (0)