From c509a154a99ed1f830f79550146332132802381e Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:59:54 +0200 Subject: [PATCH] feat(ci): firmware and RTOS fixtures for the nightly scan regression (#313) Eleven source-archive targets cover every Firmwerk provider: Make, CMake, Arduino, PlatformIO, embedded Rust, ESP-IDF, Zephyr (west.yml), FreeRTOS via CMake FetchContent and via source archaeology, a Yocto layer that must be reported as unsupported, and the upstream Zephyr example application at a pinned commit (downloaded by the workflow). The harness zips fixture directories on upload, so the trees stay reviewable in the repository. Fixes the fixtures turned up: - Archives wrapped in a single top-level folder (GitHub's "Download ZIP") are unwrapped at ingest; the Zephyr example read as "no build system". - A firmware target without a firmware SBOM records a skipped firmware_sbom stage with the reason (no supported build system, nothing resolvable without a build, analysis failure or timeout). - Source archives record a skipped code_scan stage: SAST, secrets and the package SBOM run on git repositories only (#325). The baselines capture today's thin analysis-only SBOM (toolchain without a version, no libraries); #317 tracks the gaps and will re-bless them. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p --- .gitea/workflows/nightly.yml | 11 ++ compliance-agent/src/ingest/mod.rs | 43 +++++- .../src/pipeline/firmware_sbom.rs | 85 +++++++++-- compliance-agent/src/pipeline/orchestrator.rs | 27 +++- compliance-agent/tests/nightly.rs | 43 +++++- fixtures/nightly/baselines/fw-arduino.json | 12 ++ .../nightly/baselines/fw-cargo-embedded.json | 12 ++ fixtures/nightly/baselines/fw-cmake.json | 12 ++ fixtures/nightly/baselines/fw-espidf.json | 12 ++ .../nightly/baselines/fw-freertos-cmake.json | 12 ++ .../baselines/fw-freertos-lostbuild.json | 12 ++ fixtures/nightly/baselines/fw-make.json | 12 ++ fixtures/nightly/baselines/fw-platformio.json | 11 ++ .../nightly/baselines/fw-yocto-layer.json | 11 ++ .../baselines/fw-zephyr-example-pinned.json | 12 ++ .../nightly/baselines/fw-zephyr-pinned.json | 12 ++ fixtures/nightly/firmware/README.md | 22 +++ fixtures/nightly/firmware/arduino/blink.ino | 11 ++ fixtures/nightly/firmware/arduino/sketch.yaml | 4 + .../cargo-embedded/.cargo/config.toml | 2 + .../firmware/cargo-embedded/Cargo.toml | 8 ++ .../cargo-embedded/rust-toolchain.toml | 3 + .../nightly/firmware/cmake/CMakeLists.txt | 4 + .../nightly/firmware/cmake/toolchain.cmake | 4 + .../nightly/firmware/espidf/CMakeLists.txt | 3 + .../firmware/espidf/main/CMakeLists.txt | 1 + .../firmware/espidf/main/idf_component.yml | 4 + fixtures/nightly/firmware/espidf/main/main.c | 1 + .../firmware/espidf/sdkconfig.defaults | 2 + .../firmware/freertos-cmake/CMakeLists.txt | 17 +++ .../freertos-cmake/arm-none-eabi.cmake | 5 + .../freertos-cmake/include/FreeRTOSConfig.h | 9 ++ .../firmware/freertos-cmake/src/main.c | 15 ++ .../firmware/freertos-lostbuild/app_config.h | 4 + .../firmware/freertos-lostbuild/main.c | 13 ++ fixtures/nightly/firmware/make/Makefile | 9 ++ .../firmware/platformio/environments.ini | 6 + .../firmware/platformio/platformio.ini | 14 ++ .../firmware/yocto-layer/conf/layer.conf | 7 + .../recipes-app/pump-ctl/pump-ctl_1.0.bb | 7 + .../firmware/zephyr-pinned/CMakeLists.txt | 4 + .../nightly/firmware/zephyr-pinned/prj.conf | 2 + .../nightly/firmware/zephyr-pinned/west.yml | 13 ++ fixtures/nightly/targets.json | 134 ++++++++++++++++++ 44 files changed, 643 insertions(+), 24 deletions(-) create mode 100644 fixtures/nightly/baselines/fw-arduino.json create mode 100644 fixtures/nightly/baselines/fw-cargo-embedded.json create mode 100644 fixtures/nightly/baselines/fw-cmake.json create mode 100644 fixtures/nightly/baselines/fw-espidf.json create mode 100644 fixtures/nightly/baselines/fw-freertos-cmake.json create mode 100644 fixtures/nightly/baselines/fw-freertos-lostbuild.json create mode 100644 fixtures/nightly/baselines/fw-make.json create mode 100644 fixtures/nightly/baselines/fw-platformio.json create mode 100644 fixtures/nightly/baselines/fw-yocto-layer.json create mode 100644 fixtures/nightly/baselines/fw-zephyr-example-pinned.json create mode 100644 fixtures/nightly/baselines/fw-zephyr-pinned.json create mode 100644 fixtures/nightly/firmware/README.md create mode 100644 fixtures/nightly/firmware/arduino/blink.ino create mode 100644 fixtures/nightly/firmware/arduino/sketch.yaml create mode 100644 fixtures/nightly/firmware/cargo-embedded/.cargo/config.toml create mode 100644 fixtures/nightly/firmware/cargo-embedded/Cargo.toml create mode 100644 fixtures/nightly/firmware/cargo-embedded/rust-toolchain.toml create mode 100644 fixtures/nightly/firmware/cmake/CMakeLists.txt create mode 100644 fixtures/nightly/firmware/cmake/toolchain.cmake create mode 100644 fixtures/nightly/firmware/espidf/CMakeLists.txt create mode 100644 fixtures/nightly/firmware/espidf/main/CMakeLists.txt create mode 100644 fixtures/nightly/firmware/espidf/main/idf_component.yml create mode 100644 fixtures/nightly/firmware/espidf/main/main.c create mode 100644 fixtures/nightly/firmware/espidf/sdkconfig.defaults create mode 100644 fixtures/nightly/firmware/freertos-cmake/CMakeLists.txt create mode 100644 fixtures/nightly/firmware/freertos-cmake/arm-none-eabi.cmake create mode 100644 fixtures/nightly/firmware/freertos-cmake/include/FreeRTOSConfig.h create mode 100644 fixtures/nightly/firmware/freertos-cmake/src/main.c create mode 100644 fixtures/nightly/firmware/freertos-lostbuild/app_config.h create mode 100644 fixtures/nightly/firmware/freertos-lostbuild/main.c create mode 100644 fixtures/nightly/firmware/make/Makefile create mode 100644 fixtures/nightly/firmware/platformio/environments.ini create mode 100644 fixtures/nightly/firmware/platformio/platformio.ini create mode 100644 fixtures/nightly/firmware/yocto-layer/conf/layer.conf create mode 100644 fixtures/nightly/firmware/yocto-layer/recipes-app/pump-ctl/pump-ctl_1.0.bb create mode 100644 fixtures/nightly/firmware/zephyr-pinned/CMakeLists.txt create mode 100644 fixtures/nightly/firmware/zephyr-pinned/prj.conf create mode 100644 fixtures/nightly/firmware/zephyr-pinned/west.yml diff --git a/.gitea/workflows/nightly.yml b/.gitea/workflows/nightly.yml index 61a9616..d3673ae 100644 --- a/.gitea/workflows/nightly.yml +++ b/.gitea/workflows/nightly.yml @@ -121,6 +121,16 @@ jobs: env: RUSTC_WRAPPER: "" + # The upstream Zephyr example application, at a pinned commit so the + # result does not drift with upstream main. codeload zips are not + # byte-stable, so the commit pin (not a checksum) is the guarantee. + - name: Fetch the Zephyr example application + run: | + curl -fsSL -o /tmp/zephyr-example.zip \ + "https://codeload.github.com/zephyrproject-rtos/example-application/zip/38a6d9b276ed434454900130cacc87d058d3ac62" + env: + RUSTC_WRAPPER: "" + - name: Wait for the agent run: | for i in $(seq 1 90); do @@ -137,6 +147,7 @@ jobs: env: NIGHTLY_AGENT_URL: http://agent:3001 NIGHTLY_CODESYS_SAMPLE: /tmp/csv-blackbox.projectarchive + NIGHTLY_ZEPHYR_EXAMPLE: /tmp/zephyr-example.zip NIGHTLY_BLESS: ${{ inputs.bless && '1' || '0' }} # upload-artifact is a Node action and the Rust image has no node. diff --git a/compliance-agent/src/ingest/mod.rs b/compliance-agent/src/ingest/mod.rs index 45ac635..72647b1 100644 --- a/compliance-agent/src/ingest/mod.rs +++ b/compliance-agent/src/ingest/mod.rs @@ -181,7 +181,7 @@ fn ingest_blob( let working_path = if extract { let dest = blob::work_dir(base, ctx.target_id, &artifact.id); match blob::extract_zip(&stored, &dest) { - Ok(()) => dest, + Ok(()) => project_root(dest), Err(e) => { // Not a zip container — this is a single uploaded file (e.g. a // `.st`/`.xml` PLC project or a `.tar.gz`). The content-addressed @@ -220,6 +220,28 @@ fn ingest_blob( }) } +/// The project root of an extracted archive. GitHub's "Download ZIP" and most +/// tools wrap the project in a single top-level folder (`repo-/`), and +/// build-system detection only looks at the root, so a wrapper made a Zephyr +/// app read as "no build system". Descend while the directory holds nothing +/// but one folder (a macOS `__MACOSX` sidecar does not count). +fn project_root(mut dir: PathBuf) -> PathBuf { + loop { + let Ok(entries) = std::fs::read_dir(&dir) else { + return dir; + }; + let entries: Vec<_> = entries + .filter_map(Result::ok) + .filter(|e| e.file_name() != "__MACOSX") + .collect(); + match entries.as_slice() { + // `file_type` does not follow symlinks, so this never leaves `dir`. + [only] if only.file_type().is_ok_and(|t| t.is_dir()) => dir = only.path(), + _ => return dir, + } + } +} + /// Copy a stored blob into `dest`/`name`, returning `dest`. Used when an /// "extractable" artifact turns out to be a single file rather than an archive. fn materialize_single(stored: &Path, dest: &Path, name: &str) -> Result { @@ -439,6 +461,25 @@ mod tests { assert_eq!(set.working_paths().len(), 1); } + #[test] + fn a_single_wrapper_folder_is_unwrapped() { + let scratch = Scratch::new(); + let root = scratch.0.join("extracted"); + let app = root.join("example-application-38a6d9b").join("app"); + std::fs::create_dir_all(&app).expect("mkdir"); + std::fs::create_dir_all(root.join("__MACOSX")).expect("mkdir"); + std::fs::write(app.join("prj.conf"), "").expect("write"); + std::fs::write(root.join("example-application-38a6d9b/west.yml"), "").expect("write"); + + // Wrapper plus sidecar: descend to the folder that holds the project. + assert_eq!( + project_root(root.clone()), + root.join("example-application-38a6d9b") + ); + // A directory with several entries is already the root. + assert_eq!(project_root(app.clone()), app); + } + #[test] fn credentials_prefer_artifact_auth() { let mut artifact = Artifact::git_repo("https://git/x", "main"); diff --git a/compliance-agent/src/pipeline/firmware_sbom.rs b/compliance-agent/src/pipeline/firmware_sbom.rs index 4058132..6c918ab 100644 --- a/compliance-agent/src/pipeline/firmware_sbom.rs +++ b/compliance-agent/src/pipeline/firmware_sbom.rs @@ -33,9 +33,18 @@ pub fn is_firmware_target(target_type: TargetType) -> bool { } /// Build SBOM entries for a firmware target from its source tree. Prefers a full -/// reproducible build (sealed lock); falls back to analysis-only. Returns an -/// empty vector when Firmwerk cannot even form a build plan. -pub async fn firmware_sbom_entries(path: &Path, repo_id: &str, exec: ExecPolicy) -> Vec { +/// reproducible build (sealed lock); falls back to analysis-only. +/// +/// # Errors +/// +/// Why no firmware SBOM could be formed (no supported build system, a failed +/// analysis, a timeout), for recording on the scan run instead of completing +/// as if the firmware simply had no components. +pub async fn firmware_sbom_entries( + path: &Path, + repo_id: &str, + exec: ExecPolicy, +) -> Result, String> { let p = path.to_path_buf(); let repo = repo_id.to_string(); let allow_build = exec.untrusted_code_allowed(); @@ -44,26 +53,36 @@ pub async fn firmware_sbom_entries(path: &Path, repo_id: &str, exec: ExecPolicy) // that hangs must not wedge the scan (the orphaned task is abandoned). let handle = tokio::task::spawn_blocking(move || build_sbom_blocking(&p, &repo, allow_build)); match tokio::time::timeout(std::time::Duration::from_secs(900), handle).await { - Ok(Ok(entries)) => entries, + Ok(Ok(result)) => result, Ok(Err(e)) => { tracing::warn!(repo_id, error = %e, "Firmware SBOM: task join error"); - Vec::new() + Err(format!("firmware analysis stopped unexpectedly: {e}")) } Err(_) => { tracing::warn!(repo_id, "Firmware SBOM: build exceeded 15m; skipping"); - Vec::new() + Err("firmware analysis took longer than 15 minutes".to_string()) } } } -fn build_sbom_blocking(path: &Path, repo_id: &str, allow_build: bool) -> Vec { +fn build_sbom_blocking( + path: &Path, + repo_id: &str, + allow_build: bool, +) -> Result, String> { let repo = firmwerk_core::Repo::new(path); let plan = match firmwerk_core::provider::analyze(&repo) { Ok(Some(bp)) => bp, - Ok(None) => return Vec::new(), + Ok(None) => { + return Err( + "no supported firmware build system found (Make, CMake, Zephyr, ESP-IDF, \ + PlatformIO, Arduino, embedded Rust, or recognisable SDK headers)" + .to_string(), + ) + } Err(e) => { tracing::warn!(repo_id, error = %e, "Firmware SBOM: firmwerk analyze failed"); - return Vec::new(); + return Err(format!("firmware analysis failed: {e}")); } }; @@ -93,7 +112,7 @@ fn build_sbom_blocking(path: &Path, repo_id: &str, allow_build: bool) -> Vec { tracing::warn!(repo_id, error = %e, "Firmware SBOM: reproducible build failed; falling back to analysis-only") @@ -107,7 +126,17 @@ fn build_sbom_blocking(path: &Path, repo_id: &str, allow_build: bool) -> Vec Vec std::path::PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../fixtures/nightly/firmware") + .join(name) + } + + #[tokio::test] + async fn a_tree_without_a_supported_build_system_says_why() { + let reason = firmware_sbom_entries(&fixture("yocto-layer"), "t", ExecPolicy::default()) + .await + .expect_err("a Yocto layer forms no build plan"); + assert!( + reason.contains("no supported firmware build system"), + "{reason}" + ); + } + + #[tokio::test] + async fn a_make_project_yields_its_toolchain() { + let entries = firmware_sbom_entries(&fixture("make"), "t", ExecPolicy::default()) + .await + .expect("make forms a build plan"); + assert!( + entries.iter().any(|e| e.package_manager == "toolchain"), + "{entries:?}" + ); + } +} diff --git a/compliance-agent/src/pipeline/orchestrator.rs b/compliance-agent/src/pipeline/orchestrator.rs index 3c1c9a7..ca6a0e6 100644 --- a/compliance-agent/src/pipeline/orchestrator.rs +++ b/compliance-agent/src/pipeline/orchestrator.rs @@ -567,10 +567,15 @@ impl PipelineOrchestrator { new_count += n; } Some(_) => { - tracing::warn!( - target_id = %target_id, - "Unified pipeline: source-archive scanning not yet wired; skipping" - ); + // Recorded, not just logged, so an archive upload does not read as + // "scanned, nothing found" (#325). + self.skip_stage( + scan_run_id, + "code_scan", + "SAST, secret and package-SBOM scanning run on git repositories only; \ + uploaded source archives are not scanned yet", + ) + .await; } None => { // No code to scan (a migrated DAST target). Firmware/mobile static @@ -1076,16 +1081,24 @@ impl PipelineOrchestrator { // Analysis-based firmware SBOM: for embedded targets, derive components // (resolved libraries + cross-toolchain) from Firmwerk's build-plan // analysis over the already-ingested source — no build, no binary - // upload. Best-effort; empty when no build plan forms. + // upload. When no build plan forms (e.g. a Yocto layer), the run says + // so rather than completing as if the firmware had no components. if crate::pipeline::firmware_sbom::is_firmware_target(target.target_type) { if let Some(code) = target.code_artifact() { if let Some(path) = working_paths.get(&code.id) { - let entries = crate::pipeline::firmware_sbom::firmware_sbom_entries( + let entries = match crate::pipeline::firmware_sbom::firmware_sbom_entries( path, target_id, compliance_core::ExecPolicy::from_env(self.config.app_env), ) - .await; + .await + { + Ok(entries) => entries, + Err(reason) => { + self.skip_stage(scan_run_id, "firmware_sbom", &reason).await; + Vec::new() + } + }; if !entries.is_empty() { // Only the firmware entries: a rescan with no new // commits skips the SBOM stage, so deleting everything diff --git a/compliance-agent/tests/nightly.rs b/compliance-agent/tests/nightly.rs index bfe7601..ea869b3 100644 --- a/compliance-agent/tests/nightly.rs +++ b/compliance-agent/tests/nightly.rs @@ -84,15 +84,22 @@ impl Agent { self.call(reqwest::Method::POST, path, Some(body)).await } - /// Upload one file artifact the way the dashboard does (multipart). + /// Upload one file artifact the way the dashboard does (multipart). A + /// directory is zipped first, so source-tree fixtures stay reviewable as + /// plain files in the repository. async fn upload(&self, target_id: &str, a: &DemoArtifact, path: &Path) -> Result<(), String> { - let bytes = tokio::fs::read(path) - .await - .map_err(|e| format!("reading {}: {e}", path.display()))?; - let filename = path + let name = path .file_name() .map(|n| n.to_string_lossy().into_owned()) .unwrap_or_default(); + let (bytes, filename) = if path.is_dir() { + (zip_dir(path)?, format!("{name}.zip")) + } else { + let bytes = tokio::fs::read(path) + .await + .map_err(|e| format!("reading {}: {e}", path.display()))?; + (bytes, name) + }; let mut form = reqwest::multipart::Form::new() .text("kind", serde_name(&a.kind)) .part( @@ -150,6 +157,32 @@ fn text(v: &Value, key: &str) -> String { v[key].as_str().unwrap_or_default().to_string() } +/// Zip a fixture directory in memory, entries in a stable order. +fn zip_dir(dir: &Path) -> Result, String> { + use std::io::Write; + + let mut files: Vec = walkdir::WalkDir::new(dir) + .into_iter() + .filter_map(Result::ok) + .filter(|e| e.file_type().is_file()) + .map(|e| e.into_path()) + .collect(); + files.sort(); + let mut zip = zip::ZipWriter::new(std::io::Cursor::new(Vec::new())); + let options: zip::write::SimpleFileOptions = Default::default(); + for file in files { + let rel = file + .strip_prefix(dir) + .map_err(|e| e.to_string())? + .to_string_lossy() + .replace('\\', "/"); + zip.start_file(rel, options).map_err(|e| e.to_string())?; + let body = std::fs::read(&file).map_err(|e| format!("{}: {e}", file.display()))?; + zip.write_all(&body).map_err(|e| e.to_string())?; + } + Ok(zip.finish().map_err(|e| e.to_string())?.into_inner()) +} + /// The wire name of a snake_case enum (`plc_project`, `project_archive`). fn serde_name(value: &T) -> String { serde_json::to_value(value) diff --git a/fixtures/nightly/baselines/fw-arduino.json b/fixtures/nightly/baselines/fw-arduino.json new file mode 100644 index 0000000..f2ad394 --- /dev/null +++ b/fixtures/nightly/baselines/fw-arduino.json @@ -0,0 +1,12 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "code_scan" + ], + "sbom": [ + "toolchain:arduino-cli@" + ], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/baselines/fw-cargo-embedded.json b/fixtures/nightly/baselines/fw-cargo-embedded.json new file mode 100644 index 0000000..a2672c2 --- /dev/null +++ b/fixtures/nightly/baselines/fw-cargo-embedded.json @@ -0,0 +1,12 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "code_scan" + ], + "sbom": [ + "toolchain:rustc@" + ], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/baselines/fw-cmake.json b/fixtures/nightly/baselines/fw-cmake.json new file mode 100644 index 0000000..4efc5ed --- /dev/null +++ b/fixtures/nightly/baselines/fw-cmake.json @@ -0,0 +1,12 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "code_scan" + ], + "sbom": [ + "toolchain:arm-none-eabi-gcc@" + ], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/baselines/fw-espidf.json b/fixtures/nightly/baselines/fw-espidf.json new file mode 100644 index 0000000..4e46861 --- /dev/null +++ b/fixtures/nightly/baselines/fw-espidf.json @@ -0,0 +1,12 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "code_scan" + ], + "sbom": [ + "toolchain:esp-idf-toolchain@" + ], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/baselines/fw-freertos-cmake.json b/fixtures/nightly/baselines/fw-freertos-cmake.json new file mode 100644 index 0000000..4efc5ed --- /dev/null +++ b/fixtures/nightly/baselines/fw-freertos-cmake.json @@ -0,0 +1,12 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "code_scan" + ], + "sbom": [ + "toolchain:arm-none-eabi-gcc@" + ], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/baselines/fw-freertos-lostbuild.json b/fixtures/nightly/baselines/fw-freertos-lostbuild.json new file mode 100644 index 0000000..4efc5ed --- /dev/null +++ b/fixtures/nightly/baselines/fw-freertos-lostbuild.json @@ -0,0 +1,12 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "code_scan" + ], + "sbom": [ + "toolchain:arm-none-eabi-gcc@" + ], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/baselines/fw-make.json b/fixtures/nightly/baselines/fw-make.json new file mode 100644 index 0000000..4efc5ed --- /dev/null +++ b/fixtures/nightly/baselines/fw-make.json @@ -0,0 +1,12 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "code_scan" + ], + "sbom": [ + "toolchain:arm-none-eabi-gcc@" + ], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/baselines/fw-platformio.json b/fixtures/nightly/baselines/fw-platformio.json new file mode 100644 index 0000000..a193803 --- /dev/null +++ b/fixtures/nightly/baselines/fw-platformio.json @@ -0,0 +1,11 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "code_scan", + "firmware_sbom" + ], + "sbom": [], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/baselines/fw-yocto-layer.json b/fixtures/nightly/baselines/fw-yocto-layer.json new file mode 100644 index 0000000..a193803 --- /dev/null +++ b/fixtures/nightly/baselines/fw-yocto-layer.json @@ -0,0 +1,11 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "code_scan", + "firmware_sbom" + ], + "sbom": [], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/baselines/fw-zephyr-example-pinned.json b/fixtures/nightly/baselines/fw-zephyr-example-pinned.json new file mode 100644 index 0000000..4c850a9 --- /dev/null +++ b/fixtures/nightly/baselines/fw-zephyr-example-pinned.json @@ -0,0 +1,12 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "code_scan" + ], + "sbom": [ + "toolchain:zephyr-sdk@" + ], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/baselines/fw-zephyr-pinned.json b/fixtures/nightly/baselines/fw-zephyr-pinned.json new file mode 100644 index 0000000..4c850a9 --- /dev/null +++ b/fixtures/nightly/baselines/fw-zephyr-pinned.json @@ -0,0 +1,12 @@ +{ + "scan_status": "completed", + "skipped_stages": [ + "code_scan" + ], + "sbom": [ + "toolchain:zephyr-sdk@" + ], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/firmware/README.md b/fixtures/nightly/firmware/README.md new file mode 100644 index 0000000..c396841 --- /dev/null +++ b/fixtures/nightly/firmware/README.md @@ -0,0 +1,22 @@ +# Firmware fixtures for the nightly scan regression (#313) + +Each directory is uploaded as a source archive (the harness zips it) and +exercises one Firmwerk build-system provider. Most are copied from Firmwerk's +own provider tests (`crates/firmwerk-core/tests/fixtures`, Firmwerk v0.4.2), +extended with the manifests a real project carries (marked "+"), so the +baselines show when those start to reach the SBOM (#317): + +| Directory | Firmwerk fixture | Provider | +|---|---|---| +| `make` | `make` | Make | +| `cmake` | `cmake` | CMake with a toolchain file | +| `arduino` | `arduino` | Arduino (`sketch.yaml`) | +| `platformio` | `platformio-real` | PlatformIO (pinned platform, + `lib_deps`) | +| `cargo-embedded` | `cargo_embedded` | embedded Rust (+ pinned `rust-toolchain.toml`) | +| `espidf` | `espidf` | ESP-IDF (+ `main/idf_component.yml`) | +| `zephyr-pinned` | `zephyr-pinned` | Zephyr (`west.yml`, pinned revision, + module imports) | +| `freertos-cmake` | (ours) | CMake pulling the FreeRTOS kernel with `FetchContent` at a pinned tag | +| `freertos-lostbuild` | `lostbuild` | source archaeology: no build system, FreeRTOS found from its headers | +| `yocto-layer` | (ours) | none: Yocto is not analysed yet, so the scan must record it | + +When Firmwerk's detection changes on purpose, refresh the copy and re-bless. diff --git a/fixtures/nightly/firmware/arduino/blink.ino b/fixtures/nightly/firmware/arduino/blink.ino new file mode 100644 index 0000000..dd7a7fb --- /dev/null +++ b/fixtures/nightly/firmware/arduino/blink.ino @@ -0,0 +1,11 @@ +// Classic Arduino blink. No main() -- the Arduino core supplies it, Arduino.h, and prototypes. +void setup() { + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); +} diff --git a/fixtures/nightly/firmware/arduino/sketch.yaml b/fixtures/nightly/firmware/arduino/sketch.yaml new file mode 100644 index 0000000..da3108d --- /dev/null +++ b/fixtures/nightly/firmware/arduino/sketch.yaml @@ -0,0 +1,4 @@ +profiles: + default: + fqbn: arduino:avr:uno +default_profile: default diff --git a/fixtures/nightly/firmware/cargo-embedded/.cargo/config.toml b/fixtures/nightly/firmware/cargo-embedded/.cargo/config.toml new file mode 100644 index 0000000..5d10902 --- /dev/null +++ b/fixtures/nightly/firmware/cargo-embedded/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "thumbv7em-none-eabihf" diff --git a/fixtures/nightly/firmware/cargo-embedded/Cargo.toml b/fixtures/nightly/firmware/cargo-embedded/Cargo.toml new file mode 100644 index 0000000..0b088df --- /dev/null +++ b/fixtures/nightly/firmware/cargo-embedded/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "blinky" +version = "0.1.0" +edition = "2021" + +[dependencies] +cortex-m = "0.7" +cortex-m-rt = "0.7" diff --git a/fixtures/nightly/firmware/cargo-embedded/rust-toolchain.toml b/fixtures/nightly/firmware/cargo-embedded/rust-toolchain.toml new file mode 100644 index 0000000..89ea3ce --- /dev/null +++ b/fixtures/nightly/firmware/cargo-embedded/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.82.0" +targets = ["thumbv7em-none-eabihf"] diff --git a/fixtures/nightly/firmware/cmake/CMakeLists.txt b/fixtures/nightly/firmware/cmake/CMakeLists.txt new file mode 100644 index 0000000..5a74cc0 --- /dev/null +++ b/fixtures/nightly/firmware/cmake/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.20) +set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/toolchain.cmake) +project(firmware C) +add_executable(firmware src/main.c) diff --git a/fixtures/nightly/firmware/cmake/toolchain.cmake b/fixtures/nightly/firmware/cmake/toolchain.cmake new file mode 100644 index 0000000..b55927f --- /dev/null +++ b/fixtures/nightly/firmware/cmake/toolchain.cmake @@ -0,0 +1,4 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) +set(CMAKE_C_COMPILER arm-none-eabi-gcc) +set(CMAKE_C_FLAGS "-mcpu=cortex-m4 -mthumb") diff --git a/fixtures/nightly/firmware/espidf/CMakeLists.txt b/fixtures/nightly/firmware/espidf/CMakeLists.txt new file mode 100644 index 0000000..ccb8c22 --- /dev/null +++ b/fixtures/nightly/firmware/espidf/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.16) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(hello_world) diff --git a/fixtures/nightly/firmware/espidf/main/CMakeLists.txt b/fixtures/nightly/firmware/espidf/main/CMakeLists.txt new file mode 100644 index 0000000..52a3b94 --- /dev/null +++ b/fixtures/nightly/firmware/espidf/main/CMakeLists.txt @@ -0,0 +1 @@ +idf_component_register(SRCS "main.c" INCLUDE_DIRS ".") diff --git a/fixtures/nightly/firmware/espidf/main/idf_component.yml b/fixtures/nightly/firmware/espidf/main/idf_component.yml new file mode 100644 index 0000000..0a4df51 --- /dev/null +++ b/fixtures/nightly/firmware/espidf/main/idf_component.yml @@ -0,0 +1,4 @@ +dependencies: + idf: ">=5.1.2" + espressif/led_strip: "==2.5.3" + espressif/mdns: "^1.2.0" diff --git a/fixtures/nightly/firmware/espidf/main/main.c b/fixtures/nightly/firmware/espidf/main/main.c new file mode 100644 index 0000000..a59b79a --- /dev/null +++ b/fixtures/nightly/firmware/espidf/main/main.c @@ -0,0 +1 @@ +void app_main(void) {} diff --git a/fixtures/nightly/firmware/espidf/sdkconfig.defaults b/fixtures/nightly/firmware/espidf/sdkconfig.defaults new file mode 100644 index 0000000..e0a628c --- /dev/null +++ b/fixtures/nightly/firmware/espidf/sdkconfig.defaults @@ -0,0 +1,2 @@ +CONFIG_IDF_TARGET="esp32c3" +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y diff --git a/fixtures/nightly/firmware/freertos-cmake/CMakeLists.txt b/fixtures/nightly/firmware/freertos-cmake/CMakeLists.txt new file mode 100644 index 0000000..dba7516 --- /dev/null +++ b/fixtures/nightly/firmware/freertos-cmake/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.21) +set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/arm-none-eabi.cmake) +project(pump_rtos C ASM) + +include(FetchContent) +FetchContent_Declare(freertos_kernel + GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git + GIT_TAG V11.1.0 +) +add_library(freertos_config INTERFACE) +target_include_directories(freertos_config SYSTEM INTERFACE include) +set(FREERTOS_HEAP "4" CACHE STRING "" FORCE) +set(FREERTOS_PORT "GCC_ARM_CM4F" CACHE STRING "" FORCE) +FetchContent_MakeAvailable(freertos_kernel) + +add_executable(pump_rtos src/main.c) +target_link_libraries(pump_rtos freertos_kernel freertos_config) diff --git a/fixtures/nightly/firmware/freertos-cmake/arm-none-eabi.cmake b/fixtures/nightly/firmware/freertos-cmake/arm-none-eabi.cmake new file mode 100644 index 0000000..715efa6 --- /dev/null +++ b/fixtures/nightly/firmware/freertos-cmake/arm-none-eabi.cmake @@ -0,0 +1,5 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) +set(CMAKE_C_COMPILER arm-none-eabi-gcc) +set(CMAKE_ASM_COMPILER arm-none-eabi-gcc) +set(CMAKE_C_FLAGS_INIT "-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard") diff --git a/fixtures/nightly/firmware/freertos-cmake/include/FreeRTOSConfig.h b/fixtures/nightly/firmware/freertos-cmake/include/FreeRTOSConfig.h new file mode 100644 index 0000000..3b64af5 --- /dev/null +++ b/fixtures/nightly/firmware/freertos-cmake/include/FreeRTOSConfig.h @@ -0,0 +1,9 @@ +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H +#define configUSE_PREEMPTION 1 +#define configCPU_CLOCK_HZ 168000000 +#define configTICK_RATE_HZ 1000 +#define configMAX_PRIORITIES 5 +#define configMINIMAL_STACK_SIZE 128 +#define configTOTAL_HEAP_SIZE (32 * 1024) +#endif diff --git a/fixtures/nightly/firmware/freertos-cmake/src/main.c b/fixtures/nightly/firmware/freertos-cmake/src/main.c new file mode 100644 index 0000000..9606938 --- /dev/null +++ b/fixtures/nightly/firmware/freertos-cmake/src/main.c @@ -0,0 +1,15 @@ +#include "FreeRTOS.h" +#include "task.h" + +static void pump_task(void *arg) { + (void)arg; + for (;;) { + vTaskDelay(pdMS_TO_TICKS(100)); + } +} + +int main(void) { + xTaskCreate(pump_task, "pump", configMINIMAL_STACK_SIZE, NULL, 2, NULL); + vTaskStartScheduler(); + return 0; +} diff --git a/fixtures/nightly/firmware/freertos-lostbuild/app_config.h b/fixtures/nightly/firmware/freertos-lostbuild/app_config.h new file mode 100644 index 0000000..8133934 --- /dev/null +++ b/fixtures/nightly/firmware/freertos-lostbuild/app_config.h @@ -0,0 +1,4 @@ +#ifndef APP_CONFIG_H +#define APP_CONFIG_H +#define APP_TICK_HZ 1000 +#endif diff --git a/fixtures/nightly/firmware/freertos-lostbuild/main.c b/fixtures/nightly/firmware/freertos-lostbuild/main.c new file mode 100644 index 0000000..0d16bf6 --- /dev/null +++ b/fixtures/nightly/firmware/freertos-lostbuild/main.c @@ -0,0 +1,13 @@ +/* Motor controller firmware. Target: STM32F407VG. Build system lost in handover. */ +#include +#include "core_cm4.h" +#include "stm32f4xx.h" +#include "FreeRTOS.h" +#include "task.h" +#include "app_config.h" + +int main(void) { + for (;;) { + } + return 0; +} diff --git a/fixtures/nightly/firmware/make/Makefile b/fixtures/nightly/firmware/make/Makefile new file mode 100644 index 0000000..d7ce4bd --- /dev/null +++ b/fixtures/nightly/firmware/make/Makefile @@ -0,0 +1,9 @@ +CC = arm-none-eabi-gcc +CFLAGS = -mcpu=cortex-m4 -mthumb -Wall -Og +TARGET = firmware.elf + +$(TARGET): src/main.c + $(CC) $(CFLAGS) -o $@ $< + +clean: + rm -f $(TARGET) diff --git a/fixtures/nightly/firmware/platformio/environments.ini b/fixtures/nightly/firmware/platformio/environments.ini new file mode 100644 index 0000000..96305c7 --- /dev/null +++ b/fixtures/nightly/firmware/platformio/environments.ini @@ -0,0 +1,6 @@ +[com-esp32] +platform = ${com.esp32_platform} + +[env:esp32dev] +extends = com-esp32 +board = esp32dev diff --git a/fixtures/nightly/firmware/platformio/platformio.ini b/fixtures/nightly/firmware/platformio/platformio.ini new file mode 100644 index 0000000..a679df3 --- /dev/null +++ b/fixtures/nightly/firmware/platformio/platformio.ini @@ -0,0 +1,14 @@ +[platformio] +extra_configs = + environments.ini + +; Global defaults shared by every environment. +[env] +framework = arduino +lib_deps = + bblanchon/ArduinoJson@7.0.4 + knolleary/PubSubClient@2.8 + +; Pinned platform versions, referenced by name below (like a real project's [com] section). +[com] +esp32_platform = espressif32@6.5.0 diff --git a/fixtures/nightly/firmware/yocto-layer/conf/layer.conf b/fixtures/nightly/firmware/yocto-layer/conf/layer.conf new file mode 100644 index 0000000..61347d1 --- /dev/null +++ b/fixtures/nightly/firmware/yocto-layer/conf/layer.conf @@ -0,0 +1,7 @@ +# Nightly fixture (#313): a minimal Yocto layer. Yocto builds are not analysed +# yet, so the scan must record that instead of completing silently. +BBPATH .= ":${LAYERDIR}" +BBFILES += "${LAYERDIR}/recipes-*/*/*.bb" +BBFILE_COLLECTIONS += "pruefwerk-fixture" +BBFILE_PATTERN_pruefwerk-fixture = "^${LAYERDIR}/" +LAYERSERIES_COMPAT_pruefwerk-fixture = "scarthgap" diff --git a/fixtures/nightly/firmware/yocto-layer/recipes-app/pump-ctl/pump-ctl_1.0.bb b/fixtures/nightly/firmware/yocto-layer/recipes-app/pump-ctl/pump-ctl_1.0.bb new file mode 100644 index 0000000..0e571c1 --- /dev/null +++ b/fixtures/nightly/firmware/yocto-layer/recipes-app/pump-ctl/pump-ctl_1.0.bb @@ -0,0 +1,7 @@ +SUMMARY = "Pump controller daemon (nightly fixture)" +LICENSE = "CLOSED" +SRC_URI = "file://pump-ctl.c" +DEPENDS = "openssl" +do_compile() { + ${CC} ${CFLAGS} ${LDFLAGS} ${WORKDIR}/pump-ctl.c -o pump-ctl -lssl -lcrypto +} diff --git a/fixtures/nightly/firmware/zephyr-pinned/CMakeLists.txt b/fixtures/nightly/firmware/zephyr-pinned/CMakeLists.txt new file mode 100644 index 0000000..706c992 --- /dev/null +++ b/fixtures/nightly/firmware/zephyr-pinned/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(blinky) +target_sources(app PRIVATE src/main.c) diff --git a/fixtures/nightly/firmware/zephyr-pinned/prj.conf b/fixtures/nightly/firmware/zephyr-pinned/prj.conf new file mode 100644 index 0000000..b35bb14 --- /dev/null +++ b/fixtures/nightly/firmware/zephyr-pinned/prj.conf @@ -0,0 +1,2 @@ +CONFIG_GPIO=y +CONFIG_PRINTK=y diff --git a/fixtures/nightly/firmware/zephyr-pinned/west.yml b/fixtures/nightly/firmware/zephyr-pinned/west.yml new file mode 100644 index 0000000..8dcd3c0 --- /dev/null +++ b/fixtures/nightly/firmware/zephyr-pinned/west.yml @@ -0,0 +1,13 @@ +manifest: + remotes: + - name: zephyrproject + url-base: https://github.com/zephyrproject-rtos + projects: + - name: zephyr + remote: zephyrproject + revision: v3.6.0 + import: + name-allowlist: + - cmsis + - hal_nordic + - mbedtls diff --git a/fixtures/nightly/targets.json b/fixtures/nightly/targets.json index 86ee5fd..0f596fb 100644 --- a/fixtures/nightly/targets.json +++ b/fixtures/nightly/targets.json @@ -93,6 +93,140 @@ "plc_format": "project_archive" } ] + }, + { + "key": "fw-make", + "name": "Firmware · Make", + "target_type": "firmware_bare_metal", + "description": "Bare-metal Make project (Firmwerk make provider): cross toolchain from the Makefile.", + "artifacts": [ + { + "kind": "source_archive", + "upload": "fixtures/nightly/firmware/make" + } + ] + }, + { + "key": "fw-cmake", + "name": "Firmware · CMake", + "target_type": "firmware_bare_metal", + "description": "Bare-metal CMake project with a toolchain file (Firmwerk cmake provider).", + "artifacts": [ + { + "kind": "source_archive", + "upload": "fixtures/nightly/firmware/cmake" + } + ] + }, + { + "key": "fw-arduino", + "name": "Firmware · Arduino", + "target_type": "firmware_bare_metal", + "description": "Arduino sketch with sketch.yaml (Firmwerk arduino provider).", + "artifacts": [ + { + "kind": "source_archive", + "upload": "fixtures/nightly/firmware/arduino" + } + ] + }, + { + "key": "fw-platformio", + "name": "Firmware · PlatformIO", + "target_type": "firmware_bare_metal", + "description": "PlatformIO project with extra_configs, a pinned platform and lib_deps (Firmwerk platformio provider).", + "artifacts": [ + { + "kind": "source_archive", + "upload": "fixtures/nightly/firmware/platformio" + } + ] + }, + { + "key": "fw-cargo-embedded", + "name": "Firmware · embedded Rust", + "target_type": "firmware_bare_metal", + "description": "Embedded Rust crate with a cross target in .cargo/config.toml and a pinned rust-toolchain.toml (Firmwerk cargo_embedded provider).", + "artifacts": [ + { + "kind": "source_archive", + "upload": "fixtures/nightly/firmware/cargo-embedded" + } + ] + }, + { + "key": "fw-espidf", + "name": "Firmware · ESP-IDF", + "target_type": "firmware_rtos", + "description": "ESP-IDF project with component-manager dependencies in main/idf_component.yml (Firmwerk espidf provider).", + "artifacts": [ + { + "kind": "source_archive", + "upload": "fixtures/nightly/firmware/espidf" + } + ] + }, + { + "key": "fw-zephyr-pinned", + "name": "Firmware · Zephyr (pinned west.yml)", + "target_type": "firmware_rtos", + "description": "Zephyr application whose west.yml pins zephyr at v3.6.0 and imports three modules (Firmwerk zephyr provider).", + "artifacts": [ + { + "kind": "source_archive", + "upload": "fixtures/nightly/firmware/zephyr-pinned" + } + ] + }, + { + "key": "fw-freertos-cmake", + "name": "Firmware · FreeRTOS via CMake FetchContent", + "target_type": "firmware_rtos", + "description": "CMake project that pulls the FreeRTOS kernel with FetchContent at a pinned tag (V11.1.0), the common FreeRTOS integration.", + "artifacts": [ + { + "kind": "source_archive", + "upload": "fixtures/nightly/firmware/freertos-cmake" + } + ] + }, + { + "key": "fw-freertos-lostbuild", + "name": "Firmware · FreeRTOS, build system lost", + "target_type": "firmware_rtos", + "description": "No build system at all: Firmwerk's source archaeology must still recognise FreeRTOS and the STM32 SDK from the headers.", + "artifacts": [ + { + "kind": "source_archive", + "upload": "fixtures/nightly/firmware/freertos-lostbuild" + } + ] + }, + { + "key": "fw-yocto-layer", + "name": "Firmware · Yocto layer (unsupported)", + "target_type": "embedded_linux_yocto", + "description": "A Yocto layer. Not analysed yet, so the run must record a skipped firmware_sbom stage with the reason instead of completing as if there were no components.", + "artifacts": [ + { + "kind": "source_archive", + "upload": "fixtures/nightly/firmware/yocto-layer" + } + ] + }, + { + "key": "fw-zephyr-example-pinned", + "name": "Firmware · Zephyr example-application (pinned source)", + "target_type": "firmware_rtos", + "description": "The upstream Zephyr example application as a source archive at a pinned commit, so the result does not drift with upstream main. Not committed: the nightly job downloads it into NIGHTLY_ZEPHYR_EXAMPLE; skipped where that is unset.", + "artifacts": [ + { + "kind": "source_archive", + "upload_env": "NIGHTLY_ZEPHYR_EXAMPLE", + "optional": true, + "pin": "38a6d9b276ed434454900130cacc87d058d3ac62" + } + ] } ] } -- 2.54.1