Add unit tests for SafetyState
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 90/100
Research direction
Read src/utils/safety_state.hpp and src/utils/safety_state.cpp to understand SafetyState::evaluate and reasons_to_string, then compare the layout in test/test_utils/test_main.cpp. Make host time controllable in test/host/Arduino.h, add the specified test/test_safety/test_main.cpp suite and Makefile entry, and run make test. Done means every listed case has its own test and the suite passes.
Written by the indexing model from the issue text.
Description
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.cppsrc/utils/timing.hpp(Timer, usesmicros())test/host/Arduino.h(host stub;micros()always returns 0 today)Makefile
Steps
- Read
SafetyState::evaluate. It takes four booleans and returns a bitmask ofReasonflags.NONE(0) means the motors are armed. - Make time controllable in host tests. In
test/host/Arduino.h, in the non-FW_SIMULATIONbranch, replace the fixedmicros()with:
Runinline uint32_t host_fake_micros = 0; inline uint32_t micros() { return host_fake_micros; }make testto check nothing else broke. - Create
test/test_safety/test_main.cpp(copy the layout oftest/test_utils/test_main.cpp) and add to theMakefile:HOST_TEST_SRC_test_safety := $(TEST_DIR)/test_safety/test_main.cpp src/utils/safety_state.cpp - Write one test per case, with a fresh
SafetyStateandhost_fake_micros = 0at 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_SETTLINGis set. - Gimbal power on for
GIMBAL_POWER_SETTLE_US(3 s) or more: settling clears andmotors_armed()is true. - Power off then on again: the 3 s wait starts over.
reasons_to_string:NONEgives"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 testpasses with the newtest_safetysuite.- Each case above has its own test.
- Dominant language
- C
- Stars
- 11
- Forks
- 2
- Avg merge
- 18d 3h
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from CU-Robotics/firmware
-
Pre-flight checksOpenin progress
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
CU-Robotics/firmware#222 ·
-
Fix existing clang-tidy findingsPossibly taken @roccoagain claimed this today. Open
CU-Robotics/firmware#262 · 1 assignee ·
-
not started
Difficulty 5/5 Over a week Newbie friendliness 35/100
CU-Robotics/firmware#258 ·
-
good first issue not started
Difficulty 3/5 1-2 days Newbie friendliness 76/100
CU-Robotics/firmware#256 ·
-
in progress software-in-the-loop
Difficulty 4/5 3-5 days Newbie friendliness 42/100
CU-Robotics/firmware#250 · 1 comment ·
All issues in CU-Robotics/firmware
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
schrodinger/pymol-open-source#532 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
CTSRD-CHERI/cheribsd#2769 ·
Maintainers usually reply within 2 days
-
documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
luainkernel/lunatik#2633 ·
Maintainers usually reply within 1 day
-
type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 1 day