Skip to content

Multithreading tests and diagnostics #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ extension Driver {
}

extension Diagnostic.Message {
public static func error_i_mode(_ driverKind: DriverKind) -> Diagnostic.Message {
static func error_i_mode(_ driverKind: DriverKind) -> Diagnostic.Message {
.error(
"""
the flag '-i' is no longer required and has been removed; \
Expand All @@ -731,17 +731,14 @@ extension Driver {

// Make sure we have a non-negative integer value.
guard let numThreads = Int(numThreadsArg.asSingle), numThreads >= 0 else {
diagnosticsEngine.emit(Diagnostic.Message.error_invalid_arg_value(arg: .numThreads, value: numThreadsArg.asSingle))
diagnosticsEngine.emit(.error_invalid_arg_value(arg: .numThreads, value: numThreadsArg.asSingle))
return 0
}

#if false
// FIXME: Check for batch mode.
if false {
if case .batchCompile = compilerMode {
diagnosticsEngine.emit(.warning_cannot_multithread_batch_mode)
return 0
}
#endif

return numThreads
}
Expand Down
51 changes: 50 additions & 1 deletion Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,59 @@ final class SwiftDriverTests: XCTestCase {

func testPrimaryOutputKindsDiagnostics() throws {
try assertDriverDiagnostics(args: "swift", "-i") {
$1.expect(.error_i_mode(.interactive))
$1.expect(.error("the flag '-i' is no longer required and has been removed; use 'swift input-filename'"))
}
}

func testMultithreading() throws {

XCTAssertEqual(try Driver(args: ["swiftc"]).numThreads, 0)

XCTAssertEqual(try Driver(args: ["swiftc", "-num-threads", "4"]).numThreads, 4)

XCTAssertEqual(try Driver(args: ["swiftc", "-num-threads", "0"]).numThreads, 0)

XCTAssertEqual(try Driver(args: ["swiftc", "-num-threads", "-1"]).numThreads, 0)

XCTAssertEqual(try Driver(args: ["swiftc", "-enable-batch-mode", "-num-threads", "4"]).numThreads, 0)

XCTAssertNil(try Driver(args: ["swiftc"]).numParallelJobs)

XCTAssertEqual(try Driver(args: ["swiftc", "-j", "4"]).numParallelJobs, 4)

XCTAssertNil(try Driver(args: ["swiftc", "-j", "0"]).numParallelJobs)

XCTAssertEqual(
try Driver(
args: ["swiftc", "-j", "4", "-target", "x86_64-apple-macosx10.15"],
env: ["SWIFTC_MAXIMUM_DETERMINISM": "1"]
).numParallelJobs,
1
)
}

func testMultithreadingDiagnostics() throws {

try assertDriverDiagnostics(args: "swift", "-num-threads", "-1") {
$1.expect(.error_invalid_arg_value(arg: .numThreads, value: "-1"))
}

try assertDriverDiagnostics(args: "swiftc", "-enable-batch-mode", "-num-threads", "4") {
$1.expect(.warning("ignoring -num-threads argument; cannot multithread batch mode"))
}

try assertDriverDiagnostics(args: "swiftc", "-j", "0") {
$1.expect(.error_invalid_arg_value(arg: .j, value: "0"))
}

try assertDriverDiagnostics(
args: "swiftc", "-j", "8", "-target", "x86_64-apple-macosx10.15",
env: ["SWIFTC_MAXIMUM_DETERMINISM": "1"]
) {
$1.expect(.remark("SWIFTC_MAXIMUM_DETERMINISM overriding -j"))
}
}

func testDebugSettings() throws {
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module") { driver in
XCTAssertNil(driver.debugInfoLevel)
Expand Down