Changeset f1ee72e for src/tests/test.py


Ignore:
Timestamp:
Jun 23, 2016, 12:23:00 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
4d3ca1d8
Parents:
c2931ea (diff), d56c05d0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ctor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/test.py

    rc2931ea rf1ee72e  
    22from __future__ import print_function
    33
    4 from os import listdir
    5 from os.path import isfile, join
     4from os import listdir, environ
     5from os.path import isfile, join, splitext
    66from subprocess import Popen, PIPE, STDOUT
    77
    88import argparse
     9import os
     10import re
    911import sys
    1012
     
    1315################################################################################
    1416def listTests():
    15         list = [f.rstrip('.c') for f in listdir('.')
    16                 if not f.startswith('.') and (
    17                         not isfile(f) or f.endswith('.c')
    18                 )]
     17        list = [splitext(f)[0] for f in listdir('./.expect')
     18                if not f.startswith('.') and f.endswith('.txt')
     19                ]
    1920
    2021        return list
     
    2930                return proc.returncode
    3031
     32def 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
     47def fix_MakeLevel(file) :
     48        if environ.get('MAKELEVEL') :
     49                file_replace(file, "make\[%i\]" % int(environ.get('MAKELEVEL')), 'make' )
     50
     51
    3152################################################################################
    3253#               running test functions
     
    4061
    4162        # build, skipping to next test on error
    42         make_ret = sh("make -j 8 %s > %s 2>&1" % (test, out_file), dry_run)
     63        make_ret = sh("make -j 8 %s 2> %s 1> /dev/null" % (test, out_file), dry_run)
    4364
    4465        if make_ret == 0 :
     
    5071
    5172        retcode = 0
     73
     74        fix_MakeLevel(out_file)
     75
    5276        if not generate :
    53                 # touch expected files so empty output are supported by default
    54                 sh("touch .expect/%s.txt" % test, dry_run)
    55 
    5677                # diff the output of the files
    5778                retcode = sh("diff .expect/%s.txt .out/%s.log" % (test, test), dry_run)
     
    6788
    6889        if generate :
    69                 print( "Regenerate tests for: ", end="" )
    70                 print( ", ".join( tests ) )
     90                print( "Regenerate tests for: " )
    7191
    7292        failed = False;
    7393        for t in tests:
    74                 if not generate :
    75                         print("%20s  " % t, end="")
     94                print("%20s  " % t, end="")
    7695                sys.stdout.flush()
    7796                test_failed = run_test_instance(t, generate, dry_run)
     
    8099                if not generate :
    81100                        print("FAILED" if test_failed else "PASSED")
     101                else :
     102                        print( "Done" )
    82103
    83104        sh('make clean > /dev/null 2>&1', dry_run)
    84105
    85         if generate :
    86                 print( "Done" )
    87 
    88         return 0 if failed else 1
     106        return 1 if failed else 0
    89107
    90108################################################################################
     
    93111parser = argparse.ArgumentParser(description='Script which runs cforall tests')
    94112parser.add_argument('--dry-run', help='Don\'t run the tests, only output the commands', action='store_true')
     113parser.add_argument('--list', help='List all test available', action='store_true')
    95114parser.add_argument('--all', help='Run all test available', action='store_true')
    96 parser.add_argument('--generate-expected', help='Regenerate the .expect by running the specified tets, can be used with --all option', action='store_true')
     115parser.add_argument('--regenerate-expected', help='Regenerate the .expect by running the specified tets, can be used with --all option', action='store_true')
    97116parser.add_argument('tests', metavar='test', type=str, nargs='*', help='a list of tests to run')
    98117
    99118options = parser.parse_args()
    100119
    101 if len(options.tests) > 0 and options.all :
     120if (len(options.tests) > 0  and     options.all and not options.list) \
     121or (len(options.tests) == 0 and not options.all and not options.list) :
    102122        print('ERROR: must have option \'--all\' or non-empty test list', file=sys.stderr)
    103123        parser.print_help()
    104124        sys.exit(1)
    105125
    106 tests = listTests() if options.all else options.tests
     126allTests = listTests()
    107127
    108 sys.exit( run_tests(tests, options.generate_expected, options.dry_run) )
     128if options.all or options.list :
     129        tests = allTests
     130
     131else :
     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
     143if options.list :
     144        print("\n".join(tests))
     145
     146else :
     147        sys.exit( run_tests(tests, options.regenerate_expected, options.dry_run) )
Note: See TracChangeset for help on using the changeset viewer.