Skip to main content

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

Suite

Location

test_sensor_basics

test/sensor_board/test_sensor_basics/test_sensor_basics.c

test_ph_sensor

test/sensor_board/test_ph_sensor/test_ph_sensor.c

test_imu_sensor

test/sensor_board/test_imu_sensor/test_imu_sensor.c

Test Framework

  • Framework: Unity (open source C testing framework)
  • Build system: PlatformIO (env:sensor_board, test_filter = sensor_board/*)
  • Test type: driver logic tests exercising the data structures and math directly; the hardware access paths (ADC, HX711 GPIO, EXTI) are not mocked and not covered

Building and Running Tests

# 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. Flash with pio run -e sensor_board -t upload and open the serial monitor at 115200 baud
  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 & Troubleshooting

Issue

Cause

Solution

Sensor IDLE / DISCONNECTED

Not connected, or driver compile gated

Check wiring; for pH/pressure verify the PH_SENSOR_USE_ADC / PRESSURE_USE_ADC build flags and the CubeMX ADC config

Sensor ERROR

Communication failure

Verify HX711 wiring and timing, I2C address and pull-ups, ADC channel binding

Invalid data

Out of range values

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

Flow always 0

EXTI4 not enabled in CubeMX

Configure PA4 as EXTI4 rising edge and enable the EXTI4 NVIC line

Pump OPERATING / DISCONNECTED

No flow while commanded on

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

No UDP packets

Transmit gate or addressing

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

Low heap warning

Memory leak or queue growth

Review protobuf encode/free paths and UDP queue sizes

Serial monitor silent

Wrong port or baud

Check the ST-Link COM port and 115200 baud; verify LOG_init ran