-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
ref_integration_test.py
286 lines (244 loc) · 10.1 KB
/
ref_integration_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
""" ref_integration_test.py:
A set of integration tests to apply to the Ref app. This is intended to be a reference of integration testing.
"""
import subprocess
import time
from enum import Enum
from pathlib import Path
from fprime_gds.common.testing_fw import predicates
from fprime_gds.common.utils.event_severity import EventSeverity
"""
This enum is includes the values of EventSeverity that can be filtered by the ActiveLogger Component
"""
FilterSeverity = Enum(
"FilterSeverity",
"WARNING_HI WARNING_LO COMMAND ACTIVITY_HI ACTIVITY_LO DIAGNOSTIC",
)
def test_is_streaming(fprime_test_api):
"""Test flight software is streaming
Tests that the flight software is streaming by looking for 5 telemetry items in 10 seconds. Additionally,
"sendBuffComp.SendState" is verified to be SEND_IDLE.
"""
results = fprime_test_api.assert_telemetry_count(5, timeout=10)
for result in results:
msg = "received channel {} update: {}".format(result.get_id(), result.get_str())
print(msg)
fprime_test_api.assert_telemetry(
"sendBuffComp.SendState", value="SEND_IDLE", timeout=3
)
def set_event_filter(fprime_test_api, severity, enabled):
"""Send command to set event filter
This helper will send a command that updates the given severity filter on the ActiveLogger
Component in the Ref App.
Args:
fprime_test_api: test api to use
severity: A valid FilterSeverity Enum Value (str) or an instance of FilterSeverity
enabled: a boolean of whether or not to enable the given severity
Return:
boolean of whether the report filter was set successfully.
"""
enabled = "ENABLED" if enabled else "DISABLED"
if isinstance(severity, FilterSeverity):
severity = severity.name
else:
severity = FilterSeverity[severity].name
try:
fprime_test_api.send_command(
"eventLogger.SET_EVENT_FILTER",
[severity, enabled],
)
return True
except AssertionError:
return False
def set_default_filters(fprime_test_api):
"""Set the default (initial) event filters"""
set_event_filter(fprime_test_api, "COMMAND", True)
set_event_filter(fprime_test_api, "ACTIVITY_LO", True)
set_event_filter(fprime_test_api, "ACTIVITY_HI", True)
set_event_filter(fprime_test_api, "WARNING_LO", True)
set_event_filter(fprime_test_api, "WARNING_HI", True)
set_event_filter(fprime_test_api, "DIAGNOSTIC", False)
def test_send_command(fprime_test_api):
"""Test that commands may be sent
Tests command send, dispatch, and receipt using send_and_assert command with a pair of NO-OP commands.
"""
fprime_test_api.send_and_assert_command("cmdDisp.CMD_NO_OP", max_delay=0.1)
assert fprime_test_api.get_command_test_history().size() == 1
fprime_test_api.send_and_assert_command("cmdDisp.CMD_NO_OP", max_delay=0.1)
assert fprime_test_api.get_command_test_history().size() == 2
def test_send_command_args(fprime_test_api):
"""Test that commands may be sent with arguments
Tests command send, dispatch, and receipt using send_and_assert command with a pair of NO-OP string commands.
"""
for count, value in enumerate(["Test String 1", "Some other string"], 1):
events = [fprime_test_api.get_event_pred("cmdDisp.NoOpStringReceived", [value])]
fprime_test_api.send_and_assert_command(
"cmdDisp.CMD_NO_OP_STRING",
[
value,
],
max_delay=0.1,
events=events,
)
assert fprime_test_api.get_command_test_history().size() == count
def test_send_and_assert_no_op(fprime_test_api):
"""Test that commands may be sent in-order
Tests command send, dispatch, and receipt using send_and_assert command with NO-OP commands. Repeats the series of
commands 100 times and looks for no re-ordering nor drops.
"""
length = 100
failed = 0
evr_seq = [
"cmdDisp.OpCodeDispatched",
"cmdDisp.NoOpReceived",
"cmdDisp.OpCodeCompleted",
]
any_reordered = False
dropped = False
for i in range(0, length):
results = fprime_test_api.send_and_await_event(
"cmdDisp.CMD_NO_OP", events=evr_seq, timeout=25
)
msg = "Send and assert NO_OP Trial #{}".format(i)
if not fprime_test_api.test_assert(len(results) == 3, msg, True):
items = fprime_test_api.get_event_test_history().retrieve()
last = None
reordered = False
for item in items:
if last is not None:
if item.get_time() < last.get_time():
fprime_test_api.log(
"during iteration #{}, a reordered event was detected: {}".format(
i, item
)
)
any_reordered = True
reordered = True
break
last = item
if not reordered:
fprime_test_api.log(
"during iteration #{}, a dropped event was detected".format(i)
)
dropped = True
failed += 1
fprime_test_api.clear_histories()
case = True
case &= fprime_test_api.test_assert(
not any_reordered, "Expected no events to be reordered.", True
)
case &= fprime_test_api.test_assert(
not dropped, "Expected no events to be dropped.", True
)
msg = "{} sequences failed out of {}".format(failed, length)
case &= fprime_test_api.test_assert(failed == 0, msg, True)
assert (
case
), "Expected all checks to pass (reordering, dropped events, all passed). See log."
def test_bd_cycles_ascending(fprime_test_api):
"""Test in-order block driver updates"""
length = 60
count_pred = predicates.greater_than(length - 1)
results = fprime_test_api.await_telemetry_count(
count_pred, "blockDrv.BD_Cycles", timeout=length
)
last = None
reordered = False
ascending = True
for result in results:
if last is not None:
last_time = last.get_time()
result_time = result.get_time()
if result_time - last_time > 1.5:
msg = "FSW didn't send an update between {} and {}".format(
last_time.to_readable(), result_time.to_readable()
)
fprime_test_api.log(msg)
elif result_time < last_time:
msg = "There is potential reorder error between {} and {}".format(
last_time, result_time
)
fprime_test_api.log(msg)
reordered = True
if not result.get_val() > last.get_val():
msg = "Not all updates ascended: First ({}) Second ({})".format(
last.get_val(), result.get_val()
)
fprime_test_api.log(msg)
ascending = False
last = result
case = True
case &= fprime_test_api.test_assert(
ascending, "Expected all updates to ascend.", True
)
case &= fprime_test_api.test_assert(
not reordered, "Expected no updates to be dropped.", True
)
fprime_test_api.predicate_assert(
count_pred,
len(results) - 1,
"Expected >= {} updates".format(length - 1),
True,
)
fprime_test_api.assert_telemetry_count(0, "rateGroup1Comp.RgCycleSlips")
assert case, "Expected all checks to pass (ascending, reordering). See log."
def test_active_logger_filter(fprime_test_api):
"""Test active logger event filtering"""
set_default_filters(fprime_test_api)
try:
cmd_events = fprime_test_api.get_event_pred(severity=EventSeverity.COMMAND)
actHI_events = fprime_test_api.get_event_pred(
severity=EventSeverity.ACTIVITY_HI
)
pred = predicates.greater_than(0)
zero = predicates.equal_to(0)
# Drain time for dispatch events
time.sleep(10)
fprime_test_api.send_and_assert_command("cmdDisp.CMD_NO_OP")
fprime_test_api.send_and_assert_command("cmdDisp.CMD_NO_OP")
time.sleep(0.5)
fprime_test_api.assert_event_count(pred, cmd_events)
fprime_test_api.assert_event_count(pred, actHI_events)
set_event_filter(fprime_test_api, FilterSeverity.COMMAND, False)
# Drain time for dispatch events
time.sleep(10)
fprime_test_api.clear_histories()
fprime_test_api.send_command("cmdDisp.CMD_NO_OP")
fprime_test_api.send_command("cmdDisp.CMD_NO_OP")
time.sleep(0.5)
fprime_test_api.assert_event_count(zero, cmd_events)
fprime_test_api.assert_event_count(pred, actHI_events)
finally:
set_default_filters(fprime_test_api)
def test_signal_generation(fprime_test_api):
"""Tests the behavior of signal gen component"""
fprime_test_api.send_and_assert_command(
"SG4.SignalGen_Settings", [1, 5, 0, "SQUARE"]
)
# First telemetry item should fill only the first slot of the history
history = [0, 0, 0, 5]
pair_history = [{"time": 0, "value": value} for value in history]
info = {"type": "SQUARE", "history": history, "pairHistory": pair_history}
fprime_test_api.send_and_assert_command("SG4.SignalGen_Toggle")
fprime_test_api.assert_telemetry("SG4.History", history, timeout=6)
fprime_test_api.assert_telemetry("SG4.PairHistory", pair_history, timeout=1)
fprime_test_api.assert_telemetry("SG4.Info", info, timeout=1)
fprime_test_api.send_and_assert_command("SG4.SignalGen_Toggle")
def test_seqgen(fprime_test_api):
"""Tests the seqgen can be dispatched (requires localhost testing)"""
sequence = Path(__file__).parent / "test_seq.seq"
assert (
subprocess.run(
[
"fprime-seqgen",
"-d",
str(fprime_test_api.pipeline.dictionary_path),
str(sequence),
"/tmp/ref_test_int.bin",
]
).returncode
== 0
), "Failed to run fprime-seqgen"
fprime_test_api.send_and_assert_command(
"cmdSeq.CS_RUN", args=["/tmp/ref_test_int.bin", "BLOCK"], max_delay=5
)