24 #error "include unittest.h before any Vc header"
27 #define VC_ASSERT(cond) unittest_assert(cond, #cond, __FILE__, __LINE__);
41 #define _expand(name) #name
42 #define runTest(name) _unit_test_global.runTestInt(&name, _expand(name))
43 #define testAllTypes(name) \
44 _unit_test_global.runTestInt(&name<float_v>, #name "<float_v>"); \
45 _unit_test_global.runTestInt(&name<short_v>, #name "<short_v>"); \
46 _unit_test_global.runTestInt(&name<sfloat_v>, #name "<sfloat_v>"); \
47 _unit_test_global.runTestInt(&name<ushort_v>, #name "<ushort_v>"); \
48 _unit_test_global.runTestInt(&name<int_v>, #name "<int_v>"); \
49 _unit_test_global.runTestInt(&name<double_v>, #name "<double_v>"); \
50 _unit_test_global.runTestInt(&name<uint_v>, #name "<uint_v>")
51 #define testRealTypes(name) \
52 _unit_test_global.runTestInt(&name<float_v>, #name "<float_v>"); \
53 _unit_test_global.runTestInt(&name<double_v>, #name "<double_v>"); \
54 _unit_test_global.runTestInt(&name<sfloat_v>, #name "<sfloat_v>");
58 operator bool()
const {
return false; }
63 operator bool()
const {
return true; }
68 std::cout << AnsiColor::green <<
" PASS: " << AnsiColor::normal;
75 std::cerr <<
"CPU or OS requirements not met for the compiled in vector unit!\n";
118 std::cout <<
"\n Testing done. " <<
passedTests <<
" tests passed. " <<
failedTests <<
" tests failed." << std::endl;
156 static const char *str = 0;
158 if (mayUseColor(std::cout)) {
159 static const char *fail =
" \033[1;40;31mFAIL:\033[0m ";
162 static const char *fail =
" FAIL: ";
171 for (
int i = 1; i < argc; ++i) {
172 if (0 == std::strcmp(argv[i],
"--help") || 0 == std::strcmp(argv[i],
"-h")) {
174 "Usage: " << argv[0] <<
" [-h|--help] [--only <testname>] [--maxdist] [--plotdist <plot.dat>]\n";
177 if (0 == std::strcmp(argv[i],
"--only") && i + 1 < argc) {
178 _unit_test_global.
only_name = argv[i + 1];
179 }
else if (0 == std::strcmp(argv[i],
"--maxdist")) {
181 }
else if (0 == std::strcmp(argv[i],
"--plotdist") && i + 1 < argc) {
183 _unit_test_global.
plotFile <<
"# reference\tdistance\n";
194 if (_unit_test_global.
only_name && 0 != std::strcmp(name, _unit_test_global.
only_name)) {
197 _unit_test_global.
status =
true;
209 if (!_unit_test_global.
status) {
210 std::cout <<
"XFAIL: " << name << std::endl;
212 std::cout <<
"unexpected PASS: " << name <<
213 "\n This test should have failed but didn't. Check the code!" << std::endl;
217 if (!_unit_test_global.
status) {
230 std::cout <<
" all values matched the reference precisely.";
233 std::cout << std::endl;
240 template<>
inline bool unittest_compareHelper<Vc::int_v, Vc::int_v>(
const Vc::int_v &
a,
const Vc::int_v &b ) {
return (a == b).isFull(); }
241 template<>
inline bool unittest_compareHelper<Vc::uint_v, Vc::uint_v>(
const Vc::uint_v &
a,
const Vc::uint_v &b ) {
return (a == b).isFull(); }
242 template<>
inline bool unittest_compareHelper<Vc::float_v, Vc::float_v>(
const Vc::float_v &
a,
const Vc::float_v &b ) {
return (a == b).isFull(); }
243 template<>
inline bool unittest_compareHelper<Vc::sfloat_v, Vc::sfloat_v>(
const Vc::sfloat_v &
a,
const Vc::sfloat_v &b ) {
return (a == b).isFull(); }
244 template<>
inline bool unittest_compareHelper<Vc::double_v, Vc::double_v>(
const Vc::double_v &
a,
const Vc::double_v &b ) {
return (a == b).isFull(); }
245 template<>
inline bool unittest_compareHelper<Vc::ushort_v, Vc::ushort_v>(
const Vc::ushort_v &
a,
const Vc::ushort_v &b ) {
return (a == b).isFull(); }
246 template<>
inline bool unittest_compareHelper<Vc::short_v, Vc::short_v>(
const Vc::short_v &
a,
const Vc::short_v &b ) {
return (a == b).isFull(); }
247 template<>
inline bool unittest_compareHelper<std::type_info, std::type_info>(
const std::type_info &
a,
const std::type_info &b ) {
return &a == &b; }
284 template<
typename T1,
typename T2,
typename M>
inline void unitttest_comparePrintHelper(
const T1 &a,
const T2 &b,
const M &
m,
const char *aa,
const char *bb,
const char *file,
int line,
double fuzzyness = 0.) {
285 std::cout <<
" " << aa <<
" (" << std::setprecision(10) << a << std::setprecision(6) <<
") == " << bb <<
" (" << std::setprecision(10) << b << std::setprecision(6) <<
") -> " <<
m;
286 if (fuzzyness > 0.) {
287 std::cout <<
" with fuzzyness " << fuzzyness;
289 std::cout <<
" at " << file <<
":" << line <<
" failed.\n";
304 template<
typename T1,
typename T2>
317 template<
typename T1,
typename T2>
342 if (_unit_test_global.
plotFile.is_open()) {
403 #if defined(__x86_64__) && defined(VC_GNU_ASM)
404 asm(
"lea 0(%%rip),%0" :
"=r"(_ip));
411 template<
typename T>
static void print(
const T &
x) { std::cout <<
x; }
412 static void print(
const std::type_info &
x) { std::cout << x.name(); }
413 static void print(
const char *str) {
415 if (0 != (pos = std::strchr(str,
'\n'))) {
419 char *left = strdup(str);
420 left[pos - str] =
'\0';
436 std::cout << (b ?
"true" :
"false");
439 std::cout << std::endl;
440 _unit_test_global.
status =
false;
446 std::cout <<
"at " << _file <<
':' << _line <<
" (0x" <<
std::hex <<
m_ip << std::dec <<
')';
451 print(
"\ndistance: ");
453 print(
", allowed distance: ");
486 file << std::setprecision(12) << ref[i] <<
"\t" << dist[i] <<
"\n";
493 file << std::setprecision(12) << ref[i] <<
"\t" << dist[i] <<
"\n";
500 file << std::setprecision(12) << ref[i] <<
"\t" << dist[i] <<
"\n";
506 #define FUZZY_COMPARE( a, b ) \
507 _UnitTest_Compare(a, b, #a, #b, __FILE__, __LINE__, _UnitTest_Compare::Fuzzy) << ' '
509 #define COMPARE( a, b ) \
510 _UnitTest_Compare(a, b, #a, #b, __FILE__, __LINE__) << ' '
512 #define COMPARE_NOEQ( a, b ) \
513 _UnitTest_Compare(a, b, #a, #b, __FILE__, __LINE__, _UnitTest_Compare::NoEq) << ' '
515 #define VERIFY(cond) \
516 _UnitTest_Compare(cond, #cond, __FILE__, __LINE__) << ' '
519 _UnitTest_Compare(__FILE__, __LINE__) << ' '
542 #define assert(cond) unittest_assert(cond, #cond, __FILE__, __LINE__)
544 #define EXPECT_ASSERT_FAILURE(code) \
545 _unit_test_global.expect_assert_failure = true; \
546 _unit_test_global.assert_failure = 0; \
548 if (_unit_test_global.assert_failure == 0) { \
550 std::cout << " " << #code << " at " << __FILE__ << ":" << __LINE__ << \
551 " did not fail as was expected.\n"; \
552 _unit_test_global.status = false; \
553 throw _UnitTest_Failure(); \
556 _unit_test_global.expect_assert_failure = false
558 template<
typename Vec>
inline typename Vec::Mask
allMasks(
int i)
560 typedef typename Vec::IndexType
I;
561 typedef typename Vec::Mask M;
575 for (
int b = a + 1; b <
Vec::Size; ++b) {
578 return M(indexes == a || indexes == b);
586 for (
int a = 0; a < Vec::Size - 1; ++
a) {
587 for (
int b = a + 1; b <
Vec::Size; ++b) {
591 return M(indexes == a || indexes == b || indexes ==
c);
600 for (
int a = 0; a < Vec::Size - 1; ++
a) {
601 for (
int b = a + 1; b <
Vec::Size; ++b) {
606 return M(indexes == a || indexes == b || indexes ==
c || indexes == d);
616 for (
int a = 0; a < Vec::Size - 1; ++
a) {
617 for (
int b = a + 1; b <
Vec::Size; ++b) {
620 for (
int e = d + 1; e <
Vec::Size; ++e) {
623 return M(indexes == a || indexes == b || indexes ==
c || indexes == d || indexes == e);
634 for (
int a = 0; a < Vec::Size - 1; ++
a) {
635 for (
int b = a + 1; b <
Vec::Size; ++b) {
638 for (
int e = d + 1; e <
Vec::Size; ++e) {
642 return M(indexes == a || indexes == b || indexes ==
c || indexes == d || indexes == e || indexes ==
f);
654 for (
int a = 0; a < Vec::Size - 1; ++
a) {
655 for (
int b = a + 1; b <
Vec::Size; ++b) {
658 for (
int e = d + 1; e <
Vec::Size; ++e) {
663 return M(indexes == a || indexes == b || indexes ==
c || indexes == d
664 || indexes == e || indexes ==
f || indexes ==
g);
677 #define for_all_masks(VecType, _mask_) \
678 for (int _Vc_for_all_masks_i = 0; _Vc_for_all_masks_i == 0; ++_Vc_for_all_masks_i) \
679 for (typename VecType::Mask _mask_ = allMasks<VecType>(_Vc_for_all_masks_i++); !_mask_.isEmpty(); _mask_ = allMasks<VecType>(_Vc_for_all_masks_i++))
double dist(Rotation3D const &r1, Rotation3D const &r2)
Vc_ALWAYS_INLINE _UnitTest_Compare(const T1 &a, const T2 &b, const char *_a, const char *_b, const char *_file, int _line, OptionNoEq)
const char * _unittest_fail()
VECTOR_NAMESPACE::uint_v uint_v
VECTOR_NAMESPACE::sfloat_v sfloat_v
Vc_ALWAYS_INLINE _UnitTest_Compare(const T1 &a, const T2 &b, const char *_a, const char *_b, const char *_file, int _line)
Vc_ALWAYS_INLINE _UnitTest_Compare(const T &a, const T &b, const char *_a, const char *_b, const char *_file, int _line, OptionFuzzy)
Vec::Mask allMasks(int i)
void initTest(int argc, char **argv)
void setFuzzyness< double >(double fuzz)
void unitttest_comparePrintHelper(const T1 &a, const T2 &b, const M &m, const char *aa, const char *bb, const char *file, int line, double fuzzyness=0.)
void unittest_assert(bool cond, const char *code, const char *file, int line)
double unittest_fuzzynessHelper< float >(const float &)
Vc_ALWAYS_INLINE ~_UnitTest_Compare()
bool unittest_fuzzyCompareHelper(const T &a, const T &b)
_UnitTest_Global_Object()
static Vc_ALWAYS_INLINE size_t getIp()
Vc_ALWAYS_INLINE const _UnitTest_Compare & operator<<(const T &x) const
ClassImp(TIterator) Bool_t TIterator return false
Compare two iterator objects.
bool unittest_fuzzyCompareHelper< double >(const double &a, const double &b)
VECTOR_NAMESPACE::short_v short_v
T ulpDiffToReferenceWrapper(T a, T b)
static void print(const T &x)
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
void setFuzzyness< float >(float fuzz)
static T ulpDiffToReferenceSigned(T val, T ref)
static Vc_ALWAYS_INLINE Vector< T > abs(const Vector< T > &x)
VECTOR_NAMESPACE::ushort_v ushort_v
ADD_PASS & operator<<(const T &x)
Vc_ALWAYS_INLINE const _UnitTest_Compare & operator<<(const char ch) const
bool expect_assert_failure
#define VC_ALIGNED_PARAMETER(_Type)
VECTOR_NAMESPACE::int_v int_v
#define VC_IS_UNLIKELY(x)
VECTOR_NAMESPACE::double_v double_v
double unittest_fuzzynessHelper(const T &)
double unittest_fuzzynessHelper< double >(const double &)
Vc_ALWAYS_INLINE _UnitTest_Compare(bool good, const char *cond, const char *_file, int _line)
~_UnitTest_Global_Object()
bool unittest_compareHelper(const T1 &a, const T2 &b)
void runTestInt(testFunction fun, const char *name)
void printPosition(const char *_file, int _line)
static void print(const char ch)
static void print(bool b)
static bool _UnitTest_verify_vector_unit_supported_result
VECTOR_NAMESPACE::float_v float_v
bool _UnitTest_verify_vector_unit_supported()
static _UnitTest_Global_Object _unit_test_global
typedef void((*Func_t)())
static void writePlotData(std::fstream &file, VC_ALIGNED_PARAMETER(T) a, VC_ALIGNED_PARAMETER(T) b)
static void printFuzzyInfoImpl(VC_ALIGNED_PARAMETER(T) a, VC_ALIGNED_PARAMETER(T) b, double fuzzyness)
static T ulpDiffToReference(T val, T ref)
bool unittest_fuzzyCompareHelper< float >(const float &a, const float &b)
static void printFuzzyInfo(VC_ALIGNED_PARAMETER(T) a, VC_ALIGNED_PARAMETER(T) b)
Vc_ALWAYS_INLINE const _UnitTest_Compare & operator<<(const char *str) const
static void print(const char *str)
Vc_ALWAYS_INLINE _UnitTest_Compare(const char *_file, int _line)
static void print(const std::type_info &x)
Vc_ALWAYS_INLINE const _UnitTest_Compare & operator<<(bool b) const
static VC_TARGET_NO_SIMD bool currentImplementationSupported()
Tests that the CPU and Operating System support the vector unit which was compiled for...