Set up GNU Autotest infrastructure

Test files are moved from CommonLibs/ to tests/CommonLibs/.
Some tests are disabled in autotest because they generate timedate
related output which cannot exactly match against expected output.

Change-Id: I3d6ba625968be09297642d18090c496490e9b8fc
This commit is contained in:
Pau Espin Pedrol
2018-01-09 17:44:49 +01:00
parent d36ef2f57b
commit 2ac788b2c3
22 changed files with 359 additions and 113 deletions

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2008 Free Software Foundation, Inc.
*
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "BitVector.h"
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
BitVector v5("000011110000");
int r1 = v5.peekField(0,8);
int r2 = v5.peekField(4,4);
int r3 = v5.peekField(4,8);
cout << r1 << ' ' << r2 << ' ' << r3 << endl;
cout << v5 << endl;
v5.fillField(0,0xa,4);
int r4 = v5.peekField(0,8);
cout << v5 << endl;
cout << r4 << endl;
v5.reverse8();
cout << v5 << endl;
unsigned char ts[9] = "abcdefgh";
BitVector tp(70);
cout << "ts=" << ts << endl;
tp.unpack(ts);
cout << "tp=" << tp << endl;
tp.pack(ts);
cout << "ts=" << ts << endl;
}

View File

@@ -0,0 +1,8 @@
15 15 240
000011110000
101011110000
175
111101010000
ts=abcdefgh
tp=0110000101100010011000110110010001100101011001100110011101101000000000
ts=abcdefgh

View File

