X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=tests%2Fhwsim%2Frun-tests.py;h=499263f2dc23c9988438632e2fa700801afe39fb;hb=78a37200f8336f3e509d7165e89caf132ced2d90;hp=09a3acd4b1ce6b6b492e92f389bef97f65f7d344;hpb=a66d2248a006e529e31342be1fb2738587c5bf11;p=mech_eap.git diff --git a/tests/hwsim/run-tests.py b/tests/hwsim/run-tests.py index 09a3acd..499263f 100755 --- a/tests/hwsim/run-tests.py +++ b/tests/hwsim/run-tests.py @@ -18,10 +18,14 @@ import termios import logging logger = logging.getLogger() -if os.path.exists('../../wpaspy'): - sys.path.append('../../wpaspy') -else: - sys.path.append('../../../wpaspy') +try: + import sqlite3 + sqlite3_imported = True +except ImportError: + sqlite3_imported = False + +scriptsdir = os.path.dirname(os.path.realpath(sys.modules[__name__].__file__)) +sys.path.append(os.path.join(scriptsdir, '..', '..', 'wpaspy')) from wpasupplicant import WpaSupplicant from hostapd import HostapdGlobal @@ -82,7 +86,7 @@ def add_log_file(conn, test, run, type, path): if contents is None: return sql = "INSERT INTO logs(test,run,type,contents) VALUES(?, ?, ?, ?)" - params = (test, run, type, contents) + params = (test, run, type, sqlite3.Binary(contents)) try: conn.execute(sql, params) conn.commit() @@ -124,7 +128,7 @@ class DataCollector(object): def __enter__(self): if self._tracing: output = os.path.abspath(os.path.join(self._logdir, '%s.dat' % (self._testname, ))) - self._trace_cmd = subprocess.Popen(['sudo', 'trace-cmd', 'record', '-o', output, '-e', 'mac80211', '-e', 'cfg80211', 'sh', '-c', 'echo STARTED ; read l'], + self._trace_cmd = subprocess.Popen(['trace-cmd', 'record', '-o', output, '-e', 'mac80211', '-e', 'cfg80211', '-e', 'printk', 'sh', '-c', 'echo STARTED ; read l'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=open('/dev/null', 'w'), @@ -142,7 +146,11 @@ class DataCollector(object): self._trace_cmd.wait() if self._dmesg: output = os.path.join(self._logdir, '%s.dmesg' % (self._testname, )) - subprocess.call(['sudo', 'dmesg', '-c'], stdout=open(output, 'w')) + num = 0 + while os.path.exists(output): + output = os.path.join(self._logdir, '%s.dmesg-%d' % (self._testname, num)) + num += 1 + subprocess.call(['dmesg', '-c'], stdout=open(output, 'w')) def rename_log(logdir, basename, testname, dev): try: @@ -157,7 +165,7 @@ def rename_log(logdir, basename, testname, dev): os.rename(srcname, dstname) if dev: dev.relog() - subprocess.call(['sudo', 'chown', '-f', getpass.getuser(), srcname]) + subprocess.call(['chown', '-f', getpass.getuser(), srcname]) except Exception, e: logger.info("Failed to rename log files") logger.info(e) @@ -165,10 +173,7 @@ def rename_log(logdir, basename, testname, dev): def main(): tests = [] test_modules = [] - if os.path.exists('run-tests.py'): - files = os.listdir(".") - else: - files = os.listdir("..") + files = os.listdir(scriptsdir) for t in files: m = re.match(r'(test_.*)\.py$', t) if m: @@ -232,7 +237,9 @@ def main(): sys.exit(2) if args.database: - import sqlite3 + if not sqlite3_imported: + print "No sqlite3 module found" + sys.exit(2) conn = sqlite3.connect(args.database) conn.execute('CREATE TABLE IF NOT EXISTS results (test,result,run,time,duration,build,commitid)') conn.execute('CREATE TABLE IF NOT EXISTS tests (test,description)') @@ -245,13 +252,13 @@ def main(): # read the modules from the modules file if args.mfile: - args.testmodules = [] - with open(args.mfile) as f: - for line in f.readlines(): - line = line.strip() - if not line or line.startswith('#'): - continue - args.testmodules.append(line) + args.testmodules = [] + with open(args.mfile) as f: + for line in f.readlines(): + line = line.strip() + if not line or line.startswith('#'): + continue + args.testmodules.append(line) tests_to_run = [] if args.tests: @@ -338,7 +345,7 @@ def main(): sys.exit(1) if args.dmesg: - subprocess.call(['sudo', 'dmesg', '-c'], stdout=open('/dev/null', 'w')) + subprocess.call(['dmesg', '-c'], stdout=open('/dev/null', 'w')) if conn and args.prefill: for t in tests_to_run: @@ -393,6 +400,7 @@ def main(): t = tests_to_run.pop(0) name = t.__name__.replace('test_', '', 1) + open('/dev/kmsg', 'w').write('running hwsim test case %s\n' % name) if log_handler: log_handler.stream.close() logger.removeHandler(log_handler) @@ -445,8 +453,15 @@ def main(): except HwsimSkip, e: logger.info("Skip test case: %s" % e) result = "SKIP" + except NameError, e: + import traceback + logger.info(e) + traceback.print_exc() + result = "FAIL" except Exception, e: + import traceback logger.info(e) + traceback.print_exc() if args.loglevel == logging.WARNING: print "Exception: " + str(e) result = "FAIL" @@ -458,6 +473,10 @@ def main(): logger.info("Failed to issue TEST-STOP after {} for {}".format(name, d.ifname)) logger.info(e) result = "FAIL" + if args.no_reset: + print "Leaving devices in current state" + else: + reset_ok = reset_devs(dev, apdev) wpas = None try: wpas = WpaSupplicant(global_iface="/tmp/wpas-wlan5") @@ -468,10 +487,6 @@ def main(): pass if wpas: wpas.close_ctrl() - if args.no_reset: - print "Leaving devices in current state" - else: - reset_ok = reset_devs(dev, apdev) for i in range(0, 3): rename_log(args.logdir, 'log' + str(i), name, dev[i]) @@ -484,10 +499,20 @@ def main(): result = "FAIL" hapd = None rename_log(args.logdir, 'hostapd', name, hapd) + if hapd: + del hapd + hapd = None + # Use None here since this instance of Wlantest() will never be + # used for remote host hwsim tests on real hardware. + Wlantest.setup(None) wt = Wlantest() rename_log(args.logdir, 'hwsim0.pcapng', name, wt) rename_log(args.logdir, 'hwsim0', name, wt) + if os.path.exists(os.path.join(args.logdir, 'fst-wpa_supplicant')): + rename_log(args.logdir, 'fst-wpa_supplicant', name, None) + if os.path.exists(os.path.join(args.logdir, 'fst-hostapd')): + rename_log(args.logdir, 'fst-hostapd', name, None) end = datetime.now() diff = end - start