-
Notifications
You must be signed in to change notification settings - Fork 4
Ensure watchdog integration test cleans up after itself #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c5b4ce7
6bff6f2
b21ace8
6112503
5837f0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,34 @@ | ||
| module Components { | ||
| @ Component to blink an LED as a watchdog petter, driven by a rate group | ||
| @ Component to pet the watchdog, driven by a rate group | ||
| passive component Watchdog { | ||
| @ Command to start the watchdog | ||
| sync command START_WATCHDOG( | ||
| ) | ||
|
|
||
| @ Command to stop the watchdog petter | ||
| sync command TEST_STOP_WATCHDOG( | ||
| @ Command to stop the watchdog | ||
| sync command STOP_WATCHDOG( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed command name to no longer be prefixed by |
||
| ) | ||
|
|
||
| @ Telemetry channel counting watchdog petter transitions | ||
| @ Telemetry channel counting watchdog pet transitions | ||
| telemetry WatchdogTransitions: U32 | ||
|
|
||
| @ Event logged when the watchdog petter LED turns on or off | ||
| @ Event logged when the watchdog is started | ||
| event WatchdogStart() \ | ||
| severity activity high \ | ||
| format "Watchdog started" | ||
|
|
||
| @ Event logged when the watchdog is stopped | ||
| event WatchdogStop() \ | ||
| severity activity high \ | ||
| format "Watchdog no longer being pet!" | ||
| format "Watchdog stopped" | ||
|
|
||
| @ Port receiving calls from the rate group | ||
| sync input port run: Svc.Sched | ||
|
|
||
| @ Port to stop the watchdog petting | ||
| @ Port to start the watchdog | ||
| sync input port start: Fw.Signal | ||
|
|
||
| @ Port to stop the watchdog | ||
| sync input port stop: Fw.Signal | ||
|
|
||
| @ Port sending calls to the GPIO driver | ||
|
|
||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """ | ||
| watchdog_test.py: | ||
|
|
||
| Integration tests for the Watchdog component. | ||
| """ | ||
|
|
||
| import time | ||
|
|
||
| import pytest | ||
| from fprime_gds.common.data_types.ch_data import ChData | ||
| from fprime_gds.common.testing_fw.api import IntegrationTestAPI | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def ensure_watchdog_running(fprime_test_api: IntegrationTestAPI): | ||
| """Fixture to ensure watchdog is started before and after each test""" | ||
| start_watchdog(fprime_test_api) | ||
| yield | ||
| start_watchdog(fprime_test_api) | ||
|
|
||
|
|
||
| def start_watchdog(fprime_test_api: IntegrationTestAPI): | ||
| """Helper function to start the watchdog""" | ||
| fprime_test_api.send_and_assert_command( | ||
| "ReferenceDeployment.watchdog.START_WATCHDOG", max_delay=2 | ||
| ) | ||
| fprime_test_api.assert_event( | ||
| "ReferenceDeployment.watchdog.WatchdogStart", timeout=2 | ||
| ) | ||
|
|
||
|
|
||
| def get_watchdog_transitions(fprime_test_api: IntegrationTestAPI) -> int: | ||
| """Helper function to request packet and get fresh WatchdogTransitions telemetry""" | ||
| fprime_test_api.clear_histories() | ||
| fprime_test_api.send_and_assert_command( | ||
| "CdhCore.tlmSend.SEND_PKT", ["5"], max_delay=2 | ||
| ) | ||
| result: ChData = fprime_test_api.assert_telemetry( | ||
| "ReferenceDeployment.watchdog.WatchdogTransitions", start="NOW", timeout=3 | ||
| ) | ||
| return result.get_val() | ||
|
|
||
|
|
||
| def test_01_watchdog_telemetry_basic(fprime_test_api: IntegrationTestAPI): | ||
| """Test that we can read WatchdogTransitions telemetry""" | ||
| value = get_watchdog_transitions(fprime_test_api) | ||
| assert value >= 0, f"WatchdogTransitions should be >= 0, got {value}" | ||
|
|
||
|
|
||
| def test_02_watchdog_increments(fprime_test_api: IntegrationTestAPI): | ||
| """Test that WatchdogTransitions increments over time""" | ||
|
|
||
| initial_value = get_watchdog_transitions(fprime_test_api) | ||
| time.sleep(2.0) # Wait for watchdog to run more cycles | ||
| updated_value = get_watchdog_transitions(fprime_test_api) | ||
|
|
||
| assert updated_value > initial_value, ( | ||
| f"WatchdogTransitions should increase. Initial: {initial_value}, Updated: {updated_value}" | ||
| ) | ||
|
|
||
|
|
||
| def test_03_stop_watchdog_command(fprime_test_api: IntegrationTestAPI): | ||
| """ | ||
| Test STOP_WATCHDOG command sends and emits WatchdogStop | ||
| event and WatchdogTransitions stops incrementing | ||
| """ | ||
| fprime_test_api.clear_histories() | ||
|
|
||
| # Send stop command | ||
| fprime_test_api.send_and_assert_command( | ||
| "ReferenceDeployment.watchdog.STOP_WATCHDOG", max_delay=2 | ||
| ) | ||
|
|
||
| # Check for watchdog stop event | ||
| fprime_test_api.assert_event("ReferenceDeployment.watchdog.WatchdogStop", timeout=2) | ||
|
|
||
| # Get watchdog transition count | ||
| initial_value = get_watchdog_transitions(fprime_test_api) | ||
|
|
||
| # Wait and check that it's no longer incrementing | ||
| time.sleep(2.0) | ||
| final_value = get_watchdog_transitions(fprime_test_api) | ||
|
|
||
| assert final_value == initial_value, ( | ||
| f"Watchdog should remain stopped. Initial: {initial_value}, Final: {final_value}" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swapped logic from running when false to running when true. Helps me understand the state of the watchdog.