From ee4adf600bdd3aa60cc0e92a39f2111be0a90bc6 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 27 May 2015 15:00:06 +0200 Subject: Added library for supporting unit tests (nw) --- .../UnitTest++/Posix/SignalTranslator.cpp | 46 ++++++++++++++++++++++ .../UnitTest++/Posix/SignalTranslator.h | 42 ++++++++++++++++++++ .../unittest-cpp/UnitTest++/Posix/TimeHelpers.cpp | 33 ++++++++++++++++ .../unittest-cpp/UnitTest++/Posix/TimeHelpers.h | 28 +++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.cpp create mode 100644 3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.h create mode 100644 3rdparty/unittest-cpp/UnitTest++/Posix/TimeHelpers.cpp create mode 100644 3rdparty/unittest-cpp/UnitTest++/Posix/TimeHelpers.h (limited to '3rdparty/unittest-cpp/UnitTest++/Posix') diff --git a/3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.cpp b/3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.cpp new file mode 100644 index 00000000000..3689c8c34d0 --- /dev/null +++ b/3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.cpp @@ -0,0 +1,46 @@ +#include "SignalTranslator.h" + +namespace UnitTest { + +sigjmp_buf* SignalTranslator::s_jumpTarget = 0; + +namespace { + +void SignalHandler(int sig) +{ + siglongjmp(*SignalTranslator::s_jumpTarget, sig ); +} + +} + + +SignalTranslator::SignalTranslator() +{ + m_oldJumpTarget = s_jumpTarget; + s_jumpTarget = &m_currentJumpTarget; + + struct sigaction action; + action.sa_flags = 0; + action.sa_handler = SignalHandler; + sigemptyset( &action.sa_mask ); + + sigaction( SIGSEGV, &action, &m_old_SIGSEGV_action ); + sigaction( SIGFPE , &action, &m_old_SIGFPE_action ); + sigaction( SIGTRAP, &action, &m_old_SIGTRAP_action ); + sigaction( SIGBUS , &action, &m_old_SIGBUS_action ); + sigaction( SIGILL , &action, &m_old_SIGBUS_action ); +} + +SignalTranslator::~SignalTranslator() +{ + sigaction( SIGILL , &m_old_SIGBUS_action , 0 ); + sigaction( SIGBUS , &m_old_SIGBUS_action , 0 ); + sigaction( SIGTRAP, &m_old_SIGTRAP_action, 0 ); + sigaction( SIGFPE , &m_old_SIGFPE_action , 0 ); + sigaction( SIGSEGV, &m_old_SIGSEGV_action, 0 ); + + s_jumpTarget = m_oldJumpTarget; +} + + +} diff --git a/3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.h b/3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.h new file mode 100644 index 00000000000..50da5f996f6 --- /dev/null +++ b/3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.h @@ -0,0 +1,42 @@ +#ifndef UNITTEST_SIGNALTRANSLATOR_H +#define UNITTEST_SIGNALTRANSLATOR_H + +#include +#include + +namespace UnitTest { + +class SignalTranslator +{ +public: + SignalTranslator(); + ~SignalTranslator(); + + static sigjmp_buf* s_jumpTarget; + +private: + sigjmp_buf m_currentJumpTarget; + sigjmp_buf* m_oldJumpTarget; + + struct sigaction m_old_SIGFPE_action; + struct sigaction m_old_SIGTRAP_action; + struct sigaction m_old_SIGSEGV_action; + struct sigaction m_old_SIGBUS_action; + struct sigaction m_old_SIGABRT_action; + struct sigaction m_old_SIGALRM_action; +}; + +#if !defined (__GNUC__) + #define UNITTEST_EXTENSION +#else + #define UNITTEST_EXTENSION __extension__ +#endif + +#define UNITTEST_THROW_SIGNALS_POSIX_ONLY \ + UnitTest::SignalTranslator sig; \ + if (UNITTEST_EXTENSION sigsetjmp(*UnitTest::SignalTranslator::s_jumpTarget, 1) != 0) \ + throw ("Unhandled system exception"); + +} + +#endif diff --git a/3rdparty/unittest-cpp/UnitTest++/Posix/TimeHelpers.cpp b/3rdparty/unittest-cpp/UnitTest++/Posix/TimeHelpers.cpp new file mode 100644 index 00000000000..65c63937a0e --- /dev/null +++ b/3rdparty/unittest-cpp/UnitTest++/Posix/TimeHelpers.cpp @@ -0,0 +1,33 @@ +#include "TimeHelpers.h" +#include + +namespace UnitTest { + +Timer::Timer() +{ + m_startTime.tv_sec = 0; + m_startTime.tv_usec = 0; +} + +void Timer::Start() +{ + gettimeofday(&m_startTime, 0); +} + +double Timer::GetTimeInMs() const +{ + struct timeval currentTime; + gettimeofday(¤tTime, 0); + + double const dsecs = currentTime.tv_sec - m_startTime.tv_sec; + double const dus = currentTime.tv_usec - m_startTime.tv_usec; + + return (dsecs * 1000.0) + (dus / 1000.0); +} + +void TimeHelpers::SleepMs(int ms) +{ + usleep(ms * 1000); +} + +} diff --git a/3rdparty/unittest-cpp/UnitTest++/Posix/TimeHelpers.h b/3rdparty/unittest-cpp/UnitTest++/Posix/TimeHelpers.h new file mode 100644 index 00000000000..0de4b1a9c7e --- /dev/null +++ b/3rdparty/unittest-cpp/UnitTest++/Posix/TimeHelpers.h @@ -0,0 +1,28 @@ +#ifndef UNITTEST_TIMEHELPERS_H +#define UNITTEST_TIMEHELPERS_H + +#include + +namespace UnitTest { + +class Timer +{ +public: + Timer(); + void Start(); + double GetTimeInMs() const; + +private: + struct timeval m_startTime; +}; + + +namespace TimeHelpers +{ + void SleepMs(int ms); +} + + +} + +#endif -- cgit v1.2.3 From eab88c568793f9d84fc612d83d25337df4d7a2ee Mon Sep 17 00:00:00 2001 From: Curt Coder Date: Wed, 27 May 2015 16:39:12 +0300 Subject: Fixed clang build. (nw) --- 3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to '3rdparty/unittest-cpp/UnitTest++/Posix') diff --git a/3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.h b/3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.h index 50da5f996f6..5b98d977b93 100644 --- a/3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.h +++ b/3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.h @@ -22,8 +22,8 @@ private: struct sigaction m_old_SIGTRAP_action; struct sigaction m_old_SIGSEGV_action; struct sigaction m_old_SIGBUS_action; - struct sigaction m_old_SIGABRT_action; - struct sigaction m_old_SIGALRM_action; + //struct sigaction m_old_SIGABRT_action; + //struct sigaction m_old_SIGALRM_action; }; #if !defined (__GNUC__) @@ -35,7 +35,7 @@ private: #define UNITTEST_THROW_SIGNALS_POSIX_ONLY \ UnitTest::SignalTranslator sig; \ if (UNITTEST_EXTENSION sigsetjmp(*UnitTest::SignalTranslator::s_jumpTarget, 1) != 0) \ - throw ("Unhandled system exception"); + throw ("Unhandled system exception"); } -- cgit v1.2.3