Loading prrt/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ add_subdirectory(proto) add_subdirectory(util) add_executable(sender sender.c) add_executable(receiver receiver.c ../tests/common.h) add_executable(receiver receiver.c) target_link_libraries(sender LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(receiver LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT}) prrt/util/time.c +11 −0 Original line number Diff line number Diff line Loading @@ -21,3 +21,14 @@ struct timespec abstime_from_now(uint32_t wait_time) { return deadline; } // < 0: a less than b (b is in the future) // > 0: a greater b (b is in the past) // == 0: a equal b int64_t PrrtTimestamp_cmp(prrtTimestamp_t a, prrtTimestamp_t b) { prrtTimestamp_t diff = (prrtTimestamp_t) (a - b); if (diff < TIMESTAMP_SPACE / 2) { return diff; } else { return ((int64_t)diff) - ((int64_t)(TIMESTAMP_SPACE) + 1); } } No newline at end of file prrt/util/time.h +2 −0 Original line number Diff line number Diff line #ifndef PRRT_TIME_H #define PRRT_TIME_H #include "../proto/types/packet.h" long long timedelta(struct timespec *t1, struct timespec *t2); struct timespec abstime_from_now(uint32_t wait_time); int64_t PrrtTimestamp_cmp(prrtTimestamp_t a, prrtTimestamp_t b); #endif //PRRT_TIME_H tests/CMakeLists.txt +1 −1 Original line number Diff line number Diff line add_subdirectory(lib/gtest-1.8.0) include_directories(SYSTEM ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) add_executable(prrtTests common.h bitmap_tests.cpp receptionTable_tests.cpp delivered_packet_table_tests.cpp bptree_tests.cpp PrrtBlock_tests.cpp) add_executable(prrtTests common.h util_tests.cpp bitmap_tests.cpp receptionTable_tests.cpp delivered_packet_table_tests.cpp bptree_tests.cpp PrrtBlock_tests.cpp) target_link_libraries(prrtTests LINK_PUBLIC gtest PRRT UTIL gtest_main) No newline at end of file tests/util_tests.cpp 0 → 100644 +33 −0 Original line number Diff line number Diff line #include "common.h" extern "C" { #include "prrt/util/time.h" } class UtilTests : public ::testing::Test { protected: virtual void SetUp() { } virtual void TearDown() { } }; TEST_F(UtilTests, Timestamps) { prrtTimestamp_t a = 5; prrtTimestamp_t b = 47; prrtTimestamp_t c = 4294967295; ASSERT_EQ(PrrtTimestamp_cmp(a,b), -42); ASSERT_EQ(PrrtTimestamp_cmp(b,a), 42); ASSERT_EQ(PrrtTimestamp_cmp(c,a), -6); ASSERT_EQ(PrrtTimestamp_cmp(a,c), 6); } No newline at end of file Loading
prrt/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ add_subdirectory(proto) add_subdirectory(util) add_executable(sender sender.c) add_executable(receiver receiver.c ../tests/common.h) add_executable(receiver receiver.c) target_link_libraries(sender LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(receiver LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT})
prrt/util/time.c +11 −0 Original line number Diff line number Diff line Loading @@ -21,3 +21,14 @@ struct timespec abstime_from_now(uint32_t wait_time) { return deadline; } // < 0: a less than b (b is in the future) // > 0: a greater b (b is in the past) // == 0: a equal b int64_t PrrtTimestamp_cmp(prrtTimestamp_t a, prrtTimestamp_t b) { prrtTimestamp_t diff = (prrtTimestamp_t) (a - b); if (diff < TIMESTAMP_SPACE / 2) { return diff; } else { return ((int64_t)diff) - ((int64_t)(TIMESTAMP_SPACE) + 1); } } No newline at end of file
prrt/util/time.h +2 −0 Original line number Diff line number Diff line #ifndef PRRT_TIME_H #define PRRT_TIME_H #include "../proto/types/packet.h" long long timedelta(struct timespec *t1, struct timespec *t2); struct timespec abstime_from_now(uint32_t wait_time); int64_t PrrtTimestamp_cmp(prrtTimestamp_t a, prrtTimestamp_t b); #endif //PRRT_TIME_H
tests/CMakeLists.txt +1 −1 Original line number Diff line number Diff line add_subdirectory(lib/gtest-1.8.0) include_directories(SYSTEM ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) add_executable(prrtTests common.h bitmap_tests.cpp receptionTable_tests.cpp delivered_packet_table_tests.cpp bptree_tests.cpp PrrtBlock_tests.cpp) add_executable(prrtTests common.h util_tests.cpp bitmap_tests.cpp receptionTable_tests.cpp delivered_packet_table_tests.cpp bptree_tests.cpp PrrtBlock_tests.cpp) target_link_libraries(prrtTests LINK_PUBLIC gtest PRRT UTIL gtest_main) No newline at end of file
tests/util_tests.cpp 0 → 100644 +33 −0 Original line number Diff line number Diff line #include "common.h" extern "C" { #include "prrt/util/time.h" } class UtilTests : public ::testing::Test { protected: virtual void SetUp() { } virtual void TearDown() { } }; TEST_F(UtilTests, Timestamps) { prrtTimestamp_t a = 5; prrtTimestamp_t b = 47; prrtTimestamp_t c = 4294967295; ASSERT_EQ(PrrtTimestamp_cmp(a,b), -42); ASSERT_EQ(PrrtTimestamp_cmp(b,a), 42); ASSERT_EQ(PrrtTimestamp_cmp(c,a), -6); ASSERT_EQ(PrrtTimestamp_cmp(a,c), 6); } No newline at end of file