Skip to content

Os UT: guard shadow_read(0), fix counting semaphore tests and directory rule comments - #6004

Open
lestarch-autobot wants to merge 1 commit into
nasa:develfrom
JPL-Devin:devin/fix-5913-os-ut-shadow-read-semaphore-tests
Open

lestarch-autobot wants to merge 1 commit into
nasa:develfrom
JPL-Devin:devin/fix-5913-os-ut-shadow-read-semaphore-tests

Conversation

@lestarch-autobot

Copy link
Copy Markdown
Collaborator
Related Issue(s) Fixes #5913
Has Unit Tests (y/n) y
Documentation Included (y/n) n
Generative AI was used in this contribution (y/n) AI

Change Description

Test-only changes under Os/test/ut/:

  • file/FileRules.cpp: Tester::shadow_read(size) now skips the m_shadow.read(...) call when size == 0. A zero-length std::vector<U8> has a null data(), and Os::File::read asserts buffer != nullptr; the helper returns an empty vector and leaves the shadow file untouched, matching a zero-byte read of the file under test.
  • countingsemaphore/CommonTests.cpp: replaced ExceedMaxCount and InvalidParameters, which asserted against a non-existent maxCount parameter and accepted any of several statuses (ASSERT_TRUE(a || b || c)), with deterministic tests of the real Os::CountingSemaphore(U32 initial_count) contract:
    • PostAccumulatesCount — three posts yield exactly three tryWait() successes, then ERROR_TIMEOUT.
    • ZeroInitialCount — no token until post(); tryWait() on empty returns ERROR_TIMEOUT.
    • LargeInitialCount — an initial count of N grants exactly N wait()s.
  • directory/DirectoryRules.cpp: corrected the ReadAllFiles rule comments to state that readDirectory rewinds before and after reading (per Os/Directory.hpp), instead of "minus the original seek position" / "resets the seek position to the end".

Rationale

Closes the three OS unit-test defects reported in #5913: a helper that violates Os::File::read's non-null buffer precondition, two tautological semaphore tests that could not fail and documented semantics the API does not have, and misleading comments in the directory rules. No production code, FPP, or public API is changed.

Testing/Review Recommendations

  • Built and ran the affected OS unit tests on Linux (native): PosixFileTest, StubFileTest, PosixDirectoryTest, StubDirectoryTest, PosixCountingSemaphoreTest — 5/5 pass via ctest.
  • Review that the new semaphore assertions each expect a single status (no || alternatives) and that they match Os/CountingSemaphore.hpp.
  • Confirm shadow_read(0) still satisfies assert_file_read in the Read rule when size_desired == 0.

Future Work

None.

AI Usage (see policy)

This PR was authored by an AI agent (Devin): issue analysis, code changes, and local test execution. Changes were verified by building and running the affected unit tests.

IAMAI

…ry comments

Fixes nasa#5913

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report — base devel

Overall (line): 85.11% → 85.13% (+0.02)
Regression threshold: 0.50% (line).

Regressions

(none over threshold)

Modules changed

Module Line Δ Function Δ Branch Δ
Os/Posix 70.64 -0.39 87.50 +0.00 50.89 +0.00
Os/Generic 90.24 -0.10 89.13 +0.00 75.10 -0.57
Fw/DataStructures 98.22 +0.53 97.14 +0.00 83.03 +0.91

New modules

Module Line Function Branch
Fw/Prm 0.00 0.00 0.00

Modules without UTs

CFDP/Checksum/GTest, Drv/LinuxGpioDriver, Drv/LinuxI2cDriver, Drv/LinuxSpiDriver, Drv/Ports/DataTypes, Drv/PosixUartDriver, FppTestProject/FppTest/topology/async, FppTestProject/FppTest/topology/components/Comp, FppTestProject/FppTest/topology/components/Framework, FppTestProject/FppTest/topology/components/Receiver, FppTestProject/FppTest/topology/components/Sender, FppTestProject/FppTest/topology/guarded, FppTestProject/FppTest/topology/sync, FppTestProject/FppTest/topology/top_ports, FppTestProject/FppTest/topology/types, Fw/Com, Fw/Comp, Fw/FilePacket/GTest, Fw/Fpy, Fw/Obj, Fw/Port, Fw/Sm, Fw/Test, Fw/Types/GTest, Os/Models, Svc/Ccsds/Types, Svc/Ccsds/Utils, Svc/FatalHandler, Svc/Subtopologies/CdhCore, Svc/Subtopologies/ComCcsds, Svc/Subtopologies/ComCcsdsSdls, Svc/Subtopologies/ComFprime, Svc/Subtopologies/ComLoggerTee, Svc/Subtopologies/DataProducts, Svc/Subtopologies/DpCompression, Svc/Subtopologies/FileHandling, Svc/Subtopologies/FileHandlingCfdp, Svc/Subtopologies/FileHandlingCfdp/FileHandlingCfdpConfig, TestDeploymentsProject/Ref/DpDemo, TestDeploymentsProject/Ref/PingReceiver, TestDeploymentsProject/Ref/RecvBuffApp, TestDeploymentsProject/Ref/SendBuffApp, TestDeploymentsProject/Ref/Top, TestDeploymentsProject/Ref/TypeDemo, cmake/test/data/TestConfigDeployment, cmake/test/data/TestDeployment/TestBuildAutocoder, cmake/test/data/TestDeployment/TestDuplicateDirective, cmake/test/data/TestDeployment/TestHeaderAutocoder, cmake/test/data/TestDeployment/TestLinkDepends, cmake/test/data/TestDeployment/TestRelative, cmake/test/data/test-fprime-library/TestLibrary/TestComponent, cmake/test/data/test-fprime-library2/TestLibrary2/TestComponent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Os UT: FileRules shadow_read(0) passes a null buffer; countingsemaphore tests assert a nonexistent maxCount; directory comments wrong

1 participant