2019-02-12 09:59:40 +01:00
|
|
|
#!/usr/bin/env python3
|
2014-10-12 20:49:36 +02:00
|
|
|
#
|
|
|
|
# Parallel VM test case executor
|
2019-07-27 19:19:28 +02:00
|
|
|
# Copyright (c) 2014-2019, Jouni Malinen <j@w1.fi>
|
2014-10-12 20:49:36 +02:00
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
2019-01-24 08:45:42 +01:00
|
|
|
from __future__ import print_function
|
2014-10-19 09:37:02 +02:00
|
|
|
import curses
|
2014-10-12 20:49:36 +02:00
|
|
|
import fcntl
|
2014-12-24 10:40:03 +01:00
|
|
|
import logging
|
2019-12-27 19:31:33 +01:00
|
|
|
import multiprocessing
|
2014-10-12 20:49:36 +02:00
|
|
|
import os
|
2019-12-27 16:12:34 +01:00
|
|
|
import selectors
|
2014-10-12 20:49:36 +02:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import time
|
2019-02-10 09:43:10 +01:00
|
|
|
import errno
|
2014-10-12 20:49:36 +02:00
|
|
|
|
2014-12-24 10:40:03 +01:00
|
|
|
logger = logging.getLogger()
|
|
|
|
|
2015-03-06 22:47:34 +01:00
|
|
|
# Test cases that take significantly longer time to execute than average.
|
2019-03-15 11:10:37 +01:00
|
|
|
long_tests = ["ap_roam_open",
|
|
|
|
"wpas_mesh_password_mismatch_retry",
|
|
|
|
"wpas_mesh_password_mismatch",
|
|
|
|
"hostapd_oom_wpa2_psk_connect",
|
|
|
|
"ap_hs20_fetch_osu_stop",
|
|
|
|
"ap_roam_wpa2_psk",
|
|
|
|
"ibss_wpa_none_ccmp",
|
|
|
|
"nfc_wps_er_handover_pk_hash_mismatch_sta",
|
|
|
|
"go_neg_peers_force_diff_freq",
|
|
|
|
"p2p_cli_invite",
|
|
|
|
"sta_ap_scan_2b",
|
|
|
|
"ap_pmf_sta_unprot_deauth_burst",
|
|
|
|
"ap_bss_add_remove_during_ht_scan",
|
|
|
|
"wext_scan_hidden",
|
|
|
|
"autoscan_exponential",
|
|
|
|
"nfc_p2p_client",
|
|
|
|
"wnm_bss_keep_alive",
|
|
|
|
"ap_inactivity_disconnect",
|
|
|
|
"scan_bss_expiration_age",
|
|
|
|
"autoscan_periodic",
|
|
|
|
"discovery_group_client",
|
|
|
|
"concurrent_p2pcli",
|
|
|
|
"ap_bss_add_remove",
|
|
|
|
"wpas_ap_wps",
|
|
|
|
"wext_pmksa_cache",
|
|
|
|
"ibss_wpa_none",
|
|
|
|
"ap_ht_40mhz_intolerant_ap",
|
|
|
|
"ibss_rsn",
|
|
|
|
"discovery_pd_retries",
|
|
|
|
"ap_wps_setup_locked_timeout",
|
|
|
|
"ap_vht160",
|
2019-10-16 20:57:39 +02:00
|
|
|
'he160',
|
|
|
|
'he160b',
|
2019-03-15 11:10:37 +01:00
|
|
|
"dfs_radar",
|
|
|
|
"dfs",
|
|
|
|
"dfs_ht40_minus",
|
|
|
|
"dfs_etsi",
|
2020-03-03 17:36:10 +01:00
|
|
|
"dfs_radar_vht80_downgrade",
|
2019-03-15 11:10:37 +01:00
|
|
|
"ap_acs_dfs",
|
|
|
|
"grpform_cred_ready_timeout",
|
|
|
|
"hostapd_oom_wpa2_eap_connect",
|
|
|
|
"wpas_ap_dfs",
|
|
|
|
"autogo_many",
|
|
|
|
"hostapd_oom_wpa2_eap",
|
|
|
|
"ibss_open",
|
|
|
|
"proxyarp_open_ebtables",
|
|
|
|
"proxyarp_open_ebtables_ipv6",
|
|
|
|
"radius_failover",
|
|
|
|
"obss_scan_40_intolerant",
|
|
|
|
"dbus_connect_oom",
|
|
|
|
"proxyarp_open",
|
|
|
|
"proxyarp_open_ipv6",
|
|
|
|
"ap_wps_iteration",
|
|
|
|
"ap_wps_iteration_error",
|
|
|
|
"ap_wps_pbc_timeout",
|
2020-03-04 22:28:45 +01:00
|
|
|
"ap_wps_pbc_ap_timeout",
|
|
|
|
"ap_wps_pin_ap_timeout",
|
2019-03-15 11:10:37 +01:00
|
|
|
"ap_wps_http_timeout",
|
|
|
|
"p2p_go_move_reg_change",
|
|
|
|
"p2p_go_move_active",
|
|
|
|
"p2p_go_move_scm",
|
|
|
|
"p2p_go_move_scm_peer_supports",
|
|
|
|
"p2p_go_move_scm_peer_does_not_support",
|
|
|
|
"p2p_go_move_scm_multi"]
|
2015-03-06 22:47:34 +01:00
|
|
|
|
2014-12-24 16:34:29 +01:00
|
|
|
def get_failed(vm):
|
2014-10-19 09:37:02 +02:00
|
|
|
failed = []
|
2014-12-24 16:34:29 +01:00
|
|
|
for i in range(num_servers):
|
|
|
|
failed += vm[i]['failed']
|
|
|
|
return failed
|
2014-12-24 15:06:37 +01:00
|
|
|
|
2019-12-27 16:12:34 +01:00
|
|
|
def vm_read_stdout(vm, test_queue):
|
2014-12-24 16:34:29 +01:00
|
|
|
global total_started, total_passed, total_failed, total_skipped
|
2015-01-17 10:25:46 +01:00
|
|
|
global rerun_failures
|
2019-07-27 19:19:28 +02:00
|
|
|
global first_run_failures
|
2022-05-22 10:43:38 +02:00
|
|
|
global all_failed
|
2014-12-24 16:34:29 +01:00
|
|
|
|
2014-12-24 15:06:37 +01:00
|
|
|
ready = False
|
|
|
|
try:
|
|
|
|
out = vm['proc'].stdout.read()
|
2019-02-08 23:51:07 +01:00
|
|
|
if out == None:
|
|
|
|
return False
|
2019-02-08 23:51:08 +01:00
|
|
|
out = out.decode()
|
2019-02-10 09:43:10 +01:00
|
|
|
except IOError as e:
|
|
|
|
if e.errno == errno.EAGAIN:
|
|
|
|
return False
|
|
|
|
raise
|
2020-01-15 12:48:43 +01:00
|
|
|
logger.debug("VM[%d] stdout.read[%s]" % (vm['idx'], out.rstrip()))
|
2014-12-24 15:06:37 +01:00
|
|
|
pending = vm['pending'] + out
|
|
|
|
lines = []
|
|
|
|
while True:
|
|
|
|
pos = pending.find('\n')
|
|
|
|
if pos < 0:
|
|
|
|
break
|
|
|
|
line = pending[0:pos].rstrip()
|
|
|
|
pending = pending[(pos + 1):]
|
2019-12-27 16:12:34 +01:00
|
|
|
logger.debug("VM[%d] stdout full line[%s]" % (vm['idx'], line))
|
2014-12-24 16:34:29 +01:00
|
|
|
if line.startswith("READY"):
|
2019-12-27 09:09:43 +01:00
|
|
|
vm['starting'] = False
|
|
|
|
vm['started'] = True
|
2014-12-24 16:34:29 +01:00
|
|
|
ready = True
|
|
|
|
elif line.startswith("PASS"):
|
2014-12-24 15:06:37 +01:00
|
|
|
ready = True
|
2014-12-24 16:34:29 +01:00
|
|
|
total_passed += 1
|
|
|
|
elif line.startswith("FAIL"):
|
|
|
|
ready = True
|
|
|
|
total_failed += 1
|
2015-03-26 21:18:54 +01:00
|
|
|
vals = line.split(' ')
|
|
|
|
if len(vals) < 2:
|
2019-12-27 16:12:34 +01:00
|
|
|
logger.info("VM[%d] incomplete FAIL line: %s" % (vm['idx'],
|
|
|
|
line))
|
2015-03-26 21:18:54 +01:00
|
|
|
name = line
|
|
|
|
else:
|
|
|
|
name = vals[1]
|
2019-12-27 16:12:34 +01:00
|
|
|
logger.debug("VM[%d] test case failed: %s" % (vm['idx'], name))
|
2014-12-24 16:34:29 +01:00
|
|
|
vm['failed'].append(name)
|
2022-05-22 10:43:38 +02:00
|
|
|
all_failed.append(name)
|
2019-07-27 19:19:28 +02:00
|
|
|
if name != vm['current_name']:
|
2019-12-27 16:12:34 +01:00
|
|
|
logger.info("VM[%d] test result mismatch: %s (expected %s)" % (vm['idx'], name, vm['current_name']))
|
2019-07-27 19:19:28 +02:00
|
|
|
else:
|
|
|
|
count = vm['current_count']
|
|
|
|
if count == 0:
|
|
|
|
first_run_failures.append(name)
|
|
|
|
if rerun_failures and count < 1:
|
|
|
|
logger.debug("Requeue test case %s" % name)
|
|
|
|
test_queue.append((name, vm['current_count'] + 1))
|
2014-12-24 16:34:29 +01:00
|
|
|
elif line.startswith("NOT-FOUND"):
|
|
|
|
ready = True
|
|
|
|
total_failed += 1
|
2019-12-27 16:12:34 +01:00
|
|
|
logger.info("VM[%d] test case not found" % vm['idx'])
|
2014-12-24 16:34:29 +01:00
|
|
|
elif line.startswith("SKIP"):
|
|
|
|
ready = True
|
|
|
|
total_skipped += 1
|
2019-12-27 09:46:13 +01:00
|
|
|
elif line.startswith("REASON"):
|
|
|
|
vm['skip_reason'].append(line[7:])
|
2014-12-24 16:34:29 +01:00
|
|
|
elif line.startswith("START"):
|
|
|
|
total_started += 1
|
2015-06-18 19:44:59 +02:00
|
|
|
if len(vm['failed']) == 0:
|
|
|
|
vals = line.split(' ')
|
|
|
|
if len(vals) >= 2:
|
|
|
|
vm['fail_seq'].append(vals[1])
|
2014-12-24 15:06:37 +01:00
|
|
|
vm['out'] += line + '\n'
|
|
|
|
lines.append(line)
|
|
|
|
vm['pending'] = pending
|
|
|
|
return ready
|
|
|
|
|
2019-12-27 16:12:34 +01:00
|
|
|
def start_vm(vm, sel):
|
|
|
|
logger.info("VM[%d] starting up" % (vm['idx'] + 1))
|
2019-12-27 09:09:43 +01:00
|
|
|
vm['starting'] = True
|
|
|
|
vm['proc'] = subprocess.Popen(vm['cmd'],
|
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE)
|
|
|
|
vm['cmd'] = None
|
|
|
|
for stream in [vm['proc'].stdout, vm['proc'].stderr]:
|
|
|
|
fd = stream.fileno()
|
|
|
|
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
|
|
|
|
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
|
2019-12-27 16:12:34 +01:00
|
|
|
sel.register(stream, selectors.EVENT_READ, vm)
|
2019-12-27 09:09:43 +01:00
|
|
|
|
|
|
|
def num_vm_starting():
|
|
|
|
count = 0
|
|
|
|
for i in range(num_servers):
|
|
|
|
if vm[i]['starting']:
|
|
|
|
count += 1
|
|
|
|
return count
|
|
|
|
|
2019-12-27 16:12:34 +01:00
|
|
|
def vm_read_stderr(vm):
|
|
|
|
try:
|
|
|
|
err = vm['proc'].stderr.read()
|
|
|
|
if err != None:
|
|
|
|
err = err.decode()
|
|
|
|
if len(err) > 0:
|
|
|
|
vm['err'] += err
|
|
|
|
logger.info("VM[%d] stderr.read[%s]" % (vm['idx'], err))
|
|
|
|
except IOError as e:
|
|
|
|
if e.errno != errno.EAGAIN:
|
|
|
|
raise
|
|
|
|
|
|
|
|
def vm_next_step(_vm, scr, test_queue):
|
2023-01-20 18:46:32 +01:00
|
|
|
max_y, max_x = scr.getmaxyx()
|
|
|
|
status_line = num_servers + 1
|
|
|
|
if status_line >= max_y:
|
|
|
|
status_line = max_y - 1
|
|
|
|
if _vm['idx'] + 1 < status_line:
|
|
|
|
scr.move(_vm['idx'] + 1, 10)
|
|
|
|
scr.clrtoeol()
|
2019-12-27 16:12:34 +01:00
|
|
|
if not test_queue:
|
|
|
|
_vm['proc'].stdin.write(b'\n')
|
|
|
|
_vm['proc'].stdin.flush()
|
2023-01-20 18:46:32 +01:00
|
|
|
if _vm['idx'] + 1 < status_line:
|
|
|
|
scr.addstr("shutting down")
|
2019-12-27 16:12:34 +01:00
|
|
|
logger.info("VM[%d] shutting down" % _vm['idx'])
|
|
|
|
return
|
|
|
|
(name, count) = test_queue.pop(0)
|
|
|
|
_vm['current_name'] = name
|
|
|
|
_vm['current_count'] = count
|
|
|
|
_vm['proc'].stdin.write(name.encode() + b'\n')
|
|
|
|
_vm['proc'].stdin.flush()
|
2023-01-20 18:46:32 +01:00
|
|
|
if _vm['idx'] + 1 < status_line:
|
|
|
|
scr.addstr(name)
|
2019-12-27 16:12:34 +01:00
|
|
|
logger.debug("VM[%d] start test %s" % (_vm['idx'], name))
|
|
|
|
|
|
|
|
def check_vm_start(scr, sel, test_queue):
|
|
|
|
running = False
|
2023-01-20 18:46:32 +01:00
|
|
|
max_y, max_x = scr.getmaxyx()
|
|
|
|
status_line = num_servers + 1
|
|
|
|
if status_line >= max_y:
|
|
|
|
status_line = max_y - 1
|
2019-12-27 16:12:34 +01:00
|
|
|
for i in range(num_servers):
|
2019-12-27 19:31:33 +01:00
|
|
|
if vm[i]['proc']:
|
|
|
|
running = True
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Either not yet started or already stopped VM
|
|
|
|
max_start = multiprocessing.cpu_count()
|
|
|
|
if max_start > 4:
|
|
|
|
max_start /= 2
|
|
|
|
num_starting = num_vm_starting()
|
|
|
|
if vm[i]['cmd'] and len(test_queue) > num_starting and \
|
|
|
|
num_starting < max_start:
|
2023-01-20 18:46:32 +01:00
|
|
|
if i + 1 < status_line:
|
|
|
|
scr.move(i + 1, 10)
|
|
|
|
scr.clrtoeol()
|
|
|
|
scr.addstr(i + 1, 10, "starting VM")
|
2019-12-27 19:31:33 +01:00
|
|
|
start_vm(vm[i], sel)
|
|
|
|
return True, True
|
2019-12-27 16:12:34 +01:00
|
|
|
|
2019-12-27 19:31:33 +01:00
|
|
|
return running, False
|
2019-12-27 16:12:34 +01:00
|
|
|
|
|
|
|
def vm_terminated(_vm, scr, sel, test_queue):
|
|
|
|
updated = False
|
|
|
|
for stream in [_vm['proc'].stdout, _vm['proc'].stderr]:
|
|
|
|
sel.unregister(stream)
|
|
|
|
_vm['proc'] = None
|
2023-01-20 18:46:32 +01:00
|
|
|
max_y, max_x = scr.getmaxyx()
|
|
|
|
status_line = num_servers + 1
|
|
|
|
if status_line >= max_y:
|
|
|
|
status_line = max_y - 1
|
|
|
|
if _vm['idx'] + 1 < status_line:
|
|
|
|
scr.move(_vm['idx'] + 1, 10)
|
|
|
|
scr.clrtoeol()
|
2019-12-27 16:12:34 +01:00
|
|
|
log = '{}/{}.srv.{}/console'.format(dir, timestamp, _vm['idx'] + 1)
|
|
|
|
with open(log, 'r') as f:
|
|
|
|
if "Kernel panic" in f.read():
|
2023-01-20 18:46:32 +01:00
|
|
|
if _vm['idx'] + 1 < status_line:
|
|
|
|
scr.addstr("kernel panic")
|
2019-12-27 16:12:34 +01:00
|
|
|
logger.info("VM[%d] kernel panic" % _vm['idx'])
|
|
|
|
updated = True
|
|
|
|
if test_queue:
|
|
|
|
num_vm = 0
|
|
|
|
for i in range(num_servers):
|
|
|
|
if _vm['proc']:
|
|
|
|
num_vm += 1
|
|
|
|
if len(test_queue) > num_vm:
|
2023-01-20 18:46:32 +01:00
|
|
|
if _vm['idx'] + 1 < status_line:
|
|
|
|
scr.addstr("unexpected exit")
|
2019-12-27 16:12:34 +01:00
|
|
|
logger.info("VM[%d] unexpected exit" % i)
|
|
|
|
updated = True
|
|
|
|
return updated
|
|
|
|
|
|
|
|
def update_screen(scr, total_tests):
|
2023-01-20 18:46:32 +01:00
|
|
|
max_y, max_x = scr.getmaxyx()
|
|
|
|
status_line = num_servers + 1
|
|
|
|
if status_line >= max_y:
|
|
|
|
status_line = max_y - 1
|
|
|
|
scr.move(status_line, 10)
|
2019-12-27 16:12:34 +01:00
|
|
|
scr.clrtoeol()
|
|
|
|
scr.addstr("{} %".format(int(100.0 * (total_passed + total_failed + total_skipped) / total_tests)))
|
2023-01-20 18:46:32 +01:00
|
|
|
scr.addstr(status_line, 20,
|
2019-12-27 16:12:34 +01:00
|
|
|
"TOTAL={} STARTED={} PASS={} FAIL={} SKIP={}".format(total_tests, total_started, total_passed, total_failed, total_skipped))
|
2022-05-22 10:43:38 +02:00
|
|
|
global all_failed
|
|
|
|
max_y, max_x = scr.getmaxyx()
|
|
|
|
max_lines = max_y - num_servers - 3
|
2023-01-20 18:46:32 +01:00
|
|
|
if len(all_failed) > 0 and max_lines > 0 and num_servers + 2 < max_y - 1:
|
2019-12-27 16:12:34 +01:00
|
|
|
scr.move(num_servers + 2, 0)
|
2022-05-22 10:43:38 +02:00
|
|
|
scr.addstr("Last failed test cases:")
|
|
|
|
if max_lines >= len(all_failed):
|
|
|
|
max_lines = len(all_failed)
|
2019-12-27 16:12:34 +01:00
|
|
|
count = 0
|
2022-05-22 10:43:38 +02:00
|
|
|
for i in range(len(all_failed) - max_lines, len(all_failed)):
|
2019-12-27 16:12:34 +01:00
|
|
|
count += 1
|
2023-01-20 18:46:32 +01:00
|
|
|
if num_servers + 2 + count >= max_y:
|
|
|
|
break
|
2022-05-22 10:43:38 +02:00
|
|
|
scr.move(num_servers + 2 + count, 0)
|
|
|
|
scr.addstr(all_failed[i])
|
|
|
|
scr.clrtoeol()
|
2019-12-27 16:12:34 +01:00
|
|
|
scr.refresh()
|
|
|
|
|
2014-10-19 09:37:02 +02:00
|
|
|
def show_progress(scr):
|
|
|
|
global num_servers
|
|
|
|
global vm
|
2014-11-16 21:34:54 +01:00
|
|
|
global dir
|
|
|
|
global timestamp
|
2014-11-19 01:03:39 +01:00
|
|
|
global tests
|
2014-12-23 21:25:29 +01:00
|
|
|
global first_run_failures
|
2014-12-24 16:34:29 +01:00
|
|
|
global total_started, total_passed, total_failed, total_skipped
|
2019-07-27 19:19:28 +02:00
|
|
|
global rerun_failures
|
2014-11-19 01:03:39 +01:00
|
|
|
|
2019-12-27 16:12:34 +01:00
|
|
|
sel = selectors.DefaultSelector()
|
2014-11-19 01:03:39 +01:00
|
|
|
total_tests = len(tests)
|
2014-12-24 10:40:03 +01:00
|
|
|
logger.info("Total tests: %d" % total_tests)
|
2019-07-27 19:19:28 +02:00
|
|
|
test_queue = [(t, 0) for t in tests]
|
2019-12-27 16:12:34 +01:00
|
|
|
start_vm(vm[0], sel)
|
2014-10-19 09:37:02 +02:00
|
|
|
|
|
|
|
scr.leaveok(1)
|
2023-01-20 18:46:32 +01:00
|
|
|
max_y, max_x = scr.getmaxyx()
|
|
|
|
status_line = num_servers + 1
|
|
|
|
if status_line >= max_y:
|
|
|
|
status_line = max_y - 1
|
2014-10-19 09:37:02 +02:00
|
|
|
scr.addstr(0, 0, "Parallel test execution status", curses.A_BOLD)
|
2014-10-12 20:49:36 +02:00
|
|
|
for i in range(0, num_servers):
|
2023-01-20 18:46:32 +01:00
|
|
|
if i + 1 < status_line:
|
|
|
|
scr.addstr(i + 1, 0, "VM %d:" % (i + 1), curses.A_BOLD)
|
|
|
|
status = "starting VM" if vm[i]['proc'] else "not yet started"
|
|
|
|
scr.addstr(i + 1, 10, status)
|
|
|
|
scr.addstr(status_line, 0, "Total:", curses.A_BOLD)
|
|
|
|
scr.addstr(status_line, 20, "TOTAL={} STARTED=0 PASS=0 FAIL=0 SKIP=0".format(total_tests))
|
2014-10-19 09:37:02 +02:00
|
|
|
scr.refresh()
|
2014-10-12 20:49:36 +02:00
|
|
|
|
|
|
|
while True:
|
|
|
|
updated = False
|
2019-12-27 16:12:34 +01:00
|
|
|
events = sel.select(timeout=1)
|
|
|
|
for key, mask in events:
|
|
|
|
_vm = key.data
|
|
|
|
if not _vm['proc']:
|
2014-10-12 20:49:36 +02:00
|
|
|
continue
|
2019-12-27 16:12:34 +01:00
|
|
|
vm_read_stderr(_vm)
|
|
|
|
if vm_read_stdout(_vm, test_queue):
|
|
|
|
vm_next_step(_vm, scr, test_queue)
|
2014-12-24 15:06:37 +01:00
|
|
|
updated = True
|
2019-12-27 16:12:34 +01:00
|
|
|
vm_read_stderr(_vm)
|
|
|
|
if _vm['proc'].poll() is not None:
|
|
|
|
if vm_terminated(_vm, scr, sel, test_queue):
|
|
|
|
updated = True
|
2014-12-23 21:25:29 +01:00
|
|
|
|
2019-12-27 16:12:34 +01:00
|
|
|
running, run_update = check_vm_start(scr, sel, test_queue)
|
|
|
|
if updated or run_update:
|
|
|
|
update_screen(scr, total_tests)
|
2014-10-12 20:49:36 +02:00
|
|
|
if not running:
|
|
|
|
break
|
2019-12-27 16:12:34 +01:00
|
|
|
sel.close()
|
2014-11-19 01:03:39 +01:00
|
|
|
|
2019-07-27 19:19:28 +02:00
|
|
|
for i in range(num_servers):
|
|
|
|
if not vm[i]['proc']:
|
|
|
|
continue
|
|
|
|
vm[i]['proc'] = None
|
|
|
|
scr.move(i + 1, 10)
|
|
|
|
scr.clrtoeol()
|
|
|
|
scr.addstr("still running")
|
|
|
|
logger.info("VM[%d] still running" % i)
|
|
|
|
|
2014-11-19 01:03:39 +01:00
|
|
|
scr.refresh()
|
|
|
|
time.sleep(0.3)
|
2014-10-12 20:49:36 +02:00
|
|
|
|
2021-02-28 19:20:38 +01:00
|
|
|
def known_output(tests, line):
|
|
|
|
if not line:
|
|
|
|
return True
|
|
|
|
if line in tests:
|
|
|
|
return True
|
|
|
|
known = ["START ", "PASS ", "FAIL ", "SKIP ", "REASON ", "ALL-PASSED",
|
|
|
|
"READY",
|
|
|
|
" ", "Exception: ", "Traceback (most recent call last):",
|
|
|
|
"./run-all.sh: running",
|
|
|
|
"./run-all.sh: passing",
|
|
|
|
"Test run completed", "Logfiles are at", "Starting test run",
|
|
|
|
"passed all", "skipped ", "failed tests:"]
|
|
|
|
for k in known:
|
|
|
|
if line.startswith(k):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2014-10-19 09:37:02 +02:00
|
|
|
def main():
|
2015-03-03 23:08:40 +01:00
|
|
|
import argparse
|
2015-03-03 23:08:41 +01:00
|
|
|
import os
|
2014-10-19 09:37:02 +02:00
|
|
|
global num_servers
|
|
|
|
global vm
|
2022-05-22 10:43:38 +02:00
|
|
|
global all_failed
|
2014-11-16 21:34:54 +01:00
|
|
|
global dir
|
|
|
|
global timestamp
|
2014-11-19 01:03:39 +01:00
|
|
|
global tests
|
2014-12-23 21:25:29 +01:00
|
|
|
global first_run_failures
|
2014-12-24 16:34:29 +01:00
|
|
|
global total_started, total_passed, total_failed, total_skipped
|
2015-01-17 10:25:46 +01:00
|
|
|
global rerun_failures
|
2014-12-24 16:34:29 +01:00
|
|
|
|
|
|
|
total_started = 0
|
|
|
|
total_passed = 0
|
|
|
|
total_failed = 0
|
|
|
|
total_skipped = 0
|
2014-10-19 09:37:02 +02:00
|
|
|
|
2014-12-24 10:40:03 +01:00
|
|
|
debug_level = logging.INFO
|
2015-01-17 10:25:46 +01:00
|
|
|
rerun_failures = True
|
2014-12-19 23:51:55 +01:00
|
|
|
timestamp = int(time.time())
|
|
|
|
|
2015-03-03 23:08:41 +01:00
|
|
|
scriptsdir = os.path.dirname(os.path.realpath(sys.argv[0]))
|
|
|
|
|
2015-03-03 23:08:40 +01:00
|
|
|
p = argparse.ArgumentParser(description='run multiple testing VMs in parallel')
|
|
|
|
p.add_argument('num_servers', metavar='number of VMs', type=int, choices=range(1, 100),
|
|
|
|
help="number of VMs to start")
|
|
|
|
p.add_argument('-f', dest='testmodules', metavar='<test module>',
|
|
|
|
help='execute only tests from these test modules',
|
|
|
|
type=str, nargs='+')
|
|
|
|
p.add_argument('-1', dest='no_retry', action='store_const', const=True, default=False,
|
|
|
|
help="don't retry failed tests automatically")
|
|
|
|
p.add_argument('--debug', dest='debug', action='store_const', const=True, default=False,
|
|
|
|
help="enable debug logging")
|
|
|
|
p.add_argument('--codecov', dest='codecov', action='store_const', const=True, default=False,
|
|
|
|
help="enable code coverage collection")
|
|
|
|
p.add_argument('--shuffle-tests', dest='shuffle', action='store_const', const=True, default=False,
|
|
|
|
help="shuffle test cases to randomize order")
|
2015-03-06 22:47:34 +01:00
|
|
|
p.add_argument('--short', dest='short', action='store_const', const=True,
|
|
|
|
default=False,
|
|
|
|
help="only run short-duration test cases")
|
2015-03-03 23:08:40 +01:00
|
|
|
p.add_argument('--long', dest='long', action='store_const', const=True,
|
|
|
|
default=False,
|
|
|
|
help="include long-duration test cases")
|
2015-03-14 11:09:23 +01:00
|
|
|
p.add_argument('--valgrind', dest='valgrind', action='store_const',
|
|
|
|
const=True, default=False,
|
|
|
|
help="run tests under valgrind")
|
2019-02-05 12:26:58 +01:00
|
|
|
p.add_argument('--telnet', dest='telnet', metavar='<baseport>', type=int,
|
|
|
|
help="enable telnet server inside VMs, specify the base port here")
|
2020-01-15 12:48:43 +01:00
|
|
|
p.add_argument('--nocurses', dest='nocurses', action='store_const',
|
|
|
|
const=True, default=False, help="Don't use curses for output")
|
2015-03-03 23:08:40 +01:00
|
|
|
p.add_argument('params', nargs='*')
|
|
|
|
args = p.parse_args()
|
2015-11-24 17:39:58 +01:00
|
|
|
|
|
|
|
dir = os.environ.get('HWSIM_TEST_LOG_DIR', '/tmp/hwsim-test-logs')
|
|
|
|
try:
|
|
|
|
os.makedirs(dir)
|
2019-02-10 09:43:10 +01:00
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
raise
|
2015-11-24 17:39:58 +01:00
|
|
|
|
2015-03-03 23:08:40 +01:00
|
|
|
num_servers = args.num_servers
|
|
|
|
rerun_failures = not args.no_retry
|
|
|
|
if args.debug:
|
2014-12-24 10:40:03 +01:00
|
|
|
debug_level = logging.DEBUG
|
2015-03-03 23:08:40 +01:00
|
|
|
extra_args = []
|
2015-03-14 11:09:23 +01:00
|
|
|
if args.valgrind:
|
2019-03-15 11:10:37 +01:00
|
|
|
extra_args += ['--valgrind']
|
2015-03-03 23:08:40 +01:00
|
|
|
if args.long:
|
2019-03-15 11:10:37 +01:00
|
|
|
extra_args += ['--long']
|
2015-03-03 23:08:40 +01:00
|
|
|
if args.codecov:
|
2019-01-24 08:45:42 +01:00
|
|
|
print("Code coverage - build separate binaries")
|
2015-11-24 17:39:58 +01:00
|
|
|
logdir = os.path.join(dir, str(timestamp))
|
2014-12-19 23:51:55 +01:00
|
|
|
os.makedirs(logdir)
|
2015-03-03 23:08:41 +01:00
|
|
|
subprocess.check_call([os.path.join(scriptsdir, 'build-codecov.sh'),
|
|
|
|
logdir])
|
2014-12-19 23:51:55 +01:00
|
|
|
codecov_args = ['--codecov_dir', logdir]
|
|
|
|
codecov = True
|
|
|
|
else:
|
|
|
|
codecov_args = []
|
|
|
|
codecov = False
|
|
|
|
|
2014-12-23 21:25:29 +01:00
|
|
|
first_run_failures = []
|
2015-03-14 11:12:01 +01:00
|
|
|
if args.params:
|
|
|
|
tests = args.params
|
|
|
|
else:
|
|
|
|
tests = []
|
2019-03-15 11:10:37 +01:00
|
|
|
cmd = [os.path.join(os.path.dirname(scriptsdir), 'run-tests.py'), '-L']
|
2015-03-14 11:12:01 +01:00
|
|
|
if args.testmodules:
|
2019-03-15 11:10:37 +01:00
|
|
|
cmd += ["-f"]
|
2015-03-14 11:12:01 +01:00
|
|
|
cmd += args.testmodules
|
|
|
|
lst = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
|
|
|
for l in lst.stdout.readlines():
|
2019-02-08 23:51:08 +01:00
|
|
|
name = l.decode().split(' ')[0]
|
2015-03-14 11:12:01 +01:00
|
|
|
tests.append(name)
|
2014-11-19 01:03:39 +01:00
|
|
|
if len(tests) == 0:
|
|
|
|
sys.exit("No test cases selected")
|
|
|
|
|
2015-03-03 23:08:40 +01:00
|
|
|
if args.shuffle:
|
2015-03-03 08:47:03 +01:00
|
|
|
from random import shuffle
|
|
|
|
shuffle(tests)
|
|
|
|
elif num_servers > 2 and len(tests) > 100:
|
2014-12-21 17:20:15 +01:00
|
|
|
# Move test cases with long duration to the beginning as an
|
|
|
|
# optimization to avoid last part of the test execution running a long
|
|
|
|
# duration test case on a single VM while all other VMs have already
|
|
|
|
# completed their work.
|
2015-03-06 22:47:34 +01:00
|
|
|
for l in long_tests:
|
2014-12-21 17:20:15 +01:00
|
|
|
if l in tests:
|
|
|
|
tests.remove(l)
|
|
|
|
tests.insert(0, l)
|
2015-03-06 22:47:34 +01:00
|
|
|
if args.short:
|
|
|
|
tests = [t for t in tests if t not in long_tests]
|
2014-12-21 17:20:15 +01:00
|
|
|
|
2014-12-24 10:40:03 +01:00
|
|
|
logger.setLevel(debug_level)
|
2020-01-15 12:48:43 +01:00
|
|
|
if not args.nocurses:
|
|
|
|
log_handler = logging.FileHandler('parallel-vm.log')
|
|
|
|
else:
|
|
|
|
log_handler = logging.StreamHandler(sys.stdout)
|
2014-12-24 10:40:03 +01:00
|
|
|
log_handler.setLevel(debug_level)
|
|
|
|
fmt = "%(asctime)s %(levelname)s %(message)s"
|
|
|
|
log_formatter = logging.Formatter(fmt)
|
|
|
|
log_handler.setFormatter(log_formatter)
|
|
|
|
logger.addHandler(log_handler)
|
|
|
|
|
2022-05-22 10:43:38 +02:00
|
|
|
all_failed = []
|
2014-10-19 09:37:02 +02:00
|
|
|
vm = {}
|
|
|
|
for i in range(0, num_servers):
|
2019-12-27 09:09:43 +01:00
|
|
|
cmd = [os.path.join(scriptsdir, 'vm-run.sh'),
|
2015-03-03 23:08:41 +01:00
|
|
|
'--timestamp', str(timestamp),
|
2014-11-16 21:24:18 +01:00
|
|
|
'--ext', 'srv.%d' % (i + 1),
|
2014-12-19 23:51:55 +01:00
|
|
|
'-i'] + codecov_args + extra_args
|
2019-02-05 12:26:58 +01:00
|
|
|
if args.telnet:
|
2019-03-15 11:10:37 +01:00
|
|
|
cmd += ['--telnet', str(args.telnet + i)]
|
2014-10-19 09:37:02 +02:00
|
|
|
vm[i] = {}
|
2019-12-27 16:12:34 +01:00
|
|
|
vm[i]['idx'] = i
|
2019-12-27 09:09:43 +01:00
|
|
|
vm[i]['starting'] = False
|
|
|
|
vm[i]['started'] = False
|
|
|
|
vm[i]['cmd'] = cmd
|
|
|
|
vm[i]['proc'] = None
|
2014-10-19 09:37:02 +02:00
|
|
|
vm[i]['out'] = ""
|
2014-12-24 15:06:37 +01:00
|
|
|
vm[i]['pending'] = ""
|
2014-10-19 09:37:02 +02:00
|
|
|
vm[i]['err'] = ""
|
2014-12-24 16:34:29 +01:00
|
|
|
vm[i]['failed'] = []
|
2015-06-18 19:44:59 +02:00
|
|
|
vm[i]['fail_seq'] = []
|
2019-12-27 09:46:13 +01:00
|
|
|
vm[i]['skip_reason'] = []
|
2019-01-24 08:45:42 +01:00
|
|
|
print('')
|
2014-10-19 09:37:02 +02:00
|
|
|
|
2020-01-15 12:48:43 +01:00
|
|
|
if not args.nocurses:
|
|
|
|
curses.wrapper(show_progress)
|
|
|
|
else:
|
|
|
|
class FakeScreen:
|
|
|
|
def leaveok(self, n):
|
|
|
|
pass
|
|
|
|
def refresh(self):
|
|
|
|
pass
|
|
|
|
def addstr(self, *args, **kw):
|
|
|
|
pass
|
|
|
|
def move(self, x, y):
|
|
|
|
pass
|
|
|
|
def clrtoeol(self):
|
|
|
|
pass
|
2022-05-22 10:43:38 +02:00
|
|
|
def getmaxyx(self):
|
|
|
|
return (25, 80)
|
|
|
|
|
2020-01-15 12:48:43 +01:00
|
|
|
show_progress(FakeScreen())
|
2014-10-19 09:37:02 +02:00
|
|
|
|
2014-10-12 20:49:36 +02:00
|
|
|
with open('{}/{}-parallel.log'.format(dir, timestamp), 'w') as f:
|
|
|
|
for i in range(0, num_servers):
|
2019-03-15 20:08:10 +01:00
|
|
|
f.write('VM {}\n{}\n{}\n'.format(i + 1, vm[i]['out'], vm[i]['err']))
|
|
|
|
first = True
|
|
|
|
for i in range(0, num_servers):
|
|
|
|
for line in vm[i]['out'].splitlines():
|
|
|
|
if line.startswith("FAIL "):
|
|
|
|
if first:
|
|
|
|
first = False
|
|
|
|
print("Logs for failed test cases:")
|
|
|
|
f.write("Logs for failed test cases:\n")
|
|
|
|
fname = "%s/%d.srv.%d/%s.log" % (dir, timestamp, i + 1,
|
|
|
|
line.split(' ')[1])
|
|
|
|
print(fname)
|
|
|
|
f.write("%s\n" % fname)
|
2014-10-12 20:49:36 +02:00
|
|
|
|
2014-12-24 16:34:29 +01:00
|
|
|
failed = get_failed(vm)
|
2014-10-12 20:49:36 +02:00
|
|
|
|
2014-12-23 21:25:29 +01:00
|
|
|
if first_run_failures:
|
2019-01-24 08:45:42 +01:00
|
|
|
print("To re-run same failure sequence(s):")
|
2015-06-18 19:44:59 +02:00
|
|
|
for i in range(0, num_servers):
|
|
|
|
if len(vm[i]['failed']) == 0:
|
|
|
|
continue
|
2019-01-24 08:45:42 +01:00
|
|
|
print("./vm-run.sh", end=' ')
|
2015-11-30 18:42:56 +01:00
|
|
|
if args.long:
|
2019-01-24 08:45:42 +01:00
|
|
|
print("--long", end=' ')
|
2015-06-18 19:44:59 +02:00
|
|
|
skip = len(vm[i]['fail_seq'])
|
|
|
|
skip -= min(skip, 30)
|
|
|
|
for t in vm[i]['fail_seq']:
|
|
|
|
if skip > 0:
|
|
|
|
skip -= 1
|
|
|
|
continue
|
2019-01-24 08:45:42 +01:00
|
|
|
print(t, end=' ')
|
2022-02-15 19:54:24 +01:00
|
|
|
logger.info("Failure sequence: " + " ".join(vm[i]['fail_seq']))
|
2019-01-24 08:45:42 +01:00
|
|
|
print('')
|
|
|
|
print("Failed test cases:")
|
2014-12-23 21:25:29 +01:00
|
|
|
for f in first_run_failures:
|
2019-01-24 08:45:42 +01:00
|
|
|
print(f, end=' ')
|
2014-12-24 10:40:03 +01:00
|
|
|
logger.info("Failed: " + f)
|
2019-01-24 08:45:42 +01:00
|
|
|
print('')
|
2014-12-23 21:25:29 +01:00
|
|
|
double_failed = []
|
2014-12-24 16:34:29 +01:00
|
|
|
for name in failed:
|
2014-12-23 21:25:29 +01:00
|
|
|
double_failed.append(name)
|
|
|
|
for test in first_run_failures:
|
|
|
|
double_failed.remove(test)
|
2015-01-17 10:25:46 +01:00
|
|
|
if not rerun_failures:
|
|
|
|
pass
|
|
|
|
elif failed and not double_failed:
|
2019-01-24 08:45:42 +01:00
|
|
|
print("All failed cases passed on retry")
|
2014-12-24 10:40:03 +01:00
|
|
|
logger.info("All failed cases passed on retry")
|
2014-12-23 21:25:29 +01:00
|
|
|
elif double_failed:
|
2019-01-24 08:45:42 +01:00
|
|
|
print("Failed even on retry:")
|
2014-12-23 21:25:29 +01:00
|
|
|
for f in double_failed:
|
2019-01-24 08:45:42 +01:00
|
|
|
print(f, end=' ')
|
2014-12-24 10:40:03 +01:00
|
|
|
logger.info("Failed on retry: " + f)
|
2019-01-24 08:45:42 +01:00
|
|
|
print('')
|
2014-12-24 16:34:29 +01:00
|
|
|
res = "TOTAL={} PASS={} FAIL={} SKIP={}".format(total_started,
|
|
|
|
total_passed,
|
|
|
|
total_failed,
|
|
|
|
total_skipped)
|
2014-12-24 10:40:03 +01:00
|
|
|
print(res)
|
|
|
|
logger.info(res)
|
2019-01-24 08:45:42 +01:00
|
|
|
print("Logs: " + dir + '/' + str(timestamp))
|
2014-12-24 10:40:03 +01:00
|
|
|
logger.info("Logs: " + dir + '/' + str(timestamp))
|
2014-10-12 20:49:36 +02:00
|
|
|
|
2019-12-27 09:46:13 +01:00
|
|
|
skip_reason = []
|
2019-07-27 19:19:28 +02:00
|
|
|
for i in range(num_servers):
|
2019-12-27 09:09:43 +01:00
|
|
|
if not vm[i]['started']:
|
|
|
|
continue
|
2019-12-27 09:46:13 +01:00
|
|
|
skip_reason += vm[i]['skip_reason']
|
2014-12-24 15:06:37 +01:00
|
|
|
if len(vm[i]['pending']) > 0:
|
|
|
|
logger.info("Unprocessed stdout from VM[%d]: '%s'" %
|
|
|
|
(i, vm[i]['pending']))
|
2014-11-16 21:34:54 +01:00
|
|
|
log = '{}/{}.srv.{}/console'.format(dir, timestamp, i + 1)
|
|
|
|
with open(log, 'r') as f:
|
|
|
|
if "Kernel panic" in f.read():
|
2019-01-24 08:45:42 +01:00
|
|
|
print("Kernel panic in " + log)
|
2014-12-24 10:40:03 +01:00
|
|
|
logger.info("Kernel panic in " + log)
|
2019-12-27 09:46:13 +01:00
|
|
|
missing = {}
|
|
|
|
missing['OCV not supported'] = 'OCV'
|
|
|
|
missing['sigma_dut not available'] = 'sigma_dut'
|
|
|
|
missing['Skip test case with long duration due to --long not specified'] = 'long'
|
|
|
|
missing['TEST_ALLOC_FAIL not supported' ] = 'TEST_FAIL'
|
|
|
|
missing['TEST_ALLOC_FAIL not supported in the build'] = 'TEST_FAIL'
|
|
|
|
missing['TEST_FAIL not supported' ] = 'TEST_FAIL'
|
|
|
|
missing['veth not supported (kernel CONFIG_VETH)'] = 'KERNEL:CONFIG_VETH'
|
|
|
|
missing['WPA-EAP-SUITE-B-192 not supported'] = 'CONFIG_SUITEB192'
|
|
|
|
missing['WPA-EAP-SUITE-B not supported'] = 'CONFIG_SUITEB'
|
|
|
|
missing['wmediumd not available'] = 'wmediumd'
|
|
|
|
missing['DPP not supported'] = 'CONFIG_DPP'
|
|
|
|
missing['DPP version 2 not supported'] = 'CONFIG_DPP2'
|
2020-01-26 15:03:31 +01:00
|
|
|
missing['EAP method PWD not supported in the build'] = 'CONFIG_EAP_PWD'
|
|
|
|
missing['EAP method TEAP not supported in the build'] = 'CONFIG_EAP_TEAP'
|
|
|
|
missing['FILS not supported'] = 'CONFIG_FILS'
|
|
|
|
missing['FILS-SK-PFS not supported'] = 'CONFIG_FILS_SK_PFS'
|
|
|
|
missing['OWE not supported'] = 'CONFIG_OWE'
|
|
|
|
missing['SAE not supported'] = 'CONFIG_SAE'
|
|
|
|
missing['Not using OpenSSL'] = 'CONFIG_TLS=openssl'
|
|
|
|
missing['wpa_supplicant TLS library is not OpenSSL: internal'] = 'CONFIG_TLS=openssl'
|
2019-12-27 09:46:13 +01:00
|
|
|
missing_items = []
|
|
|
|
other_reasons = []
|
|
|
|
for reason in sorted(set(skip_reason)):
|
|
|
|
if reason in missing:
|
|
|
|
missing_items.append(missing[reason])
|
|
|
|
elif reason.startswith('OCSP-multi not supported with this TLS library'):
|
|
|
|
missing_items.append('OCSP-MULTI')
|
|
|
|
else:
|
|
|
|
other_reasons.append(reason)
|
|
|
|
if missing_items:
|
|
|
|
print("Missing items (SKIP):", missing_items)
|
|
|
|
if other_reasons:
|
|
|
|
print("Other skip reasons:", other_reasons)
|
2014-11-16 21:34:54 +01:00
|
|
|
|
2021-02-28 19:20:38 +01:00
|
|
|
for i in range(num_servers):
|
|
|
|
unknown = ""
|
|
|
|
for line in vm[i]['out'].splitlines():
|
|
|
|
if not known_output(tests, line):
|
|
|
|
unknown += line + "\n"
|
|
|
|
if unknown:
|
|
|
|
print("\nVM %d - unexpected stdout output:\n%s" % (i, unknown))
|
|
|
|
if vm[i]['err']:
|
|
|
|
print("\nVM %d - unexpected stderr output:\n%s\n" % (i, vm[i]['err']))
|
|
|
|
|
2014-12-19 23:51:55 +01:00
|
|
|
if codecov:
|
2019-01-24 08:45:42 +01:00
|
|
|
print("Code coverage - preparing report")
|
2014-12-19 23:51:55 +01:00
|
|
|
for i in range(num_servers):
|
2015-03-03 23:08:41 +01:00
|
|
|
subprocess.check_call([os.path.join(scriptsdir,
|
|
|
|
'process-codecov.sh'),
|
2014-12-19 23:51:55 +01:00
|
|
|
logdir + ".srv.%d" % (i + 1),
|
|
|
|
str(i)])
|
2015-03-03 23:08:41 +01:00
|
|
|
subprocess.check_call([os.path.join(scriptsdir, 'combine-codecov.sh'),
|
|
|
|
logdir])
|
2019-01-24 08:45:42 +01:00
|
|
|
print("file://%s/index.html" % logdir)
|
2014-12-24 10:40:03 +01:00
|
|
|
logger.info("Code coverage report: file://%s/index.html" % logdir)
|
2014-12-19 23:51:55 +01:00
|
|
|
|
2015-01-17 10:25:46 +01:00
|
|
|
if double_failed or (failed and not rerun_failures):
|
2014-12-24 10:40:03 +01:00
|
|
|
logger.info("Test run complete - failures found")
|
2014-12-23 21:25:29 +01:00
|
|
|
sys.exit(2)
|
|
|
|
if failed:
|
2014-12-24 10:40:03 +01:00
|
|
|
logger.info("Test run complete - failures found on first run; passed on retry")
|
2014-12-23 21:25:29 +01:00
|
|
|
sys.exit(1)
|
2014-12-24 10:40:03 +01:00
|
|
|
logger.info("Test run complete - no failures")
|
2014-12-23 21:25:29 +01:00
|
|
|
sys.exit(0)
|
|
|
|
|
2014-10-12 20:49:36 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|