Fixes #79: Get the Clock tests working

This commit is contained in:
John M. Penn 2015-07-01 18:21:56 -05:00
parent 63975d9f89
commit 5fb037aa00
4 changed files with 37 additions and 46 deletions

View File

@ -20,12 +20,12 @@
#include "trick/TPROCTEClock.hh"
#include "trick/BC635Clock.hh"
#include "trick/JobData.hh"
//#include "trick/RequirementScribe.hh"
namespace Trick {
// Stub for message_publish
extern "C" int message_publish(int level, const char * format_msg, ...) { return 0; }
class BC635ClockTest : public ::testing::Test {
protected:
Trick::BC635Clock bcclk;
@ -34,15 +34,11 @@ class BC635ClockTest : public ::testing::Test {
virtual void SetUp() {}
virtual void TearDown() {}
//Trick::RequirementScribe req;
} ;
//std::map< std::string , unsigned int > Trick::Requirements::num_reqs;
/* Ensure clock initializes correctly */
TEST_F(BC635ClockTest, Initialize) {
//req.add_requirement("BC635_clock");
// "The BC635 clock shall initialize reference time of 0, and all ratios set to 1.");
/* General expected clock initialization */
@ -58,9 +54,8 @@ TEST_F(BC635ClockTest, Initialize) {
/* Run tests for when no hardware is available */
#ifndef _BC635
TEST_F(BC635ClockTest, ErrorMessages) {
//req.add_requirement("BC635_clock");
//"The BC635 clock shall display error messages when attempting to use its functions with no hardware.");
/* curr_time = 0 always */
long long req_time = rand();
@ -80,7 +75,6 @@ TEST_F(BC635ClockTest, ErrorMessages) {
/* Ensure generic clock functions still work when no hardware is available */
TEST_F(BC635ClockTest, TestRefTimes) {
//req.add_requirement("BC635_clock");
//"The BC635 clock shall provide the ability to adjust the reference time");
long long secs_remainder;
@ -92,10 +86,5 @@ TEST_F(BC635ClockTest, TestRefTimes) {
bcclk.sync_to_wall_clock(align_tics_mult, tics_per_s);
secs_remainder = bcclk.ref_time_tics% clock_unit;
EXPECT_EQ(secs_remainder, 0);
}
#endif
}

View File

@ -16,7 +16,8 @@
#define RATIO_TOL 1e-9
#define TICS_PER_SEC 1000000
namespace Trick {
// Stub for message_publish
extern "C" int message_publish(int level, const char * format_msg, ...) { return 0; }
class GetTimeOfDayClockTest : public ::testing::Test {
@ -36,7 +37,7 @@ TEST_F(GetTimeOfDayClockTest, Initialize) {
//"The system clock shall initialize with time equal to computer system time, reference time of 0, and all ratios set to 1.");
struct timeval res;
Trick::GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
Trick::GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
timclk->clock_init();
@ -46,7 +47,7 @@ TEST_F(GetTimeOfDayClockTest, Initialize) {
ASSERT_EQ(timclk->ref_time_tics, 0);
/* Time of Day clock initialization tests */
EXPECT_STREQ(timclk->get_name() , "GetTimeOfDay");
EXPECT_STREQ(timclk->get_name() , "GetTimeOfDay - CLOCK_REALTIME");
gettimeofday(&res, NULL);
@ -59,7 +60,7 @@ TEST_F(GetTimeOfDayClockTest, ClockSimRatio) {
long long tim_curr;
double tic_ratio, tic_val;
Trick::GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
Trick::GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
tic_val = 100000;
@ -81,7 +82,7 @@ TEST_F(GetTimeOfDayClockTest, ClockRTRatio) {
long long tim_curr, tim_diff;
double tic_ratio;
int rt_ratio;
Trick::GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
Trick::GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
rt_ratio = 6.0;
ASSERT_EQ(timclk->sim_tic_ratio, 1);
@ -108,7 +109,7 @@ TEST_F(GetTimeOfDayClockTest, ClockSpin) {
//"The system clock shall provide the ability to spin (wait) until a specified time is reached.");
long long tim_curr, spin_time;
Trick:: GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
Trick:: GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
spin_time = 100000;
@ -126,7 +127,7 @@ TEST_F(GetTimeOfDayClockTest, ReferenceTime) {
//"The system clock shall provide the ability to set a reference time.");
long long tic_adjust;
Trick:: GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
Trick:: GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
timclk->clock_init();
@ -148,7 +149,7 @@ TEST_F(GetTimeOfDayClockTest, ClockSync) {
double align_tics_mult;
int clock_unit;
Trick::GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
Trick::GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
align_tics_mult = 1.5;
clock_unit = int((TICS_PER_SEC * align_tics_mult) /
@ -161,4 +162,3 @@ TEST_F(GetTimeOfDayClockTest, ClockSync) {
delete timclk;
}
}

View File

@ -10,25 +10,30 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.common
# Flags passed to the preprocessor.
TRICK_CPPFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -DGTEST_HAS_TR1_TUPLE=0
TRICK_LIBS = -L${TRICK_LIB_DIR} -ltrick -ltrick_units -ltrick_mm
TRICK_EXEC_LINK_LIBS += ${GTEST_HOME}/lib/libgtest.a ${GTEST_HOME}/lib/libgtest_main.a
GTEST_LIBS = ${GTEST_HOME}/lib/libgtest.a ${GTEST_HOME}/lib/libgtest_main.a
BASE_OBJECTS = ../object_${TRICK_HOST_CPU}/Clock.o\
../object_${TRICK_HOST_CPU}/clock_c_intf.o
BC635_CLOCK_OBJECTS = ${BASE_OBJECTS} BC635Clock_test.o ../object_${TRICK_HOST_CPU}/BC635Clock.o
GETTIMEOFDAY_CLOCK_OBJECTS = ${BASE_OBJECTS} GetTimeOfDayClock_test.o ../object_${TRICK_HOST_CPU}/GetTimeOfDayClock.o
TPROCTE_CLOCK_OBJECTS = ${BASE_OBJECTS} TPROCTEClock_test.o ../object_${TRICK_HOST_CPU}/TPROCTEClock.o
# All tests produced by this Makefile. Remember to add new tests you
# created to the list.
TESTS = TPROCTEClock_test BC635Clock_test
#OTHER_OBJECTS = ../../include/object_${TRICK_HOST_CPU}/io_JobData.o \
# ../../include/object_${TRICK_HOST_CPU}/io_SimObject.o
TESTS = TPROCTEClock_test BC635Clock_test GetTimeOfDayClock_test
# House-keeping build targets.
all : $(TESTS)
test: $(TESTS)
#./GetTimeOfDayClock_test --gtest_output=xml:${TRICK_HOME}/trick_test/GetTimeOfDayClock.xml
#./TPROCTEClock_test --gtest_output=xml:${TRICK_HOME}/trick_test/TPROCTEClock.xml
#./BC635Clock_test --gtest_output=xml:${TRICK_HOME}/trick_test/BC635Clock.xml
./GetTimeOfDayClock_test --gtest_output=xml:${TRICK_HOME}/trick_test/GetTimeOfDayClock.xml
./TPROCTEClock_test --gtest_output=xml:${TRICK_HOME}/trick_test/TPROCTEClock.xml
./BC635Clock_test --gtest_output=xml:${TRICK_HOME}/trick_test/BC635Clock.xml
clean :
rm -f $(TESTS) *.o
@ -36,18 +41,18 @@ clean :
GetTimeOfDayClock_test.o : GetTimeOfDayClock_test.cpp
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c $<
GetTimeOfDayClock_test : GetTimeOfDayClock_test.o
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ $(OTHER_OBJECTS) $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS)
GetTimeOfDayClock_test : ${GETTIMEOFDAY_CLOCK_OBJECTS}
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ ${GTEST_LIBS}
TPROCTEClock_test.o : TPROCTEClock_test.cpp
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c $<
TPROCTEClock_test : TPROCTEClock_test.o
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ $(OTHER_OBJECTS) $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS)
TPROCTEClock_test : ${TPROCTE_CLOCK_OBJECTS}
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ ${GTEST_LIBS}
BC635Clock_test.o : BC635Clock_test.cpp
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c $<
BC635Clock_test : BC635Clock_test.o
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ $(OTHER_OBJECTS) $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS)
BC635Clock_test : ${BC635_CLOCK_OBJECTS}
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ ${GTEST_LIBS}

View File

@ -23,9 +23,10 @@
#include "trick/TPROCTEClock.hh"
#include "trick/BC635Clock.hh"
#include "trick/JobData.hh"
//#include "trick/RequirementScribe.hh"
namespace Trick {
// Stub for message_publish
extern "C" int message_publish(int level, const char * format_msg, ...) { return 0; }
class TPROCTEClockTest : public ::testing::Test {
@ -44,7 +45,6 @@ class TPROCTEClockTest : public ::testing::Test {
/* Ensure clock initializes correctly */
TEST_F(TPROCTEClockTest, Initialize) {
//req.add_requirement("TPROCTE_clock");
//"The TPROCTE clock shall initialize reference time of 0, and all ratios set to 1.");
/* General expected clock initialization */
@ -60,7 +60,6 @@ TEST_F(TPROCTEClockTest, Initialize) {
/* Run tests for when no hardware is available */
#ifndef _TPRO_CTE
TEST_F(TPROCTEClockTest, NoHardware) {
//req.add_requirement("TPROCTE_clock");
//"The TPROCTE clock shall display error messages when attempting to use its functions with no hardware");
long long req_time = rand();
@ -83,7 +82,6 @@ TEST_F(TPROCTEClockTest, NoHardware) {
/* Ensure generic clock functions work properly */
TEST_F(TPROCTEClockTest, TestRefTimes) {
//req.add_requirement("TPROCTE_clock");
//"The TPROCTE clock shall provide the ability to adjust the reference time");
long long secs_remainder;
@ -98,5 +96,4 @@ TEST_F(TPROCTEClockTest, TestRefTimes) {
}
}