Skip to content

Commit 528b3a0

Browse files
author
Max Moiseev
committed
[benchmark] Remove precommit/registered flags, add skipTags
The idea being, we need to decide what benchmarks to run solely based on tags. `--tag` allows to list all tags that are required; `--skip-tags` allows to skip benchmarks that have any of those tags. By default, skip-tags list contains .unstable and .String, which results in the same subset of benchmarks as before.
1 parent cc723b9 commit 528b3a0

File tree

2 files changed

+34
-38
lines changed

2 files changed

+34
-38
lines changed

benchmark/utils/DriverUtils.swift

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ struct TestConfig {
107107
/// The filters applied to our test names.
108108
var filters = [String]()
109109

110-
/// The tag that we want to run
110+
/// The tags that we want to run
111111
var tags = Set<BenchmarkCategory>()
112112

113+
/// Tests tagged with any of these will not be executed
114+
var skipTags: Set<BenchmarkCategory> = [.unstable, .String]
115+
113116
/// The scalar multiple of the amount of times a test should be run. This
114117
/// enables one to cause tests to run for N iterations longer than they
115118
/// normally would. This is useful when one wishes for a test to run for a
@@ -127,14 +130,6 @@ struct TestConfig {
127130
/// Is verbose output enabled?
128131
var verbose: Bool = false
129132

130-
/// Should we only run the "pre-commit" tests?
131-
var onlyPrecommit: Bool = true
132-
133-
/// Temporary option to only run tests that have been registered with
134-
/// BenchmarkInfo. This will go away as soon as the benchmarks have been
135-
/// categorized.
136-
var onlyRegistered: Bool = false
137-
138133
/// After we run the tests, should the harness sleep to allow for utilities
139134
/// like leaks that require a PID to run on the test harness.
140135
var afterRunSleep: Int?
@@ -145,8 +140,8 @@ struct TestConfig {
145140
mutating func processArguments() -> TestAction {
146141
let validOptions = [
147142
"--iter-scale", "--num-samples", "--num-iters",
148-
"--verbose", "--delim", "--run-all", "--list", "--sleep",
149-
"--registered", "--tags"
143+
"--verbose", "--delim", "--list", "--sleep",
144+
"--tags", "--skip-tags"
150145
]
151146
let maybeBenchArgs: Arguments? = parseArgs(validOptions)
152147
if maybeBenchArgs == nil {
@@ -198,8 +193,21 @@ struct TestConfig {
198193
}
199194
}
200195

201-
if let _ = benchArgs.optionalArgsMap["--run-all"] {
202-
onlyPrecommit = false
196+
if let x = benchArgs.optionalArgsMap["--skip-tags"] {
197+
if x.isEmpty { return .fail("--skip-tags requires a value") }
198+
199+
// We support specifying multiple tags by splitting on comma, i.e.:
200+
//
201+
// --skip-tags=array,set
202+
//
203+
// FIXME: If we used Error instead of .fail, then we could have a cleaner
204+
// impl here using map on x and tags.formUnion.
205+
for t in x.split(separator: ",") {
206+
guard let cat = BenchmarkCategory(rawValue: String(t)) else {
207+
return .fail("Unknown benchmark category: '\(t)'")
208+
}
209+
skipTags.insert(cat)
210+
}
203211
}
204212

205213
if let x = benchArgs.optionalArgsMap["--sleep"] {
@@ -217,47 +225,34 @@ struct TestConfig {
217225
return .listTests
218226
}
219227

220-
if let _ = benchArgs.optionalArgsMap["--registered"] {
221-
onlyRegistered = true
222-
}
223-
224228
return .run
225229
}
226230

227231
mutating func findTestsToRun() {
228232
// Begin by creating a set of our non-legacy registeredBenchmarks
229233
var allTests = Set(registeredBenchmarks)
230234

231-
// If we are supposed to only run registered tests there isn't anything
232-
// further to do (in the future anyways).
233-
if onlyRegistered {
234-
// FIXME: for now unstable/extra benchmarks are not registered at all, but
235-
// soon they will be handled with a default exclude list.
236-
onlyPrecommit = false
237-
} else {
238-
// Merge legacy benchmark info into allTests. If we already have a
239-
// registered benchmark info, formUnion leaves this alone. This allows for
240-
// us to perform incremental work.
241-
for testList in [precommitTests, otherTests, stringTests] {
242-
allTests.formUnion(testList)
243-
}
235+
// Merge legacy benchmark info into allTests. If we already have a
236+
// registered benchmark info, formUnion leaves this alone. This allows for
237+
// us to perform incremental work.
238+
for testList in [precommitTests, otherTests, stringTests] {
239+
allTests.formUnion(testList)
244240
}
245241

246-
let benchmarkNameFilter: Set<String> = {
247-
if onlyPrecommit {
248-
return Set(precommitTests.map { $0.name })
249-
}
250-
251-
return Set(filters)
252-
}()
242+
let benchmarkNameFilter = Set(filters)
253243

254244
// t is needed so we don't capture an ivar of a mutable inout self.
255245
let t = tags
246+
let st = skipTags
256247
let filteredTests = Array(allTests.filter { benchInfo in
257248
if !t.isSubset(of: benchInfo.tags) {
258249
return false
259250
}
260251

252+
if !st.isDisjoint(with: benchInfo.tags) {
253+
return false
254+
}
255+
261256
// If the user did not specified a benchmark name filter and our tags are
262257
// a subset of the specified tags by the user, return true. We want to run
263258
// this test.

benchmark/utils/main.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ private func addTo(
147147
_ function: @escaping (Int) -> (),
148148
_ tags: [BenchmarkCategory] = []
149149
) {
150-
testSuite.append(BenchmarkInfo(name: name, runFunction: function, tags: tags))
150+
registerBenchmark(
151+
BenchmarkInfo(name: name, runFunction: function, tags: tags))
151152
}
152153

153154
// The main test suite: precommit tests

0 commit comments

Comments
 (0)