aboutsummaryrefslogtreecommitdiffstats
path: root/CommonLibs
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2018-01-09 17:44:49 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2018-01-10 11:17:32 +0100
commit2ac788b2c32e568260c192e2501c0d4d65a54fcc (patch)
treee98306e298742c8d6f2e9107f1fe6de7b6ce4b4d /CommonLibs
parentd36ef2f57bd31d528d7dd93048706630fc992b0b (diff)
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
Diffstat (limited to 'CommonLibs')
-rw-r--r--CommonLibs/BitVectorTest.cpp60
-rw-r--r--CommonLibs/InterthreadTest.cpp115
-rw-r--r--CommonLibs/LogTest.cpp62
-rw-r--r--CommonLibs/Makefile.am38
-rw-r--r--CommonLibs/PRBSTest.cpp42
-rw-r--r--CommonLibs/SocketsTest.cpp104
-rw-r--r--CommonLibs/TimevalTest.cpp45
-rw-r--r--CommonLibs/VectorTest.cpp63
8 files changed, 0 insertions, 529 deletions
diff --git a/CommonLibs/BitVectorTest.cpp b/CommonLibs/BitVectorTest.cpp
deleted file mode 100644
index 063138f..0000000
--- a/CommonLibs/BitVectorTest.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
-* 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;
-}
diff --git a/CommonLibs/InterthreadTest.cpp b/CommonLibs/InterthreadTest.cpp
deleted file mode 100644
index 03445d9..0000000
--- a/CommonLibs/InterthreadTest.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
-* 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
diff --git a/CommonLibs/LogTest.cpp b/CommonLibs/LogTest.cpp
deleted file mode 100644
index 2245386..0000000
--- a/CommonLibs/LogTest.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
-* 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();
-}
diff --git a/CommonLibs/Makefile.am b/CommonLibs/Makefile.am
index d42e82a..46cc143 100644
--- a/CommonLibs/Makefile.am
+++ b/CommonLibs/Makefile.am
@@ -38,17 +38,6 @@ libcommon_la_SOURCES = \
Timeval.cpp \
Logger.cpp
-noinst_PROGRAMS = \
- BitVectorTest \
- PRBSTest \
- InterthreadTest \
- SocketsTest \
- TimevalTest \
- VectorTest \
- LogTest
-
-# ReportingTest
-
noinst_HEADERS = \
BitVector.h \
PRBS.h \
@@ -59,30 +48,3 @@ noinst_HEADERS = \
Timeval.h \
Vector.h \
Logger.h
-
-BitVectorTest_SOURCES = BitVectorTest.cpp
-BitVectorTest_LDADD = libcommon.la
-
-PRBSTest_SOURCES = PRBSTest.cpp
-
-InterthreadTest_SOURCES = InterthreadTest.cpp
-InterthreadTest_LDADD = libcommon.la
-InterthreadTest_LDFLAGS = -lpthread
-
-SocketsTest_SOURCES = SocketsTest.cpp
-SocketsTest_LDADD = libcommon.la
-SocketsTest_LDFLAGS = -lpthread
-
-TimevalTest_SOURCES = TimevalTest.cpp
-TimevalTest_LDADD = libcommon.la
-
-VectorTest_SOURCES = VectorTest.cpp
-VectorTest_LDADD = libcommon.la
-
-# ReportingTest_SOURCES = ReportingTest.cpp
-# ReportingTest_LDADD = libcommon.la
-
-LogTest_SOURCES = LogTest.cpp
-LogTest_LDADD = libcommon.la
-
-MOSTLYCLEANFILES += testSource testDestination
diff --git a/CommonLibs/PRBSTest.cpp b/CommonLibs/PRBSTest.cpp
deleted file mode 100644
index b83e93d..0000000
--- a/CommonLibs/PRBSTest.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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);
-}
diff --git a/CommonLibs/SocketsTest.cpp b/CommonLibs/SocketsTest.cpp
deleted file mode 100644
index 3198a5e..0000000
--- a/CommonLibs/SocketsTest.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
-* 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
diff --git a/CommonLibs/TimevalTest.cpp b/CommonLibs/TimevalTest.cpp
deleted file mode 100644
index b4746f2..0000000
--- a/CommonLibs/TimevalTest.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-* 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;
-}
diff --git a/CommonLibs/VectorTest.cpp b/CommonLibs/VectorTest.cpp
deleted file mode 100644
index 6958889..0000000
--- a/CommonLibs/VectorTest.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-* 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;
-}