Skip to content

Commit d57ed57

Browse files
committed
Add command failure test
1 parent 4b42cc4 commit d57ed57

File tree

3 files changed

+126
-127
lines changed

3 files changed

+126
-127
lines changed

FprimeZephyrReference/Components/Drv/RtcManager/docs/sdd.md

Lines changed: 44 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,47 @@ The RTC Manager component interfaces with the RTC Real Time Clock (RTC) to provi
44

55
### Typical Usage
66

7-
#### `timeGetPort` Port Usage
7+
#### `TIME_SET` Command Usage
88
1. The component is instantiated and initialized during system startup
9-
2. In a deployment topology, a `time connection` is made to the component's `timeGetPort` port
9+
2. A ground station sends a `TIME_SET` command with the desired time
10+
3. On each command, the component:
11+
- Sets the time on the RTC
12+
- Emits a `TimeSet` event if the time is set successfully
13+
- Emits a `TimeNotSet` event if the time is not set successfully
14+
- Emits a `DeviceNotReady` event if the device is not ready
1015

11-
#### `timeGet` Port Usage
16+
#### `timeGetPort` Port Usage
1217
1. The component is instantiated and initialized during system startup
13-
2. A manager calls the `timeGet` ports
18+
2. In a deployment topology, a `time connection` relation is made.
1419
3. On each call, the component:
15-
- Fetches and returns the time from the RTC RTC
20+
- Fetches and returns the time from the RTC
1621
- Emits a `DeviceNotReady` event if the device is not ready
1722

18-
#### `timeSet` Port Usage
23+
#### `timeGet` Port Usage
1924
1. The component is instantiated and initialized during system startup
20-
2. A manager calls the `timeSet` ports
25+
2. A manager calls the `timeGet` ports
2126
3. On each call, the component:
22-
- Sets the time on the RTC RTC
23-
- Emits a `TimeSet` event if the time is set successfully
24-
- Emits a `TimeNotSet` event if the time is not set successfully
27+
- Fetches and returns the time from the RTC
2528
- Emits a `DeviceNotReady` event if the device is not ready
2629

2730
## Requirements
2831
| Name | Description | Validation |
2932
|---|---|---|
30-
| RtcManager-001 | Time can be set on the RTC through a port | Manual |
31-
| RtcManager-002 | Time can be read from the RTC through a port | Manual |
33+
| RtcManager-001 | The RTC Manager has a command that sets the time on the RTC | Integration test |
34+
| RtcManager-002 | The RTC Manager has a port which, when called, set the time in FPrime | Integration test |
3235
| RtcManager-003 | A device not ready event is emitted if the RTC is not ready | Manual |
33-
| RtcManager-004 | A time set event is emitted if the time is set successfully | Manual |
34-
| RtcManager-005 | A time not set event is emitted if the time is not set successfully | Manual |
36+
| RtcManager-004 | A time set event is emitted if the time is set successfully | Integration test |
37+
| RtcManager-005 | A time not set event is emitted if the time is not set successfully | Integration test |
3538

3639
## Port Descriptions
3740
| Name | Description |
3841
|---|---|
3942
| timeGetPort | Time port for FPrime topology connection to get the time from the RTC |
40-
| timeSet | Input port sets the time on the RTC |
41-
| timeGet | Input port reads the time from the RTC |
43+
44+
## Commands
45+
| Name | Description |
46+
|---|---|
47+
| SET_TIME | Sets the time on the RTC |
4248

