From: bert hubert Date: Tue, 10 Oct 2017 12:41:44 +0000 (+0200) Subject: add two tests for MTasker, including catching an exception X-Git-Tag: rec-4.1.0-rc2~46^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7346028e546b552c4534eb49e8320914142a3488;p=thirdparty%2Fpdns.git add two tests for MTasker, including catching an exception --- diff --git a/pdns/recursordist/Makefile.am b/pdns/recursordist/Makefile.am index 0775481e12..082c90c278 100644 --- a/pdns/recursordist/Makefile.am +++ b/pdns/recursordist/Makefile.am @@ -206,6 +206,7 @@ testrunner_SOURCES = \ ixfr.cc ixfr.hh \ logger.cc logger.hh \ misc.cc misc.hh \ + mtasker_fcontext.cc \ negcache.hh negcache.cc \ namespaces.hh \ nsecrecords.cc \ @@ -237,6 +238,7 @@ testrunner_SOURCES = \ test-iputils_hh.cc \ test-ixfr_cc.cc \ test-misc_hh.cc \ + test-mtasker.cc \ test-nmtree.cc \ test-negcache_cc.cc \ test-rcpgenerator_cc.cc \ @@ -254,10 +256,12 @@ testrunner_SOURCES = \ testrunner_LDFLAGS = \ $(AM_LDFLAGS) \ + $(BOOST_CONTEXT_LDFLAGS) \ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) \ $(LIBCRYPTO_LDFLAGS) testrunner_LDADD = \ + $(BOOST_CONTEXT_LIBS) \ $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) \ $(LIBCRYPTO_LIBS) \ $(RT_LIBS) diff --git a/pdns/recursordist/test-mtasker.cc b/pdns/recursordist/test-mtasker.cc new file mode 100644 index 0000000000..9da5825586 --- /dev/null +++ b/pdns/recursordist/test-mtasker.cc @@ -0,0 +1,60 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_NO_MAIN + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include "mtasker.hh" + +BOOST_AUTO_TEST_SUITE(mtasker_cc) + +static int g_result; + +static void doSomething(void* p) +{ + MTasker<>* mt = reinterpret_cast*>(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_EXCEPTION( { + MTasker<> mt; + mt.makeThread(willThrow, 0); + struct timeval now; + + for(;;) { + mt.schedule(&now); + } + }, std::exception, [](const std::exception& e) { return true; }); +} +BOOST_AUTO_TEST_SUITE_END()