mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 1 | #!/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 | |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 11 | import os, sys, dircache, string, dialog, time |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 12 | |
| 13 | def check_python_version(): |
| 14 | version = string.split(string.split(sys.version)[0], ".") |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 15 | version = [version[0], version[1]] |
| 16 | if map(int, version) < [2, 4]: |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 17 | print "Python 2.4 or newer is needed" |
| 18 | sys.exit(1) |
| 19 | |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 20 | def handle_exit_code(d, code): |
| 21 | if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 22 | if d.yesno("Do you want to exit Autotest Control Center?") == d.DIALOG_OK: |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 23 | sys.exit(0) |
| 24 | return 0 |
| 25 | else: |
| 26 | return 1 |
| 27 | |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 28 | def atcc_t_menu(test_type, t): |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 29 | dir_ls = dircache.listdir(at_dir + '/' + test_type) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 30 | |
| 31 | u = [] |
| 32 | |
| 33 | for i in dir_ls: |
| 34 | k = i, "", 0 |
| 35 | if i != ".svn": |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 36 | u.append(k) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 37 | |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 38 | (code, tag) = d.checklist(text = test_type + ":", choices = u, title = t) |
| 39 | |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 40 | return tag |
| 41 | |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 42 | def 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') |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 49 | |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 50 | def 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 | |
| 63 | def 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 | |
| 71 | def atcc_save_results2(res1, res2): |
| 72 | if os.path.isfile(at_dir + '/results/default/status'): |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 73 | os.system('cat ' + at_dir + '/results/default/status >> ' + menu_dir + '/tmp/Tests\ results') |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 74 | |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 75 | for i in res1: |
| 76 | for j in res2: |
| 77 | atcc_save_profilers_results(i, j) |
| 78 | |
| 79 | def 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 | |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 89 | def atcc_t_p_run(res, test_type): |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 90 | if len(res) == 0: |
| 91 | return -1 |
| 92 | |
| 93 | atcc_setup_tmp_dirs_files() |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 94 | |
| 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') |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 126 | atcc_save_results1("") |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 127 | |
| 128 | def atcc_tests_results(t): |
| 129 | if os.path.exists(menu_dir + "/tmp/"): |
| 130 | dir_ls = dircache.listdir(menu_dir + "/tmp/") |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 131 | else: |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 132 | d.infobox(menu_dir + "/tmp/ doesn't exist") |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 133 | time.sleep(5) |
| 134 | return -1 |
| 135 | |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 136 | if len(dir_ls) == 0: |
| 137 | return -1 |
| 138 | |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 139 | u = [] |
| 140 | |
| 141 | for i in dir_ls: |
| 142 | k = i, "" |
| 143 | u.append(k) |
| 144 | |
| 145 | while 1: |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 146 | (code, tag) = d.menu("Results:", choices = u, title = t) |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 147 | |
| 148 | if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC: |
| 149 | break |
| 150 | else: |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 151 | d.textbox(menu_dir + '/tmp/' + tag, width = -1) |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 152 | |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 153 | def 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 | |
| 179 | def 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 | |
| 189 | def atcc_config_show_help(tag, test_type): |
| 190 | if os.path.exists(at_dir + '/' + test_type + '/' + tag + '/help'): |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 191 | d.textbox(at_dir + '/' + test_type + '/' + tag + '/help', width = -1) |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 192 | else: |
| 193 | d.infobox(at_dir + '/' + test_type + '/' + tag + '/help' " doesn't exist") |
| 194 | time.sleep(5) |
| 195 | |
| 196 | def atcc_config_choose(tag, test_type): |
| 197 | conf_opt = atcc_config_read(tag, test_type) |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 198 | |
| 199 | while 1: |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 200 | (code, answer) = d.inputbox("Type 'help' to see documentation", init = conf_opt) |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 201 | |
| 202 | if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC: |
| 203 | break |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 204 | elif answer == "help": |
| 205 | atcc_config_show_help(tag, test_type) |
| 206 | continue |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 207 | else: |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 208 | atcc_config_write(tag, test_type, answer) |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 209 | break |
| 210 | |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 211 | def atcc_config(test_type, t): |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 212 | dir_ls = dircache.listdir(at_dir + '/' + test_type) |
| 213 | |
| 214 | u = [] |
| 215 | |
| 216 | for i in dir_ls: |
| 217 | k = i, "" |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 218 | if i != ".svn" and i != "netperf2" and i != "pktgen" and i != "sparse" and (os.path.exists(at_dir + '/' + test_type + '/' + i + '/control')): |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 219 | u.append(k) |
| 220 | |
| 221 | while 1: |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 222 | (code, tag) = d.menu(test_type + ":", choices = u, title = t) |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 223 | |
| 224 | if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC: |
| 225 | break |
| 226 | else: |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 227 | atcc_config_choose(tag, test_type) |
| 228 | |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 229 | def 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 | |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 267 | def atcc_upgrade(): |
| 268 | os.system("svn checkout svn://test.kernel.org/autotest/trunk " + at_dir) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 269 | |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 270 | def atcc_rsync_mirror(): |
| 271 | os.system(at_dir + "/mirror/mirror") |
| 272 | |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 273 | def atcc_main_menu(): |
| 274 | while 1: |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 275 | (code, tag) = d.menu("Main menu", |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 276 | choices = [("1", "Tests"), |
| 277 | ("2", "Parallel tests"), |
| 278 | ("3", "Profilers"), |
| 279 | ("4", "Tests' results"), |
| 280 | ("5", "Configure tests"), |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 281 | ("6", "Upgrade Autotest"), |
| 282 | ("7", "Sync local kernel.org mirror")]) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 283 | if handle_exit_code(d, code): |
| 284 | break |
| 285 | return tag |
| 286 | |
| 287 | def main(): |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 288 | while 1: |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 289 | res = int(atcc_main_menu()) |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 290 | if res == 1: |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 291 | res = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu') |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 292 | atcc_t_run(res, test_type = 'tests') |
| 293 | elif res == 2: |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 294 | res = atcc_t_menu(test_type = 'tests', t = 'Parallel tests selection menu') |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 295 | atcc_t_p_run(res, test_type = 'tests') |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 296 | elif res == 3: |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 297 | 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) |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 300 | elif res == 4: |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 301 | 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() |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 306 | elif res == 7: |
| 307 | atcc_rsync_mirror() |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 308 | elif res == 0: |
| 309 | sys.exit(1) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 310 | |
| 311 | check_python_version() |
| 312 | |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame] | 313 | menu_dir = os.path.abspath(os.path.dirname(sys.argv[0])) |
| 314 | at_dir = os.path.dirname(menu_dir) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 315 | |
mbligh | 5e753ac | 2006-10-04 03:50:45 +0000 | [diff] [blame] | 316 | d = dialog.Dialog(dialog = "dialog") |
mbligh | 0d67fa8 | 2006-10-12 04:37:34 +0000 | [diff] [blame^] | 317 | d.add_persistent_args(["--backtitle", "Autotest Control Center v0.05-p1"]) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 318 | |
| 319 | main() |