From a3c73b621bab138be434eae5aa58bd4373372dd6 Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Wed, 25 Mar 2020 18:05:59 +0100 Subject: [PATCH 1/8] Create jenkins-pipeline --- jenkins-pipeline | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 jenkins-pipeline diff --git a/jenkins-pipeline b/jenkins-pipeline new file mode 100644 index 0000000..59d9ff9 --- /dev/null +++ b/jenkins-pipeline @@ -0,0 +1,2 @@ +library 'continuous_integration_pipeline' +ciPipeline("") From a7c94f0044718d9c10ced387975af5f719196bd3 Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Thu, 16 Apr 2020 10:15:04 +0200 Subject: [PATCH 2/8] Simplify tolerances --- any_worker/test/RateTest.cpp | 103 +++++++++++++++++------------------ 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/any_worker/test/RateTest.cpp b/any_worker/test/RateTest.cpp index 597f818..fc3b638 100644 --- a/any_worker/test/RateTest.cpp +++ b/any_worker/test/RateTest.cpp @@ -8,12 +8,9 @@ // any worker #include "any_worker/Rate.hpp" -// Local and build server tolerances. -#define RATE_TEST_TOL_LOCAL 0.001 -#define RATE_TEST_TOL_BUILD_SERVER 0.007 - -// Use the build server tolerance. -#define RATE_TEST_TOL RATE_TEST_TOL_BUILD_SERVER +// time/time +#define RATE_TEST_TOL 0.05 // 5% +#define RATE_TEST_TOL_ABS 0.001 // 1ms /*! * Simulate some processing which takes a certain amount of time. @@ -23,6 +20,8 @@ void doSomething(const double duration) { std::this_thread::sleep_for(std::chrono::nanoseconds(static_cast(1e9 * duration))); } +#define EXPECT_NEAR_TEST_TOL(A, B) EXPECT_NEAR((A), (B), (RATE_TEST_TOL) * (B) + RATE_TEST_TOL_ABS) + TEST(RateTest, Initialization) { // NOLINT const std::string name = "Test"; const double timeStep = 0.1; @@ -61,13 +60,13 @@ TEST(RateTest, Reset) { // NOLINT } TEST(RateTest, SleepWithEnforceRate) { // NOLINT - const double timeStep = 0.1; + const double timeStep = 0.01; any_worker::Rate rate("Test", timeStep); rate.getOptions().enforceRate_ = true; timespec start{}; timespec end{}; - const double processingTime = 0.05; + const double processingTime = 0.005; std::vector processingTimes; std::vector summedStepTimes; @@ -76,7 +75,7 @@ TEST(RateTest, SleepWithEnforceRate) { // NOLINT rate.reset(); rate.sleep(); clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), timeStep, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), timeStep); // Test sleep() with processing additionally. clock_gettime(CLOCK_MONOTONIC, &start); @@ -84,63 +83,63 @@ TEST(RateTest, SleepWithEnforceRate) { // NOLINT doSomething(processingTime); rate.sleep(); clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), timeStep, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), timeStep); // Test sleep() with where one step takes too long, recovery within one step. - processingTimes = {0.02, 0.02, 0.15, 0.02, 0.02}; - summedStepTimes = {0.0, 0.1, 0.2, 0.35, 0.4, 0.5}; + processingTimes = {0.002, 0.002, 0.015, 0.002, 0.002}; + summedStepTimes = {0.0, 0.01, 0.02, 0.035, 0.04, 0.05}; rate.reset(); clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); // Test sleep() with where one step takes too long, recovery within two steps. - processingTimes = {0.02, 0.02, 0.19, 0.02, 0.02, 0.02}; - summedStepTimes = {0.0, 0.1, 0.2, 0.39, 0.41, 0.5, 0.6}; + processingTimes = {0.002, 0.002, 0.019, 0.002, 0.002, 0.002}; + summedStepTimes = {0.00, 0.01, 0.02, 0.039, 0.041, 0.05, 0.06}; rate.reset(); clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); // Test sleep() with where two steps take too long, recovery within one step. - processingTimes = {0.02, 0.02, 0.12, 0.12, 0.02, 0.02}; - summedStepTimes = {0.0, 0.1, 0.2, 0.32, 0.44, 0.5, 0.6}; + processingTimes = {0.002, 0.002, 0.012, 0.012, 0.002, 0.002}; + summedStepTimes = {0.00, 0.01, 0.02, 0.032, 0.044, 0.05, 0.06}; rate.reset(); clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); // Test sleep() with where two steps take too long, recovery within two steps. - processingTimes = {0.02, 0.02, 0.12, 0.12, 0.08, 0.02, 0.02}; - summedStepTimes = {0.0, 0.1, 0.2, 0.32, 0.44, 0.52, 0.6, 0.7}; + processingTimes = {0.002, 0.002, 0.012, 0.012, 0.008, 0.002, 0.002}; + summedStepTimes = {0.00, 0.01, 0.02, 0.032, 0.044, 0.052, 0.06, 0.07}; rate.reset(); clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); } TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT @@ -159,7 +158,7 @@ TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT rate.reset(); rate.sleep(); clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), timeStep, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), timeStep); // Test sleep() with processing. clock_gettime(CLOCK_MONOTONIC, &start); @@ -167,7 +166,7 @@ TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT doSomething(processingTime); rate.sleep(); clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), timeStep, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), timeStep); // Test sleep() with where one step takes too long. processingTimes = {0.02, 0.02, 0.15, 0.02, 0.02}; @@ -176,12 +175,12 @@ TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); // Test sleep() with where two steps take too long. processingTimes = {0.02, 0.02, 0.12, 0.12, 0.02, 0.02}; @@ -190,12 +189,12 @@ TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 4.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 4.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); } TEST(RateTest, WarningsAndErrors) { // NOLINT @@ -227,8 +226,8 @@ TEST(RateTest, StatisticsWithEnforceRate) { // NOLINT rate.sleep(); EXPECT_EQ(rate.getNumTimeSteps(), 1u); - EXPECT_NEAR(rate.getAwakeTime(), processingTime, 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), processingTime, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), processingTime); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), processingTime); EXPECT_TRUE(std::isnan(rate.getAwakeTimeStdDev())); // Test 10 time steps with similar processing times. @@ -240,8 +239,8 @@ TEST(RateTest, StatisticsWithEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), numTimeSteps); - EXPECT_NEAR(rate.getAwakeTime(), processingTime, 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), processingTime, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), processingTime); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), processingTime); EXPECT_LE(rate.getAwakeTimeStdDev(), RATE_TEST_TOL); EXPECT_FALSE(rate.getAwakeTimeStdDev() == 0.0); // If it is 0.0 something is fishy. @@ -254,9 +253,9 @@ TEST(RateTest, StatisticsWithEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), processingTimes.size()); - EXPECT_NEAR(rate.getAwakeTime(), *processingTimes.rbegin(), 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), 0.05, RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeStdDev(), 0.02, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), *processingTimes.rbegin()); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), 0.05); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeStdDev(), 0.02); // Test again with time step violation. rate.getOptions().timeStep_ = 0.035; @@ -267,9 +266,9 @@ TEST(RateTest, StatisticsWithEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), processingTimes.size()); - EXPECT_NEAR(rate.getAwakeTime(), *processingTimes.rbegin(), 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), 0.05, RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeStdDev(), 0.02, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), *processingTimes.rbegin()); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), 0.05); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeStdDev(), 0.02); } TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT @@ -284,8 +283,8 @@ TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT rate.sleep(); EXPECT_EQ(rate.getNumTimeSteps(), 1u); - EXPECT_NEAR(rate.getAwakeTime(), processingTime, 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), processingTime, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), processingTime); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), processingTime); EXPECT_TRUE(std::isnan(rate.getAwakeTimeStdDev())); // Test 10 time steps with similar processing times. @@ -297,8 +296,8 @@ TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), numTimeSteps); - EXPECT_NEAR(rate.getAwakeTime(), processingTime, 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), processingTime, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), processingTime); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), processingTime); EXPECT_LE(rate.getAwakeTimeStdDev(), RATE_TEST_TOL); EXPECT_FALSE(rate.getAwakeTimeStdDev() == 0.0); // If it is 0.0 something is fishy. @@ -311,9 +310,9 @@ TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), processingTimes.size()); - EXPECT_NEAR(rate.getAwakeTime(), *processingTimes.rbegin(), 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), 0.05, RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeStdDev(), 0.02, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), *processingTimes.rbegin()); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), 0.05); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeStdDev(), 0.02); // Test again with time step violation. rate.getOptions().timeStep_ = 0.035; @@ -324,7 +323,7 @@ TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), processingTimes.size()); - EXPECT_NEAR(rate.getAwakeTime(), *processingTimes.rbegin(), 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), 0.05, RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeStdDev(), 0.02, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), *processingTimes.rbegin()); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), 0.05); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeStdDev(), 0.02); } From d29bd0ca30bf0917e6331ea862762bbec2d7703b Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Tue, 21 Apr 2020 10:08:40 +0200 Subject: [PATCH 3/8] Disable Statistics test --- any_worker/test/RateTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/any_worker/test/RateTest.cpp b/any_worker/test/RateTest.cpp index 597f818..ef282ee 100644 --- a/any_worker/test/RateTest.cpp +++ b/any_worker/test/RateTest.cpp @@ -215,7 +215,7 @@ TEST(RateTest, WarningsAndErrors) { // NOLINT EXPECT_EQ(rate.getNumErrors(), 1u); } -TEST(RateTest, StatisticsWithEnforceRate) { // NOLINT +TEST(RateTest, DISABLED_StatisticsWithEnforceRate) { // NOLINT const double timeStep = 0.1; any_worker::Rate rate("Test", timeStep); rate.getOptions().enforceRate_ = true; From 15b5328ba2a1fcb58457a377aa94fb236d7c6d44 Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Thu, 23 Apr 2020 09:52:20 +0200 Subject: [PATCH 4/8] Disable unreliable tests --- any_worker/test/RateTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/any_worker/test/RateTest.cpp b/any_worker/test/RateTest.cpp index 6c34e11..734cdb1 100644 --- a/any_worker/test/RateTest.cpp +++ b/any_worker/test/RateTest.cpp @@ -59,7 +59,7 @@ TEST(RateTest, Reset) { // NOLINT EXPECT_TRUE(std::isnan(rate.getAwakeTimeStdDev())); } -TEST(RateTest, SleepWithEnforceRate) { // NOLINT +TEST(RateTest, DISABLED_SleepWithEnforceRate) { // NOLINT const double timeStep = 0.01; any_worker::Rate rate("Test", timeStep); rate.getOptions().enforceRate_ = true; @@ -142,7 +142,7 @@ TEST(RateTest, SleepWithEnforceRate) { // NOLINT EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); } -TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT +TEST(RateTest, DISABLED_SleepWithoutEnforceRate) { // NOLINT const double timeStep = 0.1; any_worker::Rate rate("Test", timeStep); rate.getOptions().enforceRate_ = false; @@ -271,7 +271,7 @@ TEST(RateTest, DISABLED_StatisticsWithEnforceRate) { // NOLINT EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeStdDev(), 0.02); } -TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT +TEST(RateTest, DISABLED_StatisticsWithoutEnforceRate) { // NOLINT const double timeStep = 0.1; any_worker::Rate rate("Test", timeStep); rate.getOptions().enforceRate_ = false; From 891be45b0d8b23ed1fb1e0fa7269455a5f5375ef Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Wed, 25 Mar 2020 18:05:59 +0100 Subject: [PATCH 5/8] Create jenkins-pipeline --- jenkins-pipeline | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 jenkins-pipeline diff --git a/jenkins-pipeline b/jenkins-pipeline new file mode 100644 index 0000000..59d9ff9 --- /dev/null +++ b/jenkins-pipeline @@ -0,0 +1,2 @@ +library 'continuous_integration_pipeline' +ciPipeline("") From 43652c3dfe8ff66975d6f45160103887665aa247 Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Tue, 21 Apr 2020 10:08:40 +0200 Subject: [PATCH 6/8] Disable Statistics test --- any_worker/test/RateTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/any_worker/test/RateTest.cpp b/any_worker/test/RateTest.cpp index 597f818..ef282ee 100644 --- a/any_worker/test/RateTest.cpp +++ b/any_worker/test/RateTest.cpp @@ -215,7 +215,7 @@ TEST(RateTest, WarningsAndErrors) { // NOLINT EXPECT_EQ(rate.getNumErrors(), 1u); } -TEST(RateTest, StatisticsWithEnforceRate) { // NOLINT +TEST(RateTest, DISABLED_StatisticsWithEnforceRate) { // NOLINT const double timeStep = 0.1; any_worker::Rate rate("Test", timeStep); rate.getOptions().enforceRate_ = true; From 073d298e1c9272052896d242d600d28f030796b6 Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Thu, 16 Apr 2020 10:15:04 +0200 Subject: [PATCH 7/8] Simplify tolerances --- any_worker/test/RateTest.cpp | 103 +++++++++++++++++------------------ 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/any_worker/test/RateTest.cpp b/any_worker/test/RateTest.cpp index ef282ee..6c34e11 100644 --- a/any_worker/test/RateTest.cpp +++ b/any_worker/test/RateTest.cpp @@ -8,12 +8,9 @@ // any worker #include "any_worker/Rate.hpp" -// Local and build server tolerances. -#define RATE_TEST_TOL_LOCAL 0.001 -#define RATE_TEST_TOL_BUILD_SERVER 0.007 - -// Use the build server tolerance. -#define RATE_TEST_TOL RATE_TEST_TOL_BUILD_SERVER +// time/time +#define RATE_TEST_TOL 0.05 // 5% +#define RATE_TEST_TOL_ABS 0.001 // 1ms /*! * Simulate some processing which takes a certain amount of time. @@ -23,6 +20,8 @@ void doSomething(const double duration) { std::this_thread::sleep_for(std::chrono::nanoseconds(static_cast(1e9 * duration))); } +#define EXPECT_NEAR_TEST_TOL(A, B) EXPECT_NEAR((A), (B), (RATE_TEST_TOL) * (B) + RATE_TEST_TOL_ABS) + TEST(RateTest, Initialization) { // NOLINT const std::string name = "Test"; const double timeStep = 0.1; @@ -61,13 +60,13 @@ TEST(RateTest, Reset) { // NOLINT } TEST(RateTest, SleepWithEnforceRate) { // NOLINT - const double timeStep = 0.1; + const double timeStep = 0.01; any_worker::Rate rate("Test", timeStep); rate.getOptions().enforceRate_ = true; timespec start{}; timespec end{}; - const double processingTime = 0.05; + const double processingTime = 0.005; std::vector processingTimes; std::vector summedStepTimes; @@ -76,7 +75,7 @@ TEST(RateTest, SleepWithEnforceRate) { // NOLINT rate.reset(); rate.sleep(); clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), timeStep, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), timeStep); // Test sleep() with processing additionally. clock_gettime(CLOCK_MONOTONIC, &start); @@ -84,63 +83,63 @@ TEST(RateTest, SleepWithEnforceRate) { // NOLINT doSomething(processingTime); rate.sleep(); clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), timeStep, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), timeStep); // Test sleep() with where one step takes too long, recovery within one step. - processingTimes = {0.02, 0.02, 0.15, 0.02, 0.02}; - summedStepTimes = {0.0, 0.1, 0.2, 0.35, 0.4, 0.5}; + processingTimes = {0.002, 0.002, 0.015, 0.002, 0.002}; + summedStepTimes = {0.0, 0.01, 0.02, 0.035, 0.04, 0.05}; rate.reset(); clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); // Test sleep() with where one step takes too long, recovery within two steps. - processingTimes = {0.02, 0.02, 0.19, 0.02, 0.02, 0.02}; - summedStepTimes = {0.0, 0.1, 0.2, 0.39, 0.41, 0.5, 0.6}; + processingTimes = {0.002, 0.002, 0.019, 0.002, 0.002, 0.002}; + summedStepTimes = {0.00, 0.01, 0.02, 0.039, 0.041, 0.05, 0.06}; rate.reset(); clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); // Test sleep() with where two steps take too long, recovery within one step. - processingTimes = {0.02, 0.02, 0.12, 0.12, 0.02, 0.02}; - summedStepTimes = {0.0, 0.1, 0.2, 0.32, 0.44, 0.5, 0.6}; + processingTimes = {0.002, 0.002, 0.012, 0.012, 0.002, 0.002}; + summedStepTimes = {0.00, 0.01, 0.02, 0.032, 0.044, 0.05, 0.06}; rate.reset(); clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); // Test sleep() with where two steps take too long, recovery within two steps. - processingTimes = {0.02, 0.02, 0.12, 0.12, 0.08, 0.02, 0.02}; - summedStepTimes = {0.0, 0.1, 0.2, 0.32, 0.44, 0.52, 0.6, 0.7}; + processingTimes = {0.002, 0.002, 0.012, 0.012, 0.008, 0.002, 0.002}; + summedStepTimes = {0.00, 0.01, 0.02, 0.032, 0.044, 0.052, 0.06, 0.07}; rate.reset(); clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); } TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT @@ -159,7 +158,7 @@ TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT rate.reset(); rate.sleep(); clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), timeStep, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), timeStep); // Test sleep() with processing. clock_gettime(CLOCK_MONOTONIC, &start); @@ -167,7 +166,7 @@ TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT doSomething(processingTime); rate.sleep(); clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), timeStep, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), timeStep); // Test sleep() with where one step takes too long. processingTimes = {0.02, 0.02, 0.15, 0.02, 0.02}; @@ -176,12 +175,12 @@ TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 2.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); // Test sleep() with where two steps take too long. processingTimes = {0.02, 0.02, 0.12, 0.12, 0.02, 0.02}; @@ -190,12 +189,12 @@ TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT clock_gettime(CLOCK_MONOTONIC, &start); for (unsigned int i = 0; i < processingTimes.size(); i++) { clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[i], 4.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[i]); doSomething(processingTimes[i]); rate.sleep(); } clock_gettime(CLOCK_MONOTONIC, &end); - EXPECT_NEAR(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()], 4.0 * RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); } TEST(RateTest, WarningsAndErrors) { // NOLINT @@ -227,8 +226,8 @@ TEST(RateTest, DISABLED_StatisticsWithEnforceRate) { // NOLINT rate.sleep(); EXPECT_EQ(rate.getNumTimeSteps(), 1u); - EXPECT_NEAR(rate.getAwakeTime(), processingTime, 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), processingTime, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), processingTime); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), processingTime); EXPECT_TRUE(std::isnan(rate.getAwakeTimeStdDev())); // Test 10 time steps with similar processing times. @@ -240,8 +239,8 @@ TEST(RateTest, DISABLED_StatisticsWithEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), numTimeSteps); - EXPECT_NEAR(rate.getAwakeTime(), processingTime, 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), processingTime, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), processingTime); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), processingTime); EXPECT_LE(rate.getAwakeTimeStdDev(), RATE_TEST_TOL); EXPECT_FALSE(rate.getAwakeTimeStdDev() == 0.0); // If it is 0.0 something is fishy. @@ -254,9 +253,9 @@ TEST(RateTest, DISABLED_StatisticsWithEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), processingTimes.size()); - EXPECT_NEAR(rate.getAwakeTime(), *processingTimes.rbegin(), 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), 0.05, RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeStdDev(), 0.02, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), *processingTimes.rbegin()); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), 0.05); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeStdDev(), 0.02); // Test again with time step violation. rate.getOptions().timeStep_ = 0.035; @@ -267,9 +266,9 @@ TEST(RateTest, DISABLED_StatisticsWithEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), processingTimes.size()); - EXPECT_NEAR(rate.getAwakeTime(), *processingTimes.rbegin(), 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), 0.05, RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeStdDev(), 0.02, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), *processingTimes.rbegin()); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), 0.05); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeStdDev(), 0.02); } TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT @@ -284,8 +283,8 @@ TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT rate.sleep(); EXPECT_EQ(rate.getNumTimeSteps(), 1u); - EXPECT_NEAR(rate.getAwakeTime(), processingTime, 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), processingTime, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), processingTime); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), processingTime); EXPECT_TRUE(std::isnan(rate.getAwakeTimeStdDev())); // Test 10 time steps with similar processing times. @@ -297,8 +296,8 @@ TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), numTimeSteps); - EXPECT_NEAR(rate.getAwakeTime(), processingTime, 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), processingTime, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), processingTime); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), processingTime); EXPECT_LE(rate.getAwakeTimeStdDev(), RATE_TEST_TOL); EXPECT_FALSE(rate.getAwakeTimeStdDev() == 0.0); // If it is 0.0 something is fishy. @@ -311,9 +310,9 @@ TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), processingTimes.size()); - EXPECT_NEAR(rate.getAwakeTime(), *processingTimes.rbegin(), 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), 0.05, RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeStdDev(), 0.02, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), *processingTimes.rbegin()); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), 0.05); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeStdDev(), 0.02); // Test again with time step violation. rate.getOptions().timeStep_ = 0.035; @@ -324,7 +323,7 @@ TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT } EXPECT_EQ(rate.getNumTimeSteps(), processingTimes.size()); - EXPECT_NEAR(rate.getAwakeTime(), *processingTimes.rbegin(), 2.0 * RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeMean(), 0.05, RATE_TEST_TOL); - EXPECT_NEAR(rate.getAwakeTimeStdDev(), 0.02, RATE_TEST_TOL); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTime(), *processingTimes.rbegin()); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeMean(), 0.05); + EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeStdDev(), 0.02); } From 4f256fe1b5f72c4a4a3085182edc1d4c5c7e38ae Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Thu, 23 Apr 2020 09:52:20 +0200 Subject: [PATCH 8/8] Disable unreliable tests --- any_worker/test/RateTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/any_worker/test/RateTest.cpp b/any_worker/test/RateTest.cpp index 6c34e11..734cdb1 100644 --- a/any_worker/test/RateTest.cpp +++ b/any_worker/test/RateTest.cpp @@ -59,7 +59,7 @@ TEST(RateTest, Reset) { // NOLINT EXPECT_TRUE(std::isnan(rate.getAwakeTimeStdDev())); } -TEST(RateTest, SleepWithEnforceRate) { // NOLINT +TEST(RateTest, DISABLED_SleepWithEnforceRate) { // NOLINT const double timeStep = 0.01; any_worker::Rate rate("Test", timeStep); rate.getOptions().enforceRate_ = true; @@ -142,7 +142,7 @@ TEST(RateTest, SleepWithEnforceRate) { // NOLINT EXPECT_NEAR_TEST_TOL(any_worker::Rate::GetDuration(start, end), summedStepTimes[processingTimes.size()]); } -TEST(RateTest, SleepWithoutEnforceRate) { // NOLINT +TEST(RateTest, DISABLED_SleepWithoutEnforceRate) { // NOLINT const double timeStep = 0.1; any_worker::Rate rate("Test", timeStep); rate.getOptions().enforceRate_ = false; @@ -271,7 +271,7 @@ TEST(RateTest, DISABLED_StatisticsWithEnforceRate) { // NOLINT EXPECT_NEAR_TEST_TOL(rate.getAwakeTimeStdDev(), 0.02); } -TEST(RateTest, StatisticsWithoutEnforceRate) { // NOLINT +TEST(RateTest, DISABLED_StatisticsWithoutEnforceRate) { // NOLINT const double timeStep = 0.1; any_worker::Rate rate("Test", timeStep); rate.getOptions().enforceRate_ = false;