# Testing

Test organization, the Unity testing framework usage, coverage per suite, manual hardware testing checklists and a debugging/troubleshooting guide. Reminder: the sensor board code was only partially tested; unit tests cover the pure-logic parts of the drivers, and end to end hardware validation was not completed by the 2025-2026 team.

## Test Organization

<table id="bkmrk-test-suites-table"><colgroup><col></col><col></col></colgroup><tbody><tr><th>Suite

</th><th>Location

</th></tr><tr><td>test\_sensor\_basics

</td><td>test/sensor\_board/test\_sensor\_basics/test\_sensor\_basics.c

</td></tr><tr><td>test\_ph\_sensor

</td><td>test/sensor\_board/test\_ph\_sensor/test\_ph\_sensor.c

</td></tr><tr><td>test\_imu\_sensor

</td><td>test/sensor\_board/test\_imu\_sensor/test\_imu\_sensor.c

</td></tr></tbody></table>

## Test Framework

- **Framework:**<span style="white-space: pre-wrap;"> Unity (open source C testing framework)</span>
- **Build system:**<span style="white-space: pre-wrap;"> PlatformIO (env:sensor\_board, test\_filter = sensor\_board/\*)</span>
- **Test type:**<span style="white-space: pre-wrap;"> driver logic tests exercising the data structures and math directly; the hardware access paths (ADC, HX711 GPIO, EXTI) are not mocked and not covered</span>

## Building and Running Tests

```bash
# All sensor board tests
pio test -e sensor_board

# One suite
pio test -e sensor_board -f test_ph_sensor

# Verbose output
pio test -e sensor_board -f test_sensor_basics -v
```

## Coverage Per Suite

### test\_sensor\_basics

- Accelerometer boundary values: ±160.0 accepted, ±160.1 rejected
- Multi-axis validation: one bad axis fails validate\_imu\_data()
- Temperature and pressure conversion tests exist but are commented out together with their implementations

### test\_ph\_sensor

- Initialization defaults (raw 0, voltage 0, pH 7.0, stored reference voltage)
- ADC to voltage to pH conversion with a 12-bit ADC scale
- Clamping at the extremes (ADC 0 clamps to pH 14, full scale clamps to pH 0 with the test calibration)
- Calibration changes the measurement (offset and slope applied)

### test\_imu\_sensor

- Initialization zeroes all axes and the timestamp
- Update and read round-trip for accel/gyro/mag and timestamp
- Acceleration magnitude (3-4-12 triangle gives 13)
- Pitch and roll helpers from accelerometer data
- Range validators accept zeros and reject out-of-range values

## Manual Hardware Testing Checklist

1. <span style="white-space: pre-wrap;">Flash with </span>`<span class="editor-theme-code">pio run -e sensor_board -t upload</span>`<span style="white-space: pre-wrap;"> and open the serial monitor at 115200 baud</span>
2. Confirm the boot banner and each "init completed" line (IMU, pH, load cells, pressure, flow, pump, Ethernet)
3. Confirm the three LEDs toggle every 5 seconds (loop heartbeat)
4. Check the per-sensor status lines: connected hardware should read OPERATING | OK, absent hardware IDLE | DISCONNECTED
5. Load cells: press on each cell and watch raw\_counts/force change; verify tare at startup reads near zero
6. Flow and pump: with tubing wet, enabling the pump must produce flow pulses; "commanded on but no flow detected" indicates a dry/absent pump or a not-configured EXTI4 line
7. Network: set sendUDP = true, then capture UDP datagrams on port 1500 at 192.168.0.222 and decode with the PBEnvelope schema
8. Send a SensorBoardPumpInfo command packet and verify the pump speed changes

## Debugging &amp; Troubleshooting

<table id="bkmrk-troubleshooting-table"><colgroup><col></col><col></col><col></col></colgroup><tbody><tr><th>Issue

</th><th>Cause

</th><th>Solution

</th></tr><tr><td>Sensor IDLE / DISCONNECTED

</td><td>Not connected, or driver compile gated

</td><td>Check wiring; for pH/pressure verify the PH\_SENSOR\_USE\_ADC / PRESSURE\_USE\_ADC build flags and the CubeMX ADC config

</td></tr><tr><td>Sensor ERROR

</td><td>Communication failure

</td><td>Verify HX711 wiring and timing, I2C address and pull-ups, ADC channel binding

</td></tr><tr><td>Invalid data

</td><td>Out of range values

</td><td>Check calibration parameters (pH slope/offset, load cell scale/tare, pressure scale/offset)

</td></tr><tr><td>Flow always 0

</td><td>EXTI4 not enabled in CubeMX

</td><td>Configure PA4 as EXTI4 rising edge and enable the EXTI4 NVIC line

</td></tr><tr><td>Pump OPERATING / DISCONNECTED

</td><td>No flow while commanded on

</td><td>Pump absent, dry, or stalled; or the flow sensor is not installed/configured

</td></tr><tr><td>No UDP packets

</td><td>Transmit gate or addressing

</td><td>Set sendUDP = true; check IP/MAC constants, MAC filtering, and that port 1500 is not blocked

</td></tr><tr><td>Low heap warning

</td><td>Memory leak or queue growth

</td><td>Review protobuf encode/free paths and UDP queue sizes

</td></tr><tr><td>Serial monitor silent

</td><td>Wrong port or baud

</td><td>Check the ST-Link COM port and 115200 baud; verify LOG\_init ran

</td></tr></tbody></table>