blob: 01c4cede71a5e795459aa17727789cc8140c79b3 [file] [log] [blame]
mblighbe2ac852006-09-28 04:44:30 +00001#!/usr/bin/python
2
mbligh4a70c132007-07-17 20:46:28 +00003# Copyright (C) 2006 - 2007 Michal Piotrowski <michal.k.k.piotrowski@gmail.com>
mblighbe2ac852006-09-28 04:44:30 +00004#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9
mbligh2615f972006-09-30 15:19:48 +000010import os, sys, dircache, string, dialog, time
mbligh4a70c132007-07-17 20:46:28 +000011from menu_lib import *
mblighbe2ac852006-09-28 04:44:30 +000012
mblighbe2ac852006-09-28 04:44:30 +000013def handle_exit_code(d, code):
14 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
mbligh2615f972006-09-30 15:19:48 +000015 if d.yesno("Do you want to exit Autotest Control Center?") == d.DIALOG_OK:
mblighbe2ac852006-09-28 04:44:30 +000016 sys.exit(0)
17 return 0
18 else:
19 return 1
20
mbligh5e753ac2006-10-04 03:50:45 +000021def atcc_t_menu(test_type, t):
mbligh4a70c132007-07-17 20:46:28 +000022 u = atcc_list_control_files(test_type, at_dir)
mblighbe2ac852006-09-28 04:44:30 +000023
mbligh4a70c132007-07-17 20:46:28 +000024 (code, tag) = d.checklist(text = test_type + ":", choices = u, title = t)
mbligh0d67fa82006-10-12 04:37:34 +000025
mblighbe2ac852006-09-28 04:44:30 +000026 return tag
27
mbligh0d67fa82006-10-12 04:37:34 +000028def atcc_t_run(res, test_type):
29 if len(res) == 0:
30 return -1
31
mbligh4a70c132007-07-17 20:46:28 +000032 atcc_setup_tmp_dirs_files(menu_dir)
mbligh0d67fa82006-10-12 04:37:34 +000033
34 for i in res:
mbligh4a70c132007-07-17 20:46:28 +000035 os.system(at_dir + '/bin/autotest ' + at_dir + '/' + test_type + '/' + i)
36 atcc_save_results1(i, at_dir, menu_dir)
mbligh0d67fa82006-10-12 04:37:34 +000037
mbligh5e753ac2006-10-04 03:50:45 +000038def atcc_t_p_run(res, test_type):
mbligh0d67fa82006-10-12 04:37:34 +000039 if len(res) == 0:
40 return -1
41
mbligh4a70c132007-07-17 20:46:28 +000042 atcc_setup_tmp_dirs_files(menu_dir)
mbligh5e753ac2006-10-04 03:50:45 +000043
44 file = (menu_dir + '/tmp/parallel')
45 f = open(file, 'w')
46
47 for i in res:
mbligh4a70c132007-07-17 20:46:28 +000048 z = i.split('/')
49 line = ("def " + z[0] + "():\n")
mbligh5e753ac2006-10-04 03:50:45 +000050 z = str(line)
51 f.write(z)
52
mbligh4a70c132007-07-17 20:46:28 +000053 file = (at_dir + '/' + test_type + '/' + i)
mbligh5e753ac2006-10-04 03:50:45 +000054 f2 = open(file, 'r')
55 k = f2.readlines()
56
57 for i in k:
58 x = ("\t" + i + "\n")
59 z = str(x)
60 f.write(z)
61
62 f2.close()
63
64 f.write('job.parallel(')
65
66 for i in range(len(res)):
mbligh4a70c132007-07-17 20:46:28 +000067 z = res[i].split('/')
68 z = ('[' + z[0] + '],')
mbligh5e753ac2006-10-04 03:50:45 +000069 z = str(z)
70 f.write(z)
71
72 f.write(')')
73
74 f.close()
75
76 os.system(at_dir + '/bin/autotest ' + menu_dir + '/tmp/parallel')
mbligh4a70c132007-07-17 20:46:28 +000077 atcc_save_results1("", at_dir, menu_dir)
78
79def atcc_profilers_run(res1, res2):
80 if len(res1) == 0 or len(res2) == 0:
81 return -1
82
83 atcc_setup_tmp_dirs_files(menu_dir)
84
85 file = (menu_dir + '/tmp/profilers')
86 f = open(file, 'w')
87
88 f.write('for profiler in (')
89
90 for i in range(len(res1)):
91 z = res1[i].split('/')
92 z = ('\'' + z[0] + '\', ')
93 z = str(z)
94 f.write(z)
95
96 f.write('):\n')
97
98 f.write('\ttry:\n')
99 f.write('\t\tprint "Testing profiler %s ..." % profiler\n')
100 f.write('\t\tjob.profilers.add(profiler)\n')
101
102 for i in range(len(res2)):
103 z = atcc_control_file_read(res2[i], 'tests', at_dir)
104 n = res2[i].split('/')
105 k = ('\t\tjob.run_test(\'' + n[0] + '\',' + z + ')\n')
106 k = str(k)
107 f.write(k)
108
109 f.write('\t\tjob.profilers.delete(profiler)\n')
110 f.write('\texcept:\n')
111 f.write('\t\tprint "Test of profiler %s failed" % profiler\n')
112 f.write('\t\traise\n')
113
114 f.close()
115
116 os.system(at_dir + '/bin/autotest ' + menu_dir + '/tmp/profilers')
117 atcc_save_results2(res1, res2, at_dir, menu_dir)
118
119def atcc_remote_get_ip():
120 while 1:
121 (code, answer) = d.inputbox("IP address of remote host", init = "192.168.0.1")
122
123 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
124 break
125 return answer
126
127def atcc_t_remote_run(ip, res, test_type):
128 if len(res) == 0:
129 return -1
130
131 atcc_setup_tmp_dirs_files(menu_dir)
132
133 file = (menu_dir + '/tmp/remote_test')
134 f = open(file, 'w')
135
136 st = str("remote_host = hosts.SSHHost(\"" + ip +"\")")
137 f.write(st + "\n")
138 st = str("at = autotest.Autotest()")
139 f.write(st + "\n")
140
141 file2 = (menu_dir + '/tmp/remote_control')
142 f2 = open(file2, 'w')
143
144 for i in res:
145 print i
146 file3 = (at_dir + '/' + test_type + '/' + i)
147 f3 = open(file3, 'r')
148 k = f3.readlines()
149 for i in k:
150 x = (i + "\n")
151 z = str(x)
152 f2.write(z)
153 f3.close()
154
155 f2.close()
156 st = str("at.run(\"" + menu_dir + "/tmp/remote_control\",\"results\", remote_host)")
157 f.write(st + "\n")
158 f.close()
159
160 os.system(srv_dir + '/autoserv ' + menu_dir + '/tmp/remote_test')
161
162def atcc_t_p_remote_run(ip, res, test_type):
163 if len(res) == 0:
164 return -1
165
166 atcc_setup_tmp_dirs_files(menu_dir)
167
168 file = (menu_dir + '/tmp/remote_parallel_control')
169 f = open(file, 'w')
170
171 for i in res:
172 z = i.split('/')
173 line = ("def " + z[0] + "():\n")
174 z = str(line)
175 f.write(z)
176
177 file = (at_dir + '/' + test_type + '/' + i)
178 f2 = open(file, 'r')
179 k = f2.readlines()
180
181 for i in k:
182 x = ("\t" + i + "\n")
183 z = str(x)
184 f.write(z)
185
186 f2.close()
187
188 f.write('job.parallel(')
189
190 for i in range(len(res)):
191 z = res[i].split('/')
192 z = ('[' + z[0] + '],')
193 z = str(z)
194 f.write(z)
195
196 f.write(')')
197
198 f.close()
199
200 file = (menu_dir + '/tmp/remote_parallel_test')
201 f = open(file, 'w')
202
203 st = str("remote_host = hosts.SSHHost(\"" + ip +"\")")
204 f.write(st + "\n")
205 st = str("at = autotest.Autotest()")
206 f.write(st + "\n")
207
208 st = str("at.run(\"" + menu_dir + "/tmp/remote_parallel_control\",\"results\", remote_host)")
209 f.write(st + "\n")
210 f.close()
211
212 os.system(srv_dir + '/autoserv ' + menu_dir + '/tmp/remote_parallel_test')
213
214def atcc_profilers_remote_run(ip, res1, res2):
215 if len(res1) == 0 or len(res2) == 0:
216 return -1
217
218 atcc_setup_tmp_dirs_files(menu_dir)
219
220 file = (menu_dir + '/tmp/remote_profilers_control')
221 f = open(file, 'w')
222
223 f.write('for profiler in (')
224
225 for i in range(len(res1)):
226 z = res1[i].split('/')
227 z = ('\'' + z[0] + '\', ')
228 z = str(z)
229 f.write(z)
230
231 f.write('):\n')
232
233 f.write('\ttry:\n')
234 f.write('\t\tprint "Testing profiler %s ..." % profiler\n')
235 f.write('\t\tjob.profilers.add(profiler)\n')
236
237 for i in range(len(res2)):
238 z = atcc_control_file_read(res2[i], 'tests', at_dir)
239 n = res2[i].split('/')
240 k = ('\t\tjob.run_test(\'' + n[0] + '\',' + z + ')\n')
241 k = str(k)
242 f.write(k)
243
244 f.write('\t\tjob.profilers.delete(profiler)\n')
245 f.write('\texcept:\n')
246 f.write('\t\tprint "Test of profiler %s failed" % profiler\n')
247 f.write('\t\traise\n')
248
249 f.close()
250
251 file = (menu_dir + '/tmp/remote_profilers')
252 f = open(file, 'w')
253
254 st = str("remote_host = hosts.SSHHost(\"" + ip +"\")")
255 f.write(st + "\n")
256 st = str("at = autotest.Autotest()")
257 f.write(st + "\n")
258
259 st = str("at.run(\"" + menu_dir + "/tmp/remote_profilers_control\",\"results\", remote_host)")
260 f.write(st + "\n")
261 f.close()
262
263 os.system(srv_dir + '/autoserv ' + menu_dir + '/tmp/remote_profilers')
mbligh5e753ac2006-10-04 03:50:45 +0000264
265def atcc_tests_results(t):
266 if os.path.exists(menu_dir + "/tmp/"):
267 dir_ls = dircache.listdir(menu_dir + "/tmp/")
mbligh2615f972006-09-30 15:19:48 +0000268 else:
mbligh5e753ac2006-10-04 03:50:45 +0000269 d.infobox(menu_dir + "/tmp/ doesn't exist")
mbligh2615f972006-09-30 15:19:48 +0000270 time.sleep(5)
271 return -1
272
mbligh5e753ac2006-10-04 03:50:45 +0000273 if len(dir_ls) == 0:
274 return -1
275
mbligh2615f972006-09-30 15:19:48 +0000276 u = []
277
278 for i in dir_ls:
279 k = i, ""
280 u.append(k)
281
282 while 1:
mbligh5e753ac2006-10-04 03:50:45 +0000283 (code, tag) = d.menu("Results:", choices = u, title = t)
mbligh2615f972006-09-30 15:19:48 +0000284
285 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
286 break
287 else:
mbligh0d67fa82006-10-12 04:37:34 +0000288 d.textbox(menu_dir + '/tmp/' + tag, width = -1)
mbligh2615f972006-09-30 15:19:48 +0000289
mbligh5e753ac2006-10-04 03:50:45 +0000290def atcc_config_show_help(tag, test_type):
mbligh4a70c132007-07-17 20:46:28 +0000291 tag = tag.split('/')
292 tag = tag[0]
mbligh5e753ac2006-10-04 03:50:45 +0000293 if os.path.exists(at_dir + '/' + test_type + '/' + tag + '/help'):
mbligh0d67fa82006-10-12 04:37:34 +0000294 d.textbox(at_dir + '/' + test_type + '/' + tag + '/help', width = -1)
mbligh5e753ac2006-10-04 03:50:45 +0000295 else:
296 d.infobox(at_dir + '/' + test_type + '/' + tag + '/help' " doesn't exist")
297 time.sleep(5)
298
mbligh4a70c132007-07-17 20:46:28 +0000299def atcc_config_edit(tag, test_type, ed):
300 os.system(ed + " " + at_dir + '/' + test_type + '/' + tag)
mbligh2615f972006-09-30 15:19:48 +0000301
mbligh4a70c132007-07-17 20:46:28 +0000302def atcc_config_help_or_edit(tag, test_type):
303 ed = "vim"
mbligh2615f972006-09-30 15:19:48 +0000304 while 1:
mbligh4a70c132007-07-17 20:46:28 +0000305 (code, answer) = d.inputbox("Type 'help' to see documentation, or name of favourite text editor", init = ed)
mbligh2615f972006-09-30 15:19:48 +0000306
307 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
308 break
mbligh5e753ac2006-10-04 03:50:45 +0000309 elif answer == "help":
310 atcc_config_show_help(tag, test_type)
311 continue
mbligh2615f972006-09-30 15:19:48 +0000312 else:
mbligh4a70c132007-07-17 20:46:28 +0000313 ed = answer
314 atcc_config_edit(tag, test_type, ed)
mbligh2615f972006-09-30 15:19:48 +0000315 break
316
mbligh4a70c132007-07-17 20:46:28 +0000317def atcc_config_choose_control_file(test_type, t):
318 u_tmp = atcc_list_control_files(test_type, at_dir)
mbligh2615f972006-09-30 15:19:48 +0000319 u = []
mbligh4a70c132007-07-17 20:46:28 +0000320 for i in u_tmp:
321 k = i[0], ""
322 u.append(k)
mbligh2615f972006-09-30 15:19:48 +0000323
324 while 1:
mbligh5e753ac2006-10-04 03:50:45 +0000325 (code, tag) = d.menu(test_type + ":", choices = u, title = t)
mbligh2615f972006-09-30 15:19:48 +0000326
327 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
328 break
329 else:
mbligh4a70c132007-07-17 20:46:28 +0000330 atcc_config_help_or_edit(tag, test_type)
mbligh0d67fa82006-10-12 04:37:34 +0000331
mbligh5e753ac2006-10-04 03:50:45 +0000332def atcc_upgrade():
mbligh4a70c132007-07-17 20:46:28 +0000333 os.system("svn checkout svn://test.kernel.org/autotest/trunk " + at_dir + "/../")
mblighbe2ac852006-09-28 04:44:30 +0000334
mbligh0d67fa82006-10-12 04:37:34 +0000335def atcc_rsync_mirror():
mblighee297ae2007-02-21 22:06:27 +0000336 os.system(at_dir + "/../mirror/mirror")
mbligh0d67fa82006-10-12 04:37:34 +0000337
mblighbe2ac852006-09-28 04:44:30 +0000338def atcc_main_menu():
339 while 1:
mbligh2615f972006-09-30 15:19:48 +0000340 (code, tag) = d.menu("Main menu",
mbligh4a70c132007-07-17 20:46:28 +0000341 choices = [("1", "Tests (local)"),
342 ("2", "Parallel tests (local)"),
343 ("3", "Profilers (local)"),
344 ("4", "Tests (remote)"),
345 ("5", "Parallel tests (remote)"),
346 ("6", "Profilers (remote)"),
347 ("7", "Tests' results"),
348 ("8", "Configure tests"),
349 ("9", "Upgrade Autotest"),
350 ("10", "Sync local kernel.org mirror")])
mblighbe2ac852006-09-28 04:44:30 +0000351 if handle_exit_code(d, code):
352 break
353 return tag
354
355def main():
mbligh2615f972006-09-30 15:19:48 +0000356 while 1:
mbligh5e753ac2006-10-04 03:50:45 +0000357 res = int(atcc_main_menu())
mbligh2615f972006-09-30 15:19:48 +0000358 if res == 1:
mbligh0d67fa82006-10-12 04:37:34 +0000359 res = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
mbligh2615f972006-09-30 15:19:48 +0000360 atcc_t_run(res, test_type = 'tests')
361 elif res == 2:
mbligh0d67fa82006-10-12 04:37:34 +0000362 res = atcc_t_menu(test_type = 'tests', t = 'Parallel tests selection menu')
mbligh5e753ac2006-10-04 03:50:45 +0000363 atcc_t_p_run(res, test_type = 'tests')
mbligh2615f972006-09-30 15:19:48 +0000364 elif res == 3:
mbligh0d67fa82006-10-12 04:37:34 +0000365 res1 = atcc_t_menu(test_type = 'profilers', t = 'Profilers selection menu')
366 res2 = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
367 atcc_profilers_run(res1, res2)
mbligh2615f972006-09-30 15:19:48 +0000368 elif res == 4:
mbligh4a70c132007-07-17 20:46:28 +0000369 ip = atcc_remote_get_ip()
370 res = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
371 atcc_t_remote_run(ip, res, test_type = 'tests')
mbligh5e753ac2006-10-04 03:50:45 +0000372 elif res == 5:
mbligh4a70c132007-07-17 20:46:28 +0000373 ip = atcc_remote_get_ip()
374 res = atcc_t_menu(test_type = 'tests', t = 'Parallel tests selection menu')
375 atcc_t_p_remote_run(ip, res, test_type = 'tests')
mbligh5e753ac2006-10-04 03:50:45 +0000376 elif res == 6:
mbligh4a70c132007-07-17 20:46:28 +0000377 ip = atcc_remote_get_ip()
378 res1 = atcc_t_menu(test_type = 'profilers', t = 'Profilers selection menu')
379 res2 = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
380 atcc_profilers_remote_run(ip, res1, res2)
mbligh0d67fa82006-10-12 04:37:34 +0000381 elif res == 7:
mbligh4a70c132007-07-17 20:46:28 +0000382 atcc_tests_results(t = 'Tests\' results menu')
383 elif res == 8:
384 atcc_config_choose_control_file(test_type = 'tests', t = 'Tests configuration menu')
385 elif res == 9:
386 atcc_upgrade()
387 elif res == 10:
mbligh0d67fa82006-10-12 04:37:34 +0000388 atcc_rsync_mirror()
mbligh2615f972006-09-30 15:19:48 +0000389 elif res == 0:
390 sys.exit(1)
mblighbe2ac852006-09-28 04:44:30 +0000391
392check_python_version()
393
mbligh2615f972006-09-30 15:19:48 +0000394menu_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
mblighee297ae2007-02-21 22:06:27 +0000395at_dir = os.path.dirname(menu_dir + "/../client/")
mbligh4a70c132007-07-17 20:46:28 +0000396srv_dir = os.path.dirname(menu_dir + "/../server/")
mblighbe2ac852006-09-28 04:44:30 +0000397
mbligh5e753ac2006-10-04 03:50:45 +0000398d = dialog.Dialog(dialog = "dialog")
mbligh4a70c132007-07-17 20:46:28 +0000399d.add_persistent_args(["--backtitle", "Autotest Control Center v0.07"])
mblighbe2ac852006-09-28 04:44:30 +0000400
401main()