@@ -30,11 +30,11 @@ use treemap::TreeMap;
30
30
use std:: comm:: { stream, SharedChan } ;
31
31
use std:: either;
32
32
use std:: io;
33
- use std:: option;
34
33
use std:: result;
35
34
use std:: task;
36
35
use std:: to_str:: ToStr ;
37
36
use std:: u64;
37
+ use std:: f64;
38
38
use std:: hashmap:: HashMap ;
39
39
use std:: os;
40
40
@@ -149,6 +149,7 @@ pub struct TestOpts {
149
149
run_tests : bool ,
150
150
run_benchmarks : bool ,
151
151
ratchet_metrics : Option < Path > ,
152
+ ratchet_noise_percent : Option < f64 > ,
152
153
save_metrics : Option < Path > ,
153
154
logfile : Option < Path >
154
155
}
@@ -163,6 +164,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
163
164
getopts:: optflag ( "bench" ) ,
164
165
getopts:: optopt ( "save-metrics" ) ,
165
166
getopts:: optopt ( "ratchet-metrics" ) ,
167
+ getopts:: optopt ( "ratchet-noise-percent" ) ,
166
168
getopts:: optopt ( "logfile" ) ] ;
167
169
let matches =
168
170
match getopts:: getopts ( args_, opts) {
@@ -172,8 +174,8 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
172
174
173
175
let filter =
174
176
if matches. free . len ( ) > 0 {
175
- option :: Some ( copy ( matches) . free [ 0 ] )
176
- } else { option :: None } ;
177
+ Some ( copy ( matches) . free [ 0 ] )
178
+ } else { None } ;
177
179
178
180
let run_ignored = getopts:: opt_present ( & matches, "ignored" ) ;
179
181
@@ -187,6 +189,10 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
187
189
let ratchet_metrics = getopts:: opt_maybe_str ( & matches, "ratchet-metrics" ) ;
188
190
let ratchet_metrics = ratchet_metrics. map ( |s| Path ( * s) ) ;
189
191
192
+ let ratchet_noise_percent =
193
+ getopts:: opt_maybe_str ( & matches, "ratchet-noise-percent" ) ;
194
+ let ratchet_noise_percent = ratchet_noise_percent. map ( |s| f64:: from_str ( * s) . get ( ) ) ;
195
+
190
196
let save_metrics = getopts:: opt_maybe_str ( & matches, "save-metrics" ) ;
191
197
let save_metrics = save_metrics. map ( |s| Path ( * s) ) ;
192
198
@@ -196,6 +202,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
196
202
run_tests : run_tests,
197
203
run_benchmarks : run_benchmarks,
198
204
ratchet_metrics : ratchet_metrics,
205
+ ratchet_noise_percent : ratchet_noise_percent,
199
206
save_metrics : save_metrics,
200
207
logfile : logfile
201
208
} ;
@@ -405,14 +412,22 @@ impl ConsoleTestState {
405
412
}
406
413
}
407
414
408
- pub fn write_run_finish(&self, ratchet_metrics: &Option<Path>) -> bool {
415
+ pub fn write_run_finish(&self,
416
+ ratchet_metrics: &Option<Path>,
417
+ ratchet_pct: Option<f64>) -> bool {
409
418
assert!(self.passed + self.failed + self.ignored + self.benchmarked == self.total);
410
419
411
420
let ratchet_success = match *ratchet_metrics {
412
421
None => true,
413
422
Some(ref pth) => {
414
423
self.out.write_str(fmt!("\n using metrics ratchet: %s\n " , pth. to_str( ) ) ) ;
415
- let ( diff, ok) = self . metrics . ratchet ( pth) ;
424
+ match ratchet_pct {
425
+ None => ( ) ,
426
+ Some ( pct) =>
427
+ self . out . write_str ( fmt ! ( "with noise-tolerance forced to: %f%%\n " ,
428
+ pct as float) )
429
+ }
430
+ let ( diff, ok) = self . metrics . ratchet ( pth, ratchet_pct) ;
416
431
self . write_metric_diff ( & diff) ;
417
432
ok
418
433
}
@@ -488,7 +503,7 @@ pub fn run_tests_console(opts: &TestOpts,
488
503
st. out . write_str ( fmt ! ( "\n metrics saved to: %s" , pth. to_str( ) ) ) ;
489
504
}
490
505
}
491
- return st. write_run_finish ( & opts. ratchet_metrics ) ;
506
+ return st. write_run_finish ( & opts. ratchet_metrics , opts . ratchet_noise_percent ) ;
492
507
}
493
508
494
509
#[ test]
@@ -510,18 +525,19 @@ fn should_sort_failures_before_printing_them() {
510
525
511
526
let st = @ConsoleTestState {
512
527
out : wr,
513
- log_out : option:: None ,
528
+ log_out : None ,
529
+ term : None ,
514
530
use_color : false ,
515
531
total : 0 u,
516
532
passed : 0 u,
517
533
failed : 0 u,
518
534
ignored : 0 u,
519
535
benchmarked : 0 u,
520
- metrics : MetricsMap :: new ( ) ,
536
+ metrics : MetricMap :: new ( ) ,
521
537
failures : ~[ test_b, test_a]
522
538
} ;
523
539
524
- print_failures ( st ) ;
540
+ st . write_failures ( ) ;
525
541
} ;
526
542
527
543
let apos = s. find_str ( "a" ) . get ( ) ;
@@ -624,15 +640,17 @@ pub fn filter_tests(
624
640
filtered
625
641
} else {
626
642
let filter_str = match opts. filter {
627
- option : : Some ( ref f) => copy * f,
628
- option : : None => ~""
643
+ Some ( ref f) => copy * f,
644
+ None => ~""
629
645
} ;
630
646
631
647
fn filter_fn( test: TestDescAndFn , filter_str: & str) ->
632
648
Option < TestDescAndFn > {
633
649
if test. desc. name. to_str( ) . contains( filter_str) {
634
- return option:: Some ( test) ;
635
- } else { return option:: None ; }
650
+ return Some ( test) ;
651
+ } else {
652
+ return None ;
653
+ }
636
654
}
637
655
638
656
filtered. consume_iter( ) . filter_map( |x| filter_fn( x, filter_str) ) . collect( )
@@ -757,14 +775,19 @@ impl MetricMap {
757
775
}
758
776
759
777
/// Compare against another MetricMap
760
- pub fn compare_to_old( & self , old: MetricMap ) -> MetricDiff {
778
+ pub fn compare_to_old( & self , old: MetricMap ,
779
+ noise_pct: Option < f64 > ) -> MetricDiff {
761
780
let mut diff : MetricDiff = TreeMap :: new( ) ;
762
781
for old. iter( ) . advance |( k, vold) | {
763
782
let r = match self . find( k) {
764
783
None => MetricRemoved ,
765
784
Some ( v) => {
766
785
let delta = ( v. value - vold. value) ;
767
- if delta. abs( ) < vold. noise. abs ( ) {
786
+ let noise = match noise_pct {
787
+ None => f64:: max( vold. noise. abs( ) , v. noise. abs( ) ) ,
788
+ Some ( pct) => vold. value * pct / 100 . 0
789
+ } ;
790
+ if delta. abs( ) < noise {
768
791
LikelyNoise
769
792
} else {
770
793
let pct = delta. abs( ) / v. value * 100.0 ;
@@ -827,14 +850,14 @@ impl MetricMap {
827
850
/// file to contain the metrics in `self` if none of the
828
851
/// `MetricChange`s are `Regression`. Returns the diff as well
829
852
/// as a boolean indicating whether the ratchet succeeded.
830
- pub fn ratchet ( & self , p : & Path ) -> ( MetricDiff , bool ) {
853
+ pub fn ratchet ( & self , p : & Path , pct : Option < f64 > ) -> ( MetricDiff , bool ) {
831
854
let old = if os:: path_exists ( p) {
832
855
MetricMap :: load ( p)
833
856
} else {
834
857
MetricMap :: new ( )
835
858
} ;
836
859
837
- let diff : MetricDiff = self . compare_to_old ( old) ;
860
+ let diff : MetricDiff = self . compare_to_old ( old, pct ) ;
838
861
let ok = do diff. iter ( ) . all ( ) |( _, v) | {
839
862
match * v {
840
863
Regression ( _) => false ,
@@ -1092,12 +1115,14 @@ mod tests {
1092
1115
// unignored tests and flip the ignore flag on the rest to false
1093
1116
1094
1117
let opts = TestOpts {
1095
- filter : option :: None ,
1118
+ filter : None ,
1096
1119
run_ignored : true ,
1097
- logfile : option :: None ,
1120
+ logfile : None ,
1098
1121
run_tests : true ,
1099
1122
run_benchmarks : false ,
1100
- ratchet : option:: None ,
1123
+ ratchet_noise_percent : None ,
1124
+ ratchet_metrics : None ,
1125
+ save_metrics : None ,
1101
1126
} ;
1102
1127
1103
1128
let tests = ~[
@@ -1128,13 +1153,14 @@ mod tests {
1128
1153
#[test]
1129
1154
pub fn sort_tests() {
1130
1155
let opts = TestOpts {
1131
- filter: option:: None,
1156
+ filter: None,
1132
1157
run_ignored: false,
1133
- logfile: option:: None,
1158
+ logfile: None,
1134
1159
run_tests: true,
1135
1160
run_benchmarks: false,
1136
- ratchet_metrics: option::None,
1137
- save_metrics: option::None,
1161
+ ratchet_noise_percent: None,
1162
+ ratchet_metrics: None,
1163
+ save_metrics: None,
1138
1164
};
1139
1165
1140
1166
let names =
0 commit comments