Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #5803 from ahupowerdns/zero-exception
Fix throwing exceptions from MThreads, plus add unit tests
- Loading branch information
Showing
4 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#define BOOST_TEST_DYN_LINK | ||
#define BOOST_TEST_NO_MAIN | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
#include <boost/test/unit_test.hpp> | ||
#include <boost/test/floating_point_comparison.hpp> | ||
#include "mtasker.hh" | ||
|
||
BOOST_AUTO_TEST_SUITE(mtasker_cc) | ||
|
||
static int g_result; | ||
|
||
static void doSomething(void* p) | ||
{ | ||
MTasker<>* mt = reinterpret_cast<MTasker<>*>(p); | ||
int i=12, o; | ||
mt->waitEvent(i, &o); | ||
g_result = o; | ||
|
||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_Simple) { | ||
MTasker<> mt; | ||
mt.makeThread(doSomething, &mt); | ||
struct timeval now; | ||
gettimeofday(&now, 0); | ||
bool first=true; | ||
int o=24; | ||
for(;;) { | ||
while(mt.schedule(&now)); | ||
if(first) { | ||
mt.sendEvent(12, &o); | ||
first=false; | ||
} | ||
if(mt.noProcesses()) | ||
break; | ||
} | ||
BOOST_CHECK_EQUAL(g_result, o); | ||
} | ||
|
||
static void willThrow(void* p) | ||
{ | ||
throw std::runtime_error("Help!"); | ||
} | ||
|
||
|
||
BOOST_AUTO_TEST_CASE(test_MtaskerException) { | ||
BOOST_CHECK_THROW( { | ||
MTasker<> mt; | ||
mt.makeThread(willThrow, 0); | ||
struct timeval now; | ||
|
||
for(;;) { | ||
mt.schedule(&now); | ||
} | ||
}, std::exception); | ||
} | ||
BOOST_AUTO_TEST_SUITE_END() |