4349
## Events
4450
| Name | Description |
@@ -59,8 +65,8 @@ classDiagram
5965
+ RtcManager(char* compName)
6066
+ ~RtcManager()
6167
- void timeGetPort_handler(FwIndexType portNum, Fw::Time& time)
62-
- U32 timeGet_handler(FwIndexType portNum)
63-
- void timeSet_handler(FwIndexType portNum, const Drv::TimeData& time)
68+
- Fw::CmdResponse timeSet_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq, const Drv::TimeData& time)
69+
- Fw::Time timeGet(U32& posix_time, U32& u_secs)
6470
}
6571
}
6672
RtcManagerComponentBase <|-- RtcManager : inherits
@@ -78,11 +84,11 @@ sequenceDiagram
7884
participant Deployment Time Connection
7985
participant RTC Manager
8086
participant Zephyr Time API
81-
participant RTC RTC
87+
participant RTC
8288
Deployment Time Connection-->>RTC Manager: Call timeGetPort time port
8389
RTC Manager->>Zephyr Time API: Read time
84-
Zephyr Time API->>RTC RTC: Read time
85-
RTC RTC->>Zephyr Time API: Return time
90+
Zephyr Time API->>RTC: Read time
91+
RTC->>Zephyr Time API: Return time
8692
Zephyr Time API->>RTC Manager: Return time
8793
RTC Manager-->>Deployment Time Connection: Return time
8894
```
@@ -94,70 +100,32 @@ sequenceDiagram
94100
participant Deployment Time Connection
95101
participant RTC Manager
96102
participant Zephyr Time API
97-
participant RTC RTC
103+
participant RTC
98104
Deployment Time Connection->>RTC Manager: Call timeGetPort time port
99105
RTC Manager->>Zephyr Time API: Read time
100-
Zephyr Time API->>RTC RTC: Read time
101-
RTC RTC->>Zephyr Time API: Return device not ready
106+
Zephyr Time API->>RTC: Read time
107+
RTC->>Zephyr Time API: Return device not ready
102108
Zephyr Time API->>RTC Manager: Return device not ready
103109
RTC Manager->>Event Log: Emit DeviceNotReady event
104110
RTC Manager->>Deployment Time Connection: Return 0 time
105111
```
106112

107-
### `timeGet` port
108-
109-
The `timeGet` port is called from a manager component to get the current time from the RTC.
110-
111-
#### Success
112-
```mermaid
113-
sequenceDiagram
114-
participant Event Log
115-
participant Manager
116-
participant RTC Manager
117-
participant Zephyr Time API
118-
participant RTC RTC
119-
Manager-->>RTC Manager: Call timeGet synchronous input port
120-
RTC Manager->>Zephyr Time API: Read time
121-
Zephyr Time API->>RTC RTC: Read time
122-
RTC RTC->>Zephyr Time API: Return time
123-
Zephyr Time API->>RTC Manager: Return time
124-
RTC Manager->>Event Log: Emit event GetTime
125-
```
126-
127-
#### Device Not Ready
128-
```mermaid
129-
sequenceDiagram
130-
participant Event Log
131-
participant Manager
132-
participant RTC Manager
133-
participant Zephyr Time API
134-
participant RTC RTC
135-
Manager-->>RTC Manager: Call timeGet synchronous input port
136-
RTC Manager->>Zephyr Time API: Read time
137-
Zephyr Time API->>RTC RTC: Read time
138-
RTC RTC->>Zephyr Time API: Return device not ready
139-
Zephyr Time API->>RTC Manager: Return device not ready
140-
RTC Manager->>Event Log: Emit event DeviceNotReady
141-
```
142-
143-
### `timeSet` port
113+
### `TIME_SET` Command
144114

145-
The `timeSet` port is called from a manager component to set the current time on the RTC.
115+
The `TIME_SET` command is called to set the current time on the RTC.
146116

