Changeset f806b61


Ignore:
Timestamp:
Mar 28, 2019, 5:19:52 PM (5 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b611fc3
Parents:
ea62265
Message:

Tests are now run in temporary directory

Location:
tests
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tests/Makefile.am

    rea62265 rf806b61  
    3636        -Wno-unused-function \
    3737        -quiet @CFA_FLAGS@ \
    38         -DIN_DIR="${srcdir}/.in/"
     38        -DIN_DIR="${abs_srcdir}/.in/"
    3939
    4040AM_CFLAGS += ${DEBUG_FLAGS} ${INSTALL_FLAGS} ${ARCH_FLAGS}
  • tests/Makefile.in

    rea62265 rf806b61  
    382382# applies to both programs
    383383AM_CFLAGS = $(if $(test), 2> $(test), ) -g -Wall -Wno-unused-function \
    384         -quiet @CFA_FLAGS@ -DIN_DIR="${srcdir}/.in/" ${DEBUG_FLAGS} \
    385         ${INSTALL_FLAGS} ${ARCH_FLAGS}
     384        -quiet @CFA_FLAGS@ -DIN_DIR="${abs_srcdir}/.in/" \
     385        ${DEBUG_FLAGS} ${INSTALL_FLAGS} ${ARCH_FLAGS}
    386386PRETTY_PATH = cd ${srcdir} &&
    387387avl_test_SOURCES = avltree/avl_test.cfa avltree/avl0.cfa avltree/avl1.cfa avltree/avl2.cfa avltree/avl3.cfa avltree/avl4.cfa avltree/avl-private.cfa
  • tests/pybin/tools.py

    rea62265 rf806b61  
    1111import subprocess
    1212import sys
     13import tempfile
    1314import time
    1415import types
    1516
    1617from pybin import settings
    17 from subprocess import Popen, PIPE, STDOUT
    1818
    1919################################################################################
     
    2727        # if this is a dry_run, only print the commands that would be ran
    2828        if settings.dry_run :
    29                 cmd = "cmd: {}".format(' '.join(cmd))
    30                 if output and output != subprocess.DEVNULL and output != subprocess.PIPE:
     29                cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd))
     30                if output and not isinstance(output, int):
    3131                        cmd += " > "
    3232                        cmd += output
    3333
    34                 if error and error != subprocess.DEVNULL and error != subprocess.PIPE and error != subprocess.STDOUT:
     34                if error and not isinstance(error, int):
    3535                        cmd += " 2> "
    3636                        cmd += error
    3737
    38                 if input and input != subprocess.DEVNULL and os.path.isfile(input):
     38                if input and not isinstance(input, int) and os.path.isfile(input):
    3939                        cmd += " < "
    4040                        cmd += input
     
    4545        with contextlib.ExitStack() as onexit:
    4646                # add input redirection if needed
    47                 if input and input != subprocess.DEVNULL:
    48                         if os.path.isfile(input):
    49                                 input = open(input)
    50                                 onexit.push(input)
    51                         else:
    52                                 input = None
     47                input = openfd(input, 'r', onexit, True)
    5348
    5449                # add output redirection if needed
    55                 if output and output != subprocess.DEVNULL and output != subprocess.PIPE:
    56                         output = open(output, 'w')
    57                         onexit.push(output)
     50                output = openfd(output, 'w', onexit, False)
     51
     52                # add error redirection if needed
     53                error = openfd(error, 'w', onexit, False)
    5854
    5955                # run the desired command
     
    6359                                stdin =input,
    6460                                stdout=output,
    65                                 stderr=STDOUT,
     61                                stderr=error,
    6662                                timeout=settings.timeout.single if timeout else None
    6763                        )
     
    9187def is_exe(fname):
    9288        return os.path.isfile(fname) and os.access(fname, os.X_OK)
     89
     90def openfd(file, mode, exitstack, checkfile):
     91        if not file:
     92                return file
     93
     94        if isinstance(file, int):
     95                return file
     96
     97        if checkfile and not os.path.isfile(file):
     98                return None
     99
     100        file = open(file, mode)
     101        exitstack.push(file)
     102        return file
    93103
    94104# Remove 1 or more files silently
     
    159169    return None
    160170
     171@contextlib.contextmanager
     172def tempdir():
     173        cwd = os.getcwd()
     174        with tempfile.TemporaryDirectory() as temp:
     175                os.chdir(temp)
     176                try:
     177                        yield temp
     178                finally:
     179                        os.chdir(cwd)
     180
    161181################################################################################
    162182#               file handling
     
    259279
    260280def core_info(path):
     281        if not os.path.isfile(path):
     282                return 1, "ERR Executable path is wrong"
     283
    261284        cmd   = os.path.join(settings.SRCDIR, "pybin/print-core.gdb")
    262285        if not os.path.isfile(cmd):
    263286                return 1, "ERR Printing format for core dumps not found"
    264287
    265         dname = os.path.dirname(path)
    266         core  = os.path.join(dname, "core" )
    267         if not os.path.isfile(path):
    268                 return 1, "ERR Executable path is wrong"
     288        core  = os.path.join(os.getcwd(), "core" )
    269289
    270290        if not os.path.isfile(core):
  • tests/test.py

    rea62265 rf806b61  
    88import re
    99import sys
     10import tempfile
    1011import time
    1112
     
    143144                make_ret, _ = make( test.target(), output=subprocess.DEVNULL, error=out_file, error_file = err_file )
    144145
    145         # if the make command succeds continue otherwise skip to diff
    146146        run_dur = None
    147         if success(make_ret):
    148                 with Timed() as run_dur:
    149                         if settings.dry_run or is_exe(exe_file):
    150                                 # run test
    151                                 retcode, _ = sh(exe_file, output=out_file, input=in_file, timeout=True)
     147        # run everything in a temp directory to make sure core file are handled properly
     148        with tempdir():
     149                # if the make command succeds continue otherwise skip to diff
     150                if success(make_ret):
     151                        with Timed() as run_dur:
     152                                if settings.dry_run or is_exe(exe_file):
     153                                        # run test
     154                                        retcode, _ = sh(exe_file, output=out_file, input=in_file, timeout=True)
     155                                else :
     156                                        # simply cat the result into the output
     157                                        retcode = cat(exe_file, out_file)
     158                else:
     159                        retcode = mv(err_file, out_file)
     160
     161                if success(retcode):
     162                        if settings.generating :
     163                                # if we are ounly generating the output we still need to check that the test actually exists
     164                                if no_rule(out_file, test.target()) :
     165                                        retcode = 1
     166                                        error = "\t\tNo make target for test %s!" % test.target()
     167                                        rm(out_file)
     168                                else:
     169                                        error = None
    152170                        else :
    153                                 # simply cat the result into the output
    154                                 retcode = cat(exe_file, out_file)
    155         else:
    156                 retcode = mv(err_file, out_file)
    157 
    158         if success(retcode):
    159                 if settings.generating :
    160                         # if we are ounly generating the output we still need to check that the test actually exists
    161                         if no_rule(out_file, test.target()) :
    162                                 retcode = 1
    163                                 error = "\t\tNo make target for test %s!" % test.target()
    164                                 rm(out_file)
    165                         else:
    166                                 error = None
    167                 else :
    168                         # fetch return code and error from the diff command
    169                         retcode, error = diff(cmp_file, out_file)
    170 
    171         else:
    172                 with open (out_file, "r") as myfile:
    173                         error = myfile.read()
    174 
    175                 ret, info = core_info(exe_file)
    176                 error = error + info if error else info
     171                                # fetch return code and error from the diff command
     172                                retcode, error = diff(cmp_file, out_file)
     173
     174                else:
     175                        with open (out_file, "r") as myfile:
     176                                error = myfile.read()
     177
     178                        ret, info = core_info(exe_file)
     179                        error = error + info if error else info
    177180
    178181
Note: See TracChangeset for help on using the changeset viewer.