diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2018-01-15 10:06:32 +0100 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2018-01-15 10:46:42 +0100 |
commit | 708b8b44aeb8c0e57b8defb3007aef432f2e2b45 (patch) | |
tree | 747bdfd3eb92f8706c4c8cdc602e60451ca5a69d /tests | |
parent | cb0fc9b21ad0aea667f14c17d339e2e1a3177a3d (diff) |
tests: SocketsTest: Avoid hang forever if test fails
Change-Id: Ia95e216a2ab6d397ab02c828b70f2b95d1671257
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CommonLibs/SocketsTest.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/tests/CommonLibs/SocketsTest.cpp b/tests/CommonLibs/SocketsTest.cpp index 9a7d6f0..bde86b8 100644 --- a/tests/CommonLibs/SocketsTest.cpp +++ b/tests/CommonLibs/SocketsTest.cpp @@ -30,10 +30,16 @@ #include "Threads.h" #include <stdio.h> #include <stdlib.h> - +#include <unistd.h> +#include <signal.h> static const int gNumToSend = 10; +static void sigalarm_handler(int foo) +{ + printf("FAIL: test did not run successfully\n"); + exit(EXIT_FAILURE); +} void *testReaderIP(void *param) { @@ -56,6 +62,14 @@ void *testReaderIP(void *param) int main(int argc, char * argv[] ) { + if (signal(SIGALRM, sigalarm_handler) == SIG_ERR) { + perror("signal"); + exit(EXIT_FAILURE); + } + + /* If the test takes longer than 2*gNumToSend seconds, abort it */ + alarm(2* gNumToSend); + UDPSocket readSocket("127.0.0.1", 0); UDPSocket socket1("127.0.0.1", 0, "localhost", readSocket.port()); |