Skip to content

feat: S08.09 SolidSyslogFreeRtosTcpStream + tcp_transport BDD on QEMU#341

Merged
DavidCozens merged 3 commits into
mainfrom
feat/s08-09-freertos-tcp-stream
May 11, 2026
Merged

feat: S08.09 SolidSyslogFreeRtosTcpStream + tcp_transport BDD on QEMU#341
DavidCozens merged 3 commits into
mainfrom
feat/s08-09-freertos-tcp-stream

Conversation

@DavidCozens

@DavidCozens DavidCozens commented May 11, 2026

Copy link
Copy Markdown
Owner

Closes #338.

First of three slices for #271 (S08.06 TCP transport on FreeRTOS-Plus-TCP). Lands the FreeRTOS TCP stream adapter, extends the FreeRTOS sockets fake to cover the TCP-side API, flips Plus-TCP into TCP mode in the BDD target, and wraps UDP+TCP under SolidSyslogSwitchingSender so behave's `--transport tcp` flips the active transport over the UART.

Summary

  • New `Platform/FreeRtos/{Interface,Source}/SolidSyslogFreeRtosTcpStream.{h,c}` — Plus-TCP-backed `SolidSyslogStream` (socket -> setsockopt(SNDTIMEO=200ms) -> connect -> clear timeouts; non-blocking Send/Read with close-on-failure). 32 ZOMBIES-ordered tests pin every argument to every FreeRTOS call (`FREERTOS_AF_INET`/`SOCK_STREAM`/`IPPROTO_TCP`; setsockopt socket, level, optname, optval, optlen; connect socket+addr+addrlen; send/recv socket+buffer+length+flags; closesocket socket).
  • Extended `Tests/Support/FreeRtosFakes` sockets fake with `FreeRTOS_connect` / `_send` / `_recv` / `_setsockopt` including per-call fail toggles, explicit return-value setters, and last-arg accessors (plus an SNDTIMEO-at-connect snapshot to prove the bounded-connect contract).
  • Flipped `Bdd/Targets/FreeRtos/FreeRTOSIPConfig.h` to `ipconfigUSE_TCP=1` with TCP keep-alive (10 s) and the network buffer descriptor pool doubled (8 -> 16) to cover TCP retransmit windows alongside in-flight UDP.
  • Wired `SolidSyslogSwitchingSender` into `Bdd/Targets/FreeRtos/main.c` with UDP + TCP inner senders; default is UDP so existing `@udp` scenarios stay green, and a new `set transport <udp|tcp>` handler routes through `BddTargetSwitchConfig_SetByName` so `--transport tcp` from the behave harness flips the SwitchingSender selector at runtime.
  • Bumped `INTERACTIVE_TASK_STACK_DEPTH` from `*40` to `*48` — the StreamSender path adds `SolidSyslogAddressStorage` + a `SolidSyslogFormatter` sized for `SOLIDSYSLOG_MAX_HOST_SIZE` + a small octet-prefix formatter to the per-call stack, empirically tipping the `*40` budget into a Cortex-M lockup when SwitchingSender flipped UDP->TCP->UDP across repeated sends.
  • Behave harness: added `--transport` -> `transport` mapping in `Bdd/features/steps/target_driver.py`; updated `ci/docker-compose.bdd.yml`'s freertos tag filter to admit `@tcp` while excluding `@buffered` (no FreeRTOS file abstraction yet) and `@windows_wip`.

The third commit on the branch rolls in the code-hygiene round (negative-logic removal, helper extraction to a single level of abstraction, MISRA-style class prefixes on every static, intent-revealing test macros, named test fixtures, magic-number cleanup) — see the commit message for the full list.

