3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-21 22:09:23 +01:00

testrunner: Fix /tmp files cleanup on error

Since the list of files copied to /tmp was part of the return value from
pre_test(), if an exception occurred inside pre_test(), "copied" would
be undefined and the post_test(ctx, copied) call in the finally clause
cause another exception:

raceback (most recent call last):
  File "/home/balrog/repos/iwd/tools/test-runner", line 1508, in <module>
    run_tests()
  File "/home/balrog/repos/iwd/tools/test-runner", line 1242, in run_tests
    run_auto_tests(config.ctx, args)
  File "/home/balrog/repos/iwd/tools/test-runner", line 1166, in run_auto_tests
    post_test(ctx, copied)
UnboundLocalError: local variable 'copied' referenced before assignment

(apart from not being able to clean up the files).  Pass "copied" as a
paremeter to pre_test instead.
This commit is contained in:
Andrew Zaborowski 2021-01-25 18:56:14 +01:00 committed by Denis Kenzior
parent 6fdae0c4eb
commit a55f8864d2

View File

@ -973,7 +973,7 @@ def start_test(ctx, subtests, rqueue):
# This may not be required since we are manually popping sys.modules
importlib.invalidate_caches()
def pre_test(ctx, test):
def pre_test(ctx, test, copied):
'''
Copy test files, start processes, and any other pre test work.
'''
@ -1005,6 +1005,7 @@ def pre_test(ctx, test):
shutil.copytree(f, '/tmp/' + f)
else:
shutil.copy(f, '/tmp')
copied.append(f)
# Prune down any subtests if needed
if ctx.args.sub_tests:
@ -1044,7 +1045,7 @@ def pre_test(ctx, test):
sys.path.insert(1, test)
return (to_copy, sorted(subtests))
return sorted(subtests)
def post_test(ctx, to_copy):
'''
@ -1119,8 +1120,9 @@ def run_auto_tests(ctx, args):
shutil.copy(args.testhome + '/autotests/misc/phonesim/phonesim.conf', '/tmp')
for test in tests:
copied = []
try:
copied, subtests = pre_test(ctx, test)
subtests = pre_test(ctx, test, copied)
if args.shell:
#