147117
#### Success
148118
```mermaid
149119
sequenceDiagram
150120
participant Ground Station
151121
participant Event Log
152-
participant Manager
153122
participant RTC Manager
154123
participant Zephyr Time API
155-
participant RTC RTC
156-
Ground Station-->>Manager: Command to set time with Drv::TimeData struct
157-
Manager->>RTC Manager: Call the timeSet synchronous input port with Drv::TimeData struct
124+
participant RTC
125+
Ground Station-->>RTC Manager: Command to set time with Drv::TimeData struct
158126
RTC Manager->>Zephyr Time API: Set time
159-
Zephyr Time API->>RTC RTC: Set time
160-
RTC RTC->>Zephyr Time API: Return set success
127+
Zephyr Time API->>RTC: Set time
128+
RTC->>Zephyr Time API: Return set success
161129
Zephyr Time API->>RTC Manager: Return set success
162130
RTC Manager->>Event Log: Emit event TimeSet
163131
```
@@ -167,15 +135,13 @@ sequenceDiagram
167135
sequenceDiagram
168136
participant Ground Station
169137
participant Event Log
170-
participant Manager
171138
participant RTC Manager
172139
participant Zephyr Time API
173-
participant RTC RTC
174-
Ground Station-->>Manager: Command to set time with Drv::TimeData struct
175-
Manager->>RTC Manager: Call the timeSet synchronous input port with Drv::TimeData struct
140+
participant RTC
141+
Ground Station-->>RTC Manager: Command to set time with Drv::TimeData struct
176142
RTC Manager->>Zephyr Time API: Set time
177-
Zephyr Time API->>RTC RTC: Set time
178-
RTC RTC->>Zephyr Time API: Return device not ready
143+
Zephyr Time API->>RTC: Set time
144+
RTC->>Zephyr Time API: Return device not ready
179145
Zephyr Time API->>RTC Manager: Return device not ready
180146
RTC Manager->>Event Log: Emit event DeviceNotReady
181147
```
@@ -185,15 +151,13 @@ sequenceDiagram
185151
sequenceDiagram
186152
participant Ground Station
187153
participant Event Log
188-
participant Manager
189154
participant RTC Manager
190155
participant Zephyr Time API
191-
participant RTC RTC
192-
Ground Station-->>Manager: Command to set time with Drv::TimeData struct
193-
Manager->>RTC Manager: Call the timeSet synchronous input port with Drv::TimeData struct
156+
participant RTC
157+
Ground Station-->>RTC Manager: Command to set time with Drv::TimeData struct
194158
RTC Manager->>Zephyr Time API: Set time
195-
Zephyr Time API->>RTC RTC: Set time
196-
RTC RTC->>Zephyr Time API: Return set failure
159+
Zephyr Time API->>RTC: Set time
160+
RTC->>Zephyr Time API: Return set failure
197161
Zephyr Time API->>RTC Manager: Return set failure
198162
RTC Manager->>Event Log: Emit event TimeNotSet
199163
```
Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
1-
# """
2-
# integration_test.py:
1+
"""
2+
integration_test.py:
33
4-
# Simple integration tests for the Watchdog component.
5-
# Tests are ordered so that stop tests run last.
6-
# """
4+
Simple integration tests for the Watchdog component.
5+
Tests are ordered so that stop tests run last.
6+
"""
77

8-
# def get_watchdog_transitions(fprime_test_api):
9-
# """Helper function to request packet and get fresh WatchdogTransitions telemetry"""
10-
# fprime_test_api.clear_histories()
11-
# fprime_test_api.send_and_assert_command("CdhCore.tlmSend.SEND_PKT", ["5"], max_delay=2)
12-
# result = fprime_test_api.assert_telemetry(
13-
# "ReferenceDeployment.watchdog.WatchdogTransitions",
14-
# start="NOW", timeout=3
15-
# )
16-
# return result.get_val()
8+
def get_watchdog_transitions(fprime_test_api):
9+
"""Helper function to request packet and get fresh WatchdogTransitions telemetry"""
10+
fprime_test_api.clear_histories()
11+
fprime_test_api.send_and_assert_command("CdhCore.tlmSend.SEND_PKT", ["5"], max_delay=2)
12+
result = fprime_test_api.assert_telemetry(
13+
"ReferenceDeployment.watchdog.WatchdogTransitions",
14+
start="NOW", timeout=3
15+
)
16+
return result.get_val()
1717

1818

19-
# def test_01_watchdog_telemetry_basic(fprime_test_api):
20-
# """Test that we can read WatchdogTransitions telemetry"""
21-
# value = get_watchdog_transitions(fprime_test_api)
22-
# assert value >= 0, f"WatchdogTransitions should be >= 0, got {value}"
19+
def test_01_watchdog_telemetry_basic(fprime_test_api):
20+
"""Test that we can read WatchdogTransitions telemetry"""
21+
value = get_watchdog_transitions(fprime_test_api)
22+
assert value >= 0, f"WatchdogTransitions should be >= 0, got {value}"
2323

2424

25-
# def test_02_watchdog_increments(fprime_test_api):
26-
# """Test that WatchdogTransitions increments over time"""
27-
# import time
25+
def test_02_watchdog_increments(fprime_test_api):
26+
"""Test that WatchdogTransitions increments over time"""
27+
import time
2828

29-
# initial_value = get_watchdog_transitions(fprime_test_api)
30-
# time.sleep(2.0) # Wait for watchdog to run more cycles
31-
# updated_value = get_watchdog_transitions(fprime_test_api)
29+
initial_value = get_watchdog_transitions(fprime_test_api)
30+
time.sleep(2.0) # Wait for watchdog to run more cycles
31+
updated_value = get_watchdog_transitions(fprime_test_api)
3232

33-
# assert updated_value > initial_value, \
34-
# f"WatchdogTransitions should increase. Initial: {initial_value}, Updated: {updated_value}"
33+
assert updated_value > initial_value, \
34+
f"WatchdogTransitions should increase. Initial: {initial_value}, Updated: {updated_value}"
3535

3636

37-
# def test_03_stop_watchdog_command(fprime_test_api):
38-
# """Test TEST_STOP_WATCHDOG command sends and emits WatchdogStop event"""
39-
# fprime_test_api.clear_histories()
37+
def test_03_stop_watchdog_command(fprime_test_api):
38+
"""Test TEST_STOP_WATCHDOG command sends and emits WatchdogStop event"""
39+
fprime_test_api.clear_histories()
4040

41-
# fprime_test_api.send_and_assert_command(
42-
# "ReferenceDeployment.watchdog.TEST_STOP_WATCHDOG",
43-
# max_delay=2
44-
# )
41+
fprime_test_api.send_and_assert_command(
42+
"ReferenceDeployment.watchdog.TEST_STOP_WATCHDOG",
43+
max_delay=2
44+
)
4545

46-
# fprime_test_api.assert_event(
47-
# "ReferenceDeployment.watchdog.WatchdogStop",
48-
# timeout=2
49-
# )
46+
fprime_test_api.assert_event(
47+
"ReferenceDeployment.watchdog.WatchdogStop",
48+
timeout=2
49+
)
5050

5151

52-
# def test_04_watchdog_stops_incrementing(fprime_test_api):
53-
# """Test that WatchdogTransitions stops incrementing after TEST_STOP_WATCHDOG"""
54-
# import time
52+
def test_04_watchdog_stops_incrementing(fprime_test_api):
53+
"""Test that WatchdogTransitions stops incrementing after TEST_STOP_WATCHDOG"""
54+
import time
5555

56-
# # Get initial value (should be from stopped watchdog from previous test)
57-
# initial_value = get_watchdog_transitions(fprime_test_api)
56+
# Get initial value (should be from stopped watchdog from previous test)
57+
initial_value = get_watchdog_transitions(fprime_test_api)
5858

59-
# # Wait and check that it's not incrementing (watchdog should already be stopped)
60-
# time.sleep(2.0)
61-
# final_value = get_watchdog_transitions(fprime_test_api)
59+
# Wait and check that it's not incrementing (watchdog should already be stopped)
60+
time.sleep(2.0)
61+
final_value = get_watchdog_transitions(fprime_test_api)
6262

63-
# assert final_value == initial_value, \
64-
# f"Watchdog should remain stopped. Initial: {initial_value}, Final: {final_value}"
63+
assert final_value == initial_value, \
64+
f"Watchdog should remain stopped. Initial: {initial_value}, Final: {final_value}"

FprimeZephyrReference/test/int/rtc_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,38 @@ def test_02_time_incrementing(fprime_test_api: IntegrationTestAPI):
130130
assert updated_time > initial_time, (
131131
f"Time should increase. Initial: {initial_time}, Updated: {updated_time}"
132132
)
133+
134+
135+
def test_03_time_not_set_event(fprime_test_api: IntegrationTestAPI):
136+
"""Test that a TimeNotSet event is emitted when setting time with invalid data"""
137+
138+
# Clear histories
139+
fprime_test_api.clear_histories()
140+
141+
# Send command to set the time with invalid data
142+
time_data = dict(
143+
Year=0,
144+
Month=12345, # Invalid month
145+
Day=12345,
146+
Hour=12345,
147+
Minute=12345,
148+
Second=12345,
149+
)
150+
time_data_str = json.dumps(time_data)
151+
fprime_test_api.send_command(
152+
"ReferenceDeployment.rtcManager.TIME_SET",
153+
[
154+
time_data_str,
155+
],
156+
)
157+
158+
# Assert time not set event is emitted
159+
fprime_test_api.assert_event(
160+
"ReferenceDeployment.rtcManager.TimeNotSet", timeout=2
161+
)
162+
fprime_test_api.assert_event(
163+
"CdhCore.cmdDisp.OpCodeDispatched", timeout=2
164+
)
165+
fprime_test_api.assert_event(
166+
"CdhCore.cmdDisp.OpCodeError", timeout=2
167+
)

0 commit comments

Comments
 (0)