-
Notifications
You must be signed in to change notification settings - Fork 123
Fix/logging snprintf negative time 4556 #4593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tarek-y-ismail
merged 10 commits into
canonical:main
from
DigraJatin:fix/logging-snprintf-negative-time-4556
Jan 9, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
549b3c4
fix : fixes incorrect logging of future timestamps
DigraJatin d972dc0
added unit tests for negative timestamp logging
DigraJatin 598d652
addressed code review comments
DigraJatin c9a57c1
pre-commit: apply automatic fixes
pre-commit-ci-lite[bot] 8fedcd4
fixed failing unit tests on CI
DigraJatin 90f7278
Merge branch 'fix/logging-snprintf-negative-time-4556' of https://git…
DigraJatin 0e35fab
pre-commit: apply automatic fixes
pre-commit-ci-lite[bot] 343fa3d
fix unit test for CI
DigraJatin 51386ca
Merge branch 'fix/logging-snprintf-negative-time-4556' of https://git…
DigraJatin 7084aee
Remove redundant `chrono_literals` use statement
tarek-y-ismail File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| list(APPEND UNIT_TEST_SOURCES | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/test_display_report.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/test_compositor_report.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/test_input_timestamp.cpp | ||
| ) | ||
|
|
||
| set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} PARENT_SCOPE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright © Canonical Ltd. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 or 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include <mir/logging/input_timestamp.h> | ||
|
|
||
| #include <gtest/gtest.h> | ||
| #include <gmock/gmock.h> | ||
| #include <chrono> | ||
| #include <string> | ||
|
|
||
| using namespace std::chrono; | ||
| using namespace std::chrono_literals; | ||
| using namespace testing; | ||
| namespace ml = mir::logging; | ||
|
|
||
| TEST(TimestampTest, past_time_is_correctly_formatted) | ||
| { | ||
| auto const past_event = steady_clock::now().time_since_epoch() - 500ms; | ||
|
|
||
| std::string out = ml::input_timestamp(past_event); | ||
|
|
||
| EXPECT_THAT(out, Not(HasSubstr(".-"))); | ||
| EXPECT_THAT(out, HasSubstr("500.0")); | ||
| EXPECT_THAT(out, HasSubstr("ms ago")); | ||
| } | ||
|
|
||
| TEST(TimestampTest, future_time_is_correctly_formatted) | ||
| { | ||
| auto const future_event = steady_clock::now().time_since_epoch() + 1000ms + 10us; | ||
|
|
||
| std::string out = ml::input_timestamp(future_event); | ||
|
|
||
| EXPECT_THAT(out, Not(HasSubstr(".-"))); | ||
| EXPECT_THAT(out, HasSubstr("in the future")); | ||
| EXPECT_THAT(out, HasSubstr("1000.0")); | ||
|
||
| EXPECT_THAT(out, HasSubstr("ms")); | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test checks for an exact substring '500.0' which may be fragile if the implementation changes decimal precision or formatting. Consider using a more flexible pattern or checking just for '500' and 'ms ago' separately to avoid false negatives.