Test plan

  • `SolidSyslogFreeRtosTcpStreamTest` passes under `build-freertos-host-tdd`.
  • `SolidSyslogBddTarget.elf` cross-builds under `build-freertos-target`.
  • `bdd-freertos-qemu` green — `tcp_transport.feature` against QEMU plus the existing `@udp` regression set.
  • All standard host gates (build-linux-gcc, build-linux-clang, sanitize-linux-gcc, coverage-linux-gcc, analyze-tidy, analyze-cppcheck, analyze-format, analyze-iwyu) clean — gcc/sanitize/tidy/cppcheck/format verified locally; clang/iwyu rely on CI.
  • Local QEMU smoke: UDP `send 1`, TCP `set transport tcp`+`send 1`, and UDP<->TCP<->UDP switch+send cycle all complete cleanly under the bumped stack (verified by hand).

Out of scope (deferred)

Summary by CodeRabbit

  • New Features

    • Added TCP transport support for FreeRTOS target
    • Enabled runtime transport selection between UDP and TCP
  • Tests

    • Expanded test coverage for TCP stream operations
    • Enhanced test framework with socket operation mocking
  • Chores

    • Updated test runner configuration for TCP test scenarios
    • Configured FreeRTOS TCP network settings and increased buffer capacity

Review Change Stack

- Flip ipconfigUSE_TCP=1 in Bdd/Targets/FreeRtos/FreeRTOSIPConfig.h with
  keep-alive enabled (10s) and the network buffer descriptor pool doubled
  (8 -> 16) to cover TCP retransmit windows alongside in-flight UDP.
- Wire SolidSyslogSwitchingSender into Bdd/Targets/FreeRtos/main.c with
  UDP + TCP inner senders; default to UDP so existing @udp scenarios stay
  green, and add a `transport` set handler that routes through
  BddTargetSwitchConfig_SetByName so `--transport tcp` from the Behave
  harness lands as a transport flip over the UART.
- Bump INTERACTIVE_TASK_STACK_DEPTH from *40 to *48 to absorb the extra
  formatter+address storage that StreamSender.Connect / TransmitFramed
  layer on top of the UDP-only stack consumption.
- Pin setsockopt arg coverage in SolidSyslogFreeRtosTcpStreamTest (socket
  handle, level=0, optlen=sizeof(TickType_t)) so any regression in the
  bounded-connect contract surfaces at the test bar.
- Add `--transport` -> `transport` translation in Behave's
  target_driver.py and admit @tcp scenarios in the freertos compose tag
  filter (excluding the @Buffered store-and-forward features that need
  the file abstraction not yet on FreeRTOS).
Production (Platform/FreeRtos/Source/SolidSyslogFreeRtosTcpStream.c):
- Prefix every static with FreeRtosTcpStream_ for MISRA file-scope
  identifier uniqueness.
- Replace negative guard `if (!IsOpen)` with `IsClosed` predicate so
  Open's outer condition reads positively.
- Extract OpenSocket / ConnectOrCloseOnFailure / TryConnect /
  ClearTimeouts so Open / Send / Read each read as a single sequence
  at the stream-of-abstraction level (no native FreeRTOS calls inline).
- Mirror the same Try* / *OrCloseOnFailure shape across Send and Read
  (SendOrCloseOnFailure / TrySend / AllBytesSent and
  ReceiveOrCloseOnFailure) so the three paths now read symmetrically.
- Rename `rc` -> `sentCount` / `receivedCount` for intent.
- Name the magic literals: SETSOCKOPT_LEVEL_DEFAULT and
  SEND_RECV_FLAGS_DEFAULT for the FreeRTOS-Plus-TCP placeholder zeros,
  and READ_FAILED for the -1 EOF/error sentinel from
  SolidSyslogStream_Read.

Tests (Tests/FreeRtos/SolidSyslogFreeRtosTcpStreamTest.cpp):
- Lift TEST_PORT / TEST_MESSAGE / TEST_MESSAGE_LEN /
  TEST_SHORT_WRITE_BYTES / TEST_READ_BYTES to file scope; replace
  inline literals throughout.
- Add openStream() / readIntoBuffer() helpers on the TEST_GROUP so the
  arrange step in 25+ tests collapses to one line.
