Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/test.py

    r122cac7 rf6ed7fd  
    22from __future__ import print_function
    33
    4 from os import listdir, environ
    5 from os.path import isfile, join, splitext
     4from os import listdir
     5from os.path import isfile, join
    66from subprocess import Popen, PIPE, STDOUT
    77
    88import argparse
    9 import os
    10 import re
    119import sys
    1210
     
    1513################################################################################
    1614def listTests():
    17         list = [splitext(f)[0] for f in listdir('./.expect')
    18                 if not f.startswith('.') and f.endswith('.txt')
    19                 ]
     15        list = [f.rstrip('.c') for f in listdir('.')
     16                if not f.startswith('.') and (
     17                        not isfile(f) or f.endswith('.c')
     18                )]
    2019
    2120        return list
     
    3029                return proc.returncode
    3130
    32 def file_replace(fname, pat, s_after):
    33     # first, see if the pattern is even in the file.
    34     with open(fname) as f:
    35         if not any(re.search(pat, line) for line in f):
    36             return # pattern does not occur in file so we are done.
    37 
    38     # pattern is in the file, so perform replace operation.
    39     with open(fname) as f:
    40         out_fname = fname + ".tmp"
    41         out = open(out_fname, "w")
    42         for line in f:
    43             out.write(re.sub(pat, s_after, line))
    44         out.close()
    45         os.rename(out_fname, fname)
    46 
    47 def fix_MakeLevel(file) :
    48         if environ.get('MAKELEVEL') :
    49                 file_replace(file, "make\[%i\]" % int(environ.get('MAKELEVEL')), 'make' )
    50 
    51 
    5231################################################################################
    5332#               running test functions
     
    6140
    6241        # build, skipping to next test on error
    63         make_ret = sh("make -j 8 %s 2> %s 1> /dev/null" % (test, out_file), dry_run)
     42        make_ret = sh("make -j 8 %s > %s 2>&1" % (test, out_file), dry_run)
    6443
    6544        if make_ret == 0 :
     
    7150
    7251        retcode = 0
     52        if not generate :
     53                # touch expected files so empty output are supported by default
     54                sh("touch .expect/%s.txt" % test, dry_run)
    7355
    74         fix_MakeLevel(out_file)
    75 
    76         if not generate :
    7756                # diff the output of the files
    7857                retcode = sh("diff .expect/%s.txt .out/%s.log" % (test, test), dry_run)
     
    8867
    8968        if generate :
    90                 print( "Regenerate tests for: " )
     69                print( "Regenerate tests for: ", end="" )
     70                print( ", ".join( tests ) )
    9171
    9272        failed = False;
    9373        for t in tests:
    94                 print("%20s  " % t, end="")
     74                if not generate :
     75                        print("%20s  " % t, end="")
    9576                sys.stdout.flush()
    9677                test_failed = run_test_instance(t, generate, dry_run)
     
    9980                if not generate :
    10081                        print("FAILED" if test_failed else "PASSED")
    101                 else :
    102                         print( "Done" )
    10382
    10483        sh('make clean > /dev/null 2>&1', dry_run)
    10584
    106         return 1 if failed else 0
     85        if generate :
     86                print( "Done" )
     87
     88        return 0 if failed else 1
    10789
    10890################################################################################
     
    11193parser = argparse.ArgumentParser(description='Script which runs cforall tests')
    11294parser.add_argument('--dry-run', help='Don\'t run the tests, only output the commands', action='store_true')
    113 parser.add_argument('--list', help='List all test available', action='store_true')
    11495parser.add_argument('--all', help='Run all test available', action='store_true')
    115 parser.add_argument('--regenerate-expected', help='Regenerate the .expect by running the specified tets, can be used with --all option', action='store_true')
     96parser.add_argument('--generate-expected', help='Regenerate the .expect by running the specified tets, can be used with --all option', action='store_true')
    11697parser.add_argument('tests', metavar='test', type=str, nargs='*', help='a list of tests to run')
    11798
    11899options = parser.parse_args()
    119100
    120 if (len(options.tests) > 0  and     options.all and not options.list) \
    121 or (len(options.tests) == 0 and not options.all and not options.list) :
     101if len(options.tests) > 0 and options.all :
    122102        print('ERROR: must have option \'--all\' or non-empty test list', file=sys.stderr)
    123103        parser.print_help()
    124104        sys.exit(1)
    125105
    126 allTests = listTests()
     106tests = listTests() if options.all else options.tests
    127107
    128 if options.all or options.list :
    129         tests = allTests
    130 
    131 else :
    132         tests = []
    133         for test in options.tests:
    134                 if test in allTests :
    135                         tests.append(test)
    136                 else :
    137                         print('ERROR: No expected file for test %s, ignoring it' % test, file=sys.stderr)
    138 
    139         if len(tests) == 0 :
    140                 print('ERROR: No valid test to run', file=sys.stderr)
    141                 sys.exit(1)
    142 
    143 if options.list :
    144         print("\n".join(tests))
    145 
    146 else :
    147         sys.exit( run_tests(tests, options.regenerate_expected, options.dry_run) )
     108sys.exit( run_tests(tests, options.generate_expected, options.dry_run) )
Note: See TracChangeset for help on using the changeset viewer.