mirror of
https://github.com/nasa/trick.git
synced 2025-01-30 08:03:51 +00:00
Fixes #79: Get the Clock tests working
This commit is contained in:
parent
63975d9f89
commit
5fb037aa00
@ -20,12 +20,12 @@
|
|||||||
#include "trick/TPROCTEClock.hh"
|
#include "trick/TPROCTEClock.hh"
|
||||||
#include "trick/BC635Clock.hh"
|
#include "trick/BC635Clock.hh"
|
||||||
#include "trick/JobData.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 {
|
class BC635ClockTest : public ::testing::Test {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Trick::BC635Clock bcclk;
|
Trick::BC635Clock bcclk;
|
||||||
|
|
||||||
@ -34,15 +34,11 @@ class BC635ClockTest : public ::testing::Test {
|
|||||||
virtual void SetUp() {}
|
virtual void SetUp() {}
|
||||||
virtual void TearDown() {}
|
virtual void TearDown() {}
|
||||||
|
|
||||||
//Trick::RequirementScribe req;
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
//std::map< std::string , unsigned int > Trick::Requirements::num_reqs;
|
|
||||||
|
|
||||||
/* Ensure clock initializes correctly */
|
/* Ensure clock initializes correctly */
|
||||||
TEST_F(BC635ClockTest, Initialize) {
|
TEST_F(BC635ClockTest, Initialize) {
|
||||||
|
|
||||||
//req.add_requirement("BC635_clock");
|
|
||||||
// "The BC635 clock shall initialize reference time of 0, and all ratios set to 1.");
|
// "The BC635 clock shall initialize reference time of 0, and all ratios set to 1.");
|
||||||
|
|
||||||
/* General expected clock initialization */
|
/* General expected clock initialization */
|
||||||
@ -58,9 +54,8 @@ TEST_F(BC635ClockTest, Initialize) {
|
|||||||
/* Run tests for when no hardware is available */
|
/* Run tests for when no hardware is available */
|
||||||
#ifndef _BC635
|
#ifndef _BC635
|
||||||
TEST_F(BC635ClockTest, ErrorMessages) {
|
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.");
|
//"The BC635 clock shall display error messages when attempting to use its functions with no hardware.");
|
||||||
|
|
||||||
/* curr_time = 0 always */
|
/* curr_time = 0 always */
|
||||||
|
|
||||||
long long req_time = rand();
|
long long req_time = rand();
|
||||||
@ -80,7 +75,6 @@ TEST_F(BC635ClockTest, ErrorMessages) {
|
|||||||
|
|
||||||
/* Ensure generic clock functions still work when no hardware is available */
|
/* Ensure generic clock functions still work when no hardware is available */
|
||||||
TEST_F(BC635ClockTest, TestRefTimes) {
|
TEST_F(BC635ClockTest, TestRefTimes) {
|
||||||
//req.add_requirement("BC635_clock");
|
|
||||||
//"The BC635 clock shall provide the ability to adjust the reference time");
|
//"The BC635 clock shall provide the ability to adjust the reference time");
|
||||||
|
|
||||||
long long secs_remainder;
|
long long secs_remainder;
|
||||||
@ -92,10 +86,5 @@ TEST_F(BC635ClockTest, TestRefTimes) {
|
|||||||
bcclk.sync_to_wall_clock(align_tics_mult, tics_per_s);
|
bcclk.sync_to_wall_clock(align_tics_mult, tics_per_s);
|
||||||
secs_remainder = bcclk.ref_time_tics% clock_unit;
|
secs_remainder = bcclk.ref_time_tics% clock_unit;
|
||||||
EXPECT_EQ(secs_remainder, 0);
|
EXPECT_EQ(secs_remainder, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
#define RATIO_TOL 1e-9
|
#define RATIO_TOL 1e-9
|
||||||
#define TICS_PER_SEC 1000000
|
#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 {
|
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.");
|
//"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;
|
struct timeval res;
|
||||||
Trick::GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
|
Trick::GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
|
||||||
|
|
||||||
timclk->clock_init();
|
timclk->clock_init();
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ TEST_F(GetTimeOfDayClockTest, Initialize) {
|
|||||||
ASSERT_EQ(timclk->ref_time_tics, 0);
|
ASSERT_EQ(timclk->ref_time_tics, 0);
|
||||||
|
|
||||||
/* Time of Day clock initialization tests */
|
/* Time of Day clock initialization tests */
|
||||||
EXPECT_STREQ(timclk->get_name() , "GetTimeOfDay");
|
EXPECT_STREQ(timclk->get_name() , "GetTimeOfDay - CLOCK_REALTIME");
|
||||||
|
|
||||||
gettimeofday(&res, NULL);
|
gettimeofday(&res, NULL);
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ TEST_F(GetTimeOfDayClockTest, ClockSimRatio) {
|
|||||||
|
|
||||||
long long tim_curr;
|
long long tim_curr;
|
||||||
double tic_ratio, tic_val;
|
double tic_ratio, tic_val;
|
||||||
Trick::GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
|
Trick::GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
|
||||||
|
|
||||||
tic_val = 100000;
|
tic_val = 100000;
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ TEST_F(GetTimeOfDayClockTest, ClockRTRatio) {
|
|||||||
long long tim_curr, tim_diff;
|
long long tim_curr, tim_diff;
|
||||||
double tic_ratio;
|
double tic_ratio;
|
||||||
int rt_ratio;
|
int rt_ratio;
|
||||||
Trick::GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
|
Trick::GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
|
||||||
|
|
||||||
rt_ratio = 6.0;
|
rt_ratio = 6.0;
|
||||||
ASSERT_EQ(timclk->sim_tic_ratio, 1);
|
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.");
|
//"The system clock shall provide the ability to spin (wait) until a specified time is reached.");
|
||||||
|
|
||||||
long long tim_curr, spin_time;
|
long long tim_curr, spin_time;
|
||||||
Trick:: GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
|
Trick:: GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
|
||||||
|
|
||||||
spin_time = 100000;
|
spin_time = 100000;
|
||||||
|
|
||||||
@ -126,7 +127,7 @@ TEST_F(GetTimeOfDayClockTest, ReferenceTime) {
|
|||||||
//"The system clock shall provide the ability to set a reference time.");
|
//"The system clock shall provide the ability to set a reference time.");
|
||||||
|
|
||||||
long long tic_adjust;
|
long long tic_adjust;
|
||||||
Trick:: GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
|
Trick:: GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
|
||||||
|
|
||||||
timclk->clock_init();
|
timclk->clock_init();
|
||||||
|
|
||||||
@ -148,7 +149,7 @@ TEST_F(GetTimeOfDayClockTest, ClockSync) {
|
|||||||
|
|
||||||
double align_tics_mult;
|
double align_tics_mult;
|
||||||
int clock_unit;
|
int clock_unit;
|
||||||
Trick::GetTimeOfDayClock * timclk = new GetTimeOfDayClock;
|
Trick::GetTimeOfDayClock * timclk = new Trick::GetTimeOfDayClock;
|
||||||
|
|
||||||
align_tics_mult = 1.5;
|
align_tics_mult = 1.5;
|
||||||
clock_unit = int((TICS_PER_SEC * align_tics_mult) /
|
clock_unit = int((TICS_PER_SEC * align_tics_mult) /
|
||||||
@ -161,4 +162,3 @@ TEST_F(GetTimeOfDayClockTest, ClockSync) {
|
|||||||
delete timclk;
|
delete timclk;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -10,25 +10,30 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.common
|
|||||||
# Flags passed to the preprocessor.
|
# Flags passed to the preprocessor.
|
||||||
TRICK_CPPFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -DGTEST_HAS_TR1_TUPLE=0
|
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
|
GTEST_LIBS = ${GTEST_HOME}/lib/libgtest.a ${GTEST_HOME}/lib/libgtest_main.a
|
||||||
TRICK_EXEC_LINK_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
|
# All tests produced by this Makefile. Remember to add new tests you
|
||||||
# created to the list.
|
# created to the list.
|
||||||
TESTS = TPROCTEClock_test BC635Clock_test
|
TESTS = TPROCTEClock_test BC635Clock_test GetTimeOfDayClock_test
|
||||||
|
|
||||||
#OTHER_OBJECTS = ../../include/object_${TRICK_HOST_CPU}/io_JobData.o \
|
|
||||||
# ../../include/object_${TRICK_HOST_CPU}/io_SimObject.o
|
|
||||||
|
|
||||||
# House-keeping build targets.
|
# House-keeping build targets.
|
||||||
|
|
||||||
all : $(TESTS)
|
all : $(TESTS)
|
||||||
|
|
||||||
test: $(TESTS)
|
test: $(TESTS)
|
||||||
#./GetTimeOfDayClock_test --gtest_output=xml:${TRICK_HOME}/trick_test/GetTimeOfDayClock.xml
|
./GetTimeOfDayClock_test --gtest_output=xml:${TRICK_HOME}/trick_test/GetTimeOfDayClock.xml
|
||||||
#./TPROCTEClock_test --gtest_output=xml:${TRICK_HOME}/trick_test/TPROCTEClock.xml
|
./TPROCTEClock_test --gtest_output=xml:${TRICK_HOME}/trick_test/TPROCTEClock.xml
|
||||||
#./BC635Clock_test --gtest_output=xml:${TRICK_HOME}/trick_test/BC635Clock.xml
|
./BC635Clock_test --gtest_output=xml:${TRICK_HOME}/trick_test/BC635Clock.xml
|
||||||
|
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
rm -f $(TESTS) *.o
|
rm -f $(TESTS) *.o
|
||||||
@ -36,18 +41,18 @@ clean :
|
|||||||
GetTimeOfDayClock_test.o : GetTimeOfDayClock_test.cpp
|
GetTimeOfDayClock_test.o : GetTimeOfDayClock_test.cpp
|
||||||
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c $<
|
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c $<
|
||||||
|
|
||||||
GetTimeOfDayClock_test : GetTimeOfDayClock_test.o
|
GetTimeOfDayClock_test : ${GETTIMEOFDAY_CLOCK_OBJECTS}
|
||||||
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ $(OTHER_OBJECTS) $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS)
|
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ ${GTEST_LIBS}
|
||||||
|
|
||||||
TPROCTEClock_test.o : TPROCTEClock_test.cpp
|
TPROCTEClock_test.o : TPROCTEClock_test.cpp
|
||||||
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c $<
|
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c $<
|
||||||
|
|
||||||
TPROCTEClock_test : TPROCTEClock_test.o
|
TPROCTEClock_test : ${TPROCTE_CLOCK_OBJECTS}
|
||||||
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ $(OTHER_OBJECTS) $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS)
|
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ ${GTEST_LIBS}
|
||||||
|
|
||||||
BC635Clock_test.o : BC635Clock_test.cpp
|
BC635Clock_test.o : BC635Clock_test.cpp
|
||||||
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c $<
|
$(TRICK_CPPC) $(TRICK_CPPFLAGS) -c $<
|
||||||
|
|
||||||
BC635Clock_test : BC635Clock_test.o
|
BC635Clock_test : ${BC635_CLOCK_OBJECTS}
|
||||||
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ $(OTHER_OBJECTS) $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS)
|
$(TRICK_LD) $(TRICK_LDFLAGS) -o $@ $^ ${GTEST_LIBS}
|
||||||
|
|
||||||
|
@ -23,9 +23,10 @@
|
|||||||
#include "trick/TPROCTEClock.hh"
|
#include "trick/TPROCTEClock.hh"
|
||||||
#include "trick/BC635Clock.hh"
|
#include "trick/BC635Clock.hh"
|
||||||
#include "trick/JobData.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 {
|
class TPROCTEClockTest : public ::testing::Test {
|
||||||
|
|
||||||
@ -44,7 +45,6 @@ class TPROCTEClockTest : public ::testing::Test {
|
|||||||
|
|
||||||
/* Ensure clock initializes correctly */
|
/* Ensure clock initializes correctly */
|
||||||
TEST_F(TPROCTEClockTest, Initialize) {
|
TEST_F(TPROCTEClockTest, Initialize) {
|
||||||
//req.add_requirement("TPROCTE_clock");
|
|
||||||
//"The TPROCTE clock shall initialize reference time of 0, and all ratios set to 1.");
|
//"The TPROCTE clock shall initialize reference time of 0, and all ratios set to 1.");
|
||||||
|
|
||||||
/* General expected clock initialization */
|
/* General expected clock initialization */
|
||||||
@ -60,7 +60,6 @@ TEST_F(TPROCTEClockTest, Initialize) {
|
|||||||
/* Run tests for when no hardware is available */
|
/* Run tests for when no hardware is available */
|
||||||
#ifndef _TPRO_CTE
|
#ifndef _TPRO_CTE
|
||||||
TEST_F(TPROCTEClockTest, NoHardware) {
|
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");
|
//"The TPROCTE clock shall display error messages when attempting to use its functions with no hardware");
|
||||||
|
|
||||||
long long req_time = rand();
|
long long req_time = rand();
|
||||||
@ -83,7 +82,6 @@ TEST_F(TPROCTEClockTest, NoHardware) {
|
|||||||
|
|
||||||
/* Ensure generic clock functions work properly */
|
/* Ensure generic clock functions work properly */
|
||||||
TEST_F(TPROCTEClockTest, TestRefTimes) {
|
TEST_F(TPROCTEClockTest, TestRefTimes) {
|
||||||
//req.add_requirement("TPROCTE_clock");
|
|
||||||
//"The TPROCTE clock shall provide the ability to adjust the reference time");
|
//"The TPROCTE clock shall provide the ability to adjust the reference time");
|
||||||
|
|
||||||
long long secs_remainder;
|
long long secs_remainder;
|
||||||
@ -98,5 +96,4 @@ TEST_F(TPROCTEClockTest, TestRefTimes) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user