mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-25 18:50:40 +08:00
* Remove test_ prefix in tests
* tests now honor EIGEN_REPEAT and EIGEN_SEED if no arguments were passed
This commit is contained in:
parent
b0100a336a
commit
de25059502
@ -19,7 +19,7 @@ endmacro(ei_add_property)
|
||||
|
||||
#internal. See documentation of ei_add_test for details.
|
||||
macro(ei_add_test_internal testname testname_with_suffix)
|
||||
set(targetname test_${testname_with_suffix})
|
||||
set(targetname ${testname_with_suffix})
|
||||
|
||||
set(filename ${testname}.cpp)
|
||||
add_executable(${targetname} ${filename})
|
||||
@ -79,8 +79,8 @@ endmacro(ei_add_test_internal)
|
||||
#
|
||||
# A. Default behavior
|
||||
#
|
||||
# this macro add an executable test_<testname> as well as a ctest test
|
||||
# named <testname>.
|
||||
# this macro adds an executable <testname> as well as a ctest test
|
||||
# named <testname> too.
|
||||
#
|
||||
# On platforms with bash simply run:
|
||||
# "ctest -V" or "ctest -V -R <testname>"
|
||||
@ -102,7 +102,7 @@ endmacro(ei_add_test_internal)
|
||||
# executables is built passing -DEIGEN_TEST_PART_N. This allows to split large tests
|
||||
# into smaller executables.
|
||||
#
|
||||
# Moreover, targets test_<testname> are still generated, they
|
||||
# Moreover, targets <testname> are still generated, they
|
||||
# have the effect of building all the parts of the test.
|
||||
#
|
||||
# Again, ctest -R allows to run all matching tests.
|
||||
@ -118,11 +118,11 @@ macro(ei_add_test testname)
|
||||
string(REGEX REPLACE "CALL_SUBTEST_|EIGEN_TEST_PART_" "" suffixes "${occurences}")
|
||||
list(REMOVE_DUPLICATES suffixes)
|
||||
if(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
|
||||
add_custom_target(test_${testname})
|
||||
add_custom_target(${testname})
|
||||
foreach(suffix ${suffixes})
|
||||
ei_add_test_internal(${testname} ${testname}_${suffix}
|
||||
"${ARGV1} -DEIGEN_TEST_PART_${suffix}=1" "${ARGV2}")
|
||||
add_dependencies(test_${testname} test_${testname}_${suffix})
|
||||
add_dependencies(${testname} ${testname}_${suffix})
|
||||
endforeach(suffix)
|
||||
else(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
|
||||
set(symbols_to_enable_all_parts "")
|
||||
|
@ -9,7 +9,7 @@ fi
|
||||
|
||||
TESTSLIST="${EIGEN_TESTS_LIST}"
|
||||
|
||||
targets_to_make=`echo "$TESTSLIST" | egrep "$1" | sed s/^/test_/g | xargs echo`
|
||||
targets_to_make=`echo "$TESTSLIST" | egrep "$1" | xargs echo`
|
||||
|
||||
if [ $# == 1 ]
|
||||
then
|
||||
|
75
test/main.h
75
test/main.h
@ -24,6 +24,7 @@
|
||||
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cerrno>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@ -49,6 +50,8 @@ namespace Eigen
|
||||
{
|
||||
static std::vector<std::string> g_test_stack;
|
||||
static int g_repeat;
|
||||
static unsigned int g_seed;
|
||||
static bool g_has_set_repeat, g_has_set_seed;
|
||||
}
|
||||
|
||||
#define EI_PP_MAKE_STRING2(S) #S
|
||||
@ -385,46 +388,55 @@ void EIGEN_CAT(test_,EIGEN_TEST_FUNC)();
|
||||
|
||||
using namespace Eigen;
|
||||
|
||||
void set_repeat_from_string(const char *str)
|
||||
{
|
||||
errno = 0;
|
||||
g_repeat = int(strtoul(str, 0, 10));
|
||||
if(errno || g_repeat <= 0)
|
||||
{
|
||||
std::cout << "Invalid repeat value " << str << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
g_has_set_repeat = true;
|
||||
}
|
||||
|
||||
void set_seed_from_string(const char *str)
|
||||
{
|
||||
errno = 0;
|
||||
g_seed = strtoul(str, 0, 10);
|
||||
if(errno || g_seed == 0)
|
||||
{
|
||||
std::cout << "Invalid seed value " << str << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
g_has_set_seed = true;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bool has_set_repeat = false;
|
||||
bool has_set_seed = false;
|
||||
g_has_set_repeat = false;
|
||||
g_has_set_seed = false;
|
||||
bool need_help = false;
|
||||
unsigned int seed = 0;
|
||||
int repeat = DEFAULT_REPEAT;
|
||||
|
||||
for(int i = 1; i < argc; i++)
|
||||
{
|
||||
if(argv[i][0] == 'r')
|
||||
{
|
||||
if(has_set_repeat)
|
||||
if(g_has_set_repeat)
|
||||
{
|
||||
std::cout << "Argument " << argv[i] << " conflicting with a former argument" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
repeat = atoi(argv[i]+1);
|
||||
has_set_repeat = true;
|
||||
if(repeat <= 0)
|
||||
{
|
||||
std::cout << "Invalid \'repeat\' value " << argv[i]+1 << std::endl;
|
||||
return 1;
|
||||
}
|
||||
set_repeat_from_string(argv[i]+1);
|
||||
}
|
||||
else if(argv[i][0] == 's')
|
||||
{
|
||||
if(has_set_seed)
|
||||
if(g_has_set_seed)
|
||||
{
|
||||
std::cout << "Argument " << argv[i] << " conflicting with a former argument" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
seed = int(strtoul(argv[i]+1, 0, 10));
|
||||
has_set_seed = true;
|
||||
bool ok = seed!=0;
|
||||
if(!ok)
|
||||
{
|
||||
std::cout << "Invalid \'seed\' value " << argv[i]+1 << std::endl;
|
||||
return 1;
|
||||
}
|
||||
set_seed_from_string(argv[i]+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -437,17 +449,26 @@ int main(int argc, char *argv[])
|
||||
std::cout << "This test application takes the following optional arguments:" << std::endl;
|
||||
std::cout << " rN Repeat each test N times (default: " << DEFAULT_REPEAT << ")" << std::endl;
|
||||
std::cout << " sN Use N as seed for random numbers (default: based on current time)" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "If defined, the environment variables EIGEN_REPEAT and EIGEN_SEED" << std::endl;
|
||||
std::cout << "will be used as default values for these parameters." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!has_set_seed) seed = (unsigned int) time(NULL);
|
||||
if(!has_set_repeat) repeat = DEFAULT_REPEAT;
|
||||
char *env_EIGEN_REPEAT = getenv("EIGEN_REPEAT");
|
||||
if(!g_has_set_repeat && env_EIGEN_REPEAT)
|
||||
set_repeat_from_string(env_EIGEN_REPEAT);
|
||||
char *env_EIGEN_SEED = getenv("EIGEN_SEED");
|
||||
if(!g_has_set_seed && env_EIGEN_SEED)
|
||||
set_seed_from_string(env_EIGEN_SEED);
|
||||
|
||||
std::cout << "Initializing random number generator with seed " << seed << std::endl;
|
||||
srand(seed);
|
||||
std::cout << "Repeating each test " << repeat << " times" << std::endl;
|
||||
if(!g_has_set_seed) g_seed = (unsigned int) time(NULL);
|
||||
if(!g_has_set_repeat) g_repeat = DEFAULT_REPEAT;
|
||||
|
||||
std::cout << "Initializing random number generator with seed " << g_seed << std::endl;
|
||||
srand(g_seed);
|
||||
std::cout << "Repeating each test " << g_repeat << " times" << std::endl;
|
||||
|
||||
Eigen::g_repeat = repeat;
|
||||
Eigen::g_test_stack.push_back(EI_PP_MAKE_STRING(EIGEN_TEST_FUNC));
|
||||
|
||||
EIGEN_CAT(test_,EIGEN_TEST_FUNC)();
|
||||
|
@ -9,7 +9,7 @@ magenta='\E[35m'
|
||||
cyan='\E[36m'
|
||||
white='\E[37m'
|
||||
|
||||
if ! ./test_$1 > /dev/null 2> .runtest.log ; then
|
||||
if ! ./$1 > /dev/null 2> .runtest.log ; then
|
||||
echo -e $red Test $1 failed: $black
|
||||
echo -e $blue
|
||||
cat .runtest.log
|
||||
|
@ -4,14 +4,14 @@ ADD_CUSTOM_TARGET(unsupported_examples)
|
||||
|
||||
FOREACH(example_src ${examples_SRCS})
|
||||
GET_FILENAME_COMPONENT(example ${example_src} NAME_WE)
|
||||
ADD_EXECUTABLE(${example} ${example_src})
|
||||
ADD_EXECUTABLE(example_${example} ${example_src})
|
||||
GET_TARGET_PROPERTY(example_executable
|
||||
${example} LOCATION)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET ${example}
|
||||
TARGET example_${example}
|
||||
POST_BUILD
|
||||
COMMAND ${example_executable}
|
||||
ARGS >${CMAKE_CURRENT_BINARY_DIR}/${example}.out
|
||||
)
|
||||
ADD_DEPENDENCIES(unsupported_examples ${example})
|
||||
ADD_DEPENDENCIES(unsupported_examples example_${example})
|
||||
ENDFOREACH(example_src)
|
||||
|
Loading…
x
Reference in New Issue
Block a user