35 #define CATCH_CONFIG_MAIN
36 #include <catch2/catch_amalgamated.hpp>
65 constexpr
int number(
const Defaults rhs) noexcept {
66 return static_cast<int>(rhs);
70 int array[array_size] = { 0 };
73 void reset(
int v1,
int array_value) {
74 int _sync_value = sync_value;
77 for(
int i=0; i<array_size; i++) {
78 array[i] = array_value;
83 void putThreadType01(
int _len,
int startValue) {
84 const int len = std::min(
number(array_size), _len);
86 int _sync_value = sync_value;
87 _sync_value = startValue;
88 for(
int i=0; i<len; i++) {
89 array[i] = _sync_value+i;
92 sync_value = _sync_value;
95 void getThreadType01(
const std::string msg,
int _len,
int startValue) {
96 const int len = std::min(
number(array_size), _len);
99 while( startValue != ( _sync_value = sync_value ) ) ;
100 REQUIRE_MSG(msg+
": %s: value at read value1 (sync)", _sync_value == value1);
101 REQUIRE_MSG(msg+
": %s: value at read value1 (start)", startValue == value1);
103 for(
int i=0; i<len; i++) {
108 sync_value = _sync_value;
111 void putThreadType11(
int indexAndValue) {
112 const int idx = std::min(
number(array_size)-1, indexAndValue);
120 _sync_value = sync_value;
121 }
while( idx != (_sync_value * -1) - 1 );
126 sync_value = _sync_value;
129 void getThreadType11(
const std::string msg,
int _idx) {
130 const int idx = std::min(
number(array_size)-1, _idx);
138 _sync_value = sync_value;
139 }
while( idx != _sync_value );
144 _sync_value = (idx+1)%array_size;
145 _sync_value = ( _sync_value + 1 ) * -1;
147 value1 = _sync_value;
148 sync_value = _sync_value;
155 : value1(0), sync_value(0) {}
158 INFO_STR(
"\n\ntest01_Read1Write1.a\n");
161 std::thread getThread01(&TestMemModelSCDRF00::getThreadType01,
this,
"test01.get01", array_size, 3);
162 std::thread putThread01(&TestMemModelSCDRF00::putThreadType01,
this, array_size, 3);
168 INFO_STR(
"\n\ntest01_Read2Write1.a\n");
171 std::thread getThread00(&TestMemModelSCDRF00::getThreadType01,
this,
"test01.get00", array_size, 4);
172 std::thread getThread01(&TestMemModelSCDRF00::getThreadType01,
this,
"test01.get01", array_size, 4);
173 std::thread putThread01(&TestMemModelSCDRF00::putThreadType01,
this, array_size, 4);
179 INFO_STR(
"\n\ntest01_Read2Write1.b\n");
182 std::thread putThread01(&TestMemModelSCDRF00::putThreadType01,
this, array_size, 5);
183 std::thread getThread00(&TestMemModelSCDRF00::getThreadType01,
this,
"test01.get00", array_size, 5);
184 std::thread getThread01(&TestMemModelSCDRF00::getThreadType01,
this,
"test01.get01", array_size, 5);
192 INFO_STR(
"\n\ntest02_Read4Write1\n");
195 std::thread getThread01(&TestMemModelSCDRF00::getThreadType01,
this,
"test02.get01", array_size, 6);
196 std::thread getThread02(&TestMemModelSCDRF00::getThreadType01,
this,
"test02.get02", array_size, 6);
197 std::thread putThread01(&TestMemModelSCDRF00::putThreadType01,
this, array_size, 6);
198 std::thread getThread03(&TestMemModelSCDRF00::getThreadType01,
this,
"test02.get03", array_size, 6);
199 std::thread getThread04(&TestMemModelSCDRF00::getThreadType01,
this,
"test02.get04", array_size, 6);
208 INFO_STR(
"\n\ntest11_Read10Write10\n");
211 std::thread reader[array_size];
212 std::thread writer[array_size];
213 for(
int i=0; i<
number(array_size); i++) {
214 reader[i] = std::thread(&TestMemModelSCDRF00::getThreadType11,
this,
"test11.get11", i);
216 for(
int i=0; i<
number(array_size); i++) {
217 writer[i] = std::thread(&TestMemModelSCDRF00::putThreadType11,
this, i);
219 for(
int i=0; i<
number(array_size); i++) {
222 for(
int i=0; i<
number(array_size); i++) {
228 INFO_STR(
"\n\ntest12_Read10Write10\n");
231 std::thread reader[array_size];
232 std::thread writer[array_size];
233 for(
int i=0; i<
number(array_size); i++) {
234 writer[i] = std::thread(&TestMemModelSCDRF00::putThreadType11,
this, i);
236 for(
int i=0; i<
number(array_size); i++) {
237 reader[i] = std::thread(&TestMemModelSCDRF00::getThreadType11,
this,
"test12.get11", i);
239 for(
int i=0; i<
number(array_size); i++) {
242 for(
int i=0; i<
number(array_size); i++) {
248 for(
int i=
loops; i>0; i--) { test01_Read1Write1(); }
249 for(
int i=
loops; i>0; i--) { test02_Read2Write1(); }
250 for(
int i=
loops; i>0; i--) { test03_Read4Write1(); }
251 for(
int i=
loops; i>0; i--) { test11_Read10Write10(); }
252 for(
int i=
loops; i>0; i--) { test12_Read10Write10(); }