Skip to main content

Testing

Test organization, validation functions,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_gps_sensor/ │ ├── NMEA parsing verification │ ├── Coordinate validation │ └── Fix quality enumeration tests │ ├── 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/ │ ├── 3-axis data structure tests │ ├── Acceleration magnitude calculation │ └── Timestamp tracking validation │ ├── test_load_sensor/ │ ├── Force calculation (tare/scale) │ ├── Mass conversion (g/kg/lbf) │ ├── Dual sensor independence │ └── Calibration parameter storage │ ├── test_ph_sensor/ │ ├── ADC to voltage conversion │ ├── pH value calculation │ ├── Sample averaging (40-sample buffer) │ ├── Calibration offset/slope │ └── Edge cases (pH 0, 14) │ ├── test_pressure_sensor/ │ ├── Pressure reading validation │ ├── Temperature compensation │ ├── Unit conversions (bar/psi/kPa) │ └── Dual sensor independence │ └── test_sensor_basics/ ├── Conversion functions ├── Validation functions ├── Range checking └── Boundary conditions

Validation Functions

GPS Validation

result_t validate_gps_latitude(double latitude);
// Valid range: -90.0 to +90.0 degrees

result_t validate_gps_longitude(double longitude);
// Valid range: -180.0 to +180.0 degrees

result_t validate_gps_hdop(float hdop);
// Typical range: 0.0 to 50.0

result_t validate_gps_satellite_count(int32_t satellites);
// Typical range: 0 to 30 satellites

pH Validation

result_t validate_ph_value(float ph_value);
// Valid range: 0.0 to 14.0

IMU Validation

result_t validate_accelerometer_value(float accel_value);
// Typical range: -50.0 to +50.0 m/s²

result_t validate_imu_data(float accel_x, float accel_y, float accel_z);

Unit Conversion Tests(extra stuff)

result_t celsius_to_fahrenheit(float celsius, float *fahrenheit);
result_t fahrenheit_to_celsius(float fahrenheit, float *celsius);
result_t bar_to_psi(float bar, float *psi);
result_t psi_to_bar(float psi, float *bar);
test_imu_sensor.c

Test Framework

Testing Technology

  • FrameworkFramework:: Unity (open-open source C testing framework)
  • Build Systemsystem:: CMake / PlatformIO (env:sensor_board, test_filter = sensor_board/*)
  • Test Typetype:: Hosteddriver unitlogic tests exercising the data structures and math directly; the hardware access paths (runADC, onHX711 PC)
  • Mocking:GPIO, MockEXTI) ADC/UART/I2Care interfacesnot mocked and not covered

Building and Running Tests

//# BuildAll allsensor board tests
pio test -e sensor_board

//# Run specific testOne 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 connectedconnected, or driver compile gated

Check UART/I2C/SPIwiring; wiringfor pH/pressure verify the PH_SENSOR_USE_ADC / PRESSURE_USE_ADC build flags and the CubeMX ADC config

Sensor ERROR

Communication failure

Verify baudHX711 rates,wiring addressesand 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 packetprotobuf encoderencode/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