Skip to content

Generalize disabled tests to also work on Apple Silicon #603

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 4 commits into from
Apr 28, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name A
import Swift
public func FuncA() { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name E
import Swift
public func FuncE() { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name G
import Swift
import E
public func FuncG() { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name H
import Swift
import A
import E
import F
import G
public func FuncH() { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -parse-stdlib -module-name Swift
60 changes: 31 additions & 29 deletions Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
// We only care about prebuilt modules in macOS.
#if os(macOS)
func testPrebuiltModuleGenerationJobs() throws {
#if arch(arm64)
// Disabled on Apple Silicon
// rdar://76609781
throw XCTSkip()
#endif

func getInputModules(_ job: Job) -> [String] {
return job.inputs.map { input in
return input.file.absolutePath!.parentDirectory.basenameWithoutExt
Expand Down Expand Up @@ -791,7 +785,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
job.outputs[0].file.basenameWithoutExt == basenameWithoutExt
}
}

let packageRootPath = URL(fileURLWithPath: #file).pathComponents
.prefix(while: { $0 != "Tests" }).joined(separator: "/").dropFirst()
let testInputsPath = packageRootPath + "/TestInputs"
Expand All @@ -801,12 +794,12 @@ final class ExplicitModuleBuildTests: XCTestCase {
let interfaceMap = try collector.collectSwiftInterfaceMap()

// Check interface map always contain everything
XCTAssertTrue(interfaceMap["Swift"]!.count == 2)
XCTAssertTrue(interfaceMap["A"]!.count == 2)
XCTAssertTrue(interfaceMap["E"]!.count == 2)
XCTAssertTrue(interfaceMap["Swift"]!.count == 3)
XCTAssertTrue(interfaceMap["A"]!.count == 3)
XCTAssertTrue(interfaceMap["E"]!.count == 3)
XCTAssertTrue(interfaceMap["F"]!.count == 3)
XCTAssertTrue(interfaceMap["G"]!.count == 2)
XCTAssertTrue(interfaceMap["H"]!.count == 2)
XCTAssertTrue(interfaceMap["G"]!.count == 3)
XCTAssertTrue(interfaceMap["H"]!.count == 3)

try withTemporaryDirectory { path in
let main = path.appending(component: "testPrebuiltModuleGenerationJobs.swift")
Expand All @@ -821,7 +814,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
var driver = try Driver(args: ["swiftc", main.pathString,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to always use the host triple? Can we give a specific -target here to make the test arch-agnostic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having a hard time reproducing the original CI failures for this test so I'm investigating why that may be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally reproduced this locally, and the failure is because these are some of the few tests actually need to link to succeed (as opposed to just invoking the driver and inspecting the generated jobs). And when being tested with a just-built compiler, we do not have a fully-formed fat toolchain, we just have the host slice of everything.

So I think in this case it's simpler to just compile for the host to make sure these tests are still exercised on whatever platform we are testing on.

"-sdk", mockSDKPath,
])

let (jobs, danglingJobs) = try driver.generatePrebuitModuleGenerationJobs(with: interfaceMap,
into: VirtualPath(path: "/tmp/").absolutePath!,
exhaustive: true)
Expand All @@ -830,22 +822,30 @@ final class ExplicitModuleBuildTests: XCTestCase {
XCTAssertTrue(danglingJobs.allSatisfy { job in
job.moduleName == "MissingKit"
})
XCTAssertTrue(jobs.count == 13)
XCTAssertTrue(jobs.count == 18)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkcsgexi , I may not have the full context for some of the things being tested here so please take a look to ensure it's still testing the right thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this! The test updates look correct to me.

XCTAssertTrue(jobs.allSatisfy {$0.outputs.count == 1})
XCTAssertTrue(jobs.allSatisfy {$0.kind == .compile})
XCTAssertTrue(jobs.allSatisfy {$0.commandLine.contains(.flag("-compile-module-from-interface"))})
let HJobs = jobs.filter { $0.moduleName == "H"}
XCTAssertTrue(HJobs.count == 2)
XCTAssertTrue(getInputModules(HJobs[0]) == ["A", "E", "F", "G", "Swift"])
XCTAssertTrue(HJobs.count == 3)
// arm64
XCTAssertTrue(getInputModules(HJobs[0]) == ["A", "A", "E", "E", "F", "F", "G", "G", "Swift", "Swift"])
// arm64e
XCTAssertTrue(getInputModules(HJobs[1]) == ["A", "E", "F", "G", "Swift"])
// x86_64
XCTAssertTrue(getInputModules(HJobs[2]) == ["A", "E", "F", "G", "Swift"])
XCTAssertTrue(getOutputName(HJobs[0]) != getOutputName(HJobs[1]))
XCTAssertTrue(getOutputName(HJobs[1]) != getOutputName(HJobs[2]))
checkInputOutputIntegrity(HJobs[0])
checkInputOutputIntegrity(HJobs[1])
checkInputOutputIntegrity(HJobs[2])
let GJobs = jobs.filter { $0.moduleName == "G"}
XCTAssertTrue(GJobs.count == 2)
XCTAssertTrue(getInputModules(GJobs[0]) == ["E", "Swift"])
XCTAssertTrue(GJobs.count == 3)
XCTAssertTrue(getInputModules(GJobs[0]) == ["E", "E", "Swift", "Swift"])
XCTAssertTrue(getInputModules(GJobs[1]) == ["E", "Swift"])
XCTAssertTrue(getInputModules(GJobs[2]) == ["E", "Swift"])
XCTAssertTrue(getOutputName(GJobs[0]) != getOutputName(GJobs[1]))
XCTAssertTrue(getOutputName(GJobs[1]) != getOutputName(GJobs[2]))
checkInputOutputIntegrity(GJobs[0])
checkInputOutputIntegrity(GJobs[1])
}
Expand All @@ -857,28 +857,33 @@ final class ExplicitModuleBuildTests: XCTestCase {
var driver = try Driver(args: ["swiftc", main.pathString,
"-sdk", mockSDKPath,
])

let (jobs, danglingJobs) = try driver.generatePrebuitModuleGenerationJobs(with: interfaceMap,
into: VirtualPath(path: "/tmp/").absolutePath!,
exhaustive: false)

XCTAssertTrue(danglingJobs.isEmpty)
XCTAssertTrue(jobs.count == 13)
XCTAssertTrue(jobs.count == 18)
XCTAssertTrue(jobs.allSatisfy {$0.outputs.count == 1})
XCTAssertTrue(jobs.allSatisfy {$0.kind == .compile})
XCTAssertTrue(jobs.allSatisfy {$0.commandLine.contains(.flag("-compile-module-from-interface"))})
let HJobs = jobs.filter { $0.moduleName == "H"}
XCTAssertTrue(HJobs.count == 2)
XCTAssertTrue(getInputModules(HJobs[0]) == ["A", "E", "F", "G", "Swift"])
XCTAssertTrue(HJobs.count == 3)
// arm64
XCTAssertTrue(getInputModules(HJobs[0]) == ["A", "A", "E", "E", "F", "F", "G", "G", "Swift", "Swift"])
// arm64e
XCTAssertTrue(getInputModules(HJobs[1]) == ["A", "E", "F", "G", "Swift"])
// x86_64
XCTAssertTrue(getInputModules(HJobs[2]) == ["A", "E", "F", "G", "Swift"])
XCTAssertTrue(getOutputName(HJobs[0]) != getOutputName(HJobs[1]))
checkInputOutputIntegrity(HJobs[0])
checkInputOutputIntegrity(HJobs[1])
let GJobs = jobs.filter { $0.moduleName == "G"}
XCTAssertTrue(GJobs.count == 2)
XCTAssertTrue(getInputModules(GJobs[0]) == ["E", "Swift"])
XCTAssertTrue(GJobs.count == 3)
XCTAssertTrue(getInputModules(GJobs[0]) == ["E", "E", "Swift", "Swift"])
XCTAssertTrue(getInputModules(GJobs[1]) == ["E", "Swift"])
XCTAssertTrue(getInputModules(GJobs[2]) == ["E", "Swift"])
XCTAssertTrue(getOutputName(GJobs[0]) != getOutputName(GJobs[1]))
XCTAssertTrue(getOutputName(GJobs[1]) != getOutputName(GJobs[2]))
checkInputOutputIntegrity(GJobs[0])
checkInputOutputIntegrity(GJobs[1])
}
Expand All @@ -890,13 +895,12 @@ final class ExplicitModuleBuildTests: XCTestCase {
var driver = try Driver(args: ["swiftc", main.pathString,
"-sdk", mockSDKPath,
])

let (jobs, danglingJobs) = try driver.generatePrebuitModuleGenerationJobs(with: interfaceMap,
into: VirtualPath(path: "/tmp/").absolutePath!,
exhaustive: false)

XCTAssertTrue(danglingJobs.isEmpty)
XCTAssert(jobs.count == 2)
XCTAssert(jobs.count == 3)
XCTAssert(jobs.allSatisfy { $0.moduleName == "Swift" })
}
try withTemporaryDirectory { path in
Expand All @@ -907,13 +911,12 @@ final class ExplicitModuleBuildTests: XCTestCase {
var driver = try Driver(args: ["swiftc", main.pathString,
"-sdk", mockSDKPath,
])

let (jobs, danglingJobs) = try driver.generatePrebuitModuleGenerationJobs(with: interfaceMap,
into: VirtualPath(path: "/tmp/").absolutePath!,
exhaustive: false)

XCTAssertTrue(danglingJobs.isEmpty)
XCTAssertTrue(jobs.count == 7)
XCTAssertTrue(jobs.count == 9)
jobs.forEach({ job in
// Check we don't pull in other modules than A, F and Swift
XCTAssertTrue(["A", "F", "Swift"].contains(job.moduleName))
Expand All @@ -928,7 +931,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
var driver = try Driver(args: ["swiftc", main.pathString,
"-sdk", mockSDKPath,
])

let (jobs, _) = try driver.generatePrebuitModuleGenerationJobs(with: interfaceMap,
into: VirtualPath(path: "/tmp/").absolutePath!,
exhaustive: false)
Expand Down
52 changes: 20 additions & 32 deletions Tests/SwiftDriverTests/JobExecutorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,8 @@ extension DarwinToolchain {

final class JobExecutorTests: XCTestCase {
func testDarwinBasic() throws {
#if os(macOS)
#if arch(arm64)
// Disabled on Apple Silicon
// rdar://76609781
throw XCTSkip()
#endif

#if os(macOS)
let hostTriple = try Driver(args: ["swiftc", "test.swift"]).hostTriple
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(),
processSet: ProcessSet(),
fileSystem: localFileSystem,
Expand Down Expand Up @@ -142,7 +137,7 @@ final class JobExecutorTests: XCTestCase {
"-primary-file",
.path(inputs[ "foo"]!.file),
.path(inputs["main"]!.file),
"-target", "x86_64-apple-darwin18.7.0",
"-target", .flag(hostTriple.triple),
"-enable-objc-interop",
"-sdk",
.path(.absolute(try toolchain.sdk.get())),
Expand All @@ -164,7 +159,7 @@ final class JobExecutorTests: XCTestCase {
.path(.relative(RelativePath("foo.swift"))),
"-primary-file",
.path(inputs["main"]!.file),
"-target", "x86_64-apple-darwin18.7.0",
"-target", .flag(hostTriple.triple),
"-enable-objc-interop",
"-sdk",
.path(.absolute(try toolchain.sdk.get())),
Expand All @@ -185,9 +180,7 @@ final class JobExecutorTests: XCTestCase {
.path(.temporary(RelativePath("main.o"))),
.path(.absolute(try toolchain.clangRT.get())),
"-syslibroot", .path(.absolute(try toolchain.sdk.get())),
"-lobjc", "-lSystem", "-arch", "x86_64",
"-force_load", .path(.absolute(try toolchain.compatibility50.get())),
"-force_load", .path(.absolute(try toolchain.compatibilityDynamicReplacements.get())),
"-lobjc", "-lSystem", "-arch", .flag(hostTriple.archName),
"-L", .path(.absolute(try toolchain.resourcesDirectory.get())),
"-L", .path(.absolute(try toolchain.sdkStdlib(sdk: toolchain.sdk.get()))),
"-rpath", "/usr/lib/swift", "-macosx_version_min", "10.14.0", "-no_objc_category_merging", "-o",
Expand All @@ -200,7 +193,6 @@ final class JobExecutorTests: XCTestCase {
primaryInputs: [],
outputs: [.init(file: VirtualPath.relative(RelativePath("main")).intern(), type: .image)]
)

let delegate = JobCollectingDelegate()
let executor = MultiJobExecutor(workload: .all([compileFoo, compileMain, link]),
resolver: resolver, executorDelegate: delegate, diagnosticsEngine: DiagnosticsEngine())
Expand All @@ -220,12 +212,8 @@ final class JobExecutorTests: XCTestCase {

/// Ensure the executor is capable of forwarding its standard input to the compile job that requires it.
func testInputForwarding() throws {
#if os(macOS)
#if arch(arm64)
// Disabled on Apple Silicon
// rdar://76609781
throw XCTSkip()
#endif
#if os(macOS)
let hostTriple = try Driver(args: ["swiftc", "test.swift"]).hostTriple
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(),
processSet: ProcessSet(),
fileSystem: localFileSystem,
Expand All @@ -243,7 +231,7 @@ final class JobExecutorTests: XCTestCase {
"-primary-file",
// This compile job must read the input from STDIN
"-",
"-target", "x86_64-apple-darwin18.7.0",
"-target", .flag(hostTriple.triple),
"-enable-objc-interop",
"-sdk",
.path(.absolute(try toolchain.sdk.get())),
Expand All @@ -263,9 +251,7 @@ final class JobExecutorTests: XCTestCase {
.path(.temporary(RelativePath("main.o"))),
.path(.absolute(try toolchain.clangRT.get())),
"-syslibroot", .path(.absolute(try toolchain.sdk.get())),
"-lobjc", "-lSystem", "-arch", "x86_64",
"-force_load", .path(.absolute(try toolchain.compatibility50.get())),
"-force_load", .path(.absolute(try toolchain.compatibilityDynamicReplacements.get())),
"-lobjc", "-lSystem", "-arch", .flag(hostTriple.archName),
"-L", .path(.absolute(try toolchain.resourcesDirectory.get())),
"-L", .path(.absolute(try toolchain.sdkStdlib(sdk: toolchain.sdk.get()))),
"-rpath", "/usr/lib/swift", "-macosx_version_min", "10.14.0", "-no_objc_category_merging",
Expand Down Expand Up @@ -455,13 +441,16 @@ final class JobExecutorTests: XCTestCase {
}
}

func testSaveTemps() throws {
#if os(macOS) && arch(arm64)
// Disabled on Apple Silicon
// rdar://76609781
throw XCTSkip()
private func getHostToolchainSdkArg(_ executor: SwiftDriverExecutor) throws -> [String] {
#if os(macOS)
let toolchain = DarwinToolchain(env: ProcessEnv.vars, executor: executor)
return try ["-sdk", toolchain.sdk.get().pathString]
#else
return []
#endif
}

func testSaveTemps() throws {
do {
try withTemporaryDirectory { path in
let main = path.appending(component: "main.swift")
Expand All @@ -476,7 +465,7 @@ final class JobExecutorTests: XCTestCase {
let outputPath = path.appending(component: "finalOutput")
var driver = try Driver(args: ["swiftc", main.pathString,
"-driver-filelist-threshold", "0",
"-o", outputPath.pathString],
"-o", outputPath.pathString] + getHostToolchainSdkArg(executor),
env: ProcessEnv.vars,
diagnosticsEngine: diags,
fileSystem: localFileSystem,
Expand Down Expand Up @@ -514,7 +503,7 @@ final class JobExecutorTests: XCTestCase {
var driver = try Driver(args: ["swiftc", main.pathString,
"-save-temps",
"-driver-filelist-threshold", "0",
"-o", outputPath.pathString],
"-o", outputPath.pathString] + getHostToolchainSdkArg(executor),
env: ProcessEnv.vars,
diagnosticsEngine: diags,
fileSystem: localFileSystem,
Expand Down Expand Up @@ -552,7 +541,7 @@ final class JobExecutorTests: XCTestCase {
var driver = try Driver(args: ["swiftc", main.pathString,
"-driver-filelist-threshold", "0",
"-Xfrontend", "-debug-crash-immediately",
"-o", outputPath.pathString],
"-o", outputPath.pathString] + getHostToolchainSdkArg(executor),
env: ProcessEnv.vars,
diagnosticsEngine: diags,
fileSystem: localFileSystem,
Expand All @@ -572,6 +561,5 @@ final class JobExecutorTests: XCTestCase {
)
}
}

}
}