Browse Source

If run from "main" all test res in same tempdir

Until now all tests created their own temp directory.
If running from ./main this is different now.

The main script will create a tempdir and pass that as (hidden) command line
option to the test scripts - each will pick it up and create a subdir for
its experiment in there.

If a test is done and finishes succesfully it removes its own working

If, after all tests have run the temp directory is empty, it means that all
tests have finished succesfully and the temp directory is removed
haavee 6 months ago
  1. 36
  2. 20


@ -8,7 +8,6 @@ import os, sys, copy, glob, shutil, shlex, argparse, tempfile, operator, subproc
# path/to/build_dir/apps/[j2ms2|tConvert]/\\1
# However, when installed, they're accessible as:
# path/to/install_dir/bin/{j2ms2,tConvert}
# from python shutil source code (
def _access_check(fn, mode):
@ -22,6 +21,17 @@ def which(cmd):
return candidate
return None
# argparse "type" function that checks whether it's a writable path
def is_writable_dir(p):
if os.path.isdir(p) and os.access(p, os.W_OK):
return p
raise argparse.ArgumentTypeError( "[is_writable_dir]: '{0}' is not that".format(p) )
def check_previous_results(p):
if os.path.isdir(p):
raise RuntimeError("Previous test results seem to exists at {0}. Please check and remove those first".format(p))
# This class captures the binaries from $PATH - if any.
# None if not found
class EnvironmentBinaries(object):
@ -117,11 +127,13 @@ mutexgr.add_argument('--cmake-build-dir', help="test j2ms2/tConvert binaries fro
dest='binaries', action=BuildDirAction, path='path__', default=binarys)
parsert.add_argument('--jplotter', help="Path to jplotter to use (default: from $PATH)",
dest='binaries', action=jplotterAction, path='jplpath__', default=binarys)
# according to
parsert.add_argument('--tempdir', type=is_writable_dir, default=None, help=argparse.SUPPRESS)
options, args = parsert.parse_known_args()
sys.argv[1:] = args
## Yes, technically tests should be able to run in any order
## but we're testing a toolchain here where e.g. step N+1
## uses a product generated in step N
@ -151,6 +163,12 @@ class TTC(unittest.TestCase):
def setUp(self):
if TTC.__curdir__:
# Since this is called for every test in this run, we must perform the following
# check each time; TTC.__workdir__ is only set if this code has verified that it
# did not exist first
if TTC.__workdir__ is None:
workdir = os.path.join( TTC.__tempdir__ or options.tempdir, 'ES085A' )
raise RuntimeError("Previous test results exist at {0}. Please check+remove those first".format(workdir))
print("Preparing test environment ...", end='')
# we must
@ -162,10 +180,16 @@ class TTC(unittest.TestCase):
# (possibly download it using wget)
# (3) create a temporary directory where to create new data files to compare
TTC.__tempdir__ = tempfile.mkdtemp()
# 10 Jun 2021: only do this if the outer layer did not specify one
if options.tempdir is None:
TTC.__tempdir__ = tempfile.mkdtemp()
# Only set the __workdir__ if that was allowed; check_previous_results throws if
# the workdir already exists
workdir = os.path.join( TTC.__tempdir__ or options.tempdir, 'ES085A' )
check_previous_results( workdir );
#sys.stdout.write( "\n=======> Created tmp dir: {0}\n".format(self.tempDir) )
# j2ms2 expects the directory containing data to have the same name as the vexfile
TTC.__workdir__ = os.path.join( TTC.__tempdir__, 'ES085A' )
TTC.__workdir__ = workdir
TTC.__cleanup__ = True
# And finally, we change directory to the newly created temp dir
# and populate it with the files as necessary
@ -434,7 +458,9 @@ class TTC(unittest.TestCase):
os.chdir( TTC.__curdir__ )
# if cleanup not inhibited ... do clean up
if TTC.__cleanup__:
shutil.rmtree( TTC.__tempdir__ )
# depending on whether we created the tempdir remove the whole thing or only our workdir
# (TTC.__tempdir__ is only set if no-one passed in a tempdir command line argument)
shutil.rmtree( TTC.__workdir__ if TTC.__tempdir__ is None else TTC.__tempdir__ )
print( artefacts_msg(TTC.__workdir__) )


@ -44,11 +44,27 @@ for av; do
# OK that's the command line parsed
# If we got this far, we can do this - make sure the submodule(s) are
# initialized and updated
git submodule init
git submodule update
# OK that's the command line parsed
# If we're running from here it's us who set the tempdir
tempdir=`${python} -c 'from __future__ import print_function; import tempfile; print(tempfile.mkdtemp());'`
# now we can install cleanup
trap 'cleanup' 0 1 2 3 6 15
# If, after all tests have run, the tempdir is empty, it means all tests ran succesfully
if [ -z "$(ls -A ${tempdir})" ]; then
# empty!
rm -rf ${tempdir};
for f in `find . -type f -a -name test*.py`; do
${live} exec ${python} ${f} ${testopts}
${live} ${python} ${f} ${testopts} --tempdir ${tempdir}