Skip to content

Os: compile-time alias option for File, FileSystem, Directory, Console, CountingSemaphore, Cpu, and Memory (rebase of #5955) - #6318

Open
lestarch-autobot wants to merge 20 commits into
nasa:develfrom
lestarch-autobot:multi-os-alias-rebase
Open

lestarch-autobot wants to merge 20 commits into
nasa:develfrom
lestarch-autobot:multi-os-alias-rebase

Conversation

@lestarch-autobot

@lestarch-autobot lestarch-autobot commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator
Related Issue(s) #5249 — rebase/continuation of #5955 (original work by @bevinduckett, carried as co-author)
Has Unit Tests (y/n) y (existing Os/test/ut suites exercise every service through the default delegate aliases; no new behaviour was added)
Documentation Included (y/n) y (Os/docs/sdd.md, docs/how-to/integrate/implement-osal.md, default/config/OsSelection.hpp comments)
Generative AI was used in this contribution (y/n) AI

Change Description

Continuation of #5955 (@bevinduckett's branch, all of her commits preserved; devel merged in by the autobot and review follow-ups added on top — same merge-based flow the original branch used). It extends the compile-time alias mechanism introduced for Os::RawTime (#5617) and Os::Mutex/Os::ConditionVariable (#5936) to the remaining simple OSAL services: File, FileSystem, Directory, Console, CountingSemaphore, Cpu and Memory.

For each service, formulaically:

  • Os/<Service>.hpp becomes a thin aggregator: includes Os/<Service>Interface.hpp, then #include OS_<SERVICE>_HEADER.
  • The former wrapper class moves to Os/Delegate<Service>.{hpp,cpp} (link-time delegate, unchanged behaviour) and remains the default via using <Service> = Delegate<Service>;.
  • Common non-virtual helpers (open(...) overloads, read(Fw::StringBase&), static singleton wrappers, etc.) move onto <Service>Interface so a direct alias inherits them.
  • All aliases and OS_*_HEADER macros live in the consolidated default/config/OsSelection.hpp (Os: consolidate selection config headers into config/OsSelection.hpp #6049); the per-service config/OsDelegate<Service>.hpp headers from the original PR were dropped during the rebase.

Compatibility: a project config/OsSelection.hpp written before this PR (e.g. fprime-vorago's, which selects only RawTime/Mutex/ConditionVariable) defines neither the new aliases nor the OS_*_HEADER macros; each new aggregator falls back to the link-time delegate in that case instead of #error-ing, so existing overrides keep building. FW_FILE_HANDLE_MAX_SIZE is bumped 16 → 24 because FileInterface::m_mode pushes pointer-handle implementations (fprime-zephyr) past the old budget.

Rebase adaptations beyond the original PR: upstream's FileSystem::copyFile truncation fix (#6083) is carried into FileSystemInterface.cpp; the missing Os/ConsoleInterface.cpp referenced by Os/CMakeLists.txt was added; FW_DIRECTORY_HANDLE_MAX_SIZE is bumped 16 → 32 with a sizing comment (the open-state flag moved onto DirectoryInterface, originally part of #5955).

Migration note for projects that override PlatformCfg.fpp: FW_DIRECTORY_HANDLE_MAX_SIZE must be ≥ 24 (default now 32) and FW_FILE_HANDLE_MAX_SIZE ≥ 24 for pointer-handle File implementations (default now 24); the open state formerly held by the Os::File/Os::Directory wrappers now lives on the interface classes and is counted inside the handle budget. Companion pr-6318 branches on fprime-vorago-reference and fprime-zephyr-reference carry that bump for CI.

Rationale

Projects targeting bare-metal / small-RAM platforms (see #5249) can alias Os::File etc. directly to their implementation and avoid the delegate indirection and handle storage, while every existing build keeps the link-time delegate behaviour by default.

Testing/Review Recommendations

  • CI is green with companion branches pr-6318 on fprime-community/fprime-vorago-reference and fprime-community/fprime-zephyr-reference (handle-size bumps; the Vorago one also pins Os/Baremetal/File: copy the FileInterface base in the copy constructor and operator= fprime-community/fprime-baremetal#60, a one-line FileInterface(other) copy-constructor fix). Merge those alongside this PR.

  • fprime-util build, fprime-util build --ut + ctest (133/133 pass), TestDeploymentsProject/Ref build and Ref/test/int pytest suite against the GDS all pass on the rebased head; FileManager/PrmDb file operations exercised manually through the GDS.

  • The change is large but repetitive; reviewing one service end-to-end (e.g. Os/File.hpp → Os/FileInterface.hpp → Os/DelegateFile.hpp/.cpp → OsSelection.hpp) and then diffing the pattern across the others is the quickest route.

  • Behavioural note for reviewers: the virtual 3-argument open(path, mode, overwrite) is now both a public overload and the implementation hook; it applies no length bound (documented on FileInterface.hpp). The length/Fw::ConstStringBase overloads validate as before.

  • An iterative local multi-agent review (security, correctness, supply-chain, design, operational-consequences, F´ C++ design, stale-documentation, architecture, test-quality, maintainability lenses) was run across three iterations; all must-fix findings were resolved. Residual acknowledged items are listed under Future Work.

Future Work

  • A reusable CRC helper so a direct Os::File alias need not re-implement calculateCrc/incrementalCrc/finalizeCrc.
  • static_assert(std::is_base_of<...>) in the aggregator headers to enforce the "MUST derive from the interface" rule at compile time.
  • A separately-named virtual implementation hook for File::open so the public 3-argument overload could regain a path bound.
  • No in-tree platform yet ships an alias-ready Console backend; in-tree tests cover only the default delegate aliases.

Contributor Checklist

AI Usage (see policy)

AI (Devin, operated by @LeStarch) merged devel into #5955's branch, resolved the conflicts, adapted the PR to the consolidated config/OsSelection.hpp, fixed the build, ran the unit/integration/manual tests, and ran a local-only multi-agent review loop whose findings were triaged and fixed with minimal, repeated edits only. Original design and implementation by @bevinduckett.

IAMAI

Bevin K Duckett and others added 13 commits September 11, 2026 16:48
This reverts commit 5f495b261c3c7cc69dd075db45c2df270ce371a3, reversing
changes made to ae321743ed113ab34cc48a2abcd17b97581acf6c.

Undoes the merge commit because fprime devel commit c103965 is breaking our build
… revert

The Aug 19 "Revert Merge branch devel into multi-os-alias" undid a devel
merge because fpp 3.3.0a17 broke the build. That issue was fixed upstream
by 1fadfda (bump to stable fpp 3.3.0), and both commits are already in
devel's history, but the revert's content was never re-integrated.

This commit fixes that (modifies about 170 non-Os files).
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report — base devel

Overall (line): 85.81% → 85.81% (+0.00)
Regression threshold: 0.50% (line).

Regressions

(none over threshold)

Modules changed

Module Line Δ Function Δ Branch Δ
Fw/DataStructures 97.51 -0.45 97.14 +0.00 81.93 -0.73
Os/Generic 90.18 -0.10 89.13 +0.00 75.10 -0.19
Os 20.14 +0.27 22.95 +0.37 17.49 +0.03
Os/Posix 71.08 +0.44 87.50 +0.00 51.11 +0.44
Svc/DpCatalog 89.44 +1.50 98.00 +0.13 82.44 +1.92
Svc/FprimeDeframer 100.00 +1.85 100.00 +0.00 100.00 +4.08

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

lestarch-autobot and others added 6 commits November 4, 2026 22:59
Resolves conflicts in Os/FileSystem.cpp (copyFile truncation fix nasa#6083 carried into
FileSystemInterface.cpp), Os/docs/sdd.md and default/config/CMakeLists.txt; folds the seven
config/OsDelegate<Service>.hpp headers into the consolidated config/OsSelection.hpp (nasa#6049);
adds the Os/ConsoleInterface.cpp referenced by Os/CMakeLists.txt.

Co-authored-by: M Starch <LeStarch@googlemail.com>
- DelegateFile::open(path, mode, overwrite): drop the re-applied FileNameStringSize bound so
  length-validated callers (Fw::String paths up to capacity) keep the devel behaviour
- PosixFile::operator=: copy the FileInterface base (m_mode) like the copy constructor does
- DelegateConsole: un-hide ConsoleInterface::writeMessage(const Fw::ConstStringBase&)
- Docs: complete 10-service OsSelection.hpp override example, point the TIP at
  FileInterface.hpp, correct the SDD static-wrapper sentence, note the override must define
  every alias/macro, document the FW_FILE_HANDLE_MAX_SIZE sizing

Co-authored-by: M Starch <LeStarch@googlemail.com>
- PosixDirectory, PosixConsole, StubConsole: un-hide the base read()/writeMessage() string
  overloads (matches StubDirectory/DelegateDirectory/DelegateConsole)
- DelegateConsole: move the using-declaration out of the writeMessage Doxygen block
- DelegateFile.cpp: drop the now-unused StringUtils include; DelegateFileSystem: drop the unused
  friend declaration
- Aggregator headers: correct the "included only by <Service>Interface.hpp" comment
- FileInterface.hpp: document that the 3-argument open() is the implementation hook and applies no
  length bound (use a length overload for unterminated buffers)
- OsSelection.hpp / SDD: spell out the extra obligations of a direct alias (singleton
  init()/getSingleton(), File CRC methods and open/closed guards; Console statics are not on the
  interface)

Co-authored-by: M Starch <LeStarch@googlemail.com>
- Aggregator headers: state that config/OsSelection.hpp is included via Os/<Service>Interface.hpp
- Posix/Stub Console, Posix Directory: place the using-declarations ahead of the Doxygen blocks
- FileInterface.hpp: the 4-argument open() validates and delegates to the 3-argument hook

Co-authored-by: M Starch <LeStarch@googlemail.com>
…or pointer-handle implementations

- Os/<Service>.hpp aggregators fall back to the link-time Delegate<Service> when a project
  config/OsSelection.hpp predates the new selection and defines neither the alias nor
  OS_<SERVICE>_HEADER (fixes the Vorago CI build, whose override selects only RawTime/Mutex/
  ConditionVariable)
- FW_FILE_HANDLE_MAX_SIZE 16 -> 24: FileInterface::m_mode pushes pointer-handle File
  implementations (Zephyr) past the previous budget (fixes the Zephyr CI static_assert)

Co-authored-by: M Starch <LeStarch@googlemail.com>
Co-authored-by: M Starch <LeStarch@googlemail.com>

This branch has not been deployed

No deployments
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.

2 participants