From: Michal 'vorner' Vaner Date: Mon, 1 Oct 2012 13:22:39 +0000 (+0200) Subject: Add a timeout in case something got stuck X-Git-Tag: trac2402_base~79^2~5^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c74022e2d7acf6b77979e9c8b646d5da95419ed3;p=thirdparty%2Fkea.git Add a timeout in case something got stuck --- diff --git a/src/lib/util/threads/tests/lock_unittest.cc b/src/lib/util/threads/tests/lock_unittest.cc index 748580cffb..e1edd701f2 100644 --- a/src/lib/util/threads/tests/lock_unittest.cc +++ b/src/lib/util/threads/tests/lock_unittest.cc @@ -18,6 +18,8 @@ #include #include +#include +#include using namespace isc::util::thread; @@ -117,7 +119,18 @@ performStrangeOperation(std::vector array, int direction, } } +void +no_handler(int) {} + TEST(MutexTest, swarm) { + // Create a timeout in case something got stuck here + struct sigaction ignored, original; + memset(&ignored, 0, sizeof ignored); + ignored.sa_handler = no_handler; + if (sigaction(SIGALRM, &ignored, &original)) { + FAIL() << "Couldn't set alarm"; + } + alarm(10); // This type has a low chance of being atomic itself, further raising // the chance of problems appearing. std::vector array(length); @@ -136,6 +149,11 @@ TEST(MutexTest, swarm) { sum += array[i]; } EXPECT_EQ(length * value, sum) << "Threads are badly synchronized"; + // Cancel the alarm and return the original handler + alarm(0); + if (sigaction(SIGALRM, &original, NULL)) { + FAIL() << "Couldn't restore alarm"; + } } }