Add unit tests for SafetyState

オープン 初心者向け
#257 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
90/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c
領域
testing

調査の方向性

src/utils/safety_state.hpp と src/utils/safety_state.cpp を読んで SafetyState::evaluate と reasons_to_string を理解し、test/test_utils/test_main.cpp の構成と比較してください。test/host/Arduino.h でホスト時刻を制御できるようにし、指定された test/test_safety/test_main.cpp のテストスイートと Makefile のエントリーを追加して、make test を実行してください。列挙されたすべてのケースに個別のテストがあり、スイートが成功すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
C
スター
11
フォーク
2
平均マージ
18日 3時間
マージ済み PR(30日)
3

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CU-Robotics/firmware のほかの issue

CU-Robotics/firmware の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。