tests: Allow running with arbitrary working directory

It's somewhat annoying that you can only run parallel-vm.py as
./parallel-vm.py, not from elsewhere by giving the full path,
so fix that by resolving the paths correctly in the scripts where
needed.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2015-03-03 23:08:41 +01:00 committed by Jouni Malinen
parent 4f06261bd9
commit d2002f8334
2 changed files with 15 additions and 13 deletions

View file

@ -18,10 +18,8 @@ import termios
import logging import logging
logger = logging.getLogger() logger = logging.getLogger()
if os.path.exists('../../wpaspy'): scriptsdir = os.path.dirname(os.path.realpath(sys.modules[__name__].__file__))
sys.path.append('../../wpaspy') sys.path.append(os.path.join(scriptsdir, '..', '..', 'wpaspy'))
else:
sys.path.append('../../../wpaspy')
from wpasupplicant import WpaSupplicant from wpasupplicant import WpaSupplicant
from hostapd import HostapdGlobal from hostapd import HostapdGlobal
@ -169,10 +167,7 @@ def rename_log(logdir, basename, testname, dev):
def main(): def main():
tests = [] tests = []
test_modules = [] test_modules = []
if os.path.exists('run-tests.py'): files = os.listdir(scriptsdir)
files = os.listdir(".")
else:
files = os.listdir("..")
for t in files: for t in files:
m = re.match(r'(test_.*)\.py$', t) m = re.match(r'(test_.*)\.py$', t)
if m: if m:

View file

@ -241,6 +241,7 @@ def show_progress(scr):
def main(): def main():
import argparse import argparse
import os
global num_servers global num_servers
global vm global vm
global dir global dir
@ -259,6 +260,8 @@ def main():
rerun_failures = True rerun_failures = True
timestamp = int(time.time()) timestamp = int(time.time())
scriptsdir = os.path.dirname(os.path.realpath(sys.argv[0]))
p = argparse.ArgumentParser(description='run multiple testing VMs in parallel') 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), p.add_argument('num_servers', metavar='number of VMs', type=int, choices=range(1, 100),
help="number of VMs to start") help="number of VMs to start")
@ -289,7 +292,8 @@ def main():
print "Code coverage - build separate binaries" print "Code coverage - build separate binaries"
logdir = "/tmp/hwsim-test-logs/" + str(timestamp) logdir = "/tmp/hwsim-test-logs/" + str(timestamp)
os.makedirs(logdir) os.makedirs(logdir)
subprocess.check_call(['./build-codecov.sh', logdir]) subprocess.check_call([os.path.join(scriptsdir, 'build-codecov.sh'),
logdir])
codecov_args = ['--codecov_dir', logdir] codecov_args = ['--codecov_dir', logdir]
codecov = True codecov = True
else: else:
@ -298,7 +302,7 @@ def main():
first_run_failures = [] first_run_failures = []
tests = [] tests = []
cmd = [ '../run-tests.py', '-L' ] cmd = [ os.path.join(os.path.dirname(scriptsdir), 'run-tests.py'), '-L' ]
if args.testmodules: if args.testmodules:
cmd += [ "-f" ] cmd += [ "-f" ]
cmd += args.testmodules cmd += args.testmodules
@ -377,7 +381,8 @@ def main():
for i in range(0, num_servers): for i in range(0, num_servers):
print("\rStarting virtual machine {}/{}".format(i + 1, num_servers)), print("\rStarting virtual machine {}/{}".format(i + 1, num_servers)),
logger.info("Starting virtual machine {}/{}".format(i + 1, num_servers)) logger.info("Starting virtual machine {}/{}".format(i + 1, num_servers))
cmd = ['./vm-run.sh', '--delay', str(i), '--timestamp', str(timestamp), cmd = [os.path.join(scriptsdir, 'vm-run.sh'), '--delay', str(i),
'--timestamp', str(timestamp),
'--ext', 'srv.%d' % (i + 1), '--ext', 'srv.%d' % (i + 1),
'-i'] + codecov_args + extra_args '-i'] + codecov_args + extra_args
vm[i] = {} vm[i] = {}
@ -448,10 +453,12 @@ def main():
if codecov: if codecov:
print "Code coverage - preparing report" print "Code coverage - preparing report"
for i in range(num_servers): for i in range(num_servers):
subprocess.check_call(['./process-codecov.sh', subprocess.check_call([os.path.join(scriptsdir,
'process-codecov.sh'),
logdir + ".srv.%d" % (i + 1), logdir + ".srv.%d" % (i + 1),
str(i)]) str(i)])
subprocess.check_call(['./combine-codecov.sh', logdir]) subprocess.check_call([os.path.join(scriptsdir, 'combine-codecov.sh'),
logdir])
print "file://%s/index.html" % logdir print "file://%s/index.html" % logdir
logger.info("Code coverage report: file://%s/index.html" % logdir) logger.info("Code coverage report: file://%s/index.html" % logdir)