fboss2: add unit tests for CmdUtilsCommon helpers#1295
Open
atulya-singh wants to merge 1 commit into
Open
Conversation
CmdUtilsCommon.cpp had no unit-test coverage. Add CmdUtilsCommonTest.cpp covering the pure/deterministic helpers: - formatBandwidth: N/A boundary, unit scaling (bps/Kbps/Mbps/Gbps), and its deliberate truncate-don't-round behavior. - splitFractionalSecondsFromTimer: second/millisecond split. - getEpochFromDuration: zero duration and millisecond subtraction. - parseTimeToTimeStamp: structural date-time + fractional format. Wire the new test into both the BUCK framework_test target and the CMake fboss2_framework_test target.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pre-submission checklist
pip install -r requirements-dev.txt && pre-commit installpre-commit runSummary
fboss/cli/fboss2/utils/CmdUtilsCommon.cpphad no unit-test coverage. This PR addsCmdUtilsCommonTest.cppcovering the pure/deterministic helpers in that file:formatBandwidth— theN/Aboundary (< 1byte/s), unit scaling acrossbps/Kbps/Mbps/Gbps, and its deliberate truncate-rather-than-round behavior.splitFractionalSecondsFromTimer— the second/millisecond split.getEpochFromDuration— zero duration returns ~now, and a duration is subtracted in milliseconds.parseTimeToTimeStamp— structural validation of theYYYY-MM-DD HH:MM:SS.fffformat (timezone-independent, using a fraction ≥ 100 ms so the assertion is stable).The new test is wired into both build systems: the BUCK
framework_testtarget (fboss/cli/fboss2/test/BUCK) and the CMakefboss2_framework_testtarget (cmake/CliFboss2Test.cmake).Test Plan
pre-commit run --files fboss/cli/fboss2/test/CmdUtilsCommonTest.cpp fboss/cli/fboss2/test/BUCK cmake/CliFboss2Test.cmake->clang-format ... Passed, all hooks pass.main:formatBandwidth(0.5f) == "N/A",formatBandwidth(125000000.0f) == "1Gbps", etc.splitFractionalSecondsFromTimer(6475) == {6, 475}.getEpochFromDuration(10000)is ~10 s beforegetEpochFromDuration(0).parseTimeToTimeStamp(1635292806475)matches^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.475.Note: assertions intentionally avoid the sub-100 ms millisecond zero-padding case so this PR stays green on
mainindependently; that case is covered by the related zero-padding fix in #1292.