source: proto/SymbolTable/test/symtab_testsuite.py @ 4183

Last change on this file since 4183 was 1460, checked in by vla24, 8 years ago

SymbolTable?: created a test suite under proto/SymbolTable/test/. Run symtab_testsuite.py to run the test suite

File size: 3.7 KB
Line 
1import config, argparse
2import perftest
3from subprocess import *
4import os
5
6args_namespace = {}
7default_test_files = []
8available_implementations = []
9test_files = []
10test_implementations = []
11
12def load_files(path):
13    """
14    Loads a list from path and store it to lst
15    """
16    lst = []
17
18    input_handle = open(path, 'r')
19    string = input_handle.readline()
20
21    # read per line
22    while (string != ""):
23        string = string.decode('string_escape')
24        if string[-1] == '\n':
25            string = string [:-1]
26        lst.append(string)
27        string = input_handle.readline()
28
29    input_handle.close()
30    return lst
31
32def list_test_files():
33    """
34    List test files to be tested
35    """
36    global test_files
37    arg_tests = args_namespace.testfiles
38    if arg_tests:
39        test_files.extend(arg_tests)
40    if args_namespace.use_default_test or not test_files:
41        test_files.extend(default_test_files)
42    print "Test files: " + str(test_files)
43
44def list_implementations():
45    """
46    List implementations to be tested
47    """
48    global test_implementations
49    args_impl = args_namespace.implementations
50    if not args_impl:
51        test_implementations.extend(available_implementations)
52    else:
53        test_implementations.extend(args_impl)
54
55    print "Implementations to be tested: " + str(test_implementations)
56
57def print_output(output_dir, retstr, mode, impl):
58    """
59    Print output on screen and write it on a file
60    """
61    delim = "----------------------------\n"
62    print "Implementation: " + impl
63    print retstr
64    print delim
65
66    # Write output
67    output_file = open(output_dir+"test_result", mode)
68    output_file.write ("Implementation: " + impl)
69    output_file.write (retstr)
70    output_file.write (delim)
71    output_file.close()
72
73def run_perf_test(output_dir):
74    """
75    Run performance tests
76    """
77    perftest.set_test_files(test_files)
78    perftest.set_output_dir(output_dir)
79
80    first_impl = True
81
82    for impl in test_implementations:
83        error_file = open(output_dir+"compile_info_"+impl, 'w')
84
85        # Compile program
86        cmd = "cd ./.. && make symtab_" + impl + " && cd src && make buffer_profiling_perf"
87        if args_namespace.use_idisa:
88            cmd = cmd + "_idisa"
89        try:
90            call([cmd], shell=True, stdout=error_file, stderr=error_file)
91        except:
92            print "Error: Fail to compile program"
93
94        error_file.close()
95
96        # Run tests
97        perftest.run_test()
98        retstr = perftest.analyze_result()
99
100        # Print output on screen and write it on a file
101        mode = 'a'
102        if first_impl:
103            mode = 'w'
104        print_output(output_dir, retstr, mode, impl)
105
106def get_output_dir():
107    """
108    Get output directory where all logs will be stored
109    """
110    path = args_namespace.output_dir
111    if path[-1] != '/':
112        path = path + '/'
113    return path
114
115def main():
116    # Load available implementations
117    global available_implementations
118    available_implementations = load_files("support_files/implementations_list.txt")
119
120    # Load default test files
121    global default_test_files
122    default_test_files = load_files("support_files/default_test_list.txt")
123
124    # Check for input arguments
125    global args_namespace
126    option_parser = config.get_argument_parser(available_implementations)
127    args_namespace = option_parser.parse_args()
128
129    # Process arguments
130    list_implementations()
131    list_test_files()
132
133    # Get output directory where all logs will be stored
134    output_dir = get_output_dir()
135
136    # Run tests
137    run_perf_test(output_dir)
138
139    print "Done running tests, please check \'" + output_dir[:-1] + "\' directory for all available logs"
140
141if __name__ == "__main__": main()
142           
143       
144       
145       
146       
147       
148       
149       
150       
151       
152       
153       
154       
155       
156       
Note: See TracBrowser for help on using the repository browser.