@@ -0,0 +1,115 @@
/*
* Copyright 2008 Free Software Foundation, Inc.
*
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Threads.h"
#include "Interthread.h"
#include <iostream>
using namespace std;
InterthreadQueue<int> gQ;
InterthreadMap<int,int> gMap;
void* qWriter(void*)
{
int *p;
for (int i=0; i<20; i++) {
p = new int;
*p = i;
COUT("queue write " << *p);
gQ.write(p);
if (random()%2) sleep(1);
}
p = new int;
*p = -1;
gQ.write(p);
return NULL;
}
void* qReader(void*)
{
bool done = false;
while (!done) {
int *p = gQ.read();
COUT("queue read " << *p);
if (*p<0) done=true;
delete p;
}
return NULL;
}
void* mapWriter(void*)
{
int *p;
for (int i=0; i<20; i++) {
p = new int;
*p = i;
COUT("map write " << *p);
gMap.write(i,p);
if (random()%2) sleep(1);
}
return NULL;
}
void* mapReader(void*)
{
for (int i=0; i<20; i++) {
int *p = gMap.read(i);
COUT("map read " << *p);
// InterthreadMap will delete the pointers
// delete p;
}
return NULL;
}
int main(int argc, char *argv[])
{
Thread qReaderThread;
qReaderThread.start(qReader,NULL);
Thread mapReaderThread;
mapReaderThread.start(mapReader,NULL);
Thread qWriterThread;
qWriterThread.start(qWriter,NULL);
Thread mapWriterThread;
mapWriterThread.start(mapWriter,NULL);
qReaderThread.join();
qWriterThread.join();
mapReaderThread.join();
mapWriterThread.join();
}
// vim: ts=4 sw=4

View File

@@ -0,0 +1,81 @@
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

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2009 Free Software Foundation, Inc.
* Copyright 2010 Kestrel Signal Processing, Inc.
*
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <iterator>
#include "Logger.h"
void printAlarms()
{
std::ostream_iterator<std::string> output( std::cout, "\n" );
std::list<std::string> alarms = gGetLoggerAlarms();
std::cout << "# alarms = " << alarms.size() << std::endl;
std::copy( alarms.begin(), alarms.end(), output );
}
int main(int argc, char *argv[])
{
gLogInit("LogTest","NOTICE",LOG_LOCAL7);
LOG(EMERG) << " testing the logger.";
LOG(ALERT) << " testing the logger.";
LOG(CRIT) << " testing the logger.";
LOG(ERR) << " testing the logger.";
LOG(WARNING) << " testing the logger.";
LOG(NOTICE) << " testing the logger.";
LOG(INFO) << " testing the logger.";
LOG(DEBUG) << " testing the logger.";
std::cout << "\n\n\n";
std::cout << "testing Alarms\n";
std::cout << "you should see three lines:" << std::endl;
printAlarms();
std::cout << "----------- generating 20 alarms ----------" << std::endl;
for (int i = 0 ; i < 20 ; ++i) {
LOG(ALERT) << i;
}
std::cout << "you should see ten lines with the numbers 10..19:" << std::endl;
printAlarms();
}

View File

@@ -0,0 +1,24 @@
EMERG 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:44:main: testing the logger.
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:45:main: testing the logger.
CRIT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:46:main: testing the logger.
ERR 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:47:main: testing the logger.
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 0
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 1
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 2
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 3
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 4
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 5
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 6
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 7
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 8
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 9
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 10
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 11
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 12
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 13
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 14
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 15
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 16
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 17
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 18
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 19

View File

@@ -0,0 +1,59 @@
EMERG 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:44:main: testing the logger.
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:45:main: testing the logger.
CRIT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:46:main: testing the logger.
ERR 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:47:main: testing the logger.
WARNING 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:48:main: testing the logger.
NOTICE 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:49:main: testing the logger.
testing Alarms
you should see three lines:
# alarms = 4
EMERG 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:44:main: testing the logger.
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:45:main: testing the logger.
CRIT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:46:main: testing the logger.
ERR 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:47:main: testing the logger.
----------- generating 20 alarms ----------
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 0
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 1
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 2
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 3
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 4
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 5
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 6
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 7
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 8
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 9
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 10
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 11
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 12
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 13
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 14
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 15
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 16
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 17
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 18
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 19
you should see ten lines with the numbers 10..19:
# alarms = 20
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 0
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 1
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 2
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 3
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 4
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 5
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 6
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 7
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 8
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 9
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 10
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 11
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 12
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 13
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 14
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 15
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 16
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 17
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 18
ALERT 140239160588096 17:32:27.2 /home/pespin/dev/sysmocom/git/osmo-trx/tests/CommonLibs/LogTest.cpp:58:main: 19

View File

@@ -0,0 +1,44 @@
include $(top_srcdir)/Makefile.common
AM_CPPFLAGS = -Wall -I$(top_srcdir)/CommonLibs $(STD_DEFINES_AND_INCLUDES) -g
EXTRA_DIST = BitVectorTest.ok \
PRBSTest.ok \
InterthreadTest.ok \
SocketsTest.ok \
TimevalTest.ok \
VectorTest.ok \
LogTest.ok
noinst_PROGRAMS = \
BitVectorTest \
PRBSTest \
InterthreadTest \
SocketsTest \
TimevalTest \
VectorTest \
LogTest
BitVectorTest_SOURCES = BitVectorTest.cpp
BitVectorTest_LDADD = $(COMMON_LA)
PRBSTest_SOURCES = PRBSTest.cpp
InterthreadTest_SOURCES = InterthreadTest.cpp
InterthreadTest_LDADD = $(COMMON_LA)
InterthreadTest_LDFLAGS = -lpthread
SocketsTest_SOURCES = SocketsTest.cpp
SocketsTest_LDADD = $(COMMON_LA)
SocketsTest_LDFLAGS = -lpthread
TimevalTest_SOURCES = TimevalTest.cpp
TimevalTest_LDADD = $(COMMON_LA)
VectorTest_SOURCES = VectorTest.cpp
VectorTest_LDADD = $(COMMON_LA)
LogTest_SOURCES = LogTest.cpp
LogTest_LDADD = $(COMMON_LA)
MOSTLYCLEANFILES += testSource testDestination

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2017 Alexander Chemeris <Alexander.Chemeris@fairwaves.co>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "PRBS.h"
#include <iostream>
#include <cstdlib>
#include <assert.h>
void testPrbs(PRBS &prbs, uint64_t expectedPeriod)
{
uint64_t period = 0;
do {
std::cout << prbs.generateBit();
period++;
} while (!prbs.isFinished());
std::cout << std::endl;
std::cout << "Period: " << period << std::endl;
assert(period == expectedPeriod);
}
int main(int argc, char *argv[])
{
PRBS9 prbs9(0x01);
testPrbs(prbs9, (1<<9)-1);
PRBS15 prbs15(0x01);
testPrbs(prbs15, (1<<15)-1);
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,104 @@
/*
* Copyright 2008 Free Software Foundation, Inc.
*
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Sockets.h"
#include "Threads.h"
#include <stdio.h>
#include <stdlib.h>
static const int gNumToSend = 10;
void *testReaderIP(void *)
{
UDPSocket readSocket("127.0.0.1", 5934, "localhost", 5061);
readSocket.nonblocking();
int rc = 0;
while (rc<gNumToSend) {
char buf[MAX_UDP_LENGTH];
int count = readSocket.read(buf, MAX_UDP_LENGTH);
if (count>0) {
COUT("read: " << buf);
rc++;
} else {
sleep(2);
}
}
return NULL;
}
void *testReaderUnix(void *)
{
UDDSocket readSocket("testDestination");
readSocket.nonblocking();
int rc = 0;
while (rc<gNumToSend) {
char buf[MAX_UDP_LENGTH+1];
buf[MAX_UDP_LENGTH] = '\0';
int count = readSocket.read(buf, MAX_UDP_LENGTH);
if (count>0) {
COUT("read: " << buf);
rc++;
} else {
sleep(2);
}
}
return NULL;
}
int main(int argc, char * argv[] )
{
Thread readerThreadIP;
readerThreadIP.start(testReaderIP,NULL);
Thread readerThreadUnix;
readerThreadUnix.start(testReaderUnix,NULL);
UDPSocket socket1("127.0.0.1", 5061, "127.0.0.1", 5934);
UDDSocket socket1U("testSource","testDestination");
COUT("socket1: " << socket1.port());
// give the readers time to open
sleep(1);
for (int i=0; i<gNumToSend; i++) {
socket1.write("Hello IP land");
socket1U.write("Hello Unix domain");
sleep(1);
}
readerThreadIP.join();
readerThreadUnix.join();
}
// vim: ts=4 sw=4

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2008 Free Software Foundation, Inc.
*
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Timeval.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
Timeval then(10000);
cout << then.elapsed() << endl;
while (!then.passed()) {
cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl;
usleep(500000);
}
cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl;
}

View File

@@ -0,0 +1,22 @@
-10000
now: 1515515602.357742 then: 1515515612.357710 remaining: 10000
now: 1515515602.857837 then: 1515515612.357710 remaining: 9500
now: 1515515603.357975 then: 1515515612.357710 remaining: 9000
now: 1515515603.858163 then: 1515515612.357710 remaining: 8500
now: 1515515604.358353 then: 1515515612.357710 remaining: 8000
now: 1515515604.858465 then: 1515515612.357710 remaining: 7500
now: 1515515605.358622 then: 1515515612.357710 remaining: 7000
now: 1515515605.858745 then: 1515515612.357710 remaining: 6499
now: 1515515606.358852 then: 1515515612.357710 remaining: 5999
now: 1515515606.859055 then: 1515515612.357710 remaining: 5499
now: 1515515607.359170 then: 1515515612.357710 remaining: 4999
now: 1515515607.859349 then: 1515515612.357710 remaining: 4499
now: 1515515608.359455 then: 1515515612.357710 remaining: 3999
now: 1515515608.859549 then: 1515515612.357710 remaining: 3499
now: 1515515609.359748 then: 1515515612.357710 remaining: 2998
now: 1515515609.859865 then: 1515515612.357710 remaining: 2498
now: 1515515610.360064 then: 1515515612.357710 remaining: 1998
now: 1515515610.860223 then: 1515515612.357710 remaining: 1498
now: 1515515611.360386 then: 1515515612.357710 remaining: 998
now: 1515515611.860592 then: 1515515612.357710 remaining: 498
now: 1515515612.360712 then: 1515515612.357710 remaining: -3

View File

@@ -0,0 +1,63 @@
/*
* Copyright 2008 Free Software Foundation, Inc.
*
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Vector.h"
#include <iostream>
using namespace std;
typedef Vector<int> TestVector;
int main(int argc, char *argv[])
{
TestVector test1(5);
for (int i=0; i<5; i++) test1[i]=i;
TestVector test2(5);
for (int i=0; i<5; i++) test2[i]=10+i;
cout << test1 << endl;
cout << test2 << endl;
{
TestVector testC(test1,test2);
cout << testC << endl;
cout << testC.head(3) << endl;
cout << testC.tail(3) << endl;
testC.fill(8);
cout << testC << endl;
test1.copyToSegment(testC,3);
cout << testC << endl;
TestVector testD(testC.segment(4,3));
cout << testD << endl;
testD.fill(9);
cout << testC << endl;
cout << testD << endl;
}
return 0;
}

View File

@@ -0,0 +1,10 @@
0 1 2 3 4
10 11 12 13 14
0 1 2 3 4 10 11 12 13 14
0 1 2
3 4 10 11 12 13 14
8 8 8 8 8 8 8 8 8 8
8 8 8 0 1 2 3 4 8 8
1 2 3
8 8 8 0 9 9 9 4 8 8
9 9 9

40
tests/Makefile.am Normal file
View File

@@ -0,0 +1,40 @@
SUBDIRS = \
CommonLibs \
$(NULL)
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
$(srcdir)/package.m4: $(top_srcdir)/configure.ac
:;{ \
echo '# Signature of the current package.' && \
echo 'm4_define([AT_PACKAGE_NAME],' && \
echo ' [$(PACKAGE_NAME)])' && \
echo 'm4_define([AT_PACKAGE_TARNAME],' && \
echo ' [$(PACKAGE_TARNAME)])' && \
echo 'm4_define([AT_PACKAGE_VERSION],' && \
echo ' [$(PACKAGE_VERSION)])' && \
echo 'm4_define([AT_PACKAGE_STRING],' && \
echo ' [$(PACKAGE_STRING)])' && \
echo 'm4_define([AT_PACKAGE_BUGREPORT],' && \
echo ' [$(PACKAGE_BUGREPORT)])'; \
echo 'm4_define([AT_PACKAGE_URL],' && \
echo ' [$(PACKAGE_URL)])'; \
} >'$(srcdir)/package.m4'
EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE)
TESTSUITE = $(srcdir)/testsuite
DISTCLEANFILES = atconfig $(NULL)
check-local: atconfig $(TESTSUITE)
$(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
installcheck-local: atconfig $(TESTSUITE)
$(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' $(TESTSUITEFLAGS)
clean-local:
test ! -f '$(TESTSUITE)' || $(SHELL) '$(TESTSUITE)' --clean
AUTOM4TE = $(SHELL) $(top_srcdir)/missing --run autom4te
AUTOTEST = $(AUTOM4TE) --language=autotest
$(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/package.m4
$(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at
mv $@.tmp $@

45
tests/testsuite.at Normal file
View File

@@ -0,0 +1,45 @@
AT_INIT
AT_BANNER([Regression tests.])
AT_SETUP([BitVectorTest])
AT_KEYWORDS([BitVectorTest])
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([LogTest])
#AT_KEYWORDS([LogTest])
#cat $abs_srcdir/CommonLibs/LogTest.ok > expout
#cat $abs_srcdir/CommonLibs/LogTest.err > experr
#AT_CHECK([$abs_top_builddir/tests/CommonLibs/LogTest], [], [expout], [experr])
#AT_CLEANUP
AT_SETUP([PRBSTest])
AT_KEYWORDS([PRBSTest])
cat $abs_srcdir/CommonLibs/PRBSTest.ok > expout
AT_CHECK([$abs_top_builddir/tests/CommonLibs/PRBSTest], [], [expout], [])
AT_CLEANUP
#AT_SETUP([SocketsTest])
#AT_KEYWORDS([SocketsTest])
#cat $abs_srcdir/CommonLibs/SocketsTest.ok > expout
#AT_CHECK([$abs_top_builddir/tests/CommonLibs/SocketsTest], [], [expout], [])
#AT_CLEANUP
#AT_SETUP([TimevalTest])
#AT_KEYWORDS([TimevalTest])
#cat $abs_srcdir/CommonLibs/TimevalTest.ok > expout
#AT_CHECK([$abs_top_builddir/tests/CommonLibs/TimevalTest], [], [expout], [])
#AT_CLEANUP
AT_SETUP([VectorTest])
AT_KEYWORDS([VectorTest])
cat $abs_srcdir/CommonLibs/VectorTest.ok > expout
AT_CHECK([$abs_top_builddir/tests/CommonLibs/VectorTest], [], [expout], [])
AT_CLEANUP