4 This file runs all of the yaffs unit tests and aggrates the outputs.
6 To run this file you can use:
8 $ python3 test_runner.py
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.
21 import subprocess, sys
23 test_list = ["is_yaffs_working_tests",
25 "64_and_32_bit_time/64_bit",
26 "64_and_32_bit_time/32_bit",
33 def run(makefile_paths):
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')
41 failed_tests.append( (path, is_successful) )
43 print('\033[42m' +"test passed"+'\033[0m')
46 def run_makefile_test(path):
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'))
52 return (TEST_PASSED, "test passed")
54 def clean_tests(makefile_paths):
55 cmds = [("make -j -C {} clean".format(path), path) for path in makefile_paths]
60 for cmd, is_successful, cmd_text, debug_info in run_cmds(cmds):
62 print("\033[41mtest failed to clean\033[0m {}".format(debug_info[0]))
65 print("\033[42mtest cleaned successfully\033[0m {}".format(debug_info[0]))
68 print ("\n\033[42mAll tests cleaned successfully\033[0m")
70 print ("\n\033[42mTests failed to clean successfully\033[0m")
71 print("ran {}, passed {}, failed {}".format(len(cmds), passed, failed))
73 def run_tests(makefile_paths):
74 cmds = [("make -j -C {} test".format(path), path) for path in makefile_paths]
79 print("running tests")
80 for cmd, is_successful, cmd_text, debug_info in run_cmds(cmds):
82 print("\033[41mtest failed\033[0m {}".format(debug_info[0]))
85 print("\033[42mtest passed\033[0m {}".format(debug_info[0]))
88 print ("\n\033[42mAll tests passed\033[0m")
90 print ("\n\033[41mTests failed\033[0m")
91 print("ran {}, passed {}, failed {}".format(len(cmds), passed, failed))
95 for cmd, *debug_info in cmds:
97 subprocess.check_output(cmd, shell=True)
98 output.append((cmd, True, "todo add getting text for non failing test", debug_info))
99 except subprocess.CalledProcessError as e:
100 output.append((cmd, False, e.output.decode('UTF-8'), debug_info))
102 if __name__ == "__main__":
103 if len(sys.argv) == 2 and sys.argv[1] == "clean":
104 clean_tests(test_list)
105 elif len(sys.argv) == 1:
106 #run the test runner.
107 failed_tests = run_tests(test_list)
109 print("run with command ./test_runner.py [clean]")