diff --git a/sprout/assert.hpp b/sprout/assert.hpp index 07f4b919..42d12fd4 100644 --- a/sprout/assert.hpp +++ b/sprout/assert.hpp @@ -21,14 +21,12 @@ # include #endif -#if !(defined(SPROUT_DISABLE_ASSERTS) || defined(NDEBUG)) - // - // SPROUT_ASSERTION_FAILED_FORMAT - // -# ifndef SPROUT_ASSERTION_FAILED_FORMAT -# define SPROUT_ASSERTION_FAILED_FORMAT(expr, file, line) \ - "***** Internal Program Error - assertion (" #expr ") failed: " file "(" SPROUT_PP_STRINGIZE(line) ")" -# endif +// +// SPROUT_ASSERTION_FAILED_FORMAT +// +#ifndef SPROUT_ASSERTION_FAILED_FORMAT +# define SPROUT_ASSERTION_FAILED_FORMAT(expr, file, line) \ + "***** Internal Program Error - assertion (" #expr ") failed: " file "(" SPROUT_PP_STRINGIZE(line) ")" #endif // diff --git a/testspr/assert.hpp b/testspr/assert.hpp index 0a981d92..063f8e10 100644 --- a/testspr/assert.hpp +++ b/testspr/assert.hpp @@ -8,18 +8,56 @@ #ifndef TESTSPR_ASSERT_HPP #define TESTSPR_ASSERT_HPP -#include +#include +#include #ifdef TESTSPR_CONFIG_ENABLE_STATIC_WARNING # include #endif +#include + +namespace testspr { + // + // assertion_failed + // + class assertion_failed + : public std::runtime_error + { + public: + explicit assertion_failed(std::string const& msg) + : std::runtime_error(msg) + {} + explicit assertion_failed(char const* msg) + : std::runtime_error(msg) + {} + }; + + namespace detail { + inline SPROUT_CONSTEXPR bool + assertion_check(bool cond, std::string const& msg) { + return cond ? true + : throw testspr::assertion_failed(msg) + ; + } + inline SPROUT_CONSTEXPR bool + assertion_check(bool cond, char const* msg) { + return cond ? true + : throw testspr::assertion_failed(msg) + ; + } + } // namespace detail +} // namespace testspr // // TESTSPR_STATIC_ASSERT // TESTSPR_ASSERT +// +#define TESTSPR_STATIC_ASSERT(expr) \ + static_assert(expr, #expr) +#define TESTSPR_ASSERT(expr) \ + ((void)sprout::detail::assertion_check((expr), SPROUT_ASSERTION_FAILED_FORMAT(expr, __FILE__, __LINE__))) +// // TESTSPR_BOTH_ASSERT // -#define TESTSPR_STATIC_ASSERT(expr) static_assert(expr, #expr) -#define TESTSPR_ASSERT(expr) assert(expr) #ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR # define TESTSPR_BOTH_ASSERT(expr) TESTSPR_STATIC_ASSERT(expr); TESTSPR_ASSERT(expr) #else // #ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR diff --git a/testspr/include_main.hpp b/testspr/include_main.hpp index 37921b1e..fd73ed0a 100644 --- a/testspr/include_main.hpp +++ b/testspr/include_main.hpp @@ -14,13 +14,40 @@ # error undefined TESTSPR_TEST_FUNCTION #endif +#include +#include #include #include +#include +#include int main() { - std::cout << "testspr exec: " << SPROUT_PP_STRINGIZE(TESTSPR_TEST_FUNCTION) << std::endl; - TESTSPR_TEST_FUNCTION(); - std::cout << "testspr succeeded." << std::endl; + std::cout << "testspr exec(" << SPROUT_PP_STRINGIZE(TESTSPR_TEST_FUNCTION) << "):" << std::endl; + try { + TESTSPR_TEST_FUNCTION(); + } catch (testspr::assertion_failed const& e) { + std::cout + << " testspr failed." << std::endl + << " " << e.what() << std::endl + ; + return EXIT_FAILURE; + } catch (std::exception const& e) { + std::cout + << " testspr failed for some reason." << std::endl + << " exception handled:" << std::endl + << " type = " << testspr::typename_of(e) << std::endl + << " what = " << e.what() << std::endl + ; + return EXIT_FAILURE; + } catch (...) { + std::cout + << " testspr failed for some reason." << std::endl + << " exception handled:" << std::endl + << " type = " << std::endl + ; + return EXIT_FAILURE; + } + std::cout << " testspr succeeded." << std::endl; } #endif diff --git a/testspr/sprout.cpp b/testspr/sprout.cpp index 8fcb97d8..0a5d9725 100644 --- a/testspr/sprout.cpp +++ b/testspr/sprout.cpp @@ -13,10 +13,6 @@ # define TESTSPR_CPP_INCLUDE #endif -#ifdef TESTSPR_CONFIG_INCLUDE_HEADER_ALL -# include "./header_all.hpp" -#endif - #include "../libs/array/test/array.cpp" #include "../libs/string/test/string.cpp" #include "../libs/bitset/test/bitset.cpp" diff --git a/testspr/test.sh b/testspr/test.sh deleted file mode 100755 index 3d3661f6..00000000 --- a/testspr/test.sh +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/bash -# ============================================================================= -# Copyright (c) 2011-2013 Bolero MURAKAMI -# https://github.com/bolero-MURAKAMI/Sprout -# -# Distributed under the Boost Software License, Version 1.0. (See accompanying -# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -# ============================================================================= -stagedir="testspr" -gcc_version="4.7.0 4.7.1 4.7.2 4.7.3 4.8.0 4.8.1" -clang_version="3.2 3.3" -gcc_root="/usr/local" -clang_root="/usr/local" -declare -a user_macros -user_macros=() -declare -a include_paths -include_paths=() -force=0 -use_help=0 -declare -A version_specific_options -version_specific_options=( - [clang-3.3]="-ftemplate-depth=512" -) -declare -A results -results=() - -compile() { - echo "${1}-${2} compile..." - ${5}/${1}-${2}/bin/${1/%cc}++ -Wall -pedantic -std=c++11 -o ${stagedir}/test_${1}${2//.} ${4} ${3} - results[${1}-${2}]=$? -} -execute() { - if [ ${results[${1}-${2}]} -eq 0 ]; then - echo "${1}-${2} compile succeeded." - if ${stagedir}/test_$1${2//.}; then - echo "${1}-${2} execute succeeded." - else - echo >&2 "error: ${1}-${2} execute failed." - fi - else - echo >&2 "error: ${1}-${2} compile failed." - fi -} - -args=`getopt -o S:D:I:f -l stagedir:,gcc-version:,clang-version:,gcc-root:,clang-root:,define:,include:,force,help -- "$@"` -if [ "$?" -ne 0 ]; then - echo >&2 "error: options parse error. See 'test.sh --help'" - exit 1 -fi -eval set -- ${args} -while [ -n "$1" ]; do - case $1 in - -S|--stagedir) stagedir=$2; shift 2;; - --gcc-version) gcc_version="$2"; shift 2;; - --clang-version) clang_version="$2"; shift 2;; - --gcc-root) gcc_root="$2"; shift 2;; - --clang-root) clang_root="$2"; shift 2;; - -D|--define) user_macros=(${user_macros[@]} "$2"); shift 2;; - -I|--include) include_paths=(${include_paths[@]} "$2"); shift 2;; - -f|--force) force=1; shift;; - --help) use_help=1; shift;; - --) shift; break;; - *) echo >&2 "error: unknown option($1) used."; exit 1;; - esac -done - -if [ ${use_help} -ne 0 ]; then - echo "help:" - echo "" - echo " -S, --stagedir= Output files here." - echo " Default; 'testspr'" - echo "" - echo " --gcc-version= Indicates gcc version." - echo " Default; '4.7.0 4.7.1 4.7.2 4.7.3 4.8.0 4.8.1'" - echo "" - echo " --clang-version= Indicates clang version." - echo " Default; '3.2 3.3'" - echo "" - echo " --gcc-root= Root directory that gcc installed." - echo " Default; '/usr/local'" - echo "" - echo " --clang-root= Root directory that clang installed." - echo " Default; '/usr/local'" - echo "" - echo " -D, --define= Define macro for preprocessor." - echo "" - echo " -I, --include= Add system include path." - echo "" - echo " -f, --force Allow overwrite of ." - echo "" - echo " --help This message." - exit 0 -fi - -echo "settings:" -echo " stagedir = '${stagedir}'" -echo " gcc-version = (${gcc_version})" -echo " clang-version = (${clang_version})" -echo " gcc-root = '${gcc_root}'" -echo " clang-root = '${clang_root}'" -echo " user-macros = (${user_macros[*]})" -echo " include-paths = (${include_paths[*]})" -echo " force = ${force}" - -for user_macro in ${user_macros}; do - define_options="${define_options} -D${user_macro}" -done -for include_path in ${include_paths}; do - include_options="${include_options} -I${include_path}" -done - -if [ -d "${stagedir}" ]; then - if [ ${force} -eq 0 ]; then - echo >&2 "error: stagedir(${stagedir}) already exists." - exit 1 - else - rm -f -r ${stagedir}/* - fi -else - mkdir -p ${stagedir} -fi - -for version in ${gcc_version}; do - compile gcc ${version} $(cd $(dirname $0); pwd)/sprout.cpp "${define_options} ${include_options} ${version_specific_options[gcc-${version}]}" ${gcc_root} -done -for version in ${clang_version}; do - compile clang ${version} $(cd $(dirname $0); pwd)/sprout.cpp "${define_options} ${include_options} ${version_specific_options[clang-${version}]}" ${clang_root} -done - -for version in ${gcc_version}; do - execute gcc ${version} -done -for version in ${clang_version}; do - execute clang ${version} -done diff --git a/testspr/typeinfo.hpp b/testspr/typeinfo.hpp index 05864673..a50ca6d4 100644 --- a/testspr/typeinfo.hpp +++ b/testspr/typeinfo.hpp @@ -20,6 +20,7 @@ #endif #include +#include #include #ifdef TESTSPR_HAS_CXXABI_H # include @@ -53,11 +54,19 @@ namespace testspr { inline std::string typename_of() { return testspr::detail::cxa_demangle(typeid(T).name()); } + template + inline std::string typename_of(T&& t) { + return testspr::detail::cxa_demangle(typeid(std::forward(t)).name()); + } #else template inline std::string typename_of() { return std::string(typeid(T).name()); } + template + inline std::string typename_of(T&& t) { + return std::string(typeid(std::forward(t)).name()); + } #endif } // namespace testspr diff --git a/tools/darkroom/darkcult.py b/tools/darkroom/darkcult.py index 29004fa0..d164af70 100755 --- a/tools/darkroom/darkcult.py +++ b/tools/darkroom/darkcult.py @@ -56,8 +56,8 @@ def main(): return any(pool.map( compile, [format_command(x, y) - for x in range(0, opts.width, opts.tile_width) for y in range(0, opts.height, opts.tile_height) + for x in range(0, opts.width, opts.tile_width) ] )) diff --git a/tools/darkroom/darkcult.sh b/tools/darkroom/darkcult.sh index 19f01a16..afe89332 100755 --- a/tools/darkroom/darkcult.sh +++ b/tools/darkroom/darkcult.sh @@ -46,7 +46,7 @@ while [ -n "$1" ]; do -H|--tile-height) tile_height=$2; shift 2;; -D|--define) user_macros=(${user_macros[@]} "$2"); shift 2;; -I|--include) include_paths=(${include_paths[@]} "$2"); shift 2;; - -P|--max_procs) max_procs=$2; shift 2;; + -P|--max-procs) max_procs=$2; shift 2;; -f|--force) force=1; shift;; --help) use_help=1; shift;; --) shift; break;; @@ -166,7 +166,7 @@ if [ ${max_procs} -eq 1 ]; then done echo "" - let "y_elapsed=${SECONDS}-${y_start}" + let y_elapsed=${SECONDS}-${y_start} echo " elapsed = ${y_elapsed}s" done else @@ -178,15 +178,14 @@ else "--tile_width=${tile_width}" "--tile_height=${tile_height}"" "\ "--compile_options=${compile_options}" "--darkcult_cpp=${darkcult_cpp}" \ "--max_procs=${max_procs}" + echo "" if [ $? -ne 0 ]; then - echo "" echo >&2 "error: compile failed." exit 1 fi - echo "" fi -let "elapsed=${SECONDS}-${start}" +let elapsed=${SECONDS}-${start} echo " elapsed(total) = ${elapsed}s" for ((y=0; y %s 2>&1" \ + " && %s > %s 2>&1" \ + % (compiler, bin, + opts.compile_options, eval(opts.serialized_version_specific_options).get(base, ''), + opts.test_cpp, compile_log, + bin, execute_log + ) + return sum(result != 0 for result in pool.map( + compile, + [format_command('gcc', version, opts.gcc_root) + for version in opts.gcc_version.split(' ') + ] + + + [format_command('clang', version, opts.clang_root) + for version in opts.clang_version.split(' ') + ] + )) + +if __name__=="__main__": + sys.exit(main()) diff --git a/tools/testspr/test.sh b/tools/testspr/test.sh new file mode 100755 index 00000000..5381a66e --- /dev/null +++ b/tools/testspr/test.sh @@ -0,0 +1,210 @@ +#!/bin/bash +# ============================================================================= +# Copyright (c) 2011-2013 Bolero MURAKAMI +# https://github.com/bolero-MURAKAMI/Sprout +# +# Distributed under the Boost Software License, Version 1.0. (See accompanying +# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +# ============================================================================= +# +# requires: Python (http://www.python.org/) if parallel mode +# +stagedir="testspr" +gcc_version="." +clang_version="." +gcc_root="/usr/local" +clang_root="/usr/local" +declare -a user_macros +user_macros=() +declare -a include_paths +include_paths=() +max_procs=1 +force=0 +use_help=0 +declare -a common_options +common_options=() +declare -a version_options +version_options=() +declare -A version_specific_options +version_specific_options=( + [clang-3.3]='-ftemplate-depth=512' +) +test_cpp=$(cd $(dirname $0); pwd)/test.cpp +test_py=$(cd $(dirname $0); pwd)/test.py + +args=`getopt -o S:g:c:O:o:D:I:P:f -l stagedir:,gcc-version:,clang-version:,gcc-root:,clang-root:,option:,version-option:,define:,include:,max-procs:,force,help -- "$@"` +if [ "$?" -ne 0 ]; then + echo >&2 "error: options parse error. See 'test.sh --help'" + exit 1 +fi +eval set -- ${args} +while [ -n "$1" ]; do + case $1 in + -S|--stagedir) stagedir=$2; shift 2;; + -g|--gcc-version) gcc_version="$2"; shift 2;; + -c|--clang-version) clang_version="$2"; shift 2;; + --gcc-root) gcc_root="$2"; shift 2;; + --clang-root) clang_root="$2"; shift 2;; + -O|--option) common_options=(${common_options[@]} "$2"); shift 2;; + -o|--version-option) version_options=(${version_options[@]} "$2"); shift 2;; + -D|--define) user_macros=(${user_macros[@]} "$2"); shift 2;; + -I|--include) include_paths=(${include_paths[@]} "$2"); shift 2;; + -P|--max-procs) max_procs=$2; shift 2;; + -f|--force) force=1; shift;; + --help) use_help=1; shift;; + --) shift; break;; + *) echo >&2 "error: unknown option($1) used."; exit 1;; + esac +done + +if [ ${use_help} -ne 0 ]; then + echo "help:" + echo "" + echo " -S, --stagedir= Output files here." + echo " Default; 'testspr'" + echo "" + echo " -g, --gcc-version= Indicates gcc version list (space separated)." + echo " If '.', version that is installed on the system." + echo " Default; '.'" + echo "" + echo " -c, --clang-version= Indicates clang version list (space separated)." + echo " If '.', version that is installed on the system." + echo " Default; '.'" + echo "" + echo " --gcc-root= Root directory that gcc installed." + echo " Default; '/usr/local'" + echo "" + echo " --clang-root= Root directory that clang installed." + echo " Default; '/usr/local'" + echo "" + echo " -O, --option= Add compile option." + echo "" + echo " -o, --version-option= Add version specific compile option." + echo " Example; [clang-3.3]='-ftemplate-depth=512'" + echo "" + echo " -D, --define= Define macro for preprocessor." + echo "" + echo " -I, --include= Add system include path." + echo "" + echo " -P, --max-procs= The maximum number of process use." + echo " If other than 1, processing in parallel mode." + echo " If 0, using the number of CPUs in the system." + echo " Default; 1" + echo "" + echo " -f, --force Allow overwrite of ." + echo "" + echo " --help This message." + exit 0 +fi + +echo "settings:" +echo " stagedir = '${stagedir}'" +echo " gcc-version = (${gcc_version})" +echo " clang-version = (${clang_version})" +echo " gcc-root = '${gcc_root}'" +echo " clang-root = '${clang_root}'" +echo " common-options = (${common_options[*]})" +echo " version-options = (${version_options[*]})" +echo " user-macros = (${user_macros[*]})" +echo " include-paths = (${include_paths[*]})" +echo " max-procs = ${max_procs}" +echo " force = ${force}" + +for user_macro in ${user_macros}; do + define_options="${define_options} -D${user_macro}" +done +for include_path in ${include_paths}; do + include_options="${include_options} -I${include_path}" +done +compile_options="-Wall -pedantic -std=c++11 ${define_options} ${include_options} ${common_options[*]}" +for option in ${version_options}; do + eval "version_specific_options${option}" +done + +if [ -d "${stagedir}" ]; then + if [ ${force} -eq 0 ]; then + echo >&2 "error: stagedir(${stagedir}) already exists." + exit 1 + else + rm -f -r ${stagedir}/* + fi +else + mkdir -p ${stagedir} +fi + +echo "test:" +compile() { + local base + if [ ${2} != "." ]; then + base=${1}-${2} + else + base=${1} + fi + local bin=${stagedir}/test.${base//.}.out + local compile_log=${stagedir}/test.${base//.}.compile.log + local execute_log=${stagedir}/test.${base//.}.execute.log + local compiler + if [ ${2} != "." ]; then + compiler=${6}/${base}/bin/${1/%cc}++ + else + compiler=${1/%cc}++ + fi + echo " compile(${base})..." + ${compiler} -o ${bin} ${4} ${5[${base}]} ${3} >${compile_log} 2>&1 + if [ $? -eq 0 ]; then + echo " compile succeeded." + echo " execute(${base})..." + ${bin} >${execute_log} 2>&1 + if [ $? -eq 0 ]; then + echo " execute succeeded." + else + echo >&2 " error: execute(${base}) failed." + return 1 + fi + else + echo >&2 " error: compile(${base}) failed." + return 1 + fi + return 0 +} +if [ ${max_procs} -eq 1 ]; then + fail_count=0 + for version in ${gcc_version}; do + compile gcc ${version} ${test_cpp} ${compile_options} ${version_specific_options} ${gcc_root} + let fail_count=${fail_count}+$? + done + for version in ${clang_version}; do + compile clang ${version} ${test_cpp} ${compile_options} ${version_specific_options} ${clang_root} + let fail_count=${fail_count}+$? + done + if [ ${fail_count} -ne 0 ]; then + echo >&2 " error: test(${fail_count}) failed." + else + echo " test succeeded." + fi +else + echo " processing in parallel mode." + echo -n " " + serialized_version_specific_options={` + for key in $(echo ${!version_specific_options[@]}); do + echo \'${key}\':\'${version_specific_options[${key}]}\', + done + echo \'_\':\'\' + `} + python "${test_py}" \ + "--stagedir=${stagedir}" \ + "--gcc_version=${gcc_version}" "--clang_version=${clang_version}" \ + "--gcc_root=${gcc_root}" "--clang_root=${clang_root}" \ + "--compile_options=${compile_options}" "--test_cpp=${test_cpp}" \ + "--serialized_version_specific_options=${serialized_version_specific_options}" \ + "--max_procs=${max_procs}" + fail_count=$? + echo "" + if [ ${fail_count} -ne 0 ]; then + echo >&2 " error: test(${fail_count}) failed." + else + echo " test succeeded." + fi +fi + +echo "finished."