-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathOptimizationRemarksTests.swift
72 lines (63 loc) · 3.46 KB
/
OptimizationRemarksTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Foundation
import Testing
import SWBUtil
import SWBCore
import SWBTestSupport
@Suite(.enabled(if: Diagnostic.libRemarksAvailable, "Skipping because libRemarks.dylib is not available."))
fileprivate struct OptimizationRemarksTests: CoreBasedTests {
let xcode: InstalledXcode
let infoLookup: any PlatformInfoLookup
init() async throws {
self.xcode = try await InstalledXcode.currentlySelected()
self.infoLookup = try await Self.makeCore()
}
fileprivate func compileObjectFileWithRemarks(path basePath: Path, useSwift: Bool, infoLookup: any PlatformInfoLookup) async throws -> Path {
let buildDir = basePath.join("build")
let srcDir = basePath.join("src")
try localFS.createDirectory(srcDir, recursive: true)
try localFS.createDirectory(buildDir, recursive: true)
let objectPath = buildDir.join("source.o")
let target = BuildVersion.Platform.macOS.targetTripleString(arch: "x86_64", deploymentTarget: Version(10, 15), infoLookup: infoLookup)
if useSwift {
let sourcePath = srcDir.join("source.swift")
try localFS.write(sourcePath, contents: "public func callee() -> Int { return 0 }\npublic func favorite() -> Int { return callee()}\n")
_ = try await xcode.xcrun(["-sdk", "macosx", "swiftc", "-target", target, "-module-name", "swiftremarks", "-o", objectPath.str, "-c", sourcePath.str, "-save-optimization-record=bitstream", "-O", "-wmo", "-suppress-warnings"])
} else {
let sourcePath = srcDir.join("source.c")
try localFS.write(sourcePath, contents: "int main() { return 0; }\n")
_ = try await xcode.xcrun(["-sdk", "macosx", "clang", "-target", target, "-o", objectPath.str, "-c", sourcePath.str, "-fsave-optimization-record=bitstream", "-w"])
}
return objectPath
}
/// Test that optimization remarks generated by clang are supported.
@Test
func optimizationRemarksClang() async throws {
try await withTemporaryDirectory { tmpDir -> Void in
let objectFile = try await compileObjectFileWithRemarks(path: tmpDir, useSwift: false, infoLookup: infoLookup)
let diagnostics = try Diagnostic.remarks(forObjectPath: objectFile, fs: localFS, workingDirectory: .root)
#expect(!diagnostics.isEmpty)
#expect(diagnostics.allSatisfy { diag in return diag.behavior == .remark })
}
}
/// Test that optimization remarks generated by swift are supported.
@Test
func optimizationRemarksSwift() async throws {
try await withTemporaryDirectory { tmpDir -> Void in
let objectFile = try await compileObjectFileWithRemarks(path: tmpDir, useSwift: true, infoLookup: infoLookup)
let diagnostics = try Diagnostic.remarks(forObjectPath: objectFile, fs: localFS, workingDirectory: .root)
#expect(!diagnostics.isEmpty)
#expect(diagnostics.allSatisfy { diag in return diag.behavior == .remark })
}
}
}