- Add CHECK_SOCKET_CLOSED_ONCE macro that pins both the close call
  count and the identity of the closed socket. Apply it across the
  close-on-failure tests, tightening three sites that previously only
  pinned the call count (SendClosesSocketOnError,
  ReadReturnsNegativeOneOnErrorAndClosesSocket, DestroyClosesOpenSocket).
@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 19d12962-ccd4-47ec-abef-64674dde357a

📥 Commits

Reviewing files that changed from the base of the PR and between 84302e0 and 0f89934.

📒 Files selected for processing (11)
  • Bdd/Targets/FreeRtos/CMakeLists.txt
  • Bdd/Targets/FreeRtos/FreeRTOSIPConfig.h
  • Bdd/Targets/FreeRtos/main.c
  • Bdd/features/steps/target_driver.py
  • Platform/FreeRtos/Interface/SolidSyslogFreeRtosTcpStream.h
  • Platform/FreeRtos/Source/SolidSyslogFreeRtosTcpStream.c
  • Tests/FreeRtos/CMakeLists.txt
  • Tests/FreeRtos/SolidSyslogFreeRtosTcpStreamTest.cpp
  • Tests/Support/FreeRtosFakes/Interface/FreeRtosSocketsFake.h
  • Tests/Support/FreeRtosFakes/Source/FreeRtosSocketsFake.c
  • ci/docker-compose.bdd.yml

📝 Walkthrough

Walkthrough

This PR implements TCP transport for SolidSyslog on FreeRTOS Plus-TCP. It delivers a new TCP stream adapter module, extends socket test fakes, enables TCP in the network config, integrates UDP+TCP switching into the BDD target, and adds comprehensive unit and BDD test coverage.

Changes

FreeRTOS TCP Transport Adapter and BDD Integration

Layer / File(s) Summary
TCP Stream Public API
Platform/FreeRtos/Interface/SolidSyslogFreeRtosTcpStream.h
Declares SolidSyslogFreeRtosTcpStream_Create and _Destroy functions, SolidSyslogFreeRtosTcpStreamStorage opaque buffer, and SOLIDSYSLOG_FREERTOSTCPSTREAM_SIZE constant.
Socket Fake Interface
Tests/Support/FreeRtosFakes/Interface/FreeRtosSocketsFake.h
Adds setter declarations (SetConnectFails, SetSendFails/Return, SetRecvFails/Return) and accessor declarations for connect/send/recv/setsockopt call counts, last arguments, and timeout tracking.
TCP Stream Implementation
Platform/FreeRtos/Source/SolidSyslogFreeRtosTcpStream.c
Implements FreeRTOS-Plus-TCP stream: open creates socket, applies 200ms send timeout, connects, then clears timeouts; send verifies full-buffer writes; read uses recv with zero timeout; close is idempotent.
Socket Fake Implementation
Tests/Support/FreeRtosFakes/Source/FreeRtosSocketsFake.c
Implements FreeRTOS_connect, FreeRTOS_send, FreeRTOS_recv, FreeRTOS_setsockopt wrapper functions with configurable failures, return-value overrides, call tracking, and last-argument capture; resets extended state.
Network Configuration
Bdd/Targets/FreeRtos/FreeRTOSIPConfig.h
Enables TCP (ipconfigUSE_TCP=1), configures keep-alive (enabled, 10s interval), and doubles network buffer descriptors (8→16) for TCP retransmission support.
BDD Target Transport Wiring
Bdd/Targets/FreeRtos/main.c
Adds TCP stream and sender storage; increases task stack depth to configMINIMAL_STACK_SIZE * 48U; implements transport setter in OnSet via BddTargetSwitchConfig_SetByName; wraps UDP and TCP senders in SolidSyslogSwitchingSender defaulting to UDP; updates cleanup to destroy switching sender and TCP components.
Build Configuration
Bdd/Targets/FreeRtos/CMakeLists.txt, Tests/FreeRtos/CMakeLists.txt
Adds SolidSyslogFreeRtosTcpStream.c and BddTargetSwitchConfig.c to BDD target sources; defines and registers SolidSyslogFreeRtosTcpStreamTest executable with FreeRTOS/Plus-TCP includes and CppUTest linking.
Unit Tests
Tests/FreeRtos/SolidSyslogFreeRtosTcpStreamTest.cpp
Comprehensive CppUTest suite covering construction, open (socket parameters, connect wiring, timeout configuration, idempotency), send (full/short/error writes, socket closure), read (success, would-block, errors), and close/destroy lifecycle.
Behave Harness & CI
Bdd/features/steps/target_driver.py, ci/docker-compose.bdd.yml
Maps --transport CLI flag to FreeRTOS interactive set transport command in _FREERTOS_SET_TRANSLATION; updates CI to run both @udp and @tcp BDD scenarios while excluding work-in-progress tags.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • #338: This PR directly implements the deliverables and acceptance criteria outlined in the S08.09 story.
  • #271: This PR realizes the TCP transport feature on FreeRTOS Plus-TCP requested in the parent S08.06 story.
  • #10: This PR implements TCP transport as part of the RTOS Examples epic.

