Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ test --test_summary=detailed
# Use tests profile by default for test commands
test --config=tests

# ============================================================================
# FSM Integration Test Configurations
# ============================================================================

# These configs layer on top of `tests` (which `test` already inherits) and
# add the global --copt defines needed by the FSM integration tests.
# Usage:
# bazel test //src/scheduler:fsm_test_flight --config=fsm-flight
# bazel test //src/scheduler:fsm_test_bringup --config=fsm-bringup
# bazel test //src/scheduler:fsm_test_debug (no extra config needed)

build:fsm-flight --copt=-DFLIGHT=1
build:fsm-flight '--copt=-DPACKET_HMAC_PSK="test_key_0000000000000000"'

build:fsm-bringup --copt=-DBRINGUP=1

# ============================================================================
# Optimization Settings
# ============================================================================
Expand Down
49 changes: 39 additions & 10 deletions .github/workflows/c_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- '.bazelrc'
- '.github/workflows/*.yaml'

Test:
Unit-Tests:
needs: changes
if: ${{ needs.changes.outputs.should_test == 'true' }}
runs-on: ubuntu-latest
Expand All @@ -43,21 +43,50 @@ jobs:
- name: Set up Bazel
uses: bazel-contrib/setup-bazel@0.18.0
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Store build cache per workflow.
disk-cache: ${{ github.workflow }}
# Share repository cache between workflows.
disk-cache: ${{ github.workflow }}-unit
repository-cache: true

- name: Run all tests
- name: Run unit tests
run: bazel test //src/... --test_output=errors

- name: Archive test visualization logs
- name: Archive unit test visualization logs
if: always()
uses: actions/upload-artifact@v4
with:
name: test-visualization-logs
name: unit-test-viz-logs
path: |
bazel-testlogs/**/*_viz.json
bazel-bin/**/*_viz.json
bazel-testlogs/**/test.outputs/*.json

FSM-Integration:
needs: changes
if: ${{ needs.changes.outputs.should_test == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Bazel
uses: bazel-contrib/setup-bazel@0.18.0
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}-fsm
repository-cache: true

- name: FSM test (debug)
run: bazel test //src/scheduler:fsm_test_debug --test_output=errors

- name: FSM test (flight)
run: bazel test //src/scheduler:fsm_test_flight --config=fsm-flight --test_output=errors

- name: FSM test (bringup)
run: bazel test //src/scheduler:fsm_test_bringup --config=fsm-bringup --test_output=errors

- name: Archive FSM visualization logs
if: always()
uses: actions/upload-artifact@v4
with:
name: fsm-viz-logs
path: |
bazel-testlogs/**/test.outputs/fsm_viz_*.json
2 changes: 1 addition & 1 deletion src/drivers/flash/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cc_library(
# Note: No dedicated flash mock in test_mocks, using driver_stubs
cc_library(
name = "flash_mock",
srcs = [],
srcs = ["flash_mock.c"],
hdrs = ["flash.h"],
includes = ["."],
deps = [
Expand Down
42 changes: 42 additions & 0 deletions src/drivers/flash/flash_mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @file flash_mock.c
* @brief Mock implementation of flash driver for host testing.
*/

#include "flash.h"
#include <string.h>

static persistent_data_t mock_data = {0};

persistent_data_t *init_persistent_data(void)
{
memset(&mock_data, 0, sizeof(mock_data));
mock_data.marker = 0xDEADBEEF;
mock_data.reboot_counter = 1;
return &mock_data;
}

void increment_reboot_counter()
{
mock_data.reboot_counter++;
}

uint32_t get_reboot_counter()
{
return mock_data.reboot_counter;
}

void increment_burn_wire_attempts()
{
mock_data.burn_wire_attempts++;
}

uint32_t get_burn_wire_attempts()
{
return mock_data.burn_wire_attempts;
}

void reset_burn_wire_attempts()
{
mock_data.burn_wire_attempts = 0;
}
4 changes: 3 additions & 1 deletion src/packet/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ cc_library(
"//src/common",
"//lib/tinycrypt",
] + select({
"//bzl:test_mode": [],
"//bzl:test_mode": [
"//src/drivers/logger:logger_mock",
],
"//conditions:default": [
"//src/drivers/logger",
"@pico-sdk//src/rp2_common/pico_stdlib:pico_stdlib",
Expand Down
2 changes: 0 additions & 2 deletions src/packet/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
*/

#include "packet.h"
#ifndef TEST
#include "logger.h"
#endif

#include <tinycrypt/hmac.h>
#include <tinycrypt/sha256.h>
Expand Down
42 changes: 42 additions & 0 deletions src/scheduler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,45 @@ cc_library(
],
}),
)

# ============================================================================
# FSM Integration Tests
# ============================================================================

load("//bzl:defs.bzl", "samwise_test")

# Common deps for all FSM tests
_FSM_TEST_DEPS = [
"//src/states/init:init_state",
"//src/states/running:running_state",
"//src/states/bringup:bringup_state",
"//src/states/burn_wire:burn_wire_state",
"//src/states/burn_wire_reset:burn_wire_reset_state",
]

samwise_test(
name = "fsm_test_debug",
srcs = ["test/test_fsm.c"],
deps = _FSM_TEST_DEPS,
)

# FLIGHT and BRINGUP tests require global --copt defines to propagate to
# state source files. They are tagged "manual" so they don't break
# `bazel test //...`. Run them with their dedicated configs:
# bazel test //src/scheduler:fsm_test_flight --config=fsm-flight
# bazel test //src/scheduler:fsm_test_bringup --config=fsm-bringup
samwise_test(
name = "fsm_test_flight",
srcs = ["test/test_fsm.c"],
defines = ["FLIGHT"],
tags = ["manual"],
deps = _FSM_TEST_DEPS,
)

samwise_test(
name = "fsm_test_bringup",
srcs = ["test/test_fsm.c"],
defines = ["BRINGUP"],
tags = ["manual"],
deps = _FSM_TEST_DEPS,
)
Loading