aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2018-01-15 10:29:20 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2018-01-15 10:35:11 +0100
commitcb0fc9b21ad0aea667f14c17d339e2e1a3177a3d (patch)
tree175dd9e45863d6f12a41997200e6cf88e51d6d4e
parent8639fee50452ac51c9963e7cb51e82989efbb5f1 (diff)
tests: SocketTests: Pick OS-assigned instead of setting one manually
This fixes failures if the port is already being taken by other apps or if this test is run several times concurrently in the same system. Change-Id: Iea213375e489a56cf8ed3e47fe814e17c288803e
-rw-r--r--tests/CommonLibs/SocketsTest.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/tests/CommonLibs/SocketsTest.cpp b/tests/CommonLibs/SocketsTest.cpp
index 235b8f3..9a7d6f0 100644
--- a/tests/CommonLibs/SocketsTest.cpp
+++ b/tests/CommonLibs/SocketsTest.cpp
@@ -35,14 +35,14 @@
static const int gNumToSend = 10;
-void *testReaderIP(void *)
+void *testReaderIP(void *param)
{
- UDPSocket readSocket("127.0.0.1", 5934, "localhost", 5061);
- readSocket.nonblocking();
+ UDPSocket *readSocket = (UDPSocket *)param;
+ readSocket->nonblocking();
int rc = 0;
while (rc<gNumToSend) {
char buf[MAX_UDP_LENGTH];
- int count = readSocket.read(buf, MAX_UDP_LENGTH);
+ int count = readSocket->read(buf, MAX_UDP_LENGTH);
if (count>0) {
CERR("read: " << buf);
rc++;
@@ -56,12 +56,13 @@ void *testReaderIP(void *)
int main(int argc, char * argv[] )
{
- Thread readerThreadIP;
- readerThreadIP.start(testReaderIP,NULL);
+ UDPSocket readSocket("127.0.0.1", 0);
+ UDPSocket socket1("127.0.0.1", 0, "localhost", readSocket.port());
- UDPSocket socket1("127.0.0.1", 5061, "127.0.0.1", 5934);
+ CERR("socket1: " << socket1.port() << ", readSocket: " << readSocket.port());
- CERR("socket1: " << socket1.port());
+ Thread readerThreadIP;
+ readerThreadIP.start(testReaderIP, &readSocket);
// give the readers time to open
sleep(1);