77bab485a5b559d5de49974603d21b05f24cd2af
[yaffs2.git] / direct / test-framework / unit_tests / test_runner.py
1 #!/usr/bin/env python3
2 """
3 test_runner.py
4 This file runs all of the yaffs unit tests and aggrates the outputs.
5
6 To run this file you can use:
7  
8 $ python3 test_runner.py
9
10 or 
11
12 $ ./test_runner.py
13
14 To add a new test to this test runner, add the test dir path to the
15 test_list below. Inside that folder there need to be a makefile with
16 a "test" target that compiles and runs the test script. I.e. "make test" 
17 is called in every test directory.
18 """
19
20
21 import subprocess, sys
22
23 test_list = ["is_yaffs_working_tests",
24         "quick_tests",
25         "64_and_32_bit_time/64_bit",
26         "64_and_32_bit_time/32_bit",
27         ]
28
29
30 TEST_FAILED = -1
31 TEST_PASSED = 1
32
33 def run(makefile_paths):
34         failed_tests =[]
35         for path in makefile_paths:
36                 print("\nrunning test {}".format(path))
37                 is_successful, test_output = run_makefile_test(path)
38                 if is_successful != TEST_PASSED:
39                         print('\033[41m' +'test {} failed'.format(path)+'\033[0m')
40                         print(test_output)
41                         failed_tests.append( (path, is_successful) )
42                 else:
43                         print('\033[42m' +"test passed"+'\033[0m')
44         return failed_tests
45
46 def run_makefile_test(path):
47         try:
48                 subprocess.check_output("make -j -C {} test".format(path), shell=True)  
49         except subprocess.CalledProcessError as e:
50                 return (TEST_FAILED, e.output.decode('UTF-8'))
51         
52         return (TEST_PASSED, "test passed")
53
54 if __name__ == "__main__":
55         #run the test runner.
56         failed_tests = run(test_list)
57         
58         print("\ntest summary #############")
59         if len(failed_tests) == 0:
60                 print('\033[42m' +"all tests passed"+'\033[0m')
61         else:
62                 for path, output in failed_tests:
63                         print('\033[41m' +"test {} failed".format(path)+'\033[0m')
64                 print('\033[41m' + "ran {} tests, {} failed".format(len(test_list), len(failed_tests))+'\033[0m')