blob: 583f4d03a7d66c8fc32f3ae4fc1d11639c098d50 [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()
158 z = z.split(',')
159 x = len(z)
160
161 if x == 2:
162 z = ""
163 elif x > 2:
164 z = z[2:]
165 z[-1] = z[-1].rstrip('\n')
166 z[-1] = z[-1].rstrip(')')
167 m = ""
168 for i in z:
169 m += (',' + i)
170
171 m = m.lstrip(',')
172 m = m.strip()
173 z = str(m)
174
175 f.close()
176
177 return z
178
179def atcc_config_write(tag, test_type, answer):
180 file = (at_dir + '/' + test_type + '/' + tag + '/control')
181 f = open(file, 'w')
182
183 value = ("job.runtest(None, \'" + tag + "\', " + answer + ")")
184 s = str(value)
185 z = f.write(s)
186
187 f.close()
188
189def atcc_config_show_help(tag, test_type):
190 if os.path.exists(at_dir + '/' + test_type + '/' + tag + '/help'):
mbligh0d67fa82006-10-12 04:37:34 +0000191 d.textbox(at_dir + '/' + test_type + '/' + tag + '/help', width = -1)
mbligh5e753ac2006-10-04 03:50:45 +0000192 else:
193 d.infobox(at_dir + '/' + test_type + '/' + tag + '/help' " doesn't exist")
194 time.sleep(5)
195
196def atcc_config_choose(tag, test_type):
197 conf_opt = atcc_config_read(tag, test_type)
mbligh2615f972006-09-30 15:19:48 +0000198
199 while 1:
mbligh5e753ac2006-10-04 03:50:45 +0000200 (code, answer) = d.inputbox("Type 'help' to see documentation", init = conf_opt)
mbligh2615f972006-09-30 15:19:48 +0000201
202 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
203 break
mbligh5e753ac2006-10-04 03:50:45 +0000204 elif answer == "help":
205 atcc_config_show_help(tag, test_type)
206 continue
mbligh2615f972006-09-30 15:19:48 +0000207 else:
mbligh5e753ac2006-10-04 03:50:45 +0000208 atcc_config_write(tag, test_type, answer)
mbligh2615f972006-09-30 15:19:48 +0000209 break
210
mbligh5e753ac2006-10-04 03:50:45 +0000211def atcc_config(test_type, t):
mbligh2615f972006-09-30 15:19:48 +0000212 dir_ls = dircache.listdir(at_dir + '/' + test_type)
213
214 u = []
215
216 for i in dir_ls:
217 k = i, ""
mbligh5e753ac2006-10-04 03:50:45 +0000218 if i != ".svn" and i != "netperf2" and i != "pktgen" and i != "sparse" and (os.path.exists(at_dir + '/' + test_type + '/' + i + '/control')):
mbligh2615f972006-09-30 15:19:48 +0000219 u.append(k)
220
221 while 1:
mbligh5e753ac2006-10-04 03:50:45 +0000222 (code, tag) = d.menu(test_type + ":", choices = u, title = t)
mbligh2615f972006-09-30 15:19:48 +0000223
224 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
225 break
226 else:
mbligh5e753ac2006-10-04 03:50:45 +0000227 atcc_config_choose(tag, test_type)
228
mbligh0d67fa82006-10-12 04:37:34 +0000229def atcc_profilers_run(res1, res2):
230 if len(res1) == 0 or len(res2) == 0:
231 return -1
232
233 atcc_setup_tmp_dirs_files()
234
235 file = (menu_dir + '/tmp/profilers')
236 f = open(file, 'w')
237
238 f.write('for profiler in (')
239
240 for i in range(len(res1)):
241 z = ('\'' + res1[i] + '\', ')
242 z = str(z)
243 f.write(z)
244
245 f.write('):\n')
246
247 f.write('\ttry:\n')
248 f.write('\t\tprint "Testing profiler %s ..." % profiler\n')
249 f.write('\t\tjob.profilers.add(profiler)\n')
250
251 for i in range(len(res2)):
252 z = atcc_config_read(res2[i], 'tests')
253 k = ('\t\tjob.runtest(profiler, \'' + res2[i] + '\',' + z + ')\n')
254 k = str(k)
255 f.write(k)
256
257 f.write('\t\tjob.profilers.delete(profiler)\n')
258 f.write('\texcept:\n')
259 f.write('\t\tprint "Test of profiler %s failed" % profiler\n')
260 f.write('\t\traise\n')
261
262 f.close()
263
264 os.system(at_dir + '/bin/autotest ' + menu_dir + '/tmp/profilers')
265 atcc_save_results2(res1, res2)
266
mbligh5e753ac2006-10-04 03:50:45 +0000267def atcc_upgrade():
268 os.system("svn checkout svn://test.kernel.org/autotest/trunk " + at_dir)
mblighbe2ac852006-09-28 04:44:30 +0000269
mbligh0d67fa82006-10-12 04:37:34 +0000270def atcc_rsync_mirror():
271 os.system(at_dir + "/mirror/mirror")
272
mblighbe2ac852006-09-28 04:44:30 +0000273def atcc_main_menu():
274 while 1:
mbligh2615f972006-09-30 15:19:48 +0000275 (code, tag) = d.menu("Main menu",
mbligh5e753ac2006-10-04 03:50:45 +0000276 choices = [("1", "Tests"),
277 ("2", "Parallel tests"),
278 ("3", "Profilers"),
279 ("4", "Tests' results"),
280 ("5", "Configure tests"),
mbligh0d67fa82006-10-12 04:37:34 +0000281 ("6", "Upgrade Autotest"),
282 ("7", "Sync local kernel.org mirror")])
mblighbe2ac852006-09-28 04:44:30 +0000283 if handle_exit_code(d, code):
284 break
285 return tag
286
287def main():
mbligh2615f972006-09-30 15:19:48 +0000288 while 1:
mbligh5e753ac2006-10-04 03:50:45 +0000289 res = int(atcc_main_menu())
mbligh2615f972006-09-30 15:19:48 +0000290 if res == 1:
mbligh0d67fa82006-10-12 04:37:34 +0000291 res = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
mbligh2615f972006-09-30 15:19:48 +0000292 atcc_t_run(res, test_type = 'tests')
293 elif res == 2:
mbligh0d67fa82006-10-12 04:37:34 +0000294 res = atcc_t_menu(test_type = 'tests', t = 'Parallel tests selection menu')
mbligh5e753ac2006-10-04 03:50:45 +0000295 atcc_t_p_run(res, test_type = 'tests')
mbligh2615f972006-09-30 15:19:48 +0000296 elif res == 3:
mbligh0d67fa82006-10-12 04:37:34 +0000297 res1 = atcc_t_menu(test_type = 'profilers', t = 'Profilers selection menu')
298 res2 = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
299 atcc_profilers_run(res1, res2)
mbligh2615f972006-09-30 15:19:48 +0000300 elif res == 4:
mbligh5e753ac2006-10-04 03:50:45 +0000301 atcc_tests_results(t = 'Tests\' results menu')
302 elif res == 5:
303 atcc_config(test_type = 'tests', t = 'Tests configuration menu')
304 elif res == 6:
305 atcc_upgrade()
mbligh0d67fa82006-10-12 04:37:34 +0000306 elif res == 7:
307 atcc_rsync_mirror()
mbligh2615f972006-09-30 15:19:48 +0000308 elif res == 0:
309 sys.exit(1)
mblighbe2ac852006-09-28 04:44:30 +0000310
311check_python_version()
312
mbligh2615f972006-09-30 15:19:48 +0000313menu_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
314at_dir = os.path.dirname(menu_dir)
mblighbe2ac852006-09-28 04:44:30 +0000315
mbligh5e753ac2006-10-04 03:50:45 +0000316d = dialog.Dialog(dialog = "dialog")
mbligh0d67fa82006-10-12 04:37:34 +0000317d.add_persistent_args(["--backtitle", "Autotest Control Center v0.05-p1"])
mblighbe2ac852006-09-28 04:44:30 +0000318
319main()