tests: InterThread: adapt to have reproducible output and enable autotest

Change-Id: I05d4067890b526bd72d2eb31cf76de43ee11e80f
changes/07/5707/2
Pau Espin 5 years ago
parent 2ac788b2c3
commit 93d9b114b7
  1. 32
      tests/CommonLibs/InterthreadTest.cpp
  2. 82
      tests/CommonLibs/InterthreadTest.ok
  3. 10
      tests/testsuite.at

@ -35,14 +35,20 @@ using namespace std;
InterthreadQueue<int> gQ;
InterthreadMap<int,int> gMap;
int q_last_read_val = -1;
int q_last_write_val;
int m_last_read_val;
int m_last_write_val;
void* qWriter(void*)
{
int *p;
for (int i=0; i<20; i++) {
p = new int;
*p = i;
COUT("queue write " << *p);
CERR("queue write " << *p);
gQ.write(p);
q_last_write_val = i;
if (random()%2) sleep(1);
}
p = new int;
@ -56,8 +62,14 @@ void* qReader(void*)
bool done = false;
while (!done) {
int *p = gQ.read();
COUT("queue read " << *p);
if (*p<0) done=true;
CERR("queue read " << *p);
if (*p<0) {
assert(q_last_read_val == 19 && *p == -1);
done = true;
} else {
assert(q_last_read_val == *p - 1);
q_last_read_val = *p;
}
delete p;
}
return NULL;
@ -70,8 +82,9 @@ void* mapWriter(void*)
for (int i=0; i<20; i++) {
p = new int;
*p = i;
COUT("map write " << *p);
CERR("map write " << *p);
gMap.write(i,p);
m_last_write_val = i;
if (random()%2) sleep(1);
}
return NULL;
@ -81,7 +94,9 @@ void* mapReader(void*)
{
for (int i=0; i<20; i++) {
int *p = gMap.read(i);
COUT("map read " << *p);
CERR("map read " << *p);
assert(*p == i);
m_last_read_val = *p;
// InterthreadMap will delete the pointers
// delete p;
}
@ -109,6 +124,13 @@ int main(int argc, char *argv[])
qWriterThread.join();
mapReaderThread.join();
mapWriterThread.join();
assert(q_last_write_val == 19);
assert(q_last_read_val == 19);
assert(m_last_write_val == 19);
assert(m_last_read_val == 19);
printf("Done\n");
}

@ -1,81 +1 @@
1515515500.150033 140715424245504: queue write 0
1515515500.150105 140715423979264: map write 0
1515515500.150132 140715423979264: map write 1
1515515500.150143 140715424777984: queue read 0
1515515500.150175 140715424511744: map read 0
1515515500.150194 140715424511744: map read 1
1515515501.150203 140715424245504: queue write 1
1515515501.150288 140715423979264: map write 2
1515515501.150334 140715424777984: queue read 1
1515515501.150366 140715424511744: map read 2
1515515502.150405 140715424245504: queue write 2
1515515502.150488 140715423979264: map write 3
1515515502.150533 140715424777984: queue read 2
1515515502.150612 140715423979264: map write 4
1515515502.150642 140715423979264: map write 5
1515515502.150662 140715424511744: map read 3
1515515502.150680 140715424511744: map read 4
1515515502.150686 140715424511744: map read 5
1515515503.150607 140715424245504: queue write 3
1515515503.150709 140715424777984: queue read 3
1515515503.150741 140715423979264: map write 6
1515515503.150760 140715423979264: map write 7
1515515503.150776 140715424511744: map read 6
1515515503.150788 140715424511744: map read 7
1515515504.150770 140715424245504: queue write 4
1515515504.150839 140715424245504: queue write 5
1515515504.150857 140715423979264: map write 8
1515515504.150876 140715424777984: queue read 4
1515515504.150904 140715424777984: queue read 5
1515515504.150919 140715424511744: map read 8
1515515505.150990 140715424245504: queue write 6
1515515505.151066 140715423979264: map write 9
1515515505.151095 140715424245504: queue write 7
1515515505.151127 140715424245504: queue write 8
1515515505.151143 140715424245504: queue write 9
1515515505.151163 140715424245504: queue write 10
1515515505.151179 140715424777984: queue read 6
1515515505.151210 140715424777984: queue read 7
1515515505.151217 140715424777984: queue read 8
1515515505.151221 140715424777984: queue read 9
1515515505.151226 140715424777984: queue read 10
1515515505.151249 140715423979264: map write 10
1515515505.151277 140715424511744: map read 9
1515515505.151291 140715424511744: map read 10
1515515505.151298 140715423979264: map write 11
1515515505.151317 140715424511744: map read 11
1515515506.151303 140715424245504: queue write 11
1515515506.151386 140715423979264: map write 12
1515515506.151414 140715424777984: queue read 11
1515515506.151457 140715424511744: map read 12
1515515506.151528 140715423979264: map write 13
1515515506.151567 140715423979264: map write 14
1515515506.151577 140715423979264: map write 15
1515515506.151601 140715424511744: map read 13
1515515506.151621 140715424511744: map read 14
1515515506.151628 140715424511744: map read 15
1515515507.151498 140715424245504: queue write 12
1515515507.151606 140715424777984: queue read 12
1515515507.151654 140715423979264: map write 16
1515515507.151711 140715424511744: map read 16
1515515508.151707 140715424245504: queue write 13
1515515508.151778 140715423979264: map write 17
1515515508.151816 140715423979264: map write 18
1515515508.151830 140715424511744: map read 17
1515515508.151870 140715424511744: map read 18
1515515508.151904 140715423979264: map write 19
1515515508.151963 140715424777984: queue read 13
1515515508.151997 140715424511744: map read 19
1515515509.151920 140715424245504: queue write 14
1515515509.152023 140715424777984: queue read 14
1515515510.152109 140715424245504: queue write 15
1515515510.152218 140715424777984: queue read 15
1515515511.152258 140715424245504: queue write 16
1515515511.152380 140715424777984: queue read 16
1515515512.152409 140715424245504: queue write 17
1515515512.152449 140715424245504: queue write 18
1515515512.152458 140715424777984: queue read 17
1515515512.152477 140715424777984: queue read 18
1515515513.152574 140715424245504: queue write 19
1515515513.152674 140715424777984: queue read 19
1515515513.152708 140715424777984: queue read -1
Done

@ -7,11 +7,11 @@ cat $abs_srcdir/CommonLibs/BitVectorTest.ok > expout
AT_CHECK([$abs_top_builddir/tests/CommonLibs/BitVectorTest], [], [expout], [])
AT_CLEANUP
#AT_SETUP([InterthreadTest])
#AT_KEYWORDS([InterthreadTest])
#cat $abs_srcdir/CommonLibs/InterthreadTest.ok > expout
#AT_CHECK([$abs_top_builddir/tests/CommonLibs/InterthreadTest], [], [expout], [])
#AT_CLEANUP
AT_SETUP([InterthreadTest])
AT_KEYWORDS([InterthreadTest])
cat $abs_srcdir/CommonLibs/InterthreadTest.ok > expout
AT_CHECK([$abs_top_builddir/tests/CommonLibs/InterthreadTest], [], [expout], [ignore])
AT_CLEANUP
#AT_SETUP([LogTest])
#AT_KEYWORDS([LogTest])

Loading…
Cancel
Save