blob: 2a9fe058e1f2849b1b5d8b764aa1016b2b7610e1 [file] [log] [blame]
mblighbe2ac852006-09-28 04:44:30 +00001#!/usr/bin/python
2
3# Copyright (C) 2006 Michal Piotrowski <michal.k.k.piotrowski@gmail.com>
4# Linux Testers Group
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10
mbligh2615f972006-09-30 15:19:48 +000011import os, sys, dircache, string, dialog, time
mblighbe2ac852006-09-28 04:44:30 +000012
13def check_python_version():
14 version = string.split(string.split(sys.version)[0], ".")
mbligh0d67fa82006-10-12 04:37:34 +000015 version = [version[0], version[1]]
16 if map(int, version) < [2, 4]:
mblighbe2ac852006-09-28 04:44:30 +000017 print "Python 2.4 or newer is needed"
18 sys.exit(1)
19
mblighbe2ac852006-09-28 04:44:30 +000020def handle_exit_code(d, code):
21 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
mbligh2615f972006-09-30 15:19:48 +000022 if d.yesno("Do you want to exit Autotest Control Center?") == d.DIALOG_OK:
mblighbe2ac852006-09-28 04:44:30 +000023 sys.exit(0)
24 return 0
25 else:
26 return 1
27
mbligh5e753ac2006-10-04 03:50:45 +000028def atcc_t_menu(test_type, t):
mbligh2615f972006-09-30 15:19:48 +000029 dir_ls = dircache.listdir(at_dir + '/' + test_type)
mblighbe2ac852006-09-28 04:44:30 +000030
31 u = []
32
33 for i in dir_ls:
34 k = i, "", 0
35 if i != ".svn":
mbligh2615f972006-09-30 15:19:48 +000036 u.append(k)
mblighbe2ac852006-09-28 04:44:30 +000037
mbligh0d67fa82006-10-12 04:37:34 +000038 (code, tag) = d.checklist(text = test_type + ":", choices = u, title = t)
39
mblighbe2ac852006-09-28 04:44:30 +000040 return tag
41
mbligh0d67fa82006-10-12 04:37:34 +000042def atcc_setup_tmp_dirs_files():
43 if not os.path.isdir(menu_dir + '/tmp/'):
44 os.mkdir(menu_dir + '/tmp/')
45 if os.path.isfile(menu_dir + '/tmp/Tests results'):
46 os.remove(menu_dir + '/tmp/Tests results')
47 if os.path.isfile(menu_dir + '/tmp/Possible kernel memory leaks'):
48 os.remove(menu_dir + '/tmp/Possible kernel memory leaks')
mbligh2615f972006-09-30 15:19:48 +000049
mbligh0d67fa82006-10-12 04:37:34 +000050def atcc_save_results1(i):
51 if i != "":
52 if os.path.isfile(at_dir + '/results/default/' + i + '/debug/stderr'):
53 os.system('cp ' + at_dir + '/results/default/' + i + '/debug/stderr ' + menu_dir + '/tmp/' + i + '.stderr')
54 if os.path.isfile(at_dir + '/results/default/' + i + '/debug/stdout'):
55 os.system('cp ' + at_dir + '/results/default/' + i + '/debug/stdout ' + menu_dir + '/tmp/' + i + '.stdout')
56 if os.path.isfile(at_dir + '/results/default/status'):
57 os.system('cat ' + at_dir + '/results/default/status >> ' + menu_dir + '/tmp/Tests\ results')
58 if os.path.isfile('/sys/kernel/debug/memleak'):
59 print "Saving possible kernel memory leaks"
60 os.system('echo "' + i + '" >> ' + menu_dir + '/tmp/Possible kernel memory leaks')
61 os.system('cat /sys/kernel/debug/memleak >> ' + menu_dir + '/tmp/Possible kernel memory leaks')
62
63def atcc_save_profilers_results(i, j):
64 if os.path.isfile(at_dir + '/results/default/' + j + '.' + i + '/profiling/monitor'):
65 os.system('cp ' + at_dir + '/results/default/' + j + '.' + i + '/profiling/monitor ' + menu_dir + '/tmp/' + j + '.monitor')
66 if os.path.isfile(at_dir + '/results/default/' + j + '.' + i + '/profiling/oprofile.kernel'):
67 os.system('cp ' + at_dir + '/results/default/' + j + '.' + i + '/profiling/oprofile.kernel ' + menu_dir + '/tmp/' + j + '.oprofile.kernel')
68 if os.path.isfile(at_dir + '/results/default/' + j + '.' + i + '/profiling/oprofile.user'):
69 os.system('cp ' + at_dir + '/results/default/' + j + '.' + i + '/profiling/oprofile.user ' + menu_dir + '/tmp/' + j + '.oprofile.user')
70
71def atcc_save_results2(res1, res2):
72 if os.path.isfile(at_dir + '/results/default/status'):
mbligh5e753ac2006-10-04 03:50:45 +000073 os.system('cat ' + at_dir + '/results/default/status >> ' + menu_dir + '/tmp/Tests\ results')
mbligh2615f972006-09-30 15:19:48 +000074
mbligh0d67fa82006-10-12 04:37:34 +000075 for i in res1:
76 for j in res2:
77 atcc_save_profilers_results(i, j)
78
79def atcc_t_run(res, test_type):
80 if len(res) == 0:
81 return -1
82
83 atcc_setup_tmp_dirs_files()
84
85 for i in res:
86 os.system(at_dir + '/bin/autotest ' + at_dir + '/' + test_type + '/' + i + '/control')
87 atcc_save_results1(i)
88
mbligh5e753ac2006-10-04 03:50:45 +000089def atcc_t_p_run(res, test_type):
mbligh0d67fa82006-10-12 04:37:34 +000090 if len(res) == 0:
91 return -1
92
93 atcc_setup_tmp_dirs_files()
mbligh5e753ac2006-10-04 03:50:45 +000094
95 file = (menu_dir + '/tmp/parallel')
96 f = open(file, 'w')
97
98 for i in res:
99 line = ("def " + i + "():\n")
100 z = str(line)
101 f.write(z)
102
103 file = (at_dir + '/' + test_type + '/' + i + '/control')
104 f2 = open(file, 'r')
105 k = f2.readlines()
106
107 for i in k:
108 x = ("\t" + i + "\n")
109 z = str(x)
110 f.write(z)
111
112 f2.close()
113
114 f.write('job.parallel(')
115
116 for i in range(len(res)):
117 z = ('[' + res[i] + '],')
118 z = str(z)
119 f.write(z)
120
121 f.write(')')
122
123 f.close()
124
125 os.system(at_dir + '/bin/autotest ' + menu_dir + '/tmp/parallel')
mbligh0d67fa82006-10-12 04:37:34 +0000126 atcc_save_results1("")
mbligh5e753ac2006-10-04 03:50:45 +0000127
128def atcc_tests_results(t):
129 if os.path.exists(menu_dir + "/tmp/"):
130 dir_ls = dircache.listdir(menu_dir + "/tmp/")
mbligh2615f972006-09-30 15:19:48 +0000131 else:
mbligh5e753ac2006-10-04 03:50:45 +0000132 d.infobox(menu_dir + "/tmp/ doesn't exist")
mbligh2615f972006-09-30 15:19:48 +0000133 time.sleep(5)
134 return -1
135
mbligh5e753ac2006-10-04 03:50:45 +0000136 if len(dir_ls) == 0:
137 return -1
138
mbligh2615f972006-09-30 15:19:48 +0000139 u = []
140
141 for i in dir_ls:
142 k = i, ""
143 u.append(k)
144
145 while 1:
mbligh5e753ac2006-10-04 03:50:45 +0000146 (code, tag) = d.menu("Results:", choices = u, title = t)
mbligh2615f972006-09-30 15:19:48 +0000147
148 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
149 break
150 else:
mbligh0d67fa82006-10-12 04:37:34 +0000151 d.textbox(menu_dir + '/tmp/' + tag, width = -1)
mbligh2615f972006-09-30 15:19:48 +0000152
mbligh5e753ac2006-10-04 03:50:45 +0000153def atcc_config_read(tag, test_type):
154 file = (at_dir + '/' + test_type + '/' + tag + '/control')
155 f = open(file, 'r')
156
157 z = f.readline()
mblighee297ae2007-02-21 22:06:27 +0000158 z = z.lstrip("job.run_test(")
159 z = z.rstrip('\n')
160 z = z.rstrip(')')
mbligh5e753ac2006-10-04 03:50:45 +0000161 z = z.split(',')
mblighee297ae2007-02-21 22:06:27 +0000162
mbligh5e753ac2006-10-04 03:50:45 +0000163 x = len(z)
164
mblighee297ae2007-02-21 22:06:27 +0000165 if x == 1:
mbligh5e753ac2006-10-04 03:50:45 +0000166 z = ""
mblighee297ae2007-02-21 22:06:27 +0000167 elif x > 1:
168 z = z[1:]
mbligh5e753ac2006-10-04 03:50:45 +0000169 m = ""
170 for i in z:
171 m += (',' + i)
172
173 m = m.lstrip(',')
174 m = m.strip()
175 z = str(m)
176
177 f.close()
178
179 return z
180
181def atcc_config_write(tag, test_type, answer):
182 file = (at_dir + '/' + test_type + '/' + tag + '/control')
183 f = open(file, 'w')
184
mblighee297ae2007-02-21 22:06:27 +0000185 x = len(answer)
186 if x == 0:
187 value = ("job.run_test(\'" + tag + "\')")
188 else:
189 value = ("job.run_test(\'" + tag + "\', " + answer + ")")
190
mbligh5e753ac2006-10-04 03:50:45 +0000191 s = str(value)
192 z = f.write(s)
193
194 f.close()
195
196def atcc_config_show_help(tag, test_type):
197 if os.path.exists(at_dir + '/' + test_type + '/' + tag + '/help'):
mbligh0d67fa82006-10-12 04:37:34 +0000198 d.textbox(at_dir + '/' + test_type + '/' + tag + '/help', width = -1)
mbligh5e753ac2006-10-04 03:50:45 +0000199 else:
200 d.infobox(at_dir + '/' + test_type + '/' + tag + '/help' " doesn't exist")
201 time.sleep(5)
202
203def atcc_config_choose(tag, test_type):
204 conf_opt = atcc_config_read(tag, test_type)
mbligh2615f972006-09-30 15:19:48 +0000205
206 while 1:
mbligh5e753ac2006-10-04 03:50:45 +0000207 (code, answer) = d.inputbox("Type 'help' to see documentation", init = conf_opt)
mbligh2615f972006-09-30 15:19:48 +0000208
209 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
210 break
mbligh5e753ac2006-10-04 03:50:45 +0000211 elif answer == "help":
212 atcc_config_show_help(tag, test_type)
213 continue
mbligh2615f972006-09-30 15:19:48 +0000214 else:
mbligh5e753ac2006-10-04 03:50:45 +0000215 atcc_config_write(tag, test_type, answer)
mbligh2615f972006-09-30 15:19:48 +0000216 break
217
mbligh5e753ac2006-10-04 03:50:45 +0000218def atcc_config(test_type, t):
mbligh2615f972006-09-30 15:19:48 +0000219 dir_ls = dircache.listdir(at_dir + '/' + test_type)
220
221 u = []
222
223 for i in dir_ls:
224 k = i, ""
mblighee297ae2007-02-21 22:06:27 +0000225 if i != ".svn" and i != "netperf2" and i != "pktgen" and i != "sparse" and i != "dbt2" and i != "kernelbuild" and (os.path.exists(at_dir + '/' + test_type + '/' + i + '/control')):
mbligh2615f972006-09-30 15:19:48 +0000226 u.append(k)
227
228 while 1:
mbligh5e753ac2006-10-04 03:50:45 +0000229 (code, tag) = d.menu(test_type + ":", choices = u, title = t)
mbligh2615f972006-09-30 15:19:48 +0000230
231 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
232 break
233 else:
mbligh5e753ac2006-10-04 03:50:45 +0000234 atcc_config_choose(tag, test_type)
235
mbligh0d67fa82006-10-12 04:37:34 +0000236def atcc_profilers_run(res1, res2):
237 if len(res1) == 0 or len(res2) == 0:
238 return -1
239
240 atcc_setup_tmp_dirs_files()
241
242 file = (menu_dir + '/tmp/profilers')
243 f = open(file, 'w')
244
245 f.write('for profiler in (')
246
247 for i in range(len(res1)):
248 z = ('\'' + res1[i] + '\', ')
249 z = str(z)
250 f.write(z)
251
252 f.write('):\n')
253
254 f.write('\ttry:\n')
255 f.write('\t\tprint "Testing profiler %s ..." % profiler\n')
256 f.write('\t\tjob.profilers.add(profiler)\n')
257
258 for i in range(len(res2)):
259 z = atcc_config_read(res2[i], 'tests')
mblighee297ae2007-02-21 22:06:27 +0000260 k = ('\t\tjob.run_test(\'' + res2[i] + '\',' + z + ')\n')
mbligh0d67fa82006-10-12 04:37:34 +0000261 k = str(k)
262 f.write(k)
263
264 f.write('\t\tjob.profilers.delete(profiler)\n')
265 f.write('\texcept:\n')
266 f.write('\t\tprint "Test of profiler %s failed" % profiler\n')
267 f.write('\t\traise\n')
268
269 f.close()
270
271 os.system(at_dir + '/bin/autotest ' + menu_dir + '/tmp/profilers')
272 atcc_save_results2(res1, res2)
273
mbligh5e753ac2006-10-04 03:50:45 +0000274def atcc_upgrade():
275 os.system("svn checkout svn://test.kernel.org/autotest/trunk " + at_dir)
mblighbe2ac852006-09-28 04:44:30 +0000276
mbligh0d67fa82006-10-12 04:37:34 +0000277def atcc_rsync_mirror():
mblighee297ae2007-02-21 22:06:27 +0000278 os.system(at_dir + "/../mirror/mirror")
mbligh0d67fa82006-10-12 04:37:34 +0000279
mblighbe2ac852006-09-28 04:44:30 +0000280def atcc_main_menu():
281 while 1:
mbligh2615f972006-09-30 15:19:48 +0000282 (code, tag) = d.menu("Main menu",
mbligh5e753ac2006-10-04 03:50:45 +0000283 choices = [("1", "Tests"),
284 ("2", "Parallel tests"),
285 ("3", "Profilers"),
286 ("4", "Tests' results"),
287 ("5", "Configure tests"),
mbligh0d67fa82006-10-12 04:37:34 +0000288 ("6", "Upgrade Autotest"),
289 ("7", "Sync local kernel.org mirror")])
mblighbe2ac852006-09-28 04:44:30 +0000290 if handle_exit_code(d, code):
291 break
292 return tag
293
294def main():
mbligh2615f972006-09-30 15:19:48 +0000295 while 1:
mbligh5e753ac2006-10-04 03:50:45 +0000296 res = int(atcc_main_menu())
mbligh2615f972006-09-30 15:19:48 +0000297 if res == 1:
mbligh0d67fa82006-10-12 04:37:34 +0000298 res = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
mbligh2615f972006-09-30 15:19:48 +0000299 atcc_t_run(res, test_type = 'tests')
300 elif res == 2:
mbligh0d67fa82006-10-12 04:37:34 +0000301 res = atcc_t_menu(test_type = 'tests', t = 'Parallel tests selection menu')
mbligh5e753ac2006-10-04 03:50:45 +0000302 atcc_t_p_run(res, test_type = 'tests')
mbligh2615f972006-09-30 15:19:48 +0000303 elif res == 3:
mbligh0d67fa82006-10-12 04:37:34 +0000304 res1 = atcc_t_menu(test_type = 'profilers', t = 'Profilers selection menu')
305 res2 = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
306 atcc_profilers_run(res1, res2)
mbligh2615f972006-09-30 15:19:48 +0000307 elif res == 4:
mbligh5e753ac2006-10-04 03:50:45 +0000308 atcc_tests_results(t = 'Tests\' results menu')
309 elif res == 5:
310 atcc_config(test_type = 'tests', t = 'Tests configuration menu')
311 elif res == 6:
312 atcc_upgrade()
mbligh0d67fa82006-10-12 04:37:34 +0000313 elif res == 7:
314 atcc_rsync_mirror()
mbligh2615f972006-09-30 15:19:48 +0000315 elif res == 0:
316 sys.exit(1)
mblighbe2ac852006-09-28 04:44:30 +0000317
318check_python_version()
319
mbligh2615f972006-09-30 15:19:48 +0000320menu_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
mblighee297ae2007-02-21 22:06:27 +0000321at_dir = os.path.dirname(menu_dir + "/../client/")
mblighbe2ac852006-09-28 04:44:30 +0000322
mbligh5e753ac2006-10-04 03:50:45 +0000323d = dialog.Dialog(dialog = "dialog")
mblighee297ae2007-02-21 22:06:27 +0000324d.add_persistent_args(["--backtitle", "Autotest Control Center v0.06"])
mblighbe2ac852006-09-28 04:44:30 +0000325
326main()