rename chapters
This commit is contained in:
@@ -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_SIGILL_action );
|
||||
}
|
||||
|
||||
SignalTranslator::~SignalTranslator()
|
||||
{
|
||||
sigaction( SIGILL, &m_old_SIGILL_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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef UNITTEST_SIGNALTRANSLATOR_H
|
||||
#define UNITTEST_SIGNALTRANSLATOR_H
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
|
||||
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_SIGILL_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
|
||||
33
Chapter17/cib/libs/etl/test/UnitTest++/Posix/TimeHelpers.cpp
Normal file
33
Chapter17/cib/libs/etl/test/UnitTest++/Posix/TimeHelpers.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "TimeHelpers.h"
|
||||
#include <unistd.h>
|
||||
|
||||
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(static_cast<useconds_t>(ms * 1000));
|
||||
}
|
||||
|
||||
}
|
||||
28
Chapter17/cib/libs/etl/test/UnitTest++/Posix/TimeHelpers.h
Normal file
28
Chapter17/cib/libs/etl/test/UnitTest++/Posix/TimeHelpers.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef UNITTEST_TIMEHELPERS_H
|
||||
#define UNITTEST_TIMEHELPERS_H
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
Timer();
|
||||
void Start();
|
||||
double GetTimeInMs() const;
|
||||
|
||||
private:
|
||||
struct timeval m_startTime;
|
||||
};
|
||||
|
||||
|
||||
namespace TimeHelpers
|
||||
{
|
||||
void SleepMs(int ms);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user