source: trunk/symbol_table/test/run_tests.py @ 2075

Last change on this file since 2075 was 2075, checked in by ksherdy, 7 years ago

Boo.

File size: 1.9 KB
Line 
1#
2# run_tests.py
3#
4# Symbol Table Tests
5#
6# Quick-and-dirty Python symbol table test script
7# to generates expected output files for diff test.
8#
9# 1. Use st_test_file_generator.py to generate 'st_test_UNIFORM_*' CSV symbol files.
10# 2. Execute test script.
11# 3. diff -r 'results' directory against input symbol files.
12#
13# Ken Herdy
14# April 12, 2012
15#
16#----------------------------------------------------------------------------
17# Edit:
18program_dir_path='../src'
19test_dir_path=''
20out_dir_path='out'
21#----------------------------------------------------------------------------
22import sys
23import os
24import subprocess
25import shutil
26import fnmatch                 
27import string
28
29usage='Usage: python ' + __file__ + ' <program> <test root>'
30
31def gid_testcase(program, input_file):
32    file_name = os.path.basename(input_file)
33    prefix = file_name[1:file_name.rindex(']')]
34    triples = prefix.split(']_[')
35
36    sum = 0
37    for t in triples:
38        print int(t.split('_')[2])
39        sum = sum + int(t.split('_')[2])
40
41    output = subprocess.Popen([program, input_file], stdout=subprocess.PIPE).communicate()[0]
42
43def diff_testcase(program, input_file, outfile_root):
44        (head, tail) = os.path.split(input_file)
45        outputdir = os.path.join(outfile_root, tail)
46        #if os.path.exists(outputdir)==True:
47        (head, tail) = os.path.split(outputdir)
48        if os.path.exists(head)==False:         
49                os.makedirs(head)
50        out_f = open(head + os.path.sep + tail, 'w')
51        subprocess.call([program, input_file], stderr=None, stdout=out_f)
52        out_f.close()
53
54if __name__ == "__main__":
55
56        if(len(sys.argv) < 3):
57                print usage
58                sys.exit()
59
60        program = os.path.join(program_dir_path,sys.argv[1])
61        testfile_dir = os.path.join(test_dir_path,sys.argv[2])
62
63        for dirname, dirnames, filenames in os.walk(testfile_dir):
64                for filename in filenames:
65                        if filename.endswith('.test') and not filename.endswith('.svn-base'):
66                                relfile = os.path.relpath(os.path.join(dirname, filename))
67                                #diff_testcase(program, relfile, out_dir_path)
68                                gid_testcase(program, relfile)
69
70       
Note: See TracBrowser for help on using the repository browser.