filters: Swap GP_MirrorH() and GP_MirrorV()
[gfxprim/pasky.git] / tests / runtests.py
blob8cd14775ddf53bf3716461d77cca6a55cbcbebbd
1 #!/usr/bin/env python
3 # This is a simple glue script to run the tests and collect the results
7 # We expect simple structure i.e. the tests_dir contains directories with
8 # tests, each directory that contains tests has test_list.txt with a list of
9 # tests to run. The structure is then mirrored in the results_dir filled with
10 # json logs.
13 import os
14 import datetime
17 # Relative path to root directory containing tests
19 tests_dir='.'
22 # Results directory prefix
24 results_dir='results'
27 # Relative path to the directory with GP libraries to run tests against
29 build_dir='../build'
32 # By default the glibc __libc_message() writes to /dev/tty before calling
33 # the abort(). Exporting this macro makes it to use stderr instead.
35 # The main usage of the function are malloc assertions, so this makes us catch
36 # the malloc error message by catching stderr output.
38 runline_prep='export LIBC_FATAL_STDERR_=1;'
41 # Relative path, from the current directory, to the framework preload library.
43 framework_lib='framework/libtst_preload.so'
45 debug = 0
47 def globpath(path):
48 return os.getcwd() + '/' + path
51 # Reads test_list.txt test file and executes tests one after another
53 def run_test(resdir, tstdir, runtest):
54 f = open(runtest, 'r')
55 lines = f.readlines()
56 f.close()
58 for line in lines:
59 # ignore comments
60 if (line[0] == '#'):
61 continue
62 # and blanks
63 if (line.isspace()):
64 continue
66 line = line.strip();
69 # This is a little hairy but what it does is to constructs correct
70 # paths to preload and dynamic libraries and runs the test.
72 runline = runline_prep + ' '
73 runline += 'export LD_PRELOAD="' + globpath(framework_lib) + '"; '
74 runline += 'export LD_LIBRARY_PATH="' + globpath(build_dir) + '"; '
75 runline += 'cd ' + tstdir + ' && ./' + line + ' -o "' + globpath(resdir) + '"'
77 if debug >= 2:
78 print(" LINE: %s" % runline)
80 os.system(runline)
83 # Discovers tests in directories.
85 def run_tests(resdir, testsdir):
87 if debug >= 1:
88 print('Looking for tests in "%s"' % testsdir)
90 for root, dirs, _ in os.walk(testsdir):
91 for name in dirs:
93 path = root + '/' + name
95 if debug >= 2:
96 print('Looking into dir "%s"' % path)
98 runtest = path + '/test_list.txt'
100 if (os.access(runtest, os.R_OK)):
101 # Create result directory
102 curresdir = resdir + '/' + name
103 os.mkdir(curresdir)
104 # Run tests
105 print("\n========= Running " + name + " testsuites =========\n")
106 run_test(curresdir, path, runtest)
108 def main():
109 now = datetime.datetime.now()
110 resdir = '%s_%i-%02i-%02i_%02i-%02i-%02i' % (results_dir, now.year, now.month,
111 now.day, now.hour, now.minute, now.second)
112 print('Creating result directory "%s"' % resdir)
113 os.mkdir(resdir)
115 run_tests(resdir, tests_dir)
117 if __name__ == '__main__':
118 main()