Compare commits

...

2 commits

Author SHA1 Message Date
c18765e44a Merge branch 'master' into cxx17
All checks were successful
Run UnitTests / build-and-run-unittests (push) Successful in 31s
2024-07-15 13:47:06 +09:00
38ee7c532f UnitTests: make counters atomic
All checks were successful
Run UnitTests / build-and-run-unittests (push) Successful in 13s
Publish doxygen documentation to seodisparate.com / doxygen-gen-and-publish (push) Successful in 1s
2024-07-15 13:46:35 +09:00
2 changed files with 30 additions and 29 deletions

View file

@ -1,7 +1,7 @@
#include "test_helpers.h" #include "test_helpers.h"
int checks_checked = 0; std::atomic_int64_t checks_checked = std::atomic_int64_t(0);
int checks_passed = 0; std::atomic_int64_t checks_passed = std::atomic_int64_t(0);
int main() { int main() {
TEST_EC_Bitset(); TEST_EC_Bitset();
@ -37,8 +37,8 @@ int main() {
TEST_ECThreadPool_QueryCount(); TEST_ECThreadPool_QueryCount();
TEST_ECThreadPool_easyStartAndWait(); TEST_ECThreadPool_easyStartAndWait();
std::cout << "checks_checked: " << checks_checked << '\n' std::cout << "checks_checked: " << checks_checked.load() << '\n'
<< "checks_passed: " << checks_passed << std::endl; << "checks_passed: " << checks_passed.load() << std::endl;
return checks_checked == checks_passed ? 0 : 1; return checks_checked.load() == checks_passed.load() ? 0 : 1;
} }

View file

@ -3,60 +3,61 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <atomic>
extern int checks_checked; extern std::atomic_int64_t checks_checked;
extern int checks_passed; extern std::atomic_int64_t checks_passed;
// Macros for unit testing. // Macros for unit testing.
#define CHECK_TRUE(x) \ #define CHECK_TRUE(x) \
do { \ do { \
++checks_checked; \ checks_checked.fetch_add(1); \
if (!(x)) { \ if (!(x)) { \
std::cout << "CHECK_TRUE at line " << __LINE__ << " failed: " << #x \ std::cout << "CHECK_TRUE at line " << __LINE__ << " failed: " << #x \
<< '\n'; \ << '\n'; \
} else { \ } else { \
++checks_passed; \ checks_passed.fetch_add(1); \
} \ } \
} while (false); } while (false);
#define ASSERT_TRUE(x) \ #define ASSERT_TRUE(x) \
do { \ do { \
++checks_checked; \ checks_checked.fetch_add(1); \
if (!(x)) { \ if (!(x)) { \
std::cout << "CHECK_TRUE at line " << __LINE__ << " failed: " << #x \ std::cout << "CHECK_TRUE at line " << __LINE__ << " failed: " << #x \
<< '\n'; \ << '\n'; \
return; \ return; \
} else { \ } else { \
++checks_passed; \ checks_passed.fetch_add(1); \
} \ } \
} while (false); } while (false);
#define CHECK_FALSE(x) \ #define CHECK_FALSE(x) \
do { \ do { \
++checks_checked; \ checks_checked.fetch_add(1); \
if (x) { \ if (x) { \
std::cout << "CHECK_FALSE at line " << __LINE__ << " failed: " << #x \ std::cout << "CHECK_FALSE at line " << __LINE__ << " failed: " << #x \
<< '\n'; \ << '\n'; \
} else { \ } else { \
++checks_passed; \ checks_passed.fetch_add(1); \
} \ } \
} while (false); } while (false);
#define ASSERT_FALSE(x) \ #define ASSERT_FALSE(x) \
do { \ do { \
++checks_checked; \ checks_checked.fetch_add(1); \
if (x) { \ if (x) { \
std::cout << "CHECK_FALSE at line " << __LINE__ << " failed: " << #x \ std::cout << "CHECK_FALSE at line " << __LINE__ << " failed: " << #x \
<< '\n'; \ << '\n'; \
return; \ return; \
} else { \ } else { \
++checks_passed; \ checks_passed.fetch_add(1); \
} \ } \
} while (false); } while (false);
#define CHECK_FLOAT(var, value) \ #define CHECK_FLOAT(var, value) \
do { \ do { \
++checks_checked; \ checks_checked.fetch_add(1); \
if ((var) > (value) - 0.0001F && (var) < (value) + 0.0001F) { \ if ((var) > (value) - 0.0001F && (var) < (value) + 0.0001F) { \
++checks_passed; \ checks_passed.fetch_add(1); \
} else { \ } else { \
std::cout << "CHECK_FLOAT at line " << __LINE__ << " failed: " << #var \ std::cout << "CHECK_FLOAT at line " << __LINE__ << " failed: " << #var \
<< " != " << #value << '\n'; \ << " != " << #value << '\n'; \
@ -65,9 +66,9 @@ extern int checks_passed;
#define CHECK_EQ(var, value) \ #define CHECK_EQ(var, value) \
do { \ do { \
++checks_checked; \ checks_checked.fetch_add(1); \
if ((var) == (value)) { \ if ((var) == (value)) { \
++checks_passed; \ checks_passed.fetch_add(1); \
} else { \ } else { \
std::cout << "CHECK_EQ at line " << __LINE__ << " failed: " << #var \ std::cout << "CHECK_EQ at line " << __LINE__ << " failed: " << #var \
<< " != " << #value << '\n'; \ << " != " << #value << '\n'; \
@ -75,9 +76,9 @@ extern int checks_passed;
} while (false); } while (false);
#define ASSERT_EQ(var, value) \ #define ASSERT_EQ(var, value) \
do { \ do { \
++checks_checked; \ checks_checked.fetch_add(1); \
if ((var) == (value)) { \ if ((var) == (value)) { \
++checks_passed; \ checks_passed.fetch_add(1); \
} else { \ } else { \
std::cout << "ASSERT_EQ at line " << __LINE__ << " failed: " << #var \ std::cout << "ASSERT_EQ at line " << __LINE__ << " failed: " << #var \
<< " != " << #value << '\n'; \ << " != " << #value << '\n'; \
@ -86,9 +87,9 @@ extern int checks_passed;
} while (false); } while (false);
#define CHECK_NE(var, value) \ #define CHECK_NE(var, value) \
do { \ do { \
++checks_checked; \ checks_checked.fetch_add(1); \
if ((var) != (value)) { \ if ((var) != (value)) { \
++checks_passed; \ checks_passed.fetch_add(1); \
} else { \ } else { \
std::cout << "CHECK_NE at line " << __LINE__ << " failed: " << #var \ std::cout << "CHECK_NE at line " << __LINE__ << " failed: " << #var \
<< " == " << #value << '\n'; \ << " == " << #value << '\n'; \
@ -96,9 +97,9 @@ extern int checks_passed;
} while (false); } while (false);
#define CHECK_GE(var, value) \ #define CHECK_GE(var, value) \
do { \ do { \
++checks_checked; \ checks_checked.fetch_add(1); \
if ((var) >= (value)) { \ if ((var) >= (value)) { \
++checks_passed; \ checks_passed.fetch_add(1); \
} else { \ } else { \
std::cout << "CHECK_GE at line " << __LINE__ << " failed: " << #var \ std::cout << "CHECK_GE at line " << __LINE__ << " failed: " << #var \
<< " < " << #value << '\n'; \ << " < " << #value << '\n'; \
@ -106,9 +107,9 @@ extern int checks_passed;
} while (false); } while (false);
#define CHECK_LE(var, value) \ #define CHECK_LE(var, value) \
do { \ do { \
++checks_checked; \ checks_checked.fetch_add(1); \
if ((var) <= (value)) { \ if ((var) <= (value)) { \
++checks_passed; \ checks_passed.fetch_add(1); \
} else { \ } else { \
std::cout << "CHECK_LE at line " << __LINE__ << " failed: " << #var \ std::cout << "CHECK_LE at line " << __LINE__ << " failed: " << #var \
<< " > " << #value << '\n'; \ << " > " << #value << '\n'; \
@ -117,9 +118,9 @@ extern int checks_passed;
#define CHECK_STREQ(str_a, str_b) \ #define CHECK_STREQ(str_a, str_b) \
do { \ do { \
++checks_checked; \ checks_checked.fetch_add(1); \
if (std::strcmp((str_a), (str_b)) == 0) { \ if (std::strcmp((str_a), (str_b)) == 0) { \
++checks_passed; \ checks_passed.fetch_add(1); \
} else { \ } else { \
std::cout << "CHECK_STREQ at line " << __LINE__ << "failed: " << #str_a \ std::cout << "CHECK_STREQ at line " << __LINE__ << "failed: " << #str_a \
<< " != " << #str_b << '\n'; \ << " != " << #str_b << '\n'; \