aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_mm_sc_drf_01.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-12-21 11:12:05 +0100
committerSven Gothel <[email protected]>2020-12-21 11:12:05 +0100
commita65ef73681248d14a7ec3727f349f758388d07c6 (patch)
tree3634abefe3f35dc6c5d4eb90311d2aa14a8c38e5 /test/test_mm_sc_drf_01.cpp
parent4f1583d727cfcafa087a9e98aad99ae56e481fa1 (diff)
Replace cppunit.h with Catch2 (v3-devel): Supporting CI integration, more versatile functionality (benchmarking, ..)
Diffstat (limited to 'test/test_mm_sc_drf_01.cpp')
-rw-r--r--test/test_mm_sc_drf_01.cpp84
1 files changed, 37 insertions, 47 deletions
diff --git a/test/test_mm_sc_drf_01.cpp b/test/test_mm_sc_drf_01.cpp
index 1622591..e8fe6c0 100644
--- a/test/test_mm_sc_drf_01.cpp
+++ b/test/test_mm_sc_drf_01.cpp
@@ -11,7 +11,9 @@
#include <thread>
#include <pthread.h>
-#include <cppunit.h>
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch_amalgamated.hpp>
+#include <jau/test/catch2_ext.hpp>
#include <jau/ordered_atomic.hpp>
@@ -29,7 +31,7 @@ static int loops = 10;
* </p>
* See 'test_mm_sc_drf_00' implementing same test using an atomic acquire/release critical block with spin-lock.
*/
-class Cppunit_tests : public Cppunit {
+class TestMemModelSCDRF01 {
private:
enum Defaults : int {
array_size = 10
@@ -70,11 +72,11 @@ class Cppunit_tests : public Cppunit {
while( startValue != value1 ) {
cvRead.wait(lock);
}
- CHECKM(msg+": %s: Wrong value at read value1 (start)", startValue, value1);
+ REQUIRE_MSG(msg+": %s: value at read value1 (start)", startValue == value1);
for(int i=0; i<len; i++) {
int v = array[i];
- CHECKM(msg+": %s: Wrong start value at read array #"+std::to_string(i), (startValue+i), v);
+ REQUIRE_MSG(msg+": %s: start value at read array #"+std::to_string(i), (startValue+i) == v);
}
}
@@ -89,7 +91,7 @@ class Cppunit_tests : public Cppunit {
while( idx != (value1 * -1) - 1 ) {
cvWrite.wait(lock);
}
- // fprintf(stderr, "putThreadType11.done @ %d (has %d, exp %d)\n", idx, value1, (idx+1)*-1);
+ // INFO_STR("putThreadType11.done @ %d (has %d, exp %d)\n", idx, value1, (idx+1)*-1);
value1 = idx;
array[idx] = idx; // last written checked first, SC-DRF should handle...
cvRead.notify_all();
@@ -104,15 +106,15 @@ class Cppunit_tests : public Cppunit {
// SC-DRF acquire atomic with spin-lock waiting for idx
std::unique_lock<std::mutex> lock(mtx_value);
while( idx != value1 ) {
- // fprintf(stderr, "getThreadType11.wait for has %d == exp %d\n", value1, idx);
+ // INFO_STR("getThreadType11.wait for has %d == exp %d\n", value1, idx);
cvRead.wait(lock);
}
- CHECKM(msg+": %s: Wrong value at read array (idx), idx "+std::to_string(idx), idx, array[idx]); // check last-written first
- CHECKM(msg+": %s: Wrong value at read value1 (idx), idx "+std::to_string(idx), idx, value1);
+ REQUIRE_MSG(msg+": %s: value at read array (idx), idx "+std::to_string(idx), idx == array[idx]); // check last-written first
+ REQUIRE_MSG(msg+": %s: value at read value1 (idx), idx "+std::to_string(idx), idx == value1);
// next write encoded idx
int next_idx = (idx+1)%array_size;
next_idx = ( next_idx + 1 ) * -1;
- // fprintf(stderr, "getThreadType11.done for %d, next %d (v %d)\n", idx, (idx+1)%array_size, next_idx);
+ // INFO_STR("getThreadType11.done for %d, next %d (v %d)\n", idx, (idx+1)%array_size, next_idx);
value1 = next_idx;
cvWrite.notify_all();
}
@@ -120,37 +122,37 @@ class Cppunit_tests : public Cppunit {
public:
- Cppunit_tests()
+ TestMemModelSCDRF01()
: value1(0) {}
void test01_Read1Write1() {
- fprintf(stderr, "\n\ntest01_Read1Write1.a\n");
+ INFO_STR("\n\ntest01_Read1Write1.a\n");
reset(0, 1010);
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test01.get01", array_size, 3); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 3); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF01::getThreadType01, this, "test01.get01", array_size, 3); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF01::putThreadType01, this, array_size, 3); // @suppress("Invalid arguments")
putThread01.join();
getThread01.join();
}
void test02_Read2Write1() {
- fprintf(stderr, "\n\ntest01_Read2Write1.a\n");
+ INFO_STR("\n\ntest01_Read2Write1.a\n");
reset(0, 1021);
{
- std::thread getThread00(&Cppunit_tests::getThreadType01, this, "test01.get00", array_size, 4); // @suppress("Invalid arguments")
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test01.get01", array_size, 4); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 4); // @suppress("Invalid arguments")
+ std::thread getThread00(&TestMemModelSCDRF01::getThreadType01, this, "test01.get00", array_size, 4); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF01::getThreadType01, this, "test01.get01", array_size, 4); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF01::putThreadType01, this, array_size, 4); // @suppress("Invalid arguments")
putThread01.join();
getThread00.join();
getThread01.join();
}
- fprintf(stderr, "\n\ntest01_Read2Write1.b\n");
+ INFO_STR("\n\ntest01_Read2Write1.b\n");
reset(0, 1022);
{
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 5); // @suppress("Invalid arguments")
- std::thread getThread00(&Cppunit_tests::getThreadType01, this, "test01.get00", array_size, 5); // @suppress("Invalid arguments")
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test01.get01", array_size, 5); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF01::putThreadType01, this, array_size, 5); // @suppress("Invalid arguments")
+ std::thread getThread00(&TestMemModelSCDRF01::getThreadType01, this, "test01.get00", array_size, 5); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF01::getThreadType01, this, "test01.get01", array_size, 5); // @suppress("Invalid arguments")
putThread01.join();
getThread00.join();
getThread01.join();
@@ -158,14 +160,14 @@ class Cppunit_tests : public Cppunit {
}
void test03_Read4Write1() {
- fprintf(stderr, "\n\ntest02_Read4Write1\n");
+ INFO_STR("\n\ntest02_Read4Write1\n");
reset(0, 1030);
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test02.get01", array_size, 6); // @suppress("Invalid arguments")
- std::thread getThread02(&Cppunit_tests::getThreadType01, this, "test02.get02", array_size, 6); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 6); // @suppress("Invalid arguments")
- std::thread getThread03(&Cppunit_tests::getThreadType01, this, "test02.get03", array_size, 6); // @suppress("Invalid arguments")
- std::thread getThread04(&Cppunit_tests::getThreadType01, this, "test02.get04", array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF01::getThreadType01, this, "test02.get01", array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread02(&TestMemModelSCDRF01::getThreadType01, this, "test02.get02", array_size, 6); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF01::putThreadType01, this, array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread03(&TestMemModelSCDRF01::getThreadType01, this, "test02.get03", array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread04(&TestMemModelSCDRF01::getThreadType01, this, "test02.get04", array_size, 6); // @suppress("Invalid arguments")
putThread01.join();
getThread01.join();
getThread02.join();
@@ -174,16 +176,16 @@ class Cppunit_tests : public Cppunit {
}
void test11_Read10Write10() {
- fprintf(stderr, "\n\ntest11_Read10Write10\n");
+ INFO_STR("\n\ntest11_Read10Write10\n");
reset(-1, 1110);
std::thread reader[array_size];
std::thread writer[array_size];
for(int i=0; i<number(array_size); i++) {
- reader[i] = std::thread(&Cppunit_tests::getThreadType11, this, "test11.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ reader[i] = std::thread(&TestMemModelSCDRF01::getThreadType11, this, "test11.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
- writer[i] = std::thread(&Cppunit_tests::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ writer[i] = std::thread(&TestMemModelSCDRF01::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
writer[i].join();
@@ -194,16 +196,16 @@ class Cppunit_tests : public Cppunit {
}
void test12_Read10Write10() {
- fprintf(stderr, "\n\ntest12_Read10Write10\n");
+ INFO_STR("\n\ntest12_Read10Write10\n");
reset(-1, 1120);
std::thread reader[array_size];
std::thread writer[array_size];
for(int i=0; i<number(array_size); i++) {
- writer[i] = std::thread(&Cppunit_tests::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ writer[i] = std::thread(&TestMemModelSCDRF01::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
- reader[i] = std::thread(&Cppunit_tests::getThreadType11, this, "test12.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ reader[i] = std::thread(&TestMemModelSCDRF01::getThreadType11, this, "test12.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
writer[i].join();
@@ -213,7 +215,7 @@ class Cppunit_tests : public Cppunit {
}
}
- void test_list() override {
+ void test_list() {
for(int i=loops; i>0; i--) { test01_Read1Write1(); }
for(int i=loops; i>0; i--) { test02_Read2Write1(); }
for(int i=loops; i>0; i--) { test03_Read4Write1(); }
@@ -222,16 +224,4 @@ class Cppunit_tests : public Cppunit {
}
};
-int main(int argc, char *argv[]) {
- for(int i=1; i<argc; i++) {
- std::string arg(argv[i]);
- if( "-loops" == arg && argc > i+1 ) {
- loops = atoi(argv[i+1]);
- }
- }
- fprintf(stderr, "Loops %d\n", loops);
-
- Cppunit_tests test1;
- return test1.run();
-}
-
+METHOD_AS_TEST_CASE( TestMemModelSCDRF01::test_list, "Test TestMemModelSCDRF 01- test_list");