Changeset 3c1d702


Ignore:
Timestamp:
Jun 16, 2016, 12:45:43 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
14d2bdf, 3689906
Parents:
245510f
Message:

fixed python test script and added expected file for vector_test

Location:
src/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/tests/.expect/vector_test.txt

    r245510f r3c1d702  
    1 make: *** No rule to make target `vector_int.c', needed by `vector_int.o'.  Stop.
    2 /bin/sh: ./vector_test: Is a directory
     1enter N elements and C-d on a separate line:
     2Array elements:
     31 2 3 4 5
     4Array elements reversed:
     55 4 3 2 1
  • src/tests/test.py

    r245510f r3c1d702  
    3232#               running test functions
    3333################################################################################
    34 def run_test_instance(test, dry_run):
    35         sh("rm -f .out/%s.log" % test, dry_run)
     34def run_test_instance(test, generate, dry_run):
     35
     36        out_file = (".out/%s.log" % test) if not generate else (".expect/%s.txt" % test)
     37
     38        sh("rm -f %s" % out_file, dry_run)
    3639        sh("rm -f %s > /dev/null 2>&1" % test, dry_run)
    3740
    3841        # build, skipping to next test on error
    39         sh("make -j 1 %s >> .out/%s.log 2>&1" % (test, test), dry_run)
     42        make_ret = sh("make -j 1 %s > %s 2>&1" % (test, out_file), dry_run)
    4043
    41         # fetch optional input
    42         stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test) else ""
     44        if make_ret == 0 :
     45                # fetch optional input
     46                stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test) else ""
    4347
    44         # run test
    45         sh("./%s %s >> .out/%s.log 2>&1" % (test, stdinput, test), dry_run)
     48                # run test
     49                sh("./%s %s > %s 2>&1" % (test, stdinput, out_file), dry_run)
    4650
    47         # touch expected files so empty output are supported by default
    48         sh("touch .expect/%s.txt" % test, dry_run)
     51        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)
    4955
    50         # diff the output of the files
    51         retcode = sh("diff .expect/%s.txt .out/%s.log" % (test, test), dry_run)
     56                # diff the output of the files
     57                retcode = sh("diff .expect/%s.txt .out/%s.log" % (test, test), dry_run)
    5258
    5359        # clean the executable
     
    5662        return retcode
    5763
    58 def run_tests(tests, dry_run) :
     64def run_tests(tests, generate, dry_run) :
    5965        sh('make clean > /dev/null 2>&1', dry_run)
     66        sh('mkdir -p .out .expect', dry_run)
     67
     68        if generate :
     69                print( "Regenerate tests for: ", end="" )
     70                print( ", ".join( tests ) )
    6071
    6172        failed = False;
    6273        for t in tests:
    63                 print("%10s  " % t, end="")
     74                if not generate :
     75                        print("%20s  " % t, end="")
    6476                sys.stdout.flush()
    65                 test_failed = run_test_instance(t, dry_run)
     77                test_failed = run_test_instance(t, generate, dry_run)
    6678                failed = test_failed or failed
    67                 print("FAILED" if test_failed else "PASSED")
     79
     80                if not generate :
     81                        print("FAILED" if test_failed else "PASSED")
    6882
    6983        sh('make clean > /dev/null 2>&1', dry_run)
    7084
     85        if generate :
     86                print( "Done" )
     87
    7188        return 0 if failed else 1
    72 
    73 ################################################################################
    74 #               generate expectation functions
    75 ################################################################################
    76 def generate_test_expect(test):
    77         sh("rm -f .out/%s.log" % test, False)
    78         sh("rm -f %s > /dev/null 2>&1" % test, False)
    79 
    80         # build, skipping to next test on error
    81         sh("make -j 8 %s > .expect/%s.txt 2>&1" % (test, test), False)
    82 
    83         # fetch optional input
    84         stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test) else ""
    85 
    86         # run test
    87         sh("./%s %s >> .expect/%s.txt 2>&1" % (test, stdinput, test), False)
    88 
    89         # clean the executable
    90         sh("rm -f %s > /dev/null 2>&1" % test, False)
    91 
    92 def generate_expect(tests) :
    93         sh('make clean > /dev/null 2>&1', False)
    94 
    95         print( "Regenerate tests for" )
    96 
    97         print( ", ".join( tests ) )
    98 
    99         for t in tests:
    100                 generate_test_expect( t )
    101 
    102         print( "Done" )
    103 
    104         sh('make clean > /dev/null 2>&1', False)
    10589
    10690################################################################################
     
    11599options = parser.parse_args()
    116100
    117 tests = listTests()
     101if len(options.tests) > 0 and options.all :
     102        print('ERROR: must have option \'--all\' or non-empty test list', file=sys.stderr)
     103        parser.print_help()
     104        sys.exit(1)
    118105
    119 if options.all :
    120         if len(options.tests) > 0 :
    121                 print('ERROR: cannot specify tests with \'--all\' option', file=sys.stderr)
    122                 sys.exit(1)
     106tests = listTests() if options.all else options.tests
    123107
    124         if options.generate_expected :
    125                 generate_expect( tests )
    126         else :
    127                 sys.exit( run_tests(tests, options.dry_run) )
    128 
    129 else :
    130         if len(options.tests) == 0 :
    131                 print('ERROR: must have option \'--all\' or non-empty test list', file=sys.stderr)
    132                 parser.print_help()
    133                 sys.exit(1)
    134 
    135         if options.generate_expected :
    136                 generate_expect( options.tests )
    137         else :
    138                 sys.exit( run_tests(options.tests, options.dry_run) )
    139 
    140 sys.exit(0)
     108sys.exit( run_tests(tests, options.generate_expected, options.dry_run) )
Note: See TracChangeset for help on using the changeset viewer.