a8af075afeff4bad06c03730eed786d04d657767
[yaffs2.git] / direct / test-framework / unit_tests / test_runner.py
1 #!/usr/bin/env python3
2 """
3  * YAFFS: Yet another FFS. A NAND-flash specific file system.
4  *
5  * Copyright (C) 2002-2021 Aleph One Ltd.
6  *
7  * Created by Timothy Manning <timothy@yaffs.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12 """
13
14
15 import subprocess, sys
16
17 test_list = ["is_yaffs_working_tests",
18         "quick_tests",
19         "64_and_32_bit_time/64_bit",
20         "64_and_32_bit_time/32_bit",
21         ]
22
23
24 TEST_FAILED = -1
25 TEST_PASSED = 1
26
27 def run(makefile_paths):
28         failed_tests =[]
29         for path in makefile_paths:
30                 print("\nrunning test {}".format(path))
31                 is_successful, test_output = run_makefile_test(path)
32                 if is_successful != TEST_PASSED:
33                         print('\033[41m' +'test {} failed'.format(path)+'\033[0m')
34                         print(test_output)
35                         failed_tests.append( (path, is_successful) )
36                 else:
37                         print('\033[42m' +"test passed"+'\033[0m')
38         return failed_tests
39
40 def run_makefile_test(path):
41         try:
42                 subprocess.check_output("make -j -C {} test".format(path), shell=True)  
43         except subprocess.CalledProcessError as e:
44                 return (TEST_FAILED, e.output.decode('UTF-8'))
45         
46         return (TEST_PASSED, "test passed")
47
48 if __name__ == "__main__":
49         #run the test runner.
50         failed_tests = run(test_list)
51         
52         print("\ntest summary #############")
53         if len(failed_tests) == 0:
54                 print('\033[42m' +"all tests passed"+'\033[0m')
55         else:
56                 for path, output in failed_tests:
57                         print('\033[41m' +"test {} failed".format(path)+'\033[0m')
58                 print('\033[41m' + "ran {} tests, {} failed".format(len(test_list), len(failed_tests))+'\033[0m')