@@ -13,7 +13,13 @@ mod performance_tests;
13
13
use clap:: { Arg , Command as ClapCommand } ;
14
14
use performance_tests:: * ;
15
15
use serde:: { Deserialize , Serialize } ;
16
- use std:: { env, fmt, process:: Command , sync:: mpsc:: channel, thread, time:: Duration } ;
16
+ use std:: {
17
+ env, fmt,
18
+ process:: Command ,
19
+ sync:: { mpsc:: channel, Arc } ,
20
+ thread,
21
+ time:: Duration ,
22
+ } ;
17
23
use thiserror:: Error ;
18
24
19
25
#[ derive( Error , Debug ) ]
@@ -84,6 +90,21 @@ impl Default for MetricsReport {
84
90
}
85
91
}
86
92
93
+ #[ derive( Default ) ]
94
+ pub struct PerformanceTestOverrides {
95
+ test_iterations : Option < u32 > ,
96
+ }
97
+
98
+ impl fmt:: Display for PerformanceTestOverrides {
99
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
100
+ if let Some ( test_iterations) = self . test_iterations {
101
+ write ! ( f, "test_iterations = {}" , test_iterations) ?;
102
+ }
103
+
104
+ Ok ( ( ) )
105
+ }
106
+ }
107
+
87
108
pub struct PerformanceTestControl {
88
109
test_timeout : u32 ,
89
110
test_iterations : u32 ,
@@ -142,9 +163,12 @@ struct PerformanceTest {
142
163
}
143
164
144
165
impl PerformanceTest {
145
- pub fn run ( & self ) -> PerformanceTestResult {
166
+ pub fn run ( & self , overrides : & PerformanceTestOverrides ) -> PerformanceTestResult {
146
167
let mut metrics = Vec :: new ( ) ;
147
- for _ in 0 ..self . control . test_iterations {
168
+ for _ in 0 ..overrides
169
+ . test_iterations
170
+ . unwrap_or ( self . control . test_iterations )
171
+ {
148
172
metrics. push ( ( self . func_ptr ) ( & self . control ) ) ;
149
173
}
150
174
@@ -164,8 +188,9 @@ impl PerformanceTest {
164
188
165
189
// Calculate the timeout for each test
166
190
// Note: To cover the setup/cleanup time, 20s is added for each iteration of the test
167
- pub fn calc_timeout ( & self ) -> u64 {
168
- ( ( self . control . test_timeout + 20 ) * self . control . test_iterations ) as u64
191
+ pub fn calc_timeout ( & self , test_iterations : & Option < u32 > ) -> u64 {
192
+ ( ( self . control . test_timeout + 20 ) * test_iterations. unwrap_or ( self . control . test_iterations ) )
193
+ as u64
169
194
}
170
195
}
171
196
@@ -405,12 +430,20 @@ const TEST_LIST: [PerformanceTest; 17] = [
405
430
} ,
406
431
] ;
407
432
408
- fn run_test_with_timeout ( test : & ' static PerformanceTest ) -> Result < PerformanceTestResult , Error > {
433
+ fn run_test_with_timeout (
434
+ test : & ' static PerformanceTest ,
435
+ overrides : & Arc < PerformanceTestOverrides > ,
436
+ ) -> Result < PerformanceTestResult , Error > {
409
437
let ( sender, receiver) = channel :: < Result < PerformanceTestResult , Error > > ( ) ;
438
+ let test_iterations = overrides. test_iterations ;
439
+ let overrides = overrides. clone ( ) ;
410
440
thread:: spawn ( move || {
411
- println ! ( "Test '{}' running .. ({})" , test. name, test. control) ;
441
+ println ! (
442
+ "Test '{}' running .. (control: {}, overrides: {})" ,
443
+ test. name, test. control, overrides
444
+ ) ;
412
445
413
- let output = match std:: panic:: catch_unwind ( || test. run ( ) ) {
446
+ let output = match std:: panic:: catch_unwind ( || test. run ( & overrides ) ) {
414
447
Ok ( test_result) => {
415
448
println ! (
416
449
"Test '{}' .. ok: mean = {}, std_dev = {}" ,
@@ -425,7 +458,7 @@ fn run_test_with_timeout(test: &'static PerformanceTest) -> Result<PerformanceTe
425
458
} ) ;
426
459
427
460
// Todo: Need to cleanup/kill all hanging child processes
428
- let test_timeout = test. calc_timeout ( ) ;
461
+ let test_timeout = test. calc_timeout ( & test_iterations ) ;
429
462
receiver
430
463
. recv_timeout ( Duration :: from_secs ( test_timeout) )
431
464
. map_err ( |_| {
@@ -469,6 +502,12 @@ fn main() {
469
502
. help ( "Report file. Standard error is used if not specified" )
470
503
. takes_value ( true ) ,
471
504
)
505
+ . arg (
506
+ Arg :: new ( "iterations" )
507
+ . long ( "iterations" )
508
+ . help ( "Override number of test iterations" )
509
+ . takes_value ( true ) ,
510
+ )
472
511
. get_matches ( ) ;
473
512
474
513
// It seems that the tool (ethr) used for testing the virtio-net latency
@@ -497,9 +536,17 @@ fn main() {
497
536
498
537
init_tests ( ) ;
499
538
539
+ let overrides = Arc :: new ( PerformanceTestOverrides {
540
+ test_iterations : cmd_arguments
541
+ . value_of ( "iterations" )
542
+ . map ( |s| s. parse ( ) )
543
+ . transpose ( )
544
+ . unwrap_or_default ( ) ,
545
+ } ) ;
546
+
500
547
for test in test_list. iter ( ) {
501
548
if test_filter. is_empty ( ) || test_filter. iter ( ) . any ( |& s| test. name . contains ( s) ) {
502
- match run_test_with_timeout ( test) {
549
+ match run_test_with_timeout ( test, & overrides ) {
503
550
Ok ( r) => {
504
551
metrics_report. results . push ( r) ;
505
552
}
0 commit comments