Get rid of EIGEN_TEST_FUNC, unit tests must now be declared with EIGEN_DECLARE_TEST(mytest) { /* code */ }.

This provide several advantages:
- more flexibility in designing unit tests
- unit tests can be glued to speed up compilation
- unit tests are compiled with same predefined macros, which is a requirement for zapcc
This commit is contained in:
Gael Guennebaud
2018-07-17 14:46:15 +02:00
parent 37f4bdd97d
commit 82f0ce2726
255 changed files with 325 additions and 303 deletions

View File

@@ -128,7 +128,6 @@ inline void on_temporary_creation(long int size) {
#endif
// the following file is automatically generated by cmake
#include "split_test_helper.h"
#ifdef NDEBUG
@@ -145,10 +144,6 @@ inline void on_temporary_creation(long int size) {
#define EIGEN_MAKING_DOCS
#endif
#ifndef EIGEN_TEST_FUNC
#error EIGEN_TEST_FUNC must be defined
#endif
#define DEFAULT_REPEAT 10
namespace Eigen
@@ -157,17 +152,45 @@ namespace Eigen
// level == 0 <=> abort if test fail
// level >= 1 <=> warning message to std::cerr if test fail
static int g_test_level = 0;
static int g_repeat;
static unsigned int g_seed;
static bool g_has_set_repeat, g_has_set_seed;
static int g_repeat = 1;
static unsigned int g_seed = 0;
static bool g_has_set_repeat = false, g_has_set_seed = false;
class EigenTest
{
public:
EigenTest() : m_func(0) {}
EigenTest(const char* a_name, void (*func)(void))
: m_name(a_name), m_func(func)
{
ms_registered_tests.push_back(this);
}
const std::string& name() const { return m_name; }
void operator()() const { m_func(); }
static const std::vector<EigenTest*>& all() { return ms_registered_tests; }
protected:
std::string m_name;
void (*m_func)(void);
static std::vector<EigenTest*> ms_registered_tests;
};
std::vector<EigenTest*> EigenTest::ms_registered_tests;
// Declare and register a test, e.g.:
// EIGEN_DECLARE_TEST(mytest) { ... }
// will create a function:
// void test_mytest() { ... }
// that will be automatically called.
#define EIGEN_DECLARE_TEST(X) \
void EIGEN_CAT(test_,X) (); \
static EigenTest EIGEN_CAT(test_handler_,X) (EIGEN_MAKESTRING(X), & EIGEN_CAT(test_,X)); \
void EIGEN_CAT(test_,X) ()
}
#define TRACK std::cerr << __FILE__ << " " << __LINE__ << std::endl
// #define TRACK while()
#define EI_PP_MAKE_STRING2(S) #S
#define EI_PP_MAKE_STRING(S) EI_PP_MAKE_STRING2(S)
#define EIGEN_DEFAULT_IO_FORMAT IOFormat(4, 0, " ", "\n", "", "", "", "")
#if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(__CUDA_ARCH__) && !defined(__HIP_DEVICE_COMPILE__)
@@ -225,7 +248,7 @@ namespace Eigen
} \
else if (Eigen::internal::push_assert) \
{ \
eigen_assert_list.push_back(std::string(EI_PP_MAKE_STRING(__FILE__) " (" EI_PP_MAKE_STRING(__LINE__) ") : " #a) ); \
eigen_assert_list.push_back(std::string(EIGEN_MAKESTRING(__FILE__) " (" EIGEN_MAKESTRING(__LINE__) ") : " #a) ); \
}
#ifdef EIGEN_EXCEPTIONS
@@ -338,10 +361,10 @@ inline void verify_impl(bool condition, const char *testname, const char *file,
}
}
#define VERIFY(a) ::verify_impl(a, g_test_stack.back().c_str(), __FILE__, __LINE__, EI_PP_MAKE_STRING(a))
#define VERIFY(a) ::verify_impl(a, g_test_stack.back().c_str(), __FILE__, __LINE__, EIGEN_MAKESTRING(a))
#define VERIFY_GE(a, b) ::verify_impl(a >= b, g_test_stack.back().c_str(), __FILE__, __LINE__, EI_PP_MAKE_STRING(a >= b))
#define VERIFY_LE(a, b) ::verify_impl(a <= b, g_test_stack.back().c_str(), __FILE__, __LINE__, EI_PP_MAKE_STRING(a <= b))
#define VERIFY_GE(a, b) ::verify_impl(a >= b, g_test_stack.back().c_str(), __FILE__, __LINE__, EIGEN_MAKESTRING(a >= b))
#define VERIFY_LE(a, b) ::verify_impl(a <= b, g_test_stack.back().c_str(), __FILE__, __LINE__, EIGEN_MAKESTRING(a <= b))
#define VERIFY_IS_EQUAL(a, b) VERIFY(test_is_equal(a, b, true))
@@ -358,7 +381,7 @@ inline void verify_impl(bool condition, const char *testname, const char *file,
#define STATIC_CHECK(COND) EIGEN_STATIC_ASSERT( (COND) , EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT )
#define CALL_SUBTEST(FUNC) do { \
g_test_stack.push_back(EI_PP_MAKE_STRING(FUNC)); \
g_test_stack.push_back(EIGEN_MAKESTRING(FUNC)); \
FUNC; \
g_test_stack.pop_back(); \
} while (0)
@@ -709,9 +732,6 @@ template<> std::string type_name<std::complex<double> >() { return "comple
template<> std::string type_name<std::complex<long double> >() { return "complex<long double>"; }
template<> std::string type_name<std::complex<int> >() { return "complex<int>"; }
// forward declaration of the main test function
void EIGEN_CAT(test_,EIGEN_TEST_FUNC)();
using namespace Eigen;
inline void set_repeat_from_string(const char *str)
@@ -798,9 +818,16 @@ int main(int argc, char *argv[])
srand(g_seed);
std::cout << "Repeating each test " << g_repeat << " times" << std::endl;
Eigen::g_test_stack.push_back(std::string(EI_PP_MAKE_STRING(EIGEN_TEST_FUNC)));
VERIFY(EigenTest::all().size()>0);
for(std::size_t i=0; i<EigenTest::all().size(); ++i)
{
const EigenTest& current_test = *EigenTest::all()[i];
Eigen::g_test_stack.push_back(current_test.name());
current_test();
Eigen::g_test_stack.pop_back();
}
EIGEN_CAT(test_,EIGEN_TEST_FUNC)();
return 0;
}