Add unit tests for SafetyState

Aperta Adatta ai principianti
#257 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
90/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c
Ambito
testing

Direzione di ricerca

Leggi src/utils/safety_state.hpp e src/utils/safety_state.cpp per capire SafetyState::evaluate e reasons_to_string, poi confronta la struttura di test/test_utils/test_main.cpp. Rendi controllabile il tempo dell’host in test/host/Arduino.h, aggiungi la suite specificata test/test_safety/test_main.cpp e la voce nel Makefile, quindi esegui make test. Il lavoro è completato quando ogni caso elencato ha un test dedicato e la suite passa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

good first issue not started

SafetyState decides whether the motors may move, and it has no tests. Good first task. No hardware needed.

Files

  • src/utils/safety_state.hpp, src/utils/safety_state.cpp
  • src/utils/timing.hpp (Timer, uses micros())
  • test/host/Arduino.h (host stub; micros() always returns 0 today)
  • Makefile

Steps

  1. Read SafetyState::evaluate. It takes four booleans and returns a bitmask of Reason flags. NONE (0) means the motors are armed.
  2. Make time controllable in host tests. In test/host/Arduino.h, in the non-FW_SIMULATION branch, replace the fixed micros() with:
    inline uint32_t host_fake_micros = 0;
    inline uint32_t micros() { return host_fake_micros; }
    
    Run make test to check nothing else broke.
  3. Create test/test_safety/test_main.cpp (copy the layout of test/test_utils/test_main.cpp) and add to the Makefile:
    HOST_TEST_SRC_test_safety := $(TEST_DIR)/test_safety/test_main.cpp src/utils/safety_state.cpp
    
  4. Write one test per case, with a fresh SafetyState and host_fake_micros = 0 at the start of each:
    • Each input on its own sets exactly its own bit (transmitter, not configured, slow loop, gimbal power off).
    • All four bad at once sets all four bits.
    • Gimbal power just turned on: GIMBAL_POWER_SETTLING is set.
    • Gimbal power on for GIMBAL_POWER_SETTLE_US (3 s) or more: settling clears and motors_armed() is true.
    • Power off then on again: the 3 s wait starts over.
    • reasons_to_string: NONE gives "none", two bits give both names separated by one space, and a small buffer (length 5) never overflows and stays null-terminated.

Done when

  • make test passes with the new test_safety suite.
  • Each case above has its own test.
Lingua principale
C
Stelle
11
Fork
2
Merge medio
18g 3h
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di CU-Robotics/firmware

Tutte le issue di CU-Robotics/firmware

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.