Skip to content

Commit 7e6c12a

Browse files
author
Dave Abrahams
authored
Merge pull request #9310 from palimondo/SR-4780
[benchmark] SR-4780 Can not run performance tests that are not in precommit suite
2 parents 94c00c4 + f244b54 commit 7e6c12a

File tree

2 files changed

+26
-35
lines changed

2 files changed

+26
-35
lines changed

benchmark/scripts/Benchmark_Driver

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ def instrument_test(driver_path, test, num_samples):
120120

121121
def get_tests(driver_path, args):
122122
"""Return a list of available performance tests"""
123-
tests = subprocess.check_output([driver_path, '--list']).split()[2:]
123+
driver = ([driver_path, '--list'])
124+
if args.benchmarks or args.filters:
125+
driver.append('--run-all')
126+
tests = subprocess.check_output(driver).split()[2:]
124127
if args.filters:
125128
regexes = [re.compile(pattern) for pattern in args.filters]
126129
return sorted(list(set([name for pattern in regexes

benchmark/utils/DriverUtils.swift

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,7 @@ struct Test {
5353
let name: String
5454
let index: Int
5555
let f: (Int) -> ()
56-
var run: Bool
57-
init(name: String, n: Int, f: @escaping (Int) -> ()) {
58-
self.name = name
59-
self.index = n
60-
self.f = f
61-
run = true
62-
}
56+
let run: Bool
6357
}
6458

6559
public var precommitTests: [String : (Int) -> ()] = [:]
@@ -117,9 +111,7 @@ struct TestConfig {
117111
}
118112
let benchArgs = maybeBenchArgs!
119113

120-
if let _ = benchArgs.optionalArgsMap["--list"] {
121-
return .ListTests
122-
}
114+
filters = benchArgs.positionalArgs
123115

124116
if let x = benchArgs.optionalArgsMap["--iter-scale"] {
125117
if x.isEmpty { return .Fail("--iter-scale requires a value") }
@@ -161,34 +153,30 @@ struct TestConfig {
161153
afterRunSleep = v!
162154
}
163155

164-
filters = benchArgs.positionalArgs
156+
if let _ = benchArgs.optionalArgsMap["--list"] {
157+
return .ListTests
158+
}
165159

166160
return .Run
167161
}
168162

169163
mutating func findTestsToRun() {
170-
var i = 1
171-
for benchName in precommitTests.keys.sorted() {
172-
tests.append(Test(name: benchName, n: i, f: precommitTests[benchName]!))
173-
i += 1
174-
}
175-
for benchName in otherTests.keys.sorted() {
176-
tests.append(Test(name: benchName, n: i, f: otherTests[benchName]!))
177-
i += 1
178-
}
179-
for benchName in stringTests.keys.sorted() {
180-
tests.append(Test(name: benchName, n: i, f: stringTests[benchName]!))
181-
i += 1
182-
}
183-
for i in 0..<tests.count {
184-
if onlyPrecommit && precommitTests[tests[i].name] == nil {
185-
tests[i].run = false
186-
}
187-
if !filters.isEmpty &&
188-
!filters.contains(String(tests[i].index)) &&
189-
!filters.contains(tests[i].name) {
190-
tests[i].run = false
191-
}
164+
let allTests = [precommitTests, otherTests, stringTests]
165+
.map { dictionary -> [(key: String, value: (Int)-> ())] in
166+
Array(dictionary).sorted { $0.key < $1.key } } // by name
167+
.joined()
168+
169+
let included =
170+
!filters.isEmpty ? Set(filters)
171+
: onlyPrecommit ? Set(precommitTests.keys)
172+
: Set(allTests.map { $0.key })
173+
174+
tests = zip(1...allTests.count, allTests).map {
175+
t -> Test in
176+
let (ordinal, (key: name, value: function)) = t
177+
return Test(name: name, index: ordinal, f: function,
178+
run: included.contains(name)
179+
|| included.contains(String(ordinal)))
192180
}
193181
}
194182
}
@@ -410,7 +398,7 @@ public func main() {
410398
case .ListTests:
411399
config.findTestsToRun()
412400
print("Enabled Tests:")
413-
for t in config.tests {
401+
for t in config.tests where t.run == true {
414402
print(" \(t.name)")
415403
}
416404
case .Run:

0 commit comments

Comments
 (0)