[PATCH] osmo-trx[master]: tests: SocketsTest: Avoid hang forever if test fails

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Mon Jan 15 11:00:27 UTC 2018


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/5781

to look at the new patch set (#2).

tests: SocketsTest: Avoid hang forever if test fails

Change-Id: Ia95e216a2ab6d397ab02c828b70f2b95d1671257
---
M tests/CommonLibs/SocketsTest.cpp
1 file changed, 15 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/81/5781/2

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 @@
 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());
 

-- 
To view, visit https://gerrit.osmocom.org/5781
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ia95e216a2ab6d397ab02c828b70f2b95d1671257
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list