intIntervalTotimespec moved to Common.hpp, run_test.sh stop if test failed or segfaulted

master
Denes Matetelki 14 years ago
parent ab92c991ec
commit 64efcfd9da

1
.gitignore vendored

@ -9,6 +9,7 @@
*/lcov.info
*/lcov2.info
*/core
*.gcno
*.kdev_include_paths
test/generated_main.cpp
test/test

@ -1,3 +1,7 @@
#ifndef COMMON_HPP
#define COMMON_HPP
#include <iostream>
#ifndef NOTRACE
@ -8,3 +12,24 @@
/// @todo Get rid of the "warning: statement has no effect" compiler msgs
#define TRACE(x) ""
#endif
#define STRINGIZE(c) #c
#include <time.h>
inline timespec intIntervalTotimespec(const int & interval)
{
timespec abs_time;
clock_gettime ( CLOCK_REALTIME, &abs_time );
abs_time.tv_nsec += interval * 1000000;
if ( abs_time.tv_nsec >= 1000000000 ) {
abs_time.tv_nsec -= 1000000000;
abs_time.tv_sec += 1;
}
return abs_time;
};
#endif // COMMON_HPP

@ -8,6 +8,9 @@ class Task
public:
// Task() {};
// virtual ~Task() {};
virtual void run () = 0;
virtual bool isItStucked () const = 0;

@ -2,7 +2,7 @@
#include "Common.hpp"
#include <time.h>
#include <assert.h>
ConditionVariable::ConditionVariable(Mutex& mutex)
: m_mutex(mutex)
@ -26,16 +26,10 @@ int ConditionVariable::wait(const int interval)
return pthread_cond_wait( &m_condVar,
m_mutex.getPThreadMutex() );
} else {
timespec abs_time;
clock_gettime ( CLOCK_REALTIME, &abs_time );
abs_time.tv_nsec += interval * 1000000;
if ( abs_time.tv_nsec >= 1000000000 ) {
abs_time.tv_nsec -= 1000000000;
abs_time.tv_sec += 1;
}
timespec tspec = intIntervalTotimespec(interval);
return pthread_cond_timedwait( &m_condVar,
m_mutex.getPThreadMutex(),
&abs_time );
&tspec);
}
}

@ -46,15 +46,8 @@ bool Mutex::tryLock(const int interval)
int result = pthread_mutex_trylock ( &m_mutex );
return result == 0;
} else {
timespec abs_time;
clock_gettime ( CLOCK_REALTIME, &abs_time );
abs_time.tv_nsec += interval * 1000000;
if ( abs_time.tv_nsec >= 1000000000 ) {
abs_time.tv_nsec -= 1000000000;
abs_time.tv_sec += 1;
}
int result = pthread_mutex_timedlock ( &m_mutex, &abs_time );
return result == 0;
timespec tspec = intIntervalTotimespec(interval);
return pthread_mutex_timedlock ( &m_mutex, &tspec ) == 0;
}
}

@ -3,17 +3,68 @@
# Usage:
# ./run_test.sh <TEST_BINARY>
pre="\E[00;32m"
pre="\E[00;33m"
fail="\E[00;31m"
post="\E[00;00m"
echo -e "${pre}Reset coverage files${post}"
ulimit -c unlimited
# test=$1
test=./test
# if [ $# -ne 1 ]
# then
# echo "Usage: `basename $0` <TEST_BINARY>"
# exit 1
# fi
if [ ! -e $test ]; then
echo -e "The parameter binary: $test does not exists"
exit 1
fi
echo -e "${pre}Reset & remove files${post}"
# coverage
lcov --directory . -z
rm -f ./lcov.info
# cores
rm -f ./leak.log.core.*
# cxxtest output
rm -f $test.out
echo -e "${pre}Run tests${post}"
valgrind --log-file=leak.log --leak-check=full --show-reachable=yes --show-below-main=no \
--track-origins=yes --num-callers=30 --malloc-fill=0xaa --free-fill=0xdd \
--suppressions=valgrind.supp $1
valgrind \
--log-file=leak.log \
--leak-check=full \
--show-reachable=yes \
--show-below-main=no \
--track-origins=yes \
--num-callers=30 \
--malloc-fill=0xaa \
--free-fill=0xdd \
--suppressions=valgrind.supp \
$test | tee $test.out; retval=$PIPESTATUS; (( $retval == 0 ));
# retval is 0 on success
# or the number of failed cases
# or 137 if segfault happens
if [ $retval -ne 0 ]; then
echo -e "${fail}The executed binary: $test failed.${post}"
if [ $retval -ne 137 ]; then
echo -e "${pre}Failed checks:${post}"
cat $test.out | grep "Error:" | awk -F"/test/" '{ print $2 }'
fi
cores=$(ls leak.log.core.* 2>/dev/null)
if [ "$cores" != "" ]; then
echo -e "${pre}Core file generated: ${post}"
echo $cores
fi
exit -1
fi
echo -e "${pre}Capture coverage info${post}"

@ -15,16 +15,16 @@ private:
class ThreadClass : public Thread
{
public:
// public:
ThreadClass() { TRACE(this); }
~ThreadClass() { TRACE(this); }
// ThreadClass() { TRACE(this); }
// ~ThreadClass() { TRACE(this); }
private:
ThreadClass(const ThreadClass&) { TRACE(this); }
ThreadClass& operator=(const ThreadClass&) { TRACE(this); return*this; }
// ThreadClass(const ThreadClass&) : Thread() { TRACE(this); }
// ThreadClass& operator=(const ThreadClass&) { TRACE(this); return*this; }
void* run( void ) {
TRACE(this);
@ -69,9 +69,6 @@ private:
private:
ThreadClassWithSignal(const ThreadClassWithSignal&) { TRACE(this); }
ThreadClassWithSignal& operator=(const ThreadClassWithSignal&) { TRACE(this); return*this; }
void* run( void ) {
TRACE(this);
@ -104,12 +101,15 @@ public:
{
ThreadClassWithSignal *m2 = new ThreadClassWithSignal;
m2->start();
sleep(3);
m2->sendSignal(SIGINT);
sleep(3);
void *retVal = m2->join();
TS_ASSERT(retVal);
if (retVal != 0 ) {
TS_ASSERT_EQUALS ( *((int*)retVal) , 16 );
free(retVal);
}
delete m2;
}

Loading…
Cancel
Save