diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-11-18 15:39:48 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-11-18 15:39:48 -0500 |
commit | 8d1491bae72e3500b74e1855afa10f0544068cea (patch) | |
tree | 23db7adc775a51dfd2d2aabdcf8ecc0d48a4dccd /tools/testing/ktest | |
parent | f1a27850095ebc66c138c940c1efedb8a95f92c4 (diff) |
ktest: Ask for the manditory config options instead of just failing
In keeping with the notion that all tools should be simple for
all to use. I've changed ktest.pl to ask for mandatory options
instead of just failing. It will append (or create) the options
the user types in, onto the config file.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools/testing/ktest')
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 220 |
1 files changed, 206 insertions, 14 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 04a3227ef5e0..e1c62eeb88f5 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
@@ -13,8 +13,6 @@ use FileHandle; | |||
13 | 13 | ||
14 | my $VERSION = "0.2"; | 14 | my $VERSION = "0.2"; |
15 | 15 | ||
16 | $#ARGV >= 0 || die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n"; | ||
17 | |||
18 | $| = 1; | 16 | $| = 1; |
19 | 17 | ||
20 | my %opt; | 18 | my %opt; |
@@ -47,7 +45,9 @@ $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE"; | |||
47 | $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot"; | 45 | $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot"; |
48 | $default{"STOP_AFTER_SUCCESS"} = 10; | 46 | $default{"STOP_AFTER_SUCCESS"} = 10; |
49 | $default{"STOP_AFTER_FAILURE"} = 60; | 47 | $default{"STOP_AFTER_FAILURE"} = 60; |
48 | $default{"LOCALVERSION"} = "-test"; | ||
50 | 49 | ||
50 | my $ktest_config; | ||
51 | my $version; | 51 | my $version; |
52 | my $machine; | 52 | my $machine; |
53 | my $ssh_user; | 53 | my $ssh_user; |
@@ -104,6 +104,156 @@ my $localversion; | |||
104 | my $iteration = 0; | 104 | my $iteration = 0; |
105 | my $successes = 0; | 105 | my $successes = 0; |
106 | 106 | ||
107 | my %entered_configs; | ||
108 | my %config_help; | ||
109 | |||
110 | $config_help{"MACHINE"} = << "EOF" | ||
111 | The machine hostname that you will test. | ||
112 | EOF | ||
113 | ; | ||
114 | $config_help{"SSH_USER"} = << "EOF" | ||
115 | The box is expected to have ssh on normal bootup, provide the user | ||
116 | (most likely root, since you need privileged operations) | ||
117 | EOF | ||
118 | ; | ||
119 | $config_help{"BUILD_DIR"} = << "EOF" | ||
120 | The directory that contains the Linux source code (full path). | ||
121 | EOF | ||
122 | ; | ||
123 | $config_help{"OUTPUT_DIR"} = << "EOF" | ||
124 | The directory that the objects will be built (full path). | ||
125 | (can not be same as BUILD_DIR) | ||
126 | EOF | ||
127 | ; | ||
128 | $config_help{"BUILD_TARGET"} = << "EOF" | ||
129 | The location of the compiled file to copy to the target. | ||
130 | (relative to OUTPUT_DIR) | ||
131 | EOF | ||
132 | ; | ||
133 | $config_help{"TARGET_IMAGE"} = << "EOF" | ||
134 | The place to put your image on the test machine. | ||
135 | EOF | ||
136 | ; | ||
137 | $config_help{"POWER_CYCLE"} = << "EOF" | ||
138 | A script or command to reboot the box. | ||
139 | |||
140 | Here is a digital loggers power switch example | ||
141 | POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL' | ||
142 | |||
143 | Here is an example to reboot a virtual box on the current host | ||
144 | with the name "Guest". | ||
145 | POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest | ||
146 | EOF | ||
147 | ; | ||
148 | $config_help{"CONSOLE"} = << "EOF" | ||
149 | The script or command that reads the console | ||
150 | |||
151 | If you use ttywatch server, something like the following would work. | ||
152 | CONSOLE = nc -d localhost 3001 | ||
153 | |||
154 | For a virtual machine with guest name "Guest". | ||
155 | CONSOLE = virsh console Guest | ||
156 | EOF | ||
157 | ; | ||
158 | $config_help{"LOCALVERSION"} = << "EOF" | ||
159 | Required version ending to differentiate the test | ||
160 | from other linux builds on the system. | ||
161 | EOF | ||
162 | ; | ||
163 | $config_help{"REBOOT_TYPE"} = << "EOF" | ||
164 | Way to reboot the box to the test kernel. | ||
165 | Only valid options so far are "grub" and "script". | ||
166 | |||
167 | If you specify grub, it will assume grub version 1 | ||
168 | and will search in /boot/grub/menu.lst for the title \$GRUB_MENU | ||
169 | and select that target to reboot to the kernel. If this is not | ||
170 | your setup, then specify "script" and have a command or script | ||
171 | specified in REBOOT_SCRIPT to boot to the target. | ||
172 | |||
173 | The entry in /boot/grub/menu.lst must be entered in manually. | ||
174 | The test will not modify that file. | ||
175 | EOF | ||
176 | ; | ||
177 | $config_help{"GRUB_MENU"} = << "EOF" | ||
178 | The grub title name for the test kernel to boot | ||
179 | (Only mandatory if REBOOT_TYPE = grub) | ||
180 | |||
181 | Note, ktest.pl will not update the grub menu.lst, you need to | ||
182 | manually add an option for the test. ktest.pl will search | ||
183 | the grub menu.lst for this option to find what kernel to | ||
184 | reboot into. | ||
185 | |||
186 | For example, if in the /boot/grub/menu.lst the test kernel title has: | ||
187 | title Test Kernel | ||
188 | kernel vmlinuz-test | ||
189 | GRUB_MENU = Test Kernel | ||
190 | EOF | ||
191 | ; | ||
192 | $config_help{"REBOOT_SCRIPT"} = << "EOF" | ||
193 | A script to reboot the target into the test kernel | ||
194 | (Only mandatory if REBOOT_TYPE = script) | ||
195 | EOF | ||
196 | ; | ||
197 | |||
198 | |||
199 | sub get_ktest_config { | ||
200 | my ($config) = @_; | ||
201 | |||
202 | return if (defined($opt{$config})); | ||
203 | |||
204 | if (defined($config_help{$config})) { | ||
205 | print "\n"; | ||
206 | print $config_help{$config}; | ||
207 | } | ||
208 | |||
209 | for (;;) { | ||
210 | print "$config = "; | ||
211 | if (defined($default{$config})) { | ||
212 | print "\[$default{$config}\] "; | ||
213 | } | ||
214 | $entered_configs{$config} = <STDIN>; | ||
215 | $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/; | ||
216 | if ($entered_configs{$config} =~ /^\s*$/) { | ||
217 | if ($default{$config}) { | ||
218 | $entered_configs{$config} = $default{$config}; | ||
219 | } else { | ||
220 | print "Your answer can not be blank\n"; | ||
221 | next; | ||
222 | } | ||
223 | } | ||
224 | last; | ||
225 | } | ||
226 | } | ||
227 | |||
228 | sub get_ktest_configs { | ||
229 | get_ktest_config("MACHINE"); | ||
230 | get_ktest_config("SSH_USER"); | ||
231 | get_ktest_config("BUILD_DIR"); | ||
232 | get_ktest_config("OUTPUT_DIR"); | ||
233 | get_ktest_config("BUILD_TARGET"); | ||
234 | get_ktest_config("TARGET_IMAGE"); | ||
235 | get_ktest_config("POWER_CYCLE"); | ||
236 | get_ktest_config("CONSOLE"); | ||
237 | get_ktest_config("LOCALVERSION"); | ||
238 | |||
239 | my $rtype = $opt{"REBOOT_TYPE"}; | ||
240 | |||
241 | if (!defined($rtype)) { | ||
242 | if (!defined($opt{"GRUB_MENU"})) { | ||
243 | get_ktest_config("REBOOT_TYPE"); | ||
244 | $rtype = $entered_configs{"REBOOT_TYPE"}; | ||
245 | } else { | ||
246 | $rtype = "grub"; | ||
247 | } | ||
248 | } | ||
249 | |||
250 | if ($rtype eq "grub") { | ||
251 | get_ktest_config("GRUB_MENU"); | ||
252 | } else { | ||
253 | get_ktest_config("REBOOT_SCRIPT"); | ||
254 | } | ||
255 | } | ||
256 | |||
107 | sub set_value { | 257 | sub set_value { |
108 | my ($lvalue, $rvalue) = @_; | 258 | my ($lvalue, $rvalue) = @_; |
109 | 259 | ||
@@ -241,6 +391,9 @@ sub read_config { | |||
241 | $opt{"NUM_TESTS"} = $test_num; | 391 | $opt{"NUM_TESTS"} = $test_num; |
242 | } | 392 | } |
243 | 393 | ||
394 | # make sure we have all mandatory configs | ||
395 | get_ktest_configs; | ||
396 | |||
244 | # set any defaults | 397 | # set any defaults |
245 | 398 | ||
246 | foreach my $default (keys %default) { | 399 | foreach my $default (keys %default) { |
@@ -1612,18 +1765,57 @@ sub patchcheck { | |||
1612 | return 1; | 1765 | return 1; |
1613 | } | 1766 | } |
1614 | 1767 | ||
1615 | read_config $ARGV[0]; | 1768 | $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n"; |
1616 | 1769 | ||
1617 | # mandatory configs | 1770 | if ($#ARGV == 0) { |
1618 | die "MACHINE not defined\n" if (!defined($opt{"MACHINE"})); | 1771 | $ktest_config = $ARGV[0]; |
1619 | die "SSH_USER not defined\n" if (!defined($opt{"SSH_USER"})); | 1772 | if (! -f $ktest_config) { |
1620 | die "BUILD_DIR not defined\n" if (!defined($opt{"BUILD_DIR"})); | 1773 | print "$ktest_config does not exist.\n"; |
1621 | die "OUTPUT_DIR not defined\n" if (!defined($opt{"OUTPUT_DIR"})); | 1774 | my $ans; |
1622 | die "BUILD_TARGET not defined\n" if (!defined($opt{"BUILD_TARGET"})); | 1775 | for (;;) { |
1623 | die "TARGET_IMAGE not defined\n" if (!defined($opt{"TARGET_IMAGE"})); | 1776 | print "Create it? [Y/n] "; |
1624 | die "POWER_CYCLE not defined\n" if (!defined($opt{"POWER_CYCLE"})); | 1777 | $ans = <STDIN>; |
1625 | die "CONSOLE not defined\n" if (!defined($opt{"CONSOLE"})); | 1778 | chomp $ans; |
1626 | die "LOCALVERSION not defined\n" if (!defined($opt{"LOCALVERSION"})); | 1779 | if ($ans =~ /^\s*$/) { |
1780 | $ans = "y"; | ||
1781 | } | ||
1782 | last if ($ans =~ /^y$/i || $ans =~ /^n$/i); | ||
1783 | print "Please answer either 'y' or 'n'.\n"; | ||
1784 | } | ||
1785 | if ($ans !~ /^y$/i) { | ||
1786 | exit 0; | ||
1787 | } | ||
1788 | } | ||
1789 | } else { | ||
1790 | $ktest_config = "ktest.conf"; | ||
1791 | } | ||
1792 | |||
1793 | if (! -f $ktest_config) { | ||
1794 | open(OUT, ">$ktest_config") or die "Can not create $ktest_config"; | ||
1795 | print OUT << "EOF" | ||
1796 | # Generated by ktest.pl | ||
1797 | # | ||
1798 | # Define each test with TEST_START | ||
1799 | # The config options below it will override the defaults | ||
1800 | TEST_START | ||
1801 | |||
1802 | DEFAULTS | ||
1803 | EOF | ||
1804 | ; | ||
1805 | close(OUT); | ||
1806 | } | ||
1807 | read_config $ktest_config; | ||
1808 | |||
1809 | # Append any configs entered in manually to the config file. | ||
1810 | my @new_configs = keys %entered_configs; | ||
1811 | if ($#new_configs >= 0) { | ||
1812 | print "\nAppending entered in configs to $ktest_config\n"; | ||
1813 | open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config"; | ||
1814 | foreach my $config (@new_configs) { | ||
1815 | print OUT "$config = $entered_configs{$config}\n"; | ||
1816 | $opt{$config} = $entered_configs{$config}; | ||
1817 | } | ||
1818 | } | ||
1627 | 1819 | ||
1628 | if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) { | 1820 | if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) { |
1629 | unlink $opt{"LOG_FILE"}; | 1821 | unlink $opt{"LOG_FILE"}; |