mirror of https://github.com/vitalif/openscad
Generalized the test driver a tiny bit
parent
9d97afa376
commit
5acc695399
|
@ -602,10 +602,6 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(EXISTS "${GUI_BINPATH}")
|
if(EXISTS "${GUI_BINPATH}")
|
||||||
add_executable(guicgalpngtest guicgalpngtest.cc)
|
|
||||||
set_target_properties(guicgalpngtest PROPERTIES COMPILE_FLAGS "-DBINPATH=${GUI_BINPATH}")
|
|
||||||
add_executable(guiopencsgtest guiopencsgtest.cc)
|
|
||||||
set_target_properties(guiopencsgtest PROPERTIES COMPILE_FLAGS "-DBINPATH=${GUI_BINPATH}")
|
|
||||||
message(STATUS "Found OpenSCAD GUI binary: ${GUI_BINPATH}")
|
message(STATUS "Found OpenSCAD GUI binary: ${GUI_BINPATH}")
|
||||||
else()
|
else()
|
||||||
message(STATUS "Couldn't find the OpenSCAD GUI binary: ${GUI_BINPATH}")
|
message(STATUS "Couldn't find the OpenSCAD GUI binary: ${GUI_BINPATH}")
|
||||||
|
@ -674,16 +670,28 @@ endfunction()
|
||||||
|
|
||||||
#
|
#
|
||||||
# This functions adds cmd-line tests given files.
|
# This functions adds cmd-line tests given files.
|
||||||
# Files are sent as the parameters following TESTSUFFIX
|
|
||||||
#
|
#
|
||||||
# Usage add_cmdline_test(TESTCMD TESTSUFFIX <test files>)
|
# Usage add_cmdline_test(testname [EXE <executable>] [ARGS <args to exe>]
|
||||||
|
# [EXPECTEDDIR <shared dir>] SUFFIX <suffix> FILES <test files>)
|
||||||
#
|
#
|
||||||
find_package(PythonInterp)
|
find_package(PythonInterp)
|
||||||
macro(add_cmdline_test TESTCMD TESTSUFFIX)
|
macro(add_cmdline_test TESTCMD)
|
||||||
|
cmake_parse_arguments(TESTCMD "" "EXE;SUFFIX;EXPECTEDDIR" "FILES;ARGS" ${ARGN})
|
||||||
|
|
||||||
|
# If sharing results with another test, pass on this to the python script
|
||||||
|
if (TESTCMD_EXPECTEDDIR)
|
||||||
|
set(EXTRA_OPTIONS -e ${TESTCMD_EXPECTEDDIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
get_filename_component(TESTCMD_NAME ${TESTCMD} NAME_WE)
|
get_filename_component(TESTCMD_NAME ${TESTCMD} NAME_WE)
|
||||||
|
|
||||||
|
# If no executable was specified, assume it was built by us and resides here
|
||||||
|
if (NOT TESTCMD_EXE)
|
||||||
|
set(TESTCMD_EXE ${CMAKE_BINARY_DIR}/${TESTCMD})
|
||||||
|
endif()
|
||||||
|
|
||||||
# Add tests from args
|
# Add tests from args
|
||||||
foreach (SCADFILE ${ARGN})
|
foreach (SCADFILE ${TESTCMD_FILES})
|
||||||
get_filename_component(TESTNAME ${SCADFILE} NAME_WE)
|
get_filename_component(TESTNAME ${SCADFILE} NAME_WE)
|
||||||
string(REPLACE " " "_" TESTNAME ${TESTNAME}) # Test names cannot include spaces
|
string(REPLACE " " "_" TESTNAME ${TESTNAME}) # Test names cannot include spaces
|
||||||
set(TEST_FULLNAME "${TESTCMD_NAME}_${TESTNAME}")
|
set(TEST_FULLNAME "${TESTCMD_NAME}_${TESTNAME}")
|
||||||
|
@ -705,7 +713,13 @@ macro(add_cmdline_test TESTCMD TESTSUFFIX)
|
||||||
if (MINGW_CROSS_ENV_DIR)
|
if (MINGW_CROSS_ENV_DIR)
|
||||||
set( MINGW_CROSS_ARG "--mingw-cross-env" )
|
set( MINGW_CROSS_ARG "--mingw-cross-env" )
|
||||||
endif()
|
endif()
|
||||||
add_test(NAME ${TEST_FULLNAME} ${CONFARG} ${CONFVAL} COMMAND ${PYTHON_EXECUTABLE} ${tests_SOURCE_DIR}/test_cmdline_tool.py ${MINGW_CROSS_ARG} --comparator=${COMPARATOR} -c ${ImageMagick_convert_EXECUTABLE} -s ${TESTSUFFIX} ${CMAKE_BINARY_DIR}/${TESTCMD} "${SCADFILE}")
|
|
||||||
|
# The python script cannot extract the testname when given extra parameters
|
||||||
|
if (TESTCMD_ARGS)
|
||||||
|
set(TESTNAME_OPTION -t ${TESTNAME})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_test(NAME ${TEST_FULLNAME} ${CONFARG} ${CONFVAL} COMMAND ${PYTHON_EXECUTABLE} ${tests_SOURCE_DIR}/test_cmdline_tool.py ${MINGW_CROSS_ARG} --comparator=${COMPARATOR} -c ${ImageMagick_convert_EXECUTABLE} -s ${TESTCMD_SUFFIX} ${EXTRA_OPTIONS} ${TESTNAME_OPTION} ${TESTCMD_EXE} "${SCADFILE}" ${TESTCMD_ARGS})
|
||||||
set_property(TEST ${TEST_FULLNAME} PROPERTY ENVIRONMENT "${CTEST_ENVIRONMENT}")
|
set_property(TEST ${TEST_FULLNAME} PROPERTY ENVIRONMENT "${CTEST_ENVIRONMENT}")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
@ -890,19 +904,23 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake ${TMP})
|
||||||
|
|
||||||
# Add tests
|
# Add tests
|
||||||
|
|
||||||
add_cmdline_test(echotest txt ${ECHO_FILES})
|
add_cmdline_test(echotest SUFFIX txt FILES ${ECHO_FILES})
|
||||||
add_cmdline_test(dumptest txt ${DUMPTEST_FILES})
|
add_cmdline_test(dumptest SUFFIX txt FILES ${DUMPTEST_FILES})
|
||||||
add_cmdline_test(csgtexttest txt ${MINIMAL_FILES})
|
add_cmdline_test(csgtexttest SUFFIX txt FILES ${MINIMAL_FILES})
|
||||||
add_cmdline_test(csgtermtest txt ${MINIMAL_FILES})
|
add_cmdline_test(csgtermtest SUFFIX txt FILES ${MINIMAL_FILES})
|
||||||
add_cmdline_test(cgalpngtest png ${CGALPNGTEST_FILES})
|
add_cmdline_test(cgalpngtest SUFFIX png FILES ${CGALPNGTEST_FILES})
|
||||||
add_cmdline_test(opencsgtest png ${OPENCSGTEST_FILES})
|
add_cmdline_test(opencsgtest SUFFIX png FILES ${OPENCSGTEST_FILES})
|
||||||
add_cmdline_test(throwntogethertest png ${THROWNTOGETHERTEST_FILES})
|
add_cmdline_test(throwntogethertest SUFFIX png FILES ${THROWNTOGETHERTEST_FILES})
|
||||||
add_cmdline_test(guicgalpngtest png ${GUICGALPNGTEST_FILES})
|
add_cmdline_test(guicgalpngtest EXE ${GUI_BINPATH} ARGS --render -o
|
||||||
add_cmdline_test(guiopencsgtest png ${GUIOPENCSGTEST_FILES})
|
EXPECTEDDIR cgalpngtest SUFFIX png
|
||||||
|
FILES ${GUICGALPNGTEST_FILES})
|
||||||
|
add_cmdline_test(guiopencsgtest EXE ${GUI_BINPATH} ARGS -o
|
||||||
|
EXPECTEDDIR opencsgtest SUFFIX png
|
||||||
|
FILES ${GUICGALPNGTEST_FILES})
|
||||||
|
|
||||||
# FIXME: We don't actually need to compare the output of cgalstlsanitytest
|
# FIXME: We don't actually need to compare the output of cgalstlsanitytest
|
||||||
# with anything. It's self-contained and returns != 0 on error
|
# with anything. It's self-contained and returns != 0 on error
|
||||||
add_cmdline_test(cgalstlsanitytest txt ${CGALSTLSANITYTEST_FILES})
|
add_cmdline_test(cgalstlsanitytest SUFFIX txt FILES ${CGALSTLSANITYTEST_FILES})
|
||||||
|
|
||||||
message("Available test configurations: ${TEST_CONFIGS}")
|
message("Available test configurations: ${TEST_CONFIGS}")
|
||||||
#foreach(CONF ${TEST_CONFIGS})
|
#foreach(CONF ${TEST_CONFIGS})
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
// Wrapper around openscad gui binary, so it can act like a 'test'
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#ifndef BINPATH
|
|
||||||
#error please define BINPATH=/some/path/openscad when compiling
|
|
||||||
#endif
|
|
||||||
#define PREQUOTE(x) #x
|
|
||||||
#define QUOTE(x) PREQUOTE(x)
|
|
||||||
int main( int argc, char * argv[] )
|
|
||||||
{
|
|
||||||
fprintf(stderr,"%s: wrapper for OpenSCAD at %s\n", argv[0], QUOTE( BINPATH ) );
|
|
||||||
if ( argc != 3 ) {
|
|
||||||
fprintf(stderr,"%s: bad number of arguments: %i\n", argv[0], argc);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
char *newargs[6];
|
|
||||||
char *scadfilename = argv[1];
|
|
||||||
char *pngfilename = argv[2];
|
|
||||||
newargs[0] = const_cast<char *>(QUOTE( BINPATH ));
|
|
||||||
newargs[1] = scadfilename;
|
|
||||||
newargs[2] = const_cast<char *>("-o");
|
|
||||||
newargs[3] = pngfilename;
|
|
||||||
newargs[4] = const_cast<char *>("--render");
|
|
||||||
newargs[5] = NULL;
|
|
||||||
return execv( newargs[0], newargs );
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
// Wrapper around openscad gui binary, so it can act like a 'test'
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#ifndef BINPATH
|
|
||||||
#error please define BINPATH=/some/path/openscad when compiling
|
|
||||||
#endif
|
|
||||||
#define PREQUOTE(x) #x
|
|
||||||
#define QUOTE(x) PREQUOTE(x)
|
|
||||||
int main( int argc, char * argv[] )
|
|
||||||
{
|
|
||||||
fprintf(stderr,"%s: wrapper for OpenSCAD at %s\n", argv[0], QUOTE( BINPATH ) );
|
|
||||||
if ( argc != 3 ) {
|
|
||||||
fprintf(stderr,"%s: bad number of arguments: %i\n", argv[0], argc);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
char *newargs[6];
|
|
||||||
char *scadfilename = argv[1];
|
|
||||||
char *pngfilename = argv[2];
|
|
||||||
newargs[0] = const_cast<char *>(QUOTE( BINPATH ));
|
|
||||||
newargs[1] = scadfilename;
|
|
||||||
newargs[2] = const_cast<char *>("-o");
|
|
||||||
newargs[3] = pngfilename;
|
|
||||||
newargs[4] = NULL;
|
|
||||||
return execv( newargs[0], newargs );
|
|
||||||
}
|
|
||||||
|
|
|
@ -28,22 +28,20 @@ import shutil
|
||||||
import platform
|
import platform
|
||||||
import string
|
import string
|
||||||
|
|
||||||
share_expected_imgs = {}
|
|
||||||
share_expected_imgs["guicgalpngtest"] = "cgalpngtest"
|
|
||||||
share_expected_imgs["guiopencsgtest"] = "opencsgtest"
|
|
||||||
|
|
||||||
def initialize_environment():
|
def initialize_environment():
|
||||||
if not options.generate: options.generate = bool(os.getenv("TEST_GENERATE"))
|
if not options.generate: options.generate = bool(os.getenv("TEST_GENERATE"))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def init_expected_filename(testname, cmd):
|
def init_expected_filename(testname, cmd):
|
||||||
global expecteddir, expectedfilename
|
global expecteddir, expectedfilename
|
||||||
testbinary_filename = os.path.split(cmd)[1]
|
if hasattr(options, "expecteddir"):
|
||||||
if testbinary_filename in share_expected_imgs:
|
expected_basename = options.expecteddir
|
||||||
testbinary_filename = share_expected_imgs[testbinary_filename]
|
else:
|
||||||
expecteddir = os.path.join(options.regressiondir, testbinary_filename )
|
expected_basename = os.path.split(cmd)[1]
|
||||||
|
|
||||||
|
expecteddir = os.path.join(options.regressiondir, expected_basename)
|
||||||
expectedfilename = os.path.join(expecteddir, testname + "-expected." + options.suffix)
|
expectedfilename = os.path.join(expecteddir, testname + "-expected." + options.suffix)
|
||||||
expectedfilename = os.path.normpath( expectedfilename )
|
expectedfilename = os.path.normpath(expectedfilename)
|
||||||
|
|
||||||
def verify_test(testname, cmd):
|
def verify_test(testname, cmd):
|
||||||
global expectedfilename
|
global expectedfilename
|
||||||
|
@ -108,7 +106,7 @@ def compare_png(resultfilename):
|
||||||
msg += '\n expected image: ' + expectedfilename + '\n'
|
msg += '\n expected image: ' + expectedfilename + '\n'
|
||||||
print >> sys.stderr, msg
|
print >> sys.stderr, msg
|
||||||
if not resultfilename:
|
if not resultfilename:
|
||||||
print >> sys.stderr, "Error: OpenSCAD error during test image generation"
|
print >> sys.stderr, "Error: Error during test image generation"
|
||||||
return False
|
return False
|
||||||
print >> sys.stderr, ' actual image: ', resultfilename
|
print >> sys.stderr, ' actual image: ', resultfilename
|
||||||
|
|
||||||
|
@ -181,13 +179,15 @@ def usage():
|
||||||
print >> sys.stderr, "Options:"
|
print >> sys.stderr, "Options:"
|
||||||
print >> sys.stderr, " -g, --generate Generate expected output for the given tests"
|
print >> sys.stderr, " -g, --generate Generate expected output for the given tests"
|
||||||
print >> sys.stderr, " -s, --suffix=<suffix> Write -expected and -actual files with the given suffix instead of .txt"
|
print >> sys.stderr, " -s, --suffix=<suffix> Write -expected and -actual files with the given suffix instead of .txt"
|
||||||
|
print >> sys.stderr, " -e, --expected-dir=<dir> Use -expected files from the given dir (to share files between test drivers)"
|
||||||
print >> sys.stderr, " -t, --test=<name> Specify test name instead of deducting it from the argument"
|
print >> sys.stderr, " -t, --test=<name> Specify test name instead of deducting it from the argument"
|
||||||
print >> sys.stderr, " -c, --convexec=<name> Path to ImageMagick 'convert' executable"
|
print >> sys.stderr, " -c, --convexec=<name> Path to ImageMagick 'convert' executable"
|
||||||
print >> sys.stderr, " -x, --mingw-cross-env Mingw-cross-env cross compilation"
|
print >> sys.stderr, " -x, --mingw-cross-env Mingw-cross-env cross compilation"
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Handle command-line arguments
|
# Handle command-line arguments
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "gs:c:t:m:x", ["generate", "convexec=", "suffix=", "test=", "comparator=", "mingw-cross-env"])
|
opts, args = getopt.getopt(sys.argv[1:], "gs:e:c:t:m:x", ["generate", "convexec=", "suffix=", "expected_dir=", "test=", "comparator=", "mingw-cross-env"])
|
||||||
except getopt.GetoptError, err:
|
except getopt.GetoptError, err:
|
||||||
usage()
|
usage()
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
@ -203,6 +203,8 @@ if __name__ == '__main__':
|
||||||
elif o in ("-s", "--suffix"):
|
elif o in ("-s", "--suffix"):
|
||||||
if a[0] == '.': options.suffix = a[1:]
|
if a[0] == '.': options.suffix = a[1:]
|
||||||
else: options.suffix = a
|
else: options.suffix = a
|
||||||
|
elif o in ("-e", "--expected-dir"):
|
||||||
|
options.expecteddir = a
|
||||||
elif o in ("-t", "--test"):
|
elif o in ("-t", "--test"):
|
||||||
options.testname = a
|
options.testname = a
|
||||||
elif o in ("-c", "--convexec"):
|
elif o in ("-c", "--convexec"):
|
||||||
|
|
Loading…
Reference in New Issue