Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135import Foundationimport Testing
@testable import ParcelDev
struct MeasurementABTests { @Test func gatesAndReportOnly() throws { let fixture = try MeasurementFixture() defer { fixture.cleanup() } func paired(_ base: String, _ head: String) throws -> MeasurementAB.Summary { try MeasurementSamples.paired(fixture, base: base, head: head) } let good = try paired(MeasurementSamples.report(), MeasurementSamples.report(1.02)) #expect(good.passed) #expect(good.bootstrapResamples == 10_000) #expect(good.results[0].minimumNanosecondsRatio95CI == [1.02, 1.02]) #expect( try !paired( MeasurementSamples.report(), MeasurementSamples.report().replacingOccurrences(of: "1000.0", with: "1031.0") ).passed) #expect( try !paired( MeasurementSamples.report(source: "cpu-only"), MeasurementSamples.report(1.06, source: "cpu-only") ).passed) #expect( try paired(MeasurementSamples.report(reporting: true), MeasurementSamples.report(3, reporting: true)).passed ) #expect( try paired(MeasurementSamples.report(metric: "wall"), MeasurementSamples.report(3, metric: "wall")).passed) let wallBase = MeasurementSamples.report(metric: "wall").replacingOccurrences( of: "\"counterSource\":\"selfcounts\",\"checksum\"", with: "\"counterSource\":\"smoke\",\"checksum\"") let wallHead = MeasurementSamples.report(3, metric: "wall").replacingOccurrences( of: "\"counterSource\":\"selfcounts\",\"checksum\"", with: "\"counterSource\":\"smoke\",\"checksum\"") #expect(try !paired(wallBase, wallHead).results[0].gating) #expect(try paired(MeasurementSamples.report(), MeasurementSamples.report(1.03)).passed) var rng = MeasurementAB.BootstrapRandom() #expect(rng.next() == 0.8444218515250481) #expect(rng.next() == 0.7579544029403025) }
@Test func incompatibleAndMalformedData() throws { let fixture = try MeasurementFixture() defer { fixture.cleanup() } let original = MeasurementSamples.report() let changes = [ original.replacingOccurrences(of: "\"version\":5", with: "\"version\":4"), original.replacingOccurrences(of: "\"osBuild\":\"test\"", with: "\"osBuild\":\"other\""), MeasurementSamples.report(checksum: 18), original.replacingOccurrences(of: "layout/test/10", with: "other"), original.replacingOccurrences(of: "\"instructionsPerOp\":1000.0", with: "\"instructionsPerOp\":null"), original.replacingOccurrences(of: "\"checksum\":17", with: "\"checksum\":true"), original.replacingOccurrences(of: "\"cores\":8", with: "\"cores\":false"), original.replacingOccurrences(of: "\"minimumNanoseconds\":100.0", with: "\"minimumNanoseconds\":0"), original.replacingOccurrences(of: "\"reportingOnly\":false", with: "\"reportingOnly\":0"), ] for changed in changes { #expect(throws: (any Error).self) { try MeasurementSamples.paired(fixture, base: original, head: changed) } } #expect(throws: (any Error).self) { try MeasurementAB.compare(base: [], head: []) } try fixture.write("legacy.json", "{\"version\":4}") #expect(throws: DevError.self) { try MeasurementAB.read(fixture.work.appendingPathComponent("legacy.json").path) } let checksum = 9_007_199_254_740_993 let result = try MeasurementSamples.paired( fixture, base: MeasurementSamples.report(checksum: checksum), head: MeasurementSamples.report(checksum: checksum)) let data = try MeasurementTools.write(result, output: nil) #expect(String(decoding: data, as: UTF8.self).contains("9007199254740993")) #expect(String(decoding: data, as: UTF8.self).contains("\"budget\" : null")) }
@Test func operationalOverlayAndAlternation() throws { var fixture = try MeasurementFixture() defer { fixture.cleanup() } try fixture.write("project/Tests/ParcelPerformanceTests/harness.swift", "base measurement") try fixture.write("project/Sources/production.swift", "base production") try fixture.write("project/Package.swift", "base manifest") try fixture.repository() try fixture.write("project/Tests/ParcelPerformanceTests/harness.swift", "head measurement") try fixture.write("project/Package.swift", "head manifest") try fixture.write("project/Sources/ParcelDev/tool.swift", "head tooling") try fixture.write("project/Sources/parcel-dev/main.swift", "head tooling entry point") try fixture.write("project/Tests/ParcelDevTests/tool.swift", "head tooling tests") try fixture.write("report.json", MeasurementSamples.report()) try fixture.mock( "swift", """ printf '%s\t%s\n' "$PARCEL_BENCH_CORE_ONLY" "$*" >> "$TEST_WORK/swift.log" [[ ${FAIL_BUILD:-0} == 0 ]] || exit 8 [[ $SWIFT_DETERMINISTIC_HASHING == 1 ]] if [[ $1 == test ]]; then [[ $PARCEL_BENCH_NO_COMPARE == 1 ]] cp "$TEST_WORK/report.json" "$PARCEL_BENCH_OUTPUT" fi """) try fixture.run("bench-ab.sh", ["main"]) let calls = try fixture.read("swift.log").split(separator: "\n").map(String.init) #expect(calls.count == 12) #expect(calls.prefix(2).allSatisfy { $0.hasPrefix("1\tbuild ") }) #expect(calls.dropFirst(2).allSatisfy { $0.hasPrefix("1\ttest ") }) #expect(calls.allSatisfy { $0.contains("-enable-testing") }) for (index, call) in calls.dropFirst(2).enumerated() { #expect(call.contains(index.isMultiple(of: 2) ? "/base/build" : "/head/build")) #expect(call.contains("--skip-build")) } let sessions = try FileManager.default.contentsOfDirectory( at: fixture.project.appendingPathComponent("build/bench-ab"), includingPropertiesForKeys: nil) let base = try #require(sessions.first { $0.lastPathComponent.hasPrefix("run.") }).appendingPathComponent( "base/source") #expect( try String(contentsOf: base.appendingPathComponent("Sources/production.swift"), encoding: .utf8) == "base production") #expect( try String( contentsOf: base.appendingPathComponent("Tests/ParcelPerformanceTests/harness.swift"), encoding: .utf8) == "head measurement") #expect( try String(contentsOf: base.appendingPathComponent("Package.swift"), encoding: .utf8) == "head manifest") #expect( try String(contentsOf: base.appendingPathComponent("Sources/ParcelDev/tool.swift"), encoding: .utf8) == "head tooling") #expect( try String(contentsOf: base.appendingPathComponent("Sources/parcel-dev/main.swift"), encoding: .utf8) == "head tooling entry point") #expect( try String(contentsOf: base.appendingPathComponent("Tests/ParcelDevTests/tool.swift"), encoding: .utf8) == "head tooling tests") #expect(try fixture.json("project/build/bench-ab/summary.json")["caseScope"]?.string == "common-core") fixture.environment["FAIL_BUILD"] = "1" try fixture.run("bench-ab.sh", ["main", "--all-cases"], status: 8) }}