Skip to content

refactor: S29.03 extract shared FreeRTOS BDD-target pipeline#521

Merged
DavidCozens merged 2 commits into
mainfrom
refactor/s29-03-shared-freertos-pipeline
Jun 3, 2026
Merged

refactor: S29.03 extract shared FreeRTOS BDD-target pipeline#521
DavidCozens merged 2 commits into
mainfrom
refactor/s29-03-shared-freertos-pipeline

Conversation

@DavidCozens

@DavidCozens DavidCozens commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Purpose

Closes #520. The DRY pass S29.01 deferred. The two FreeRTOS target main.c files (Plus-TCP + lwIP) had drifted to ~600 lines of near-verbatim shared code. Extract it so future changes (e.g. S29.05's Plus-FAT swap) are made once, not twice-in-sync. Pure refactor — no behaviour change.

Change Description

New Bdd/Targets/Common/BddTargetFreeRtosPipeline.{c,h} owns everything platform-independent: the SolidSyslog lifecycle, the FatFs-backed store + security-policy machinery (crc16 / hmac-sha256 / aes-256-gcm / null), the SD set, the interactive set handler, the CircularBuffer + Service drain task, ErrorHandlerEx, and the console glue.

Each main.c keeps only its network backend behind the injection seam BddTargetFreeRtosPipelineConfig:

  • DefaultHost"10.0.2.2" (Plus-TCP, no DNS) / "syslog-ng" (lwIP, DNS alias);
  • BuildSender — a thunk that brings up the platform network and returns the Switching sender, default transport selected. Runs on the interactive task so lwIP's adapters touch a started lwIP core (netif bring-up + ARP warm-up moved inside the seam);
  • GetHostname — reads the platform IP stack;
  • TeardownNetwork — releases the sender + adapters.

The pipeline owns both FreeRTOS tasks and exports GetEndpoint / GetEndpointVersion (the sender configs in each main.c wire these — they read the shared host/port), plus Sleep / Exit / InitConsole. The Service task self-registers its handle, so neither task needs the caller to plumb anything.

FreeRtos/main.c 1258 → 291, FreeRtosLwip/main.c 1111 → 320; the shared surface (956 lines incl. header) now exists once. Net −800 lines.

Test Evidence

  • Both targets cross-build clean on the new sha-0b93766 image (zero warnings under the strict bar).
  • lwIP ELF has zero Platform/PlusTcp symbols (arm-none-eabi-nm).
  • clang-format clean on the new + changed files.
  • Full BDD suite green on both targets — 44/44 scenarios each (UDP / TCP / TLS / mTLS + the entire @store suite: store_and_forward, store_capacity ×4, power_cycle_replay ×3 incl. @hmac / @aesgcm, capacity_threshold ×2, block_lifecycle ×2).

Areas Affected

  • Tier-3 BDD targets only (Bdd/Targets/): new shared pipeline TU + both main.c slimmed + both target CMakeLists. No library / Tier-1/2 source, no behaviour change.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Extracted shared FreeRTOS BDD-target pipeline for improved code consolidation
    • Refactored platform-specific implementations to leverage the shared pipeline module
    • Updated build configurations for FreeRTOS and lwIP targets
  • Tests

    • All 44 BDD scenarios pass per target; behavior preserved

The DRY pass S29.01 deferred. The two FreeRTOS target main.c files
(Plus-TCP + lwIP) shared ~600 lines of near-verbatim code: the store /
security-policy lifecycle, the OnSet handler, the SD set, the Service
drain task, the console glue, ErrorHandlerEx. Extract all of it into
Bdd/Targets/Common/BddTargetFreeRtosPipeline.{c,h}; each main.c now keeps
only its network backend behind an injection seam.