Possibly related PRs

  • DavidCozens/solid-syslog#140: Both PRs introduce platform-specific TCP stream adapters and wire stream creation/destruction into sender lifecycle.
  • DavidCozens/solid-syslog#307: Both PRs extend target_driver.py cmdline-to-UART translation (this PR adds --transport mapping).
  • DavidCozens/solid-syslog#289: Both PRs extend FreeRtos socket fakes with TCP operations (connect, send, recv, setsockopt) to support new stream testing.

Poem

🐰 A hop, a connect, a stream takes flight,
TCP now joins UDP's might!
Sockets fake and senders switch,
BDD tests confirm the pitch—
FreeRTOS transport, shiny and bright! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly specifies the main deliverable (SolidSyslogFreeRtosTcpStream) and primary objective (tcp_transport BDD on QEMU), following Conventional Commits format.
Description check ✅ Passed Description follows the template with clear Purpose (closes #338, S08.09 slice), detailed Change Description covering all modules touched, comprehensive Test Evidence listing test plans, and Areas Affected identifying key subsystems modified.
Linked Issues check ✅ Passed All coding requirements from #338 are met: TCP stream adapter created with Open/Send/Read/Close [#338], FreeRTOS fakes extended with connect/send/recv/setsockopt [#338], Plus-TCP config flipped to ipconfigUSE_TCP=1 with keep-alive [#338], SwitchingSender wired into main.c with runtime transport selector [#338], BDD tests added [#338], and behave harness mapping implemented [#338].
Out of Scope Changes check ✅ Passed All changes align with PR scope: TCP stream implementation, socket fakes extension, Plus-TCP config, BDD target wiring, stack depth adjustment, test additions, and harness mapping. No unrelated refactoring or tangential changes present in this commit slice.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/s08-09-freertos-tcp-stream

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

☀️   Quality Summary

   🚦   build-linux-gcc: 100% successful (✔️ 1111 passed, 🙈 3 skipped)
   🚦   build-linux-clang: 100% successful (✔️ 1063 passed, 🙈 3 skipped)
   🚦   sanitize-linux-gcc: 100% successful (✔️ 1063 passed, 🙈 3 skipped)
   🚦   integration-linux-openssl: 100% successful (✔️ 9 passed)
   🚦   integration-windows-openssl: 100% successful (✔️ 9 passed)
   🚦   bdd-linux-syslog-ng: 94% successful (✔️ 46 passed, 🙈 3 skipped)
   🚦   bdd-windows-otel: 90% successful (✔️ 44 passed, 🙈 5 skipped)
   🚦   bdd-freertos-qemu: 55% successful (✔️ 27 passed, 🙈 22 skipped)
   🚦   build-windows-msvc: 100% successful (✔️ 975 passed, 🙈 1 skipped)
   ⚠️   Clang-Tidy: No warnings
   ⚠️   CPPCheck: No warnings


Created by Quality Monitor v1.14.0 (#f3859fd). More details are shown in the GitHub Checks Result.

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.

S08.09: SolidSyslogFreeRtosTcpStream + tcp_transport BDD on QEMU

1 participant