Skip to content

Commit 439a53f

Browse files
committed
test.py: now correctly filters and runs integration tests
1 parent 171b77f commit 439a53f

1 file changed

Lines changed: 50 additions & 16 deletions

File tree

test/test.py

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343

4444
test_count = 0
4545

46-
def print_skipped(name, reason):
47-
print pretty.WARNING("* Skipping " + name)
48-
print " Reason: {0:40}".format(reason)
46+
def print_skipped(tests):
47+
for test in tests:
48+
if test.skip_:
49+
print pretty.WARNING("* Skipping " + test.name_)
50+
print " Reason: {0:40}".format(test.skip_reason_)
4951

5052
def valid_tests(subfolder=None):
5153
"""Returns a list of all the valid integration tests in */integration/*"""
@@ -82,9 +84,17 @@ def __init__(self, path, clean=False, command=['sudo', '-E', 'python', 'test.py'
8284
# Extract category and type from the path variable
8385
# Category is linked to the top level folder e.g. net, fs, hw
8486
# Type is linked to the type of test e.g. integration, unit, stress
85-
if not category:
87+
if self.path_ == 'stress':
88+
self.category_ = 'stress'
89+
self.type_ = 'stress'
90+
elif self.path_ == 'examples':
91+
self.category_ = 'examples'
92+
self.type_ = 'examples'
93+
elif self.path_ == 'mod/gsl':
94+
self.category_ = 'mod'
95+
self.type_ = 'mod'
96+
else:
8697
self.category_ = self.path_.split('/')[-3]
87-
if not test_type:
8898
self.type_ = self.path_.split('/')[-2]
8999

90100
if not name:
@@ -97,7 +107,6 @@ def __init__(self, path, clean=False, command=['sudo', '-E', 'python', 'test.py'
97107
self.skip_ = valid_status['skip']
98108
self.skip_reason_ = valid_status['skip_reason']
99109

100-
print pretty.INFO("Test"), "starting", self.name_
101110

102111
if clean:
103112
subprocess.check_output(["make","clean"])
@@ -289,16 +298,31 @@ def main():
289298
sys.exit(status)
290299

291300

292-
def integration_tests2():
301+
def run_tests(tests):
302+
""" Function that runs the tests that are passed to it.
303+
Filters out any invalid tests before running
293304
294-
valid = valid_tests()
305+
Arguments:
306+
tests: List containing test objects to be run
295307
296-
print pretty.HEADER("Starting " + str(len(valid)) + " integration test(s)")
297-
processes = []
308+
Returns:
309+
integer: Number of tests that failed
310+
"""
311+
312+
# Only run the valid tests
313+
tests = [ x for x in tests if not x.skip_ ]
298314

315+
# Print info before starting to run
316+
print pretty.HEADER("Starting " + str(len(tests)) + " integration test(s)")
317+
for test in tests:
318+
print pretty.INFO("Test"), "starting", test.name_
319+
320+
processes = []
299321
fail_count = 0
300-
for path in valid:
301-
processes.append(Test(path, clean = args.clean).start())
322+
323+
# Start running tests in parallell
324+
for test in tests:
325+
processes.append(test.start())
302326

303327
# Collect test results
304328
print pretty.HEADER("Collecting integration test results")
@@ -355,7 +379,10 @@ def find_leaf_nodes():
355379
leaf_nodes = []
356380

357381
for dirpath, dirnames, filenames in os.walk('.'):
358-
if dirpath[2:].split('/')[0] in test_categories:
382+
# Will now skip any path that is not defined as a test category
383+
# or ends with unit or integration -> no tests in those folders were
384+
# created
385+
if dirpath[2:].split('/')[0] in test_categories and dirpath.split('/')[-1] not in ['unit', 'integration']:
359386
if not dirnames:
360387
leaf_nodes.append(dirpath[2:])
361388

@@ -366,9 +393,16 @@ def main2():
366393
# Find leaf nodes
367394
leaves = find_leaf_nodes()
368395

369-
# Valid tests
370-
for path in leaves:
371-
print path, ' ', check_valid(path)
396+
# Populate test objects
397+
all_tests = [ Test(path) for path in leaves ]
398+
399+
net_tests = [ x for x in all_tests if x.category_ == 'net' ]
400+
print_skipped(net_tests)
401+
402+
run_tests(net_tests)
403+
404+
405+
372406
# Populate test objects
373407
#valid_test_objects = [ Test(x) for x in leaves if not x in args.skip ]
374408

0 commit comments

Comments
 (0)