mirror of https://github.com/vitalif/openscad
commit
e868b4a5a1
|
@ -602,10 +602,6 @@ else()
|
|||
endif()
|
||||
|
||||
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}")
|
||||
else()
|
||||
message(STATUS "Couldn't find the OpenSCAD GUI binary: ${GUI_BINPATH}")
|
||||
|
@ -674,16 +670,28 @@ endfunction()
|
|||
|
||||
#
|
||||
# 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)
|
||||
macro(add_cmdline_test TESTCMD TESTSUFFIX)
|
||||
function(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)
|
||||
|
||||
# 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
|
||||
foreach (SCADFILE ${ARGN})
|
||||
foreach (SCADFILE ${TESTCMD_FILES})
|
||||
get_filename_component(TESTNAME ${SCADFILE} NAME_WE)
|
||||
string(REPLACE " " "_" TESTNAME ${TESTNAME}) # Test names cannot include spaces
|
||||
set(TEST_FULLNAME "${TESTCMD_NAME}_${TESTNAME}")
|
||||
|
@ -705,11 +713,17 @@ macro(add_cmdline_test TESTCMD TESTSUFFIX)
|
|||
if (MINGW_CROSS_ENV_DIR)
|
||||
set( MINGW_CROSS_ARG "--mingw-cross-env" )
|
||||
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}")
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
endfunction()
|
||||
|
||||
enable_testing()
|
||||
|
||||
|
@ -890,19 +904,23 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake ${TMP})
|
|||
|
||||
# Add tests
|
||||
|
||||
add_cmdline_test(echotest txt ${ECHO_FILES})
|
||||
add_cmdline_test(dumptest txt ${DUMPTEST_FILES})
|
||||
add_cmdline_test(csgtexttest txt ${MINIMAL_FILES})
|
||||
add_cmdline_test(csgtermtest txt ${MINIMAL_FILES})
|
||||
add_cmdline_test(cgalpngtest png ${CGALPNGTEST_FILES})
|
||||
add_cmdline_test(opencsgtest png ${OPENCSGTEST_FILES})
|
||||
add_cmdline_test(throwntogethertest png ${THROWNTOGETHERTEST_FILES})
|
||||
add_cmdline_test(guicgalpngtest png ${GUICGALPNGTEST_FILES})
|
||||
add_cmdline_test(guiopencsgtest png ${GUIOPENCSGTEST_FILES})
|
||||
add_cmdline_test(echotest SUFFIX txt FILES ${ECHO_FILES})
|
||||
add_cmdline_test(dumptest SUFFIX txt FILES ${DUMPTEST_FILES})
|
||||
add_cmdline_test(csgtexttest SUFFIX txt FILES ${MINIMAL_FILES})
|
||||
add_cmdline_test(csgtermtest SUFFIX txt FILES ${MINIMAL_FILES})
|
||||
add_cmdline_test(cgalpngtest SUFFIX png FILES ${CGALPNGTEST_FILES})
|
||||
add_cmdline_test(opencsgtest SUFFIX png FILES ${OPENCSGTEST_FILES})
|
||||
add_cmdline_test(throwntogethertest SUFFIX png FILES ${THROWNTOGETHERTEST_FILES})
|
||||
add_cmdline_test(guicgalpngtest EXE ${GUI_BINPATH} ARGS --render -o
|
||||
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
|
||||
# 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}")
|
||||
#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 string
|
||||
|
||||
share_expected_imgs = {}
|
||||
share_expected_imgs["guicgalpngtest"] = "cgalpngtest"
|
||||
share_expected_imgs["guiopencsgtest"] = "opencsgtest"
|
||||
|
||||
def initialize_environment():
|
||||
if not options.generate: options.generate = bool(os.getenv("TEST_GENERATE"))
|
||||
return True
|
||||
|
||||
def init_expected_filename(testname, cmd):
|
||||
global expecteddir, expectedfilename
|
||||
testbinary_filename = os.path.split(cmd)[1]
|
||||
if testbinary_filename in share_expected_imgs:
|
||||
testbinary_filename = share_expected_imgs[testbinary_filename]
|
||||
expecteddir = os.path.join(options.regressiondir, testbinary_filename )
|
||||
if hasattr(options, "expecteddir"):
|
||||
expected_basename = options.expecteddir
|
||||
else:
|
||||
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.normpath( expectedfilename )
|
||||
expectedfilename = os.path.normpath(expectedfilename)
|
||||
|
||||
def verify_test(testname, cmd):
|
||||
global expectedfilename
|
||||
|
@ -108,7 +106,7 @@ def compare_png(resultfilename):
|
|||
msg += '\n expected image: ' + expectedfilename + '\n'
|
||||
print >> sys.stderr, msg
|
||||
if not resultfilename:
|
||||
print >> sys.stderr, "Error: OpenSCAD error during test image generation"
|
||||
print >> sys.stderr, "Error: Error during test image generation"
|
||||
return False
|
||||
print >> sys.stderr, ' actual image: ', resultfilename
|
||||
|
||||
|
@ -152,6 +150,8 @@ def run_test(testname, cmd, args):
|
|||
try:
|
||||
if os.path.isfile(cmd+'.exe') and options.mingw_cross_env:
|
||||
cmdline = ['wine']+[cmd+'.exe'] + args + [outputname]
|
||||
elif cmd[-4:].lower() == '.exe' and options.mingw_cross_env:
|
||||
cmdline = ['wine']+[cmd] + args + [outputname]
|
||||
else:
|
||||
cmdline = [cmd] + args + [outputname]
|
||||
proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
@ -179,15 +179,17 @@ class Options:
|
|||
def usage():
|
||||
print >> sys.stderr, "Usage: " + sys.argv[0] + " [<options>] <cmdline-tool> <argument>"
|
||||
print >> sys.stderr, "Options:"
|
||||
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, " -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, " -x, --mingw-cross-env Mingw-cross-env cross compilation"
|
||||
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, " -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, " -c, --convexec=<name> Path to ImageMagick 'convert' executable"
|
||||
print >> sys.stderr, " -x, --mingw-cross-env Mingw-cross-env cross compilation"
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Handle command-line arguments
|
||||
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:
|
||||
usage()
|
||||
sys.exit(2)
|
||||
|
@ -203,6 +205,8 @@ if __name__ == '__main__':
|
|||
elif o in ("-s", "--suffix"):
|
||||
if a[0] == '.': options.suffix = a[1:]
|
||||
else: options.suffix = a
|
||||
elif o in ("-e", "--expected-dir"):
|
||||
options.expecteddir = a
|
||||
elif o in ("-t", "--test"):
|
||||
options.testname = a
|
||||
elif o in ("-c", "--convexec"):
|
||||
|
|
|
@ -312,14 +312,21 @@ TESTLOG
|
|||
|
||||
def png_encode64( fname, width=250 ):
|
||||
# en.wikipedia.org/wiki/Data_URI_scheme
|
||||
f = open( fname, "rb" )
|
||||
data = f.read()
|
||||
try:
|
||||
f = open( fname, "rb" )
|
||||
data = f.read()
|
||||
except:
|
||||
data = ''
|
||||
data_uri = data.encode("base64").replace("\n","")
|
||||
tag = '<img'
|
||||
tag += ' style="border:1px solid gray"'
|
||||
tag += ' src="data:image/png;base64,'
|
||||
tag += data_uri + '"'
|
||||
tag += ' width="'+str(width)+'"'
|
||||
tag += ' alt="openscad_test_image"'
|
||||
if data =='':
|
||||
tag += ' alt="error: no image generated"'
|
||||
else:
|
||||
tag += ' alt="openscad_test_image"'
|
||||
tag += ' />\n'
|
||||
return tag
|
||||
|
||||
|
|
Loading…
Reference in New Issue