1515
1616startdir = os .getcwd ()
1717
18- test_categories = ['fs' , 'hw' , 'kernel' , 'mod' , 'net' , 'performance' , 'platform' , 'stl' , 'stress' , 'util' ]
18+ test_categories = ['fs' , 'hw' , 'kernel' , 'mod' , 'net' , 'performance' , 'platform' , 'stl' , 'util' ]
19+ test_types = ['integration' , 'stress' , 'unit' , 'examples' ]
1920
2021"""
2122Script used for running all the valid tests in the terminal.
@@ -74,7 +75,7 @@ def valid_tests(subfolder=None):
7475
7576class Test :
7677 """ A class to start a test as a subprocess and pretty-print status """
77- def __init__ (self , path , clean = False , command = ['sudo' , '-E' , 'python' , 'test.py' ], name = None , category = None , test_type = None ):
78+ def __init__ (self , path , clean = False , command = ['sudo' , '-E' , 'python' , 'test.py' ], name = None ):
7879
7980 self .command_ = command
8081 self .proc_ = None
@@ -93,6 +94,9 @@ def __init__(self, path, clean=False, command=['sudo', '-E', 'python', 'test.py'
9394 elif self .path_ == 'mod/gsl' :
9495 self .category_ = 'mod'
9596 self .type_ = 'mod'
97+ elif self .path_ == '.' :
98+ self .category_ = 'unit'
99+ self .type_ = 'unit'
96100 else :
97101 self .category_ = self .path_ .split ('/' )[- 3 ]
98102 self .type_ = self .path_ .split ('/' )[- 2 ]
@@ -102,11 +106,8 @@ def __init__(self, path, clean=False, command=['sudo', '-E', 'python', 'test.py'
102106 else :
103107 self .name_ = name
104108
105- # Check if the tests is valid or not
106- valid_status = check_valid (self .path_ )
107- self .skip_ = valid_status ['skip' ]
108- self .skip_reason_ = valid_status ['skip_reason' ]
109-
109+ # Check if the test is valid or not
110+ self .check_valid ()
110111
111112 if clean :
112113 subprocess .check_output (["make" ,"clean" ])
@@ -156,44 +157,39 @@ def wait_status(self):
156157
157158 return self .proc_ .returncode
158159
160+ def check_valid (self ):
161+ """ Will check if a test is valid. The following points can declare a test valid:
162+ 1. Contains the files required
163+ 2. Not listed in the skipped_tests.json
164+ 3. Not listed in the args.skip cmd line argument
159165
160-
161- def integration_tests (subfolder = None ):
162- """
163- Loops over all valid tests as defined by ./validate_all.py. Runs them one by one and gives an update of the statuses at the end.
166+ Arguments:
167+ self: Class function
164168 """
165- global test_count
166- if subfolder :
167- valid = valid_tests (subfolder )
168- else :
169- valid = valid_tests ()
170- if not valid :
171- print pretty .WARNING ("Integration tests skipped" )
172- return 0
173-
174- test_count += len (valid )
175- print pretty .HEADER ("Starting " + str (len (valid )) + " integration test(s)" )
176- processes = []
177-
178- print valid
179- sys .exit (0 )
180-
181- fail_count = 0
182- for path in valid :
183- processes .append (Test (path , clean = args .clean ).start ())
184-
185- # Collect test results
186- print pretty .HEADER ("Collecting integration test results" )
169+ # Test 1
170+ if not validate_test .validate_path (self .path_ , verb = False ):
171+ self .skip_ = True
172+ self .skip_reason_ = 'Failed validate_test, missing files'
173+ return
187174
188- for p in processes :
189- fail_count += 1 if p .wait_status () else 0
175+ # Test 2
176+ # Figure out if the test should be skipped
177+ skip_json = json .loads (open ("skipped_tests.json" ).read ())
178+ for skip in skip_json :
179+ if self .path_ == skip ['name' ]:
180+ self .skip_ = True
181+ self .skip_reason_ = 'Defined in skipped_tests.json'
182+ return
190183
191- # Exit early if any tests failed
192- if fail_count and args .fail :
193- print pretty .FAIL (str (fail_count ) + "integration tests failed" )
194- sys .exit (fail_count )
184+ # Test 3
185+ if self .path_ in args .skip or self .category_ in args .skip :
186+ self .skip_ = True
187+ self .skip_reason_ = 'Defined by cmd line argument'
188+ return
195189
196- return fail_count
190+ self .skip_ = False
191+ self .skip_reason_ = None
192+ return
197193
198194
199195def unit_tests ():
@@ -298,7 +294,7 @@ def main():
298294 sys .exit (status )
299295
300296
301- def run_tests (tests ):
297+ def integration_tests (tests ):
302298 """ Function that runs the tests that are passed to it.
303299 Filters out any invalid tests before running
304300
@@ -310,7 +306,7 @@ def run_tests(tests):
310306 """
311307
312308 # Only run the valid tests
313- tests = [ x for x in tests if not x .skip_ ]
309+ tests = [ x for x in tests if not x .skip_ and x . type_ == 'integration' ]
314310
315311 # Print info before starting to run
316312 print pretty .HEADER ("Starting " + str (len (tests )) + " integration test(s)" )
@@ -319,6 +315,8 @@ def run_tests(tests):
319315
320316 processes = []
321317 fail_count = 0
318+ global test_count
319+ test_count += len (tests )
322320
323321 # Start running tests in parallell
324322 for test in tests :
@@ -338,36 +336,6 @@ def run_tests(tests):
338336 return fail_count
339337
340338
341- def check_valid (path ):
342- """ Will check if a test is valid. The following points can declare a test valid:
343- 1. Contains the files required
344- 2. Not listed in the skipped_tests.json
345- 3. Not listed in the args.skip cmd line argument
346-
347- Arguments:
348- path: Path of test to be checked
349-
350- Returns:
351- dict: Dictionary with skip status (bool) and skip reason (string)
352- """
353- # Test 1
354- if not validate_test .validate_path (path , verb = False ):
355- return {'skip' : True , 'skip_reason' : 'Failed validate_test, missing files' }
356-
357- # Test 2
358- # Figure out if the test should be skipped
359- skip_json = json .loads (open ("skipped_tests.json" ).read ())
360- for skip in skip_json :
361- if path == skip ['name' ]:
362- return {'skip' : True , 'skip_reason' : 'Defined in skipped_tests.json' }
363-
364- # Test 3
365- if path in args .skip :
366- return {'skip' : True , 'skip_reason' : 'Defined by cmd line argument' }
367-
368- return {'skip' : False , 'skip_reason' : None }
369-
370-
371339def find_leaf_nodes ():
372340 """ Used to find all leaf nodes in the test directory,
373341 this is to help identify all possible test directories.
@@ -389,22 +357,57 @@ def find_leaf_nodes():
389357 return leaf_nodes
390358
391359
392- def main2 ():
360+ def main ():
393361 # Find leaf nodes
394362 leaves = find_leaf_nodes ()
395363
396364 # Populate test objects
397365 all_tests = [ Test (path ) for path in leaves ]
398366
399- net_tests = [ x for x in all_tests if x .category_ == 'net' ]
400- print_skipped (net_tests )
367+ # Figure out which tests are to be run
368+ test_categories_to_run = []
369+ test_types_to_run = []
370+ if args .tests :
371+ for argument in args .tests :
372+ if argument in test_categories and argument not in args .skip :
373+ test_categories_to_run .append (argument )
374+ elif argument in test_types and argument not in args .skip :
375+ test_types_to_run .append (argument )
376+ else :
377+ print 'Test specified is not recognised, exiting'
378+ sys .exit (1 )
379+ else :
380+ test_types_to_run = test_types
381+
382+
383+ if test_categories_to_run :
384+ # This means that a specific category has been requested
385+ specific_tests = [ test for test in all_tests if test .category_ in test_categories_to_run ]
401386
402- run_tests (net_tests )
387+ # Print which tests are skipped
388+ print_skipped (specific_tests )
403389
390+ # Run the tests
391+ integration = integration_tests (specific_tests )
392+ else :
393+ # Print which tests are skipped
394+ print_skipped (all_tests )
404395
396+ # Run the tests
397+ integration = integration_tests (all_tests ) if "integration" in test_types_to_run else 0
405398
406- # Populate test objects
407- #valid_test_objects = [ Test(x) for x in leaves if not x in args.skip ]
399+ stress = stress_test () if "stress" in test_types_to_run else 0
400+ unit = unit_tests () if "unit" in test_types_to_run else 0
401+ examples = examples_working () if "examples" in test_types_to_run else 0
402+
403+ status = max (integration , stress , unit , examples )
404+ if (status == 0 ):
405+ print pretty .SUCCESS (str (test_count - status ) + " / " + str (test_count )
406+ + " tests passed, exiting with code 0" )
407+ else :
408+ print pretty .FAIL (str (status ) + " / " + str (test_count ) + " tests failed " )
409+
410+ sys .exit (status )
408411
409412
410413if __name__ == '__main__' :
0 commit comments