+ try:
+ d.reset()
+ except Exception, e:
+ logger.info("Failed to reset device " + d.ifname)
+ print str(e)
+ ok = False
+
+ wpas = None
+ try:
+ wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
+ ifaces = wpas.global_request("INTERFACES").splitlines()
+ for iface in ifaces:
+ if iface.startswith("wlan"):
+ wpas.interface_remove(iface)
+ except Exception, e:
+ pass
+ if wpas:
+ wpas.close_ctrl()
+
+ try:
+ hapd = HostapdGlobal()
+ hapd.flush()
+ hapd.remove('wlan3-3')
+ hapd.remove('wlan3-2')
+ for ap in apdev:
+ hapd.remove(ap['ifname'])
+ except Exception, e:
+ logger.info("Failed to remove hostapd interface")
+ print str(e)
+ ok = False
+ return ok
+
+def add_log_file(conn, test, run, type, path):
+ if not os.path.exists(path):
+ return
+ contents = None
+ with open(path, 'r') as f:
+ contents = f.read()
+ if contents is None:
+ return
+ sql = "INSERT INTO logs(test,run,type,contents) VALUES(?, ?, ?, ?)"
+ params = (test, run, type, sqlite3.Binary(contents))
+ try:
+ conn.execute(sql, params)
+ conn.commit()
+ except Exception, e:
+ print "sqlite: " + str(e)
+ print "sql: %r" % (params, )
+
+def report(conn, prefill, build, commit, run, test, result, duration, logdir,
+ sql_commit=True):
+ if conn:
+ if not build:
+ build = ''
+ if not commit:
+ commit = ''
+ if prefill:
+ conn.execute('DELETE FROM results WHERE test=? AND run=? AND result=?', (test, run, 'NOTRUN'))
+ sql = "INSERT INTO results(test,result,run,time,duration,build,commitid) VALUES(?, ?, ?, ?, ?, ?, ?)"
+ params = (test, result, run, time.time(), duration, build, commit)
+ try:
+ conn.execute(sql, params)
+ if sql_commit:
+ conn.commit()
+ except Exception, e:
+ print "sqlite: " + str(e)
+ print "sql: %r" % (params, )
+
+ if result == "FAIL":
+ for log in [ "log", "log0", "log1", "log2", "log3", "log5",
+ "hostapd", "dmesg", "hwsim0", "hwsim0.pcapng" ]:
+ add_log_file(conn, test, run, log,
+ logdir + "/" + test + "." + log)
+
+class DataCollector(object):
+ def __init__(self, logdir, testname, tracing, dmesg):
+ self._logdir = logdir
+ self._testname = testname
+ self._tracing = tracing
+ self._dmesg = dmesg
+ def __enter__(self):
+ if self._tracing:
+ output = os.path.abspath(os.path.join(self._logdir, '%s.dat' % (self._testname, )))
+ 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'),
+ cwd=self._logdir)
+ l = self._trace_cmd.stdout.read(7)
+ while self._trace_cmd.poll() is None and not 'STARTED' in l:
+ l += self._trace_cmd.stdout.read(1)
+ res = self._trace_cmd.returncode
+ if res:
+ print "Failed calling trace-cmd: returned exit status %d" % res
+ sys.exit(1)
+ def __exit__(self, type, value, traceback):
+ if self._tracing:
+ self._trace_cmd.stdin.write('DONE\n')
+ self._trace_cmd.wait()
+ if self._dmesg:
+ output = os.path.join(self._logdir, '%s.dmesg' % (self._testname, ))
+ 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:
+ import getpass
+ srcname = os.path.join(logdir, basename)
+ dstname = os.path.join(logdir, testname + '.' + basename)
+ num = 0
+ while os.path.exists(dstname):
+ dstname = os.path.join(logdir,
+ testname + '.' + basename + '-' + str(num))
+ num = num + 1
+ os.rename(srcname, dstname)
+ if dev:
+ dev.relog()
+ subprocess.call(['chown', '-f', getpass.getuser(), srcname])
+ except Exception, e:
+ logger.info("Failed to rename log files")
+ logger.info(e)