The seam (BddTargetFreeRtosPipelineConfig): DefaultHost, a BuildSender
thunk (platform network bring-up + Switching sender, runs on the
interactive task so lwIP's adapters touch a started core), a GetHostname
callback, and a TeardownNetwork thunk. The pipeline owns the SolidSyslog
lifecycle / store / SD / both tasks and exports GetEndpoint /
GetEndpointVersion / Sleep / Exit / InitConsole. The Service task
self-registers its handle.

FreeRtos/main.c 1258 -> 291, FreeRtosLwip/main.c 1111 -> 320; the shared
surface (956 lines incl. header) now exists once (net -800 lines).

Pure refactor, no behaviour change. Both targets cross-build clean on
sha-0b93766; lwIP ELF has zero Platform/PlusTcp symbols; clang-format
clean; full BDD suite green on both targets (44/44 each: UDP/TCP/TLS/mTLS
+ the full @store suite incl. @hmac/@aesgcm/capacity/power-cycle).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@DavidCozens, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 34 minutes and 3 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 682fb158-146b-4a32-a996-443882a29f4a

📥 Commits

Reviewing files that changed from the base of the PR and between 76c83d2 and a356987.

📒 Files selected for processing (2)
  • Bdd/Targets/Common/BddTargetFreeRtosPipeline.c
  • Bdd/Targets/FreeRtos/main.c
📝 Walkthrough

Walkthrough

This PR extracts 600+ lines of duplicated FreeRTOS BDD-target logic from two main.c files into a shared BddTargetFreeRtosPipeline module. Each target's main.c now injects platform-specific callbacks (sender build, hostname read, network teardown) and uses the shared pipeline entry points, reducing code duplication while maintaining behavior across both targets.

Changes

Shared FreeRTOS Pipeline Extraction

Layer / File(s) Summary
Shared Pipeline Public Interface and State Setup
Bdd/Targets/Common/BddTargetFreeRtosPipeline.h, Bdd/Targets/Common/BddTargetFreeRtosPipeline.c
Defines BddTargetFreeRtosPipelineConfig platform seam with callback injection slots (BuildSender, GetHostname, TeardownNetwork). Exports public API: console init, config injection, endpoint/metadata accessors, task entry points, stack-size multipliers. Establishes core state: message defaults, circular buffer, lifecycle mutex, store/security-policy objects. Implements endpoint and RFC5424 metadata formatting.
Interactive Command Handler and Store Lifecycle
Bdd/Targets/Common/BddTargetFreeRtosPipeline.c
Implements OnSet command parser that mutates test parameters (app name, message fields, port, host) and stages store rebuild inputs. Provides set store file rebuild trigger that swaps NullStore to FATFS-backed BlockStore with optional at-rest security (HMAC-SHA256, AES-256-GCM, CRC16, null). Includes FatFs mount-and-format logic, security-policy creation/destruction, store teardown, and discard-policy mapping.
Task Lifecycle, Teardown, and Synchronization
Bdd/Targets/Common/BddTargetFreeRtosPipeline.c
Implements InteractiveTask (initialize defaults, build sender, create SolidSyslog/SD, run BDD loop, print stack high-water marks, full teardown-before-delete). Implements ServiceTask (self-register, wait readiness, service SolidSyslog under lock, coordinate bounded shutdown via notification, self-delete). Implements TeardownAll (destroy SolidSyslog/SD, tear down store, unmount FATFS, wait service shutdown, destroy buffer/mutex, call injected network teardown).
FreeRTOS Plus-TCP Target Integration
Bdd/Targets/FreeRtos/main.c, Bdd/Targets/FreeRtos/CMakeLists.txt
Refactors main.c to retain only Plus-TCP network wiring (static IP/netmask/gateway, UART/IRQ setup, Plus-TCP globals). Defines PIPELINE_CONFIG binding local BuildSender/GetHostname/TeardownNetwork callbacks. Task creation in vApplicationIPNetworkEventHook_Multi switched to shared pipeline entry points with stack multipliers. GetHostname reads endpoint IP and converts to string. BuildSender uses pipeline-provided endpoint accessors for UDP/TCP sender config. TeardownNetwork tears down Plus-TCP stack in reverse dependency order. CMakeLists adds shared pipeline source.
FreeRTOS lwIP Target Integration
Bdd/Targets/FreeRtosLwip/main.c, Bdd/Targets/FreeRtosLwip/CMakeLists.txt
Refactors main.c to wire lwIP backend into shared pipeline: uses BddTargetFreeRtosPipeline_InitConsole/SetConfig, creates interactive/service tasks through pipeline entry points with early exit on failure. NetworkBringUp handles netif/IP setup and ARP warm-up on tcpip thread. BuildSender performs tcpip bring-up, blocks until gateway ARP resolves, creates DNS resolver/UDP/TCP senders using pipeline-provided Sleep and endpoint/version callbacks. GetHostname reads netif IP. TeardownNetwork destroys switching sender and network stack. Removes local semihosting exit. CMakeLists adds shared pipeline source.
Build Configuration and Documentation
Bdd/Targets/FreeRtos/CMakeLists.txt, Bdd/Targets/FreeRtosLwip/CMakeLists.txt, DEVLOG.md
Adds BddTargetFreeRtosPipeline.c to both target CMakeLists source lists. Documents S29.03 refactor in DEVLOG: consolidation of duplicated store/policy/lifecycle logic, configuration seam injection, and validation results (44/44 BDD scenarios per target).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related issues

  • #512: Parent epic (E29) that coordinates extraction and refactoring of FreeRTOS BDD-target infrastructure across multiple PRs, including this shared pipeline extraction work.

Possibly related PRs

  • DavidCozens/solid-syslog#494: Implements the same TeardownAllServiceTask shutdown synchronization via notification (replacing fixed sleep), directly aligning with the bounded-wait handshake in the shared pipeline.
  • DavidCozens/solid-syslog#516: Adds FatFs-backed store implementation and expanded OnSet knobs for store rebuild; the main PR moves that store lifecycle and command wiring into the shared pipeline.
  • DavidCozens/solid-syslog#480: Touches lwIP TCP wiring and teardown of TCP stream/sender/address components that the main PR now consolidates into the shared BddTargetFreeRtosPipeline integration layer.

Poem

🐰 A rabbit extracts the shared path,
From FreeRTOS duplicates—no more wrath!
One pipeline flows, two targets stand,
Each injects its network, hand in hand.
No code survives the twice-told tale—
One truth prevails, refactoring prevails! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.51% 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 The title accurately summarizes the main change: extracting shared FreeRTOS pipeline code. It follows Conventional Commits format and is clear and specific.
Description check ✅ Passed The description covers all required template sections: Purpose (closes #520), Change Description (detailed refactor scope), Test Evidence (build and BDD results), and Areas Affected (Tier-3 targets only). Comprehensive and complete.
Linked Issues check ✅ Passed All acceptance criteria from issue #520 are met: shared pipeline TU created in Common/, both targets link it, each main.c reduced to network wiring, cross-build clean, lwIP ELF has no PlusTcp symbols, full BDD suite passes 44/44 on both targets, pure refactor with no behavior changes.
Out of Scope Changes check ✅ Passed All changes are in-scope: only Tier-3 BDD targets affected (Bdd/Targets/ directory). No library, Tier-1/2, Plus-FAT (S29.05), or Platform/PlusFat (S29.04) changes present. Pure refactor as declared.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/s29-03-shared-freertos-pipeline

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

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

☀️   Quality Summary

   🚦   build-linux-gcc: 100% successful (✔️ 1428 passed)
   🚦   build-freertos-host-tdd-plustcp: 100% successful (✔️ 1743 passed)
   🚦   build-linux-clang: 100% successful (✔️ 1362 passed)
   🚦   sanitize-linux-gcc: 100% successful (✔️ 1362 passed)
   🚦   integration-linux-openssl: 100% successful (✔️ 16 passed)
   🚦   integration-linux-mbedtls: 100% successful (✔️ 14 passed)
   🚦   integration-windows-openssl: 100% successful (✔️ 16 passed)
   🚦   bdd-linux-syslog-ng: 94% successful (✔️ 48 passed, 🙈 3 skipped)
   🚦   bdd-windows-otel: 88% successful (✔️ 45 passed, 🙈 6 skipped)
   🚦   bdd-freertos-qemu-plustcp: 86% successful (✔️ 44 passed, 🙈 7 skipped)
   🚦   bdd-freertos-qemu-lwip: 86% successful (✔️ 44 passed, 🙈 7 skipped)
   🚦   build-windows-msvc: 100% successful (✔️ 1217 passed)
   🚦   build-linux-tunable-override: 100% successful (✔️ 1362 passed)
   ⚠️   Clang-Tidy: No warnings
   ⚠️   CPPCheck: No warnings


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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Bdd/Targets/Common/BddTargetFreeRtosPipeline.c`:
- Around line 363-387: The code currently uses pendingSecurityPolicy (modified
by OnSet("security-policy")) when destroying policies, which can change after
CreateSecurityPolicy() built the actual policy; modify CreateSecurityPolicy() to
record the immutable active policy kind into a new variable (e.g.,
installedSecurityPolicy or activeSecurityPolicy) at creation time, and update
DestroySecurityPolicy() to consult that installedSecurityPolicy instead of
pendingSecurityPolicy so teardown/destroy dispatches the correct branch; ensure
OnSet still updates pendingSecurityPolicy for future creates but does not affect
the installed/active value used for destruction.

In `@Bdd/Targets/FreeRtos/main.c`:
- Around line 152-160: The code sets interactiveTaskCreated = pdTRUE
unconditionally even if xTaskCreate fails; change it to capture and check
xTaskCreate's return (BaseType_t), only set interactiveTaskCreated = pdTRUE when
xTaskCreate returns pdPASS, and on failure leave interactiveTaskCreated false
(and optionally log/error) so the next eNetworkUp will retry creating
BddTargetFreeRtosPipeline_ServiceTask; update the block that calls
xTaskCreate(BddTargetFreeRtosPipeline_ServiceTask, ...) to perform this
conditional check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb5dad38-199d-4723-9bb9-cf90b078a428

📥 Commits

Reviewing files that changed from the base of the PR and between 41f7b49 and 76c83d2.

📒 Files selected for processing (7)
  • Bdd/Targets/Common/BddTargetFreeRtosPipeline.c
  • Bdd/Targets/Common/BddTargetFreeRtosPipeline.h
  • Bdd/Targets/FreeRtos/CMakeLists.txt
  • Bdd/Targets/FreeRtos/main.c
  • Bdd/Targets/FreeRtosLwip/CMakeLists.txt
  • Bdd/Targets/FreeRtosLwip/main.c
  • DEVLOG.md

Comment thread Bdd/Targets/Common/BddTargetFreeRtosPipeline.c
Comment thread Bdd/Targets/FreeRtos/main.c Outdated
…e latch

Two pre-existing latent bugs the refactor surfaced (carried verbatim from
the old Plus-TCP main.c):

- DestroySecurityPolicy dispatched on pendingSecurityPolicy, which a later
  `set security-policy` can change after the store (and its policy) were
  built — a subsequent rebuild/teardown could then run the wrong destroy
  path. Latch the kind into installedSecurityPolicy at CreateSecurityPolicy
  time and destroy against that. Behaviour-preserving for all current BDD
  flows (the harness sets security-policy before store file).

- The Plus-TCP eNetworkUp hook latched interactiveTaskCreated even if the
  Service task's xTaskCreate failed, stranding a half-started pipeline with
  no retry. Only latch when both succeed; on Service failure delete the
  interactive task (safe — the hook runs on the higher-priority IP task, so
  the idle+1 interactive task has not been scheduled yet) so the next
  eNetworkUp retries cleanly.

Both targets cross-build clean; @store suite (all security policies +
teardown) 12/12 green on Plus-TCP.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

☀️   Quality Summary

   🚦   build-linux-gcc: 100% successful (✔️ 1428 passed)
   🚦   build-freertos-host-tdd-plustcp: 100% successful (✔️ 1743 passed)
   🚦   build-linux-clang: 100% successful (✔️ 1362 passed)
   🚦   sanitize-linux-gcc: 100% successful (✔️ 1362 passed)
   🚦   integration-linux-openssl: 100% successful (✔️ 16 passed)
   🚦   integration-linux-mbedtls: 100% successful (✔️ 14 passed)
   🚦   integration-windows-openssl: 100% successful (✔️ 16 passed)
   🚦   bdd-linux-syslog-ng: 94% successful (✔️ 48 passed, 🙈 3 skipped)
   🚦   bdd-windows-otel: No test results available
   🚦   bdd-freertos-qemu-plustcp: 86% successful (✔️ 44 passed, 🙈 7 skipped)
   🚦   bdd-freertos-qemu-lwip: 86% successful (✔️ 44 passed, 🙈 7 skipped)
   🚦   build-windows-msvc: No test results available
   🚦   build-linux-tunable-override: 100% successful (✔️ 1362 passed)
   ⚠️   Clang-Tidy: No warnings
   ⚠️   CPPCheck: No warnings


🚧   Error Messages

Quality Monitor Errors:
No matching report files found when using pattern '**/junit-bdd-windows-otel/TESTS-*.xml'! Configuration error for 'bdd-windows-otel'?
No matching report files found when using pattern '**/junit-build-windows-msvc/cpputest_*.xml'! Configuration error for 'build-windows-msvc'?

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

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

☀️   Quality Summary

   🚦   build-linux-gcc: 100% successful (✔️ 1428 passed)
   🚦   build-freertos-host-tdd-plustcp: 100% successful (✔️ 1743 passed)
   🚦   build-linux-clang: 100% successful (✔️ 1362 passed)
   🚦   sanitize-linux-gcc: 100% successful (✔️ 1362 passed)
   🚦   integration-linux-openssl: 100% successful (✔️ 16 passed)
   🚦   integration-linux-mbedtls: 100% successful (✔️ 14 passed)
   🚦   integration-windows-openssl: 100% successful (✔️ 16 passed)
   🚦   bdd-linux-syslog-ng: 94% successful (✔️ 48 passed, 🙈 3 skipped)
   🚦   bdd-windows-otel: 88% successful (✔️ 45 passed, 🙈 6 skipped)
   🚦   bdd-freertos-qemu-plustcp: 86% successful (✔️ 44 passed, 🙈 7 skipped)
   🚦   bdd-freertos-qemu-lwip: 86% successful (✔️ 44 passed, 🙈 7 skipped)
   🚦   build-windows-msvc: 100% successful (✔️ 1217 passed)
   🚦   build-linux-tunable-override: 100% successful (✔️ 1362 passed)
   ⚠️   Clang-Tidy: No warnings
   ⚠️   CPPCheck: No warnings


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

@DavidCozens DavidCozens merged commit d04ee3e into main Jun 3, 2026
52 of 53 checks passed
@DavidCozens DavidCozens deleted the refactor/s29-03-shared-freertos-pipeline branch June 3, 2026 19:33
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.

S29.03: Extract shared FreeRTOS BDD-target pipeline; main.c keeps only network wiring

1 participant