Add unit tests for SafetyState

Đang mở Phù hợp với người mới
#257 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
90/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c
Lĩnh vực
testing

Hướng nghiên cứu

Đọc src/utils/safety_state.hpp và src/utils/safety_state.cpp để hiểu SafetyState::evaluate và reasons_to_string, sau đó so sánh bố cục trong test/test_utils/test_main.cpp. Cho phép điều khiển thời gian host trong test/host/Arduino.h, thêm bộ kiểm thử test/test_safety/test_main.cpp được chỉ định và mục trong Makefile, rồi chạy make test. Công việc hoàn tất khi mỗi trường hợp được liệt kê có bài kiểm thử riêng và bộ kiểm thử chạy thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
C
Star
11
Fork
2
Merge trung bình
18 ngày 3 giờ
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CU-Robotics/firmware

Tất cả issue của CU-Robotics/firmware

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.