@@ -56,12 +56,13 @@ struct Test {
56
56
let index : Int
57
57
let f : ( Int ) -> ( )
58
58
let run : Bool
59
+ let tags : [ BenchmarkCategories ]
59
60
}
60
61
61
62
// Legacy test dictionaries.
62
- public var precommitTests : [ String : ( Int ) -> ( ) ] = [ : ]
63
- public var otherTests : [ String : ( Int ) -> ( ) ] = [ : ]
64
- public var stringTests : [ String : ( Int ) -> ( ) ] = [ : ]
63
+ public var precommitTests : [ String : ( ( Int ) -> ( ) , [ BenchmarkCategories ] ) ] = [ : ]
64
+ public var otherTests : [ String : ( ( Int ) -> ( ) , [ BenchmarkCategories ] ) ] = [ : ]
65
+ public var stringTests : [ String : ( ( Int ) -> ( ) , [ BenchmarkCategories ] ) ] = [ : ]
65
66
66
67
// We should migrate to a collection of BenchmarkInfo.
67
68
public var registeredBenchmarks = [ TestsUtils . BenchmarkInfo] ( )
@@ -79,6 +80,9 @@ struct TestConfig {
79
80
/// The filters applied to our test names.
80
81
var filters = [ String] ( )
81
82
83
+ /// The tag that we want to run
84
+ var tags = Set < BenchmarkCategories > ( )
85
+
82
86
/// The scalar multiple of the amount of times a test should be run. This
83
87
/// enables one to cause tests to run for N iterations longer than they
84
88
/// normally would. This is useful when one wishes for a test to run for a
@@ -115,7 +119,7 @@ struct TestConfig {
115
119
let validOptions = [
116
120
" --iter-scale " , " --num-samples " , " --num-iters " ,
117
121
" --verbose " , " --delim " , " --run-all " , " --list " , " --sleep " ,
118
- " --registered "
122
+ " --registered " , " --tags "
119
123
]
120
124
let maybeBenchArgs : Arguments ? = parseArgs ( validOptions)
121
125
if maybeBenchArgs == nil {
@@ -150,6 +154,73 @@ struct TestConfig {
150
154
delim = x
151
155
}
152
156
157
+ if let x = benchArgs. optionalArgsMap [ " --tags " ] {
158
+ if x. isEmpty { return . Fail( " --tags requires a value " ) }
159
+ if x. contains ( " cpubench " ) {
160
+ tags. insert ( BenchmarkCategories . cpubench)
161
+ }
162
+ if x. contains ( " unstable " ) {
163
+ tags. insert ( BenchmarkCategories . unstable)
164
+ }
165
+ if x. contains ( " validation " ) {
166
+ tags. insert ( BenchmarkCategories . validation)
167
+ }
168
+ if x. contains ( " api " ) {
169
+ tags. insert ( BenchmarkCategories . api)
170
+ }
171
+ if x. contains ( " Array " ) {
172
+ tags. insert ( BenchmarkCategories . Array)
173
+ }
174
+ if x. contains ( " String " ) {
175
+ tags. insert ( BenchmarkCategories . String)
176
+ }
177
+ if x. contains ( " Dictionary " ) {
178
+ tags. insert ( BenchmarkCategories . Dictionary)
179
+ }
180
+ if x. contains ( " Codable " ) {
181
+ tags. insert ( BenchmarkCategories . Codable)
182
+ }
183
+ if x. contains ( " Set " ) {
184
+ tags. insert ( BenchmarkCategories . Set)
185
+ }
186
+ if x. contains ( " sdk " ) {
187
+ tags. insert ( BenchmarkCategories . sdk)
188
+ }
189
+ if x. contains ( " runtime " ) {
190
+ tags. insert ( BenchmarkCategories . runtime)
191
+ }
192
+ if x. contains ( " refcount " ) {
193
+ tags. insert ( BenchmarkCategories . refcount)
194
+ }
195
+ if x. contains ( " metadata " ) {
196
+ tags. insert ( BenchmarkCategories . metadata)
197
+ }
198
+ if x. contains ( " abstraction " ) {
199
+ tags. insert ( BenchmarkCategories . abstraction)
200
+ }
201
+ if x. contains ( " safetychecks " ) {
202
+ tags. insert ( BenchmarkCategories . safetychecks)
203
+ }
204
+ if x. contains ( " exceptions " ) {
205
+ tags. insert ( BenchmarkCategories . exceptions)
206
+ }
207
+ if x. contains ( " bridging " ) {
208
+ tags. insert ( BenchmarkCategories . bridging)
209
+ }
210
+ if x. contains ( " concurrency " ) {
211
+ tags. insert ( BenchmarkCategories . concurrency)
212
+ }
213
+ if x. contains ( " algorithm " ) {
214
+ tags. insert ( BenchmarkCategories . algorithm)
215
+ }
216
+ if x. contains ( " miniapplication " ) {
217
+ tags. insert ( BenchmarkCategories . miniapplication)
218
+ }
219
+ if x. contains ( " regression " ) {
220
+ tags. insert ( BenchmarkCategories . regression)
221
+ }
222
+ }
223
+
153
224
if let _ = benchArgs. optionalArgsMap [ " --run-all " ] {
154
225
onlyPrecommit = false
155
226
}
@@ -177,35 +248,41 @@ struct TestConfig {
177
248
}
178
249
179
250
mutating func findTestsToRun( ) {
180
- var allTests : [ ( key: String , value: ( Int ) -> ( ) ) ]
251
+ var allTests : [ ( key: String , value: ( ( Int ) -> ( ) , [ BenchmarkCategories ] ) ) ]
181
252
182
253
if onlyRegistered {
183
254
allTests = registeredBenchmarks. map {
184
- bench -> ( key: String , value: ( Int ) -> ( ) ) in
185
- return ( bench. name, bench. runFunction)
255
+ bench -> ( key: String , value: ( ( Int ) -> ( ) , [ BenchmarkCategories ] ) ) in
256
+ ( bench. name, ( bench. runFunction, bench . tags ) )
186
257
}
187
258
// FIXME: for now unstable/extra benchmarks are not registered at all, but
188
259
// soon they will be handled with a default exclude list.
189
260
onlyPrecommit = false
190
261
}
191
262
else {
192
263
allTests = [ precommitTests, otherTests, stringTests]
193
- . map { dictionary -> [ ( key: String , value: ( Int ) -> ( ) ) ] in
264
+ . map { dictionary -> [ ( key: String , value: ( ( Int ) -> ( ) , [ BenchmarkCategories ] ) ) ] in
194
265
Array ( dictionary) . sorted { $0. key < $1. key } } // by name
195
266
. flatMap { $0 }
196
267
}
197
268
269
+ let filteredTests = allTests. filter { pair in tags. isSubset ( of: pair. value. 1 ) }
270
+ if ( filteredTests. isEmpty) {
271
+ return ;
272
+ }
273
+
198
274
let included =
199
275
!filters. isEmpty ? Set ( filters)
200
276
: onlyPrecommit ? Set ( precommitTests. keys)
201
- : Set ( allTests . map { $0. key } )
277
+ : Set ( filteredTests . map { $0. key } )
202
278
203
- tests = zip ( 1 ... allTests . count, allTests ) . map {
279
+ tests = zip ( 1 ... filteredTests . count, filteredTests ) . map {
204
280
t -> Test in
205
- let ( ordinal, ( key: name, value: function ) ) = t
206
- return Test ( name: name, index: ordinal, f: function ,
281
+ let ( ordinal, ( key: name, value: funcAndTags ) ) = t
282
+ return Test ( name: name, index: ordinal, f: funcAndTags . 0 ,
207
283
run: included. contains ( name)
208
- || included. contains ( String ( ordinal) ) )
284
+ || included. contains ( String ( ordinal) ) ,
285
+ tags: funcAndTags. 1 )
209
286
}
210
287
}
211
288
}
@@ -426,9 +503,9 @@ public func main() {
426
503
fatalError ( " \( msg) " )
427
504
case . ListTests:
428
505
config. findTestsToRun ( )
429
- print ( " Enabled Tests: " )
506
+ print ( " Enabled Tests \( config . delim ) Tags " )
430
507
for t in config. tests where t. run == true {
431
- print ( " \( t. name) " )
508
+ print ( " \( t. name) \( config . delim ) \( t . tags ) " )
432
509
}
433
510
case . Run:
434
511
config. findTestsToRun ( )
0 commit comments