diff --git a/diagnostic_updater/diagnostic_updater/_update_functions.py b/diagnostic_updater/diagnostic_updater/_update_functions.py index 0d6dc6be..fbf89285 100644 --- a/diagnostic_updater/diagnostic_updater/_update_functions.py +++ b/diagnostic_updater/diagnostic_updater/_update_functions.py @@ -228,10 +228,10 @@ def run(self, stat): stat.summary(DiagnosticStatus.ERROR, 'Timestamps too far in past seen.') self.late_count += 1 - if self.zero_seen: - stat.summary(DiagnosticStatus.ERROR, - 'Zero timestamp seen.') - self.zero_count += 1 + if self.zero_seen: + stat.summary(DiagnosticStatus.ERROR, + 'Zero timestamp seen.') + self.zero_count += 1 stat.add('Earliest timestamp delay:', '%f' % self.min_delta) stat.add('Latest timestamp delay:', '%f' % self.max_delta) diff --git a/diagnostic_updater/include/diagnostic_updater/update_functions.hpp b/diagnostic_updater/include/diagnostic_updater/update_functions.hpp index 0676c8ea..db247b58 100644 --- a/diagnostic_updater/include/diagnostic_updater/update_functions.hpp +++ b/diagnostic_updater/include/diagnostic_updater/update_functions.hpp @@ -370,11 +370,11 @@ class TimeStampStatus : public DiagnosticTask stat.summary(2, "Timestamps too far in past seen."); late_count_++; } + } - if (zero_seen_) { - stat.summary(2, "Zero timestamp seen."); - zero_count_++; - } + if (zero_seen_) { + stat.summary(2, "Zero timestamp seen."); + zero_count_++; } stat.addf("Earliest timestamp delay:", "%f", min_delta_); diff --git a/diagnostic_updater/test/diagnostic_updater_test.cpp b/diagnostic_updater/test/diagnostic_updater_test.cpp index 0eae2d04..d289de3c 100644 --- a/diagnostic_updater/test/diagnostic_updater_test.cpp +++ b/diagnostic_updater/test/diagnostic_updater_test.cpp @@ -307,3 +307,18 @@ TEST(DiagnosticUpdater, testTimeStampStatus) { EXPECT_STREQ("Timestamp Status", ts.getName().c_str()) << "Name should be \"Timestamp Status\""; } + +TEST(DiagnosticUpdater, testTimeStampStatusZeroOnly) { + diagnostic_updater::TimeStampStatus ts( + diagnostic_updater::DefaultTimeStampStatusParam); + + diagnostic_updater::DiagnosticStatusWrapper stat[2]; + ts.tick(0.0); + ts.run(stat[0]); + ts.run(stat[1]); + + EXPECT_EQ(2, stat[0].level) << "zero timestamps alone should be reported as an error"; + EXPECT_STREQ("Zero timestamp seen.", stat[0].message.c_str()) << + "zero timestamps alone should not be reported as no data"; + EXPECT_EQ(1, stat[1].level) << "no data after zero timestamps should return a warning"; +} diff --git a/diagnostic_updater/test/diagnostic_updater_test.py b/diagnostic_updater/test/diagnostic_updater_test.py index 95975c1d..821cdeaf 100755 --- a/diagnostic_updater/test/diagnostic_updater_test.py +++ b/diagnostic_updater/test/diagnostic_updater_test.py @@ -177,6 +177,20 @@ def testTimeStampStatus(self): self.assertEqual('Timestamp Status', ts.getName(), 'Name should be Timestamp Status') + def testTimeStampStatusZeroOnly(self): + ts = TimeStampStatus() + + ts.tick(0.0) + stat = ts.run(DiagnosticStatusWrapper()) + self.assertEqual(DiagnosticStatus.ERROR, stat.level, + 'zero timestamps alone should be reported as an error') + self.assertEqual('Zero timestamp seen.', stat.message, + 'zero timestamps alone should not be reported as no data') + + stat = ts.run(DiagnosticStatusWrapper()) + self.assertEqual(DiagnosticStatus.WARN, stat.level, + 'no data after zero timestamps should return a warning') + @pytest.mark.launch_test def generate_test_description():