Skip to content

Commit 7829287

Browse files
committed
test suite conveniency improvements
* allowing --single to be repeated * adding --only so that only a specific test inside a unit can be run * adding --skiptill useful to resume a test that crashed passed the problematic unit. useful together with --clients 1 * adding --skipfile to use a file containing list of tests names to skip * printing the names of the tests that are skiped by skipfile or denytags * adding --config to add config file options from command line
1 parent 4a30add commit 7829287

File tree

3 files changed

+79
-3
lines changed

3 files changed

+79
-3
lines changed

runtest

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ then
1111
echo "You need tcl 8.5 or newer in order to run the Redis test"
1212
exit 1
1313
fi
14-
$TCLSH tests/test_helper.tcl $*
14+
$TCLSH tests/test_helper.tcl "${@}"

tests/support/test.tcl

+20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
set ::num_tests 0
22
set ::num_passed 0
33
set ::num_failed 0
4+
set ::num_skipped 0
5+
set ::num_aborted 0
46
set ::tests_failed {}
57

68
proc fail {msg} {
@@ -68,10 +70,26 @@ proc test {name code {okpattern undefined}} {
6870
# abort if tagged with a tag to deny
6971
foreach tag $::denytags {
7072
if {[lsearch $::tags $tag] >= 0} {
73+
incr ::num_aborted
74+
send_data_packet $::test_server_fd ignore $name
7175
return
7276
}
7377
}
7478

79+
# abort if test name in skiptests
80+
if {[lsearch $::skiptests $name] >= 0} {
81+
incr ::num_skipped
82+
send_data_packet $::test_server_fd skip $name
83+
return
84+
}
85+
86+
# abort if test name in skiptests
87+
if {[llength $::only_tests] > 0 && [lsearch $::only_tests $name] < 0} {
88+
incr ::num_skipped
89+
send_data_packet $::test_server_fd skip $name
90+
return
91+
}
92+
7593
# check if tagged with at least 1 tag to allow when there *is* a list
7694
# of tags to allow, because default policy is to run everything
7795
if {[llength $::allowtags] > 0} {
@@ -82,6 +100,8 @@ proc test {name code {okpattern undefined}} {
82100
}
83101
}
84102
if {$matched < 1} {
103+
incr ::num_aborted
104+
send_data_packet $::test_server_fd ignore $name
85105
return
86106
}
87107
}

tests/test_helper.tcl

+58-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ set ::stack_logging 0
7474
set ::verbose 0
7575
set ::quiet 0
7676
set ::denytags {}
77+
set ::skiptests {}
7778
set ::allowtags {}
79+
set ::only_tests {}
80+
set ::single_tests {}
81+
set ::skip_till ""
7882
set ::external 0; # If "1" this means, we are running against external instance
7983
set ::file ""; # If set, runs only the tests in this comma separated list
8084
set ::curfile ""; # Hold the filename of the current suite
@@ -255,6 +259,8 @@ proc accept_test_clients {fd addr port} {
255259
# testing: just used to signal that a given test started.
256260
# ok: a test was executed with success.
257261
# err: a test was executed with an error.
262+
# skip: a test was skipped by skipfile or individual test options.
263+
# ignore: a test was skipped by a group tag.
258264
# exception: there was a runtime exception while executing the test.
259265
# done: all the specified test file was processed, this test client is
260266
# ready to accept a new task.
@@ -283,6 +289,14 @@ proc read_from_test_client fd {
283289
puts "\[[colorstr green $status]\]: $data"
284290
}
285291
set ::active_clients_task($fd) "(OK) $data"
292+
} elseif {$status eq {skip}} {
293+
if {!$::quiet} {
294+
puts "\[[colorstr yellow $status]\]: $data"
295+
}
296+
} elseif {$status eq {ignore}} {
297+
if {!$::quiet} {
298+
puts "\[[colorstr cyan $status]\]: $data"
299+
}
286300
} elseif {$status eq {err}} {
287301
set err "\[[colorstr red $status]\]: $data"
288302
puts $err
@@ -412,11 +426,15 @@ proc print_help_screen {} {
412426
"--stack-logging Enable OSX leaks/malloc stack logging."
413427
"--accurate Run slow randomized tests for more iterations."
414428
"--quiet Don't show individual tests."
415-
"--single <unit> Just execute the specified unit (see next option)."
429+
"--single <unit> Just execute the specified unit (see next option). this option can be repeated."
416430
"--list-tests List all the available test units."
431+
"--only <test> Just execute the specified test by test name. this option can be repeated."
432+
"--skiptill <unit> Skip all units until (and including) the specified one."
417433
"--clients <num> Number of test clients (default 16)."
418434
"--timeout <sec> Test timeout in seconds (default 10 min)."
419435
"--force-failure Force the execution of a test that always fails."
436+
"--config <k> <v> extra config file argument"
437+
"--skipfile <file> name of a file containing test names that should be skipped (one per line)"
420438
"--dont-clean don't delete redis log files after the run"
421439
"--wait-server wait after server is started (so that you can attach a debugger)"
422440
"--help Print this help screen."
@@ -436,6 +454,18 @@ for {set j 0} {$j < [llength $argv]} {incr j} {
436454
}
437455
}
438456
incr j
457+
} elseif {$opt eq {--config}} {
458+
set arg2 [lindex $argv [expr $j+2]]
459+
lappend ::global_overrides $arg
460+
lappend ::global_overrides $arg2
461+
incr j
462+
incr j
463+
} elseif {$opt eq {--skipfile}} {
464+
incr j
465+
set fp [open $arg r]
466+
set file_data [read $fp]
467+
close $fp
468+
set ::skiptests [split $file_data "\n"]
439469
} elseif {$opt eq {--valgrind}} {
440470
set ::valgrind 1
441471
} elseif {$opt eq {--stack-logging}} {
@@ -456,7 +486,13 @@ for {set j 0} {$j < [llength $argv]} {incr j} {
456486
} elseif {$opt eq {--force-failure}} {
457487
set ::force_failure 1
458488
} elseif {$opt eq {--single}} {
459-
set ::all_tests $arg
489+
lappend ::single_tests $arg
490+
incr j
491+
} elseif {$opt eq {--only}} {
492+
lappend ::only_tests $arg
493+
incr j
494+
} elseif {$opt eq {--skiptill}} {
495+
set ::skip_till $arg
460496
incr j
461497
} elseif {$opt eq {--list-tests}} {
462498
foreach t $::all_tests {
@@ -488,6 +524,26 @@ for {set j 0} {$j < [llength $argv]} {incr j} {
488524
}
489525
}
490526

527+
if {$::skip_till != ""} {
528+
set skipping 1
529+
foreach t $::all_tests {
530+
if {$skipping == 0} {
531+
lappend ::single_tests $t
532+
}
533+
if {$t == $::skip_till} {
534+
set skipping 0
535+
}
536+
}
537+
if {$skipping} {
538+
puts "test $::skip_till not found"
539+
exit 0
540+
}
541+
}
542+
543+
if {[llength $::single_tests] > 0} {
544+
set ::all_tests $::single_tests
545+
}
546+
491547
proc attach_to_replication_stream {} {
492548
set s [socket [srv 0 "host"] [srv 0 "port"]]
493549
fconfigure $s -translation binary

0 commit comments

Comments
 (0)