aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/ktest/ktest.pl
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-11-02 15:13:54 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-11-18 11:23:09 -0500
commita57419b366a20009c9363c3cdad2449dc2fa8b9c (patch)
treef91037997c9d7ca0ca3a2b2ec7a0804eab8eb754 /tools/testing/ktest/ktest.pl
parent576f627c817dff0b7081374287a77247325b9cc0 (diff)
ktest: New TEST_START instead of using [], and use real SHA1s
Change the config to use TEST_START where the options after a TEST_START automatically get the [] as it is read and they do not need to exist in the config file; TEST_START MIN_CONFIG = myconfig is the same as MIN_CONFIG[1] = myconfig The benefit is that you no longer need to keep track of test numbers with tests. Also process the commit ids that are passed to the options to get the actually SHA1 so it is no longer relative to the branch. Ie, saying HEAD will get the current SHA1 and then that will be used, and will work even if another branch is checked out. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools/testing/ktest/ktest.pl')
-rw-r--r--tools/testing/ktest/ktest.pl206
1 files changed, 182 insertions, 24 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index ef978171ecb7..a7e86e391172 100644
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -11,21 +11,23 @@ use File::Path qw(mkpath);
11use File::Copy qw(cp); 11use File::Copy qw(cp);
12use FileHandle; 12use FileHandle;
13 13
14$#ARGV >= 0 || die "usage: autotest.pl config-file\n"; 14$#ARGV >= 0 || die "usage: ktest.pl config-file\n";
15 15
16$| = 1; 16$| = 1;
17 17
18my %opt; 18my %opt;
19my %repeat_tests;
20my %repeats;
19my %default; 21my %default;
20 22
21#default opts 23#default opts
22$default{"NUM_TESTS"} = 5; 24$default{"NUM_TESTS"} = 1;
23$default{"REBOOT_TYPE"} = "grub"; 25$default{"REBOOT_TYPE"} = "grub";
24$default{"TEST_TYPE"} = "test"; 26$default{"TEST_TYPE"} = "test";
25$default{"BUILD_TYPE"} = "randconfig"; 27$default{"BUILD_TYPE"} = "randconfig";
26$default{"MAKE_CMD"} = "make"; 28$default{"MAKE_CMD"} = "make";
27$default{"TIMEOUT"} = 120; 29$default{"TIMEOUT"} = 120;
28$default{"TMP_DIR"} = "/tmp/autotest"; 30$default{"TMP_DIR"} = "/tmp/ktest";
29$default{"SLEEP_TIME"} = 60; # sleep time between tests 31$default{"SLEEP_TIME"} = 60; # sleep time between tests
30$default{"BUILD_NOCLEAN"} = 0; 32$default{"BUILD_NOCLEAN"} = 0;
31$default{"REBOOT_ON_ERROR"} = 0; 33$default{"REBOOT_ON_ERROR"} = 0;
@@ -87,29 +89,138 @@ my $target_image;
87my $localversion; 89my $localversion;
88my $iteration = 0; 90my $iteration = 0;
89 91
92sub set_value {
93 my ($lvalue, $rvalue) = @_;
94
95 if (defined($opt{$lvalue})) {
96 die "Error: Option $lvalue defined more than once!\n";
97 }
98 $opt{$lvalue} = $rvalue;
99}
100
90sub read_config { 101sub read_config {
91 my ($config) = @_; 102 my ($config) = @_;
92 103
93 open(IN, $config) || die "can't read file $config"; 104 open(IN, $config) || die "can't read file $config";
94 105
106 my $name = $config;
107 $name =~ s,.*/(.*),$1,;
108
109 my $test_num = 0;
110 my $default = 1;
111 my $repeat = 1;
112 my $num_tests_set = 0;
113 my $skip = 0;
114 my $rest;
115
95 while (<IN>) { 116 while (<IN>) {
96 117
97 # ignore blank lines and comments 118 # ignore blank lines and comments
98 next if (/^\s*$/ || /\s*\#/); 119 next if (/^\s*$/ || /\s*\#/);
99 120
100 if (/^\s*(\S+)\s*=\s*(.*?)\s*$/) { 121 if (/^\s*TEST_START(.*)/) {
122
123 $rest = $1;
124
125 if ($num_tests_set) {
126 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
127 }
128
129 my $old_test_num = $test_num;
130
131 $test_num += $repeat;
132 $default = 0;
133 $repeat = 1;
134
135 if ($rest =~ /\s+SKIP(.*)/) {
136 $rest = $1;
137 $skip = 1;
138 } else {
139 $skip = 0;
140 }
141
142 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
143 $repeat = $1;
144 $rest = $2;
145 $repeat_tests{"$test_num"} = $repeat;
146 }
147
148 if ($rest =~ /\s+SKIP(.*)/) {
149 $rest = $1;
150 $skip = 1;
151 }
152
153 if ($rest !~ /^\s*$/) {
154 die "$name: $.: Gargbage found after TEST_START\n$_";
155 }
156
157 if ($skip) {
158 $test_num = $old_test_num;
159 $repeat = 1;
160 }
161
162 } elsif (/^\s*DEFAULTS(.*)$/) {
163 $default = 1;
164
165 $rest = $1;
166
167 if ($rest =~ /\s+SKIP(.*)/) {
168 $rest = $1;
169 $skip = 1;
170 } else {
171 $skip = 0;
172 }
173
174 if ($rest !~ /^\s*$/) {
175 die "$name: $.: Gargbage found after DEFAULTS\n$_";
176 }
177
178 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
179
180 next if ($skip);
181
101 my $lvalue = $1; 182 my $lvalue = $1;
102 my $rvalue = $2; 183 my $rvalue = $2;
103 184
104 if (defined($opt{$lvalue})) { 185 if (!$default &&
105 die "Error: Option $lvalue defined more than once!\n"; 186 ($lvalue eq "NUM_TESTS" ||
187 $lvalue eq "LOG_FILE" ||
188 $lvalue eq "CLEAR_LOG")) {
189 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
190 }
191
192 if ($lvalue eq "NUM_TESTS") {
193 if ($test_num) {
194 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
195 }
196 if (!$default) {
197 die "$name: $.: NUM_TESTS must be set in default section\n";
198 }
199 $num_tests_set = 1;
200 }
201
202 if ($default || $lvalue =~ /\[\d+\]$/) {
203 set_value($lvalue, $rvalue);
204 } else {
205 my $val = "$lvalue\[$test_num\]";
206 set_value($val, $rvalue);
207
208 if ($repeat > 1) {
209 $repeats{$val} = $repeat;
210 }
106 } 211 }
107 $opt{$lvalue} = $rvalue; 212 } else {
213 die "$name: $.: Garbage found in config\n$_";
108 } 214 }
109 } 215 }
110 216
111 close(IN); 217 close(IN);
112 218
219 if ($test_num) {
220 $test_num += $repeat - 1;
221 $opt{"NUM_TESTS"} = $test_num;
222 }
223
113 # set any defaults 224 # set any defaults
114 225
115 foreach my $default (keys %default) { 226 foreach my $default (keys %default) {
@@ -398,6 +509,27 @@ sub reboot_to {
398 run_command "$reboot_script"; 509 run_command "$reboot_script";
399} 510}
400 511
512sub get_sha1 {
513 my ($commit) = @_;
514
515 doprint "git rev-list --max-count=1 $commit ... ";
516 my $sha1 = `git rev-list --max-count=1 $commit`;
517 my $ret = $?;
518
519 logit $sha1;
520
521 if ($ret) {
522 doprint "FAILED\n";
523 dodie "Failed to get git $commit";
524 }
525
526 print "SUCCESS\n";
527
528 chomp $sha1;
529
530 return $sha1;
531}
532
401sub monitor { 533sub monitor {
402 my $booted = 0; 534 my $booted = 0;
403 my $bug = 0; 535 my $bug = 0;
@@ -497,7 +629,7 @@ sub install {
497 dodie "Failed to install modules"; 629 dodie "Failed to install modules";
498 630
499 my $modlib = "/lib/modules/$version"; 631 my $modlib = "/lib/modules/$version";
500 my $modtar = "autotest-mods.tar.bz2"; 632 my $modtar = "ktest-mods.tar.bz2";
501 633
502 run_command "ssh $target rm -rf $modlib" or 634 run_command "ssh $target rm -rf $modlib" or
503 dodie "failed to remove old mods: $modlib"; 635 dodie "failed to remove old mods: $modlib";
@@ -840,6 +972,10 @@ sub bisect {
840 my $start = $opt{"BISECT_START[$i]"}; 972 my $start = $opt{"BISECT_START[$i]"};
841 my $replay = $opt{"BISECT_REPLAY[$i]"}; 973 my $replay = $opt{"BISECT_REPLAY[$i]"};
842 974
975 # convert to true sha1's
976 $good = get_sha1($good);
977 $bad = get_sha1($bad);
978
843 if (defined($opt{"BISECT_REVERSE[$i]"}) && 979 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
844 $opt{"BISECT_REVERSE[$i]"} == 1) { 980 $opt{"BISECT_REVERSE[$i]"} == 1) {
845 doprint "Performing a reverse bisect (bad is good, good is bad!)\n"; 981 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
@@ -859,20 +995,7 @@ sub bisect {
859 if (defined($check) && $check ne "0") { 995 if (defined($check) && $check ne "0") {
860 996
861 # get current HEAD 997 # get current HEAD
862 doprint "git rev-list HEAD --max-count=1 ... "; 998 my $head = get_sha1("HEAD");
863 my $head = `git rev-list HEAD --max-count=1`;
864 my $ret = $?;
865
866 logit $head;
867
868 if ($ret) {
869 doprint "FAILED\n";
870 dodie "Failed to get git HEAD";
871 }
872
873 print "SUCCESS\n";
874
875 chomp $head;
876 999
877 if ($check ne "good") { 1000 if ($check ne "good") {
878 doprint "TESTING BISECT BAD [$bad]\n"; 1001 doprint "TESTING BISECT BAD [$bad]\n";
@@ -956,6 +1079,10 @@ sub patchcheck {
956 $end = $opt{"PATCHCHECK_END[$i]"}; 1079 $end = $opt{"PATCHCHECK_END[$i]"};
957 } 1080 }
958 1081
1082 # Get the true sha1's since we can use things like HEAD~3
1083 $start = get_sha1($start);
1084 $end = get_sha1($end);
1085
959 my $type = $opt{"PATCHCHECK_TYPE[$i]"}; 1086 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
960 1087
961 # Can't have a test without having a test to run 1088 # Can't have a test without having a test to run
@@ -1054,8 +1181,29 @@ if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
1054 1181
1055doprint "\n\nSTARTING AUTOMATED TESTS\n\n"; 1182doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
1056 1183
1057foreach my $option (sort keys %opt) { 1184for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
1058 doprint "$option = $opt{$option}\n"; 1185
1186 if (!$i) {
1187 doprint "DEFAULT OPTIONS:\n";
1188 } else {
1189 doprint "\nTEST $i OPTIONS";
1190 if (defined($repeat_tests{$i})) {
1191 $repeat = $repeat_tests{$i};
1192 doprint " ITERATE $repeat";
1193 }
1194 doprint "\n";
1195 }
1196
1197 foreach my $option (sort keys %opt) {
1198
1199 if ($option =~ /\[(\d+)\]$/) {
1200 next if ($i != $1);
1201 } else {
1202 next if ($i);
1203 }
1204
1205 doprint "$option = $opt{$option}\n";
1206 }
1059} 1207}
1060 1208
1061sub set_test_option { 1209sub set_test_option {
@@ -1067,6 +1215,16 @@ sub set_test_option {
1067 return $opt{$option}; 1215 return $opt{$option};
1068 } 1216 }
1069 1217
1218 foreach my $test (keys %repeat_tests) {
1219 if ($i >= $test &&
1220 $i < $test + $repeat_tests{$test}) {
1221 $option = "$name\[$test\]";
1222 if (defined($opt{$option})) {
1223 return $opt{$option};
1224 }
1225 }
1226 }
1227
1070 if (defined($opt{$name})) { 1228 if (defined($opt{$name})) {
1071 return $opt{$name}; 1229 return $opt{$name};
1072 } 1230 }