forked from nasa/fprime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFpySequencerTester.hpp
More file actions
341 lines (301 loc) · 16.8 KB
/
FpySequencerTester.hpp
File metadata and controls
341 lines (301 loc) · 16.8 KB
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
// ======================================================================
// \title FpySequencer/test/ut/Tester.hpp
// \author zimri.leisher
// \brief hpp file for FpySequencer test harness implementation class
// ======================================================================
#ifndef FPYSEQUENCER_TESTER_HPP
#define FPYSEQUENCER_TESTER_HPP
#include "FpySequencerGTestBase.hpp"
#include "Svc/FpySequencer/FpySequencer.hpp"
namespace Svc {
class FpySequencerTester : public FpySequencerGTestBase, public ::testing::Test {
// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
public:
// Maximum size of histories storing events, telemetry, and port outputs
static const FwSizeType MAX_HISTORY_SIZE = 10;
// Instance ID supplied to the component instance under test
static const FwSizeType TEST_INSTANCE_ID = 0;
// Queue depth supplied to component instance under test
static const FwSizeType TEST_INSTANCE_QUEUE_DEPTH = 10;
//! Construct object FpySequencerTester
//!
FpySequencerTester();
//! Destroy object FpySequencerTester
//!
~FpySequencerTester();
private:
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
//! Connect ports
//!
void connectPorts();
//! Initialize components
//!
void initComponents();
protected:
// ----------------------------------------------------------------------
// Variables
// ----------------------------------------------------------------------
//! The component under test
//!
FpySequencer cmp;
FpySequencer& component; // for compatibility
// dispatches events from the queue until the component reaches the given state
void dispatchUntilState(State state, U32 bound = 100);
void resetRuntime();
// a sequence that you can build with the following functions
Fpy::Sequence seq;
U8 internalSeqBuf[Fpy::Sequence::SERIALIZED_SIZE] = {0};
FwChanIdType nextTlmId;
Fw::Time nextTlmTime;
Fw::TlmBuffer nextTlmValue;
FwPrmIdType nextPrmId;
Fw::ParamBuffer nextPrmValue;
// clears the sequence we're currently building
void clearSeq();
void allocMem(FwSizeType bytes = Fpy::Sequence::SERIALIZED_SIZE);
// writes the sequence we're building to a file with the given name
// writes up to maxBytes bytes
void writeToFile(const char* name, FwSizeType maxBytes = Fpy::Sequence::SERIALIZED_SIZE);
void removeFile(const char* name);
void addDirective(Fpy::DirectiveId id, Fw::StatementArgBuffer& buf);
void add_WAIT_REL();
void add_WAIT_REL(FpySequencer_WaitRelDirective dir);
void add_WAIT_ABS();
void add_WAIT_ABS(FpySequencer_WaitAbsDirective dir);
void add_GOTO(U32 stmtIdx);
void add_GOTO(FpySequencer_GotoDirective dir);
void add_IF(U32 gotoIfFalse);
void add_IF(FpySequencer_IfDirective dir);
void add_NO_OP();
void add_PUSH_TLM_VAL(FwChanIdType id);
void add_PUSH_TLM_VAL(FpySequencer_PushTlmValDirective dir);
void add_PUSH_TLM_VAL_AND_TIME(FwChanIdType id);
void add_PUSH_TLM_VAL_AND_TIME(FpySequencer_PushTlmValAndTimeDirective dir);
void add_PUSH_PRM(FwPrmIdType id);
void add_PUSH_PRM(FpySequencer_PushPrmDirective dir);
void add_CONST_CMD(FwOpcodeType opcode);
void add_CONST_CMD(FpySequencer_ConstCmdDirective dir);
void add_STACK_OP(Fpy::DirectiveId op);
void add_EXIT();
void add_ALLOCATE(Fpy::StackSizeType size);
void add_ALLOCATE(FpySequencer_AllocateDirective dir);
void add_STORE_REL_CONST_OFFSET(Fpy::SignedStackSizeType lvarOffset, Fpy::StackSizeType size);
void add_STORE_REL_CONST_OFFSET(FpySequencer_StoreRelConstOffsetDirective directive);
void add_LOAD_REL(Fpy::SignedStackSizeType lvarOffset, Fpy::StackSizeType size);
void add_LOAD_REL(FpySequencer_LoadRelDirective dir);
void add_DISCARD(Fpy::StackSizeType size);
void add_DISCARD(FpySequencer_DiscardDirective dir);
void add_STACK_CMD(Fpy::StackSizeType size);
void add_STACK_CMD(FpySequencer_StackCmdDirective dir);
void add_MEMCMP(Fpy::StackSizeType size);
void add_MEMCMP(FpySequencer_MemCmpDirective dir);
void add_SET_FLAG(U8 flagIdx);
void add_SET_FLAG(FpySequencer_SetFlagDirective dir);
void add_GET_FLAG(U8 flagIdx);
void add_GET_FLAG(FpySequencer_GetFlagDirective dir);
void add_PUSH_TIME();
void add_SET_SEED();
void add_PUSH_RAND();
void add_GET_FIELD(Fpy::StackSizeType parentSize, Fpy::StackSizeType memberSize);
void add_GET_FIELD(FpySequencer_GetFieldDirective dir);
void add_PEEK();
void add_PEEK(FpySequencer_PeekDirective dir);
void add_STORE_REL(Fpy::StackSizeType size);
void add_STORE_REL(FpySequencer_StoreRelDirective dir);
void add_CALL();
void add_CALL(FpySequencer_CallDirective dir);
void add_RETURN(Fpy::StackSizeType return_val_size, Fpy::StackSizeType call_args_size);
void add_RETURN(FpySequencer_ReturnDirective dir);
void add_LOAD_ABS(Fpy::StackSizeType globalOffset, Fpy::StackSizeType size);
void add_LOAD_ABS(FpySequencer_LoadAbsDirective dir);
void add_STORE_ABS(Fpy::StackSizeType size);
void add_STORE_ABS(FpySequencer_StoreAbsDirective dir);
void add_STORE_ABS_CONST_OFFSET(Fpy::StackSizeType globalOffset, Fpy::StackSizeType size);
void add_STORE_ABS_CONST_OFFSET(FpySequencer_StoreAbsConstOffsetDirective dir);
template <typename T>
void add_PUSH_VAL(T val);
//! Handle a text event
void textLogIn(FwEventIdType id, //!< The event ID
const Fw::Time& timeTag, //!< The time
const Fw::LogSeverity severity, //!< The severity
const Fw::TextLogString& text //!< The event string
) override;
void writeAndRun();
//! Default handler implementation for from_getTlmChan
Fw::TlmValid from_getTlmChan_handler(FwIndexType portNum, //!< The port number
FwChanIdType id, //!< Telemetry Channel ID
Fw::Time& timeTag, //!< Time Tag
Fw::TlmBuffer& val //!< Buffer containing serialized telemetry value.
//!< Size set to 0 if channel not found.
) override;
//! Default handler implementation for from_getParam
Fw::ParamValid from_getParam_handler(FwIndexType portNum, //!< The port number
FwPrmIdType id, //!< Parameter ID
Fw::ParamBuffer& val //!< Buffer containing serialized parameter value.
//!< Unmodified if param not found.
) override;
// Access to private and protected FpySequencer methods and members for UTs
Signal tester_noOp_directiveHandler(const FpySequencer_NoOpDirective& directive, DirectiveError& err);
Signal tester_waitRel_directiveHandler(const FpySequencer_WaitRelDirective& directive, DirectiveError& err);
Signal tester_waitAbs_directiveHandler(const FpySequencer_WaitAbsDirective& directive, DirectiveError& err);
Signal tester_goto_directiveHandler(const Svc::FpySequencer_GotoDirective& directive, DirectiveError& err);
Signal tester_if_directiveHandler(const FpySequencer_IfDirective& directive, DirectiveError& err);
Signal tester_pushPrm_directiveHandler(const FpySequencer_PushPrmDirective& directive, DirectiveError& err);
Signal tester_pushTlmVal_directiveHandler(const FpySequencer_PushTlmValDirective& directive, DirectiveError& err);
Signal tester_pushTlmValAndTime_directiveHandler(const FpySequencer_PushTlmValAndTimeDirective& directive,
DirectiveError& err);
Signal tester_exit_directiveHandler(const FpySequencer_ExitDirective& directive, DirectiveError& err);
Signal tester_constCmd_directiveHandler(const FpySequencer_ConstCmdDirective& directive, DirectiveError& err);
Signal tester_stackOp_directiveHandler(const FpySequencer_StackOpDirective& directive, DirectiveError& err);
Signal tester_discard_directiveHandler(const FpySequencer_DiscardDirective& directive, DirectiveError& err);
Signal tester_stackCmd_directiveHandler(const FpySequencer_StackCmdDirective& directive, DirectiveError& err);
Signal tester_memCmp_directiveHandler(const FpySequencer_MemCmpDirective& directive, DirectiveError& err);
Signal tester_setFlag_directiveHandler(const FpySequencer_SetFlagDirective& directive, DirectiveError& err);
Signal tester_getFlag_directiveHandler(const FpySequencer_GetFlagDirective& directive, DirectiveError& err);
Signal tester_getField_directiveHandler(const FpySequencer_GetFieldDirective& directive, DirectiveError& err);
Signal tester_peek_directiveHandler(const FpySequencer_PeekDirective& directive, DirectiveError& err);
Signal tester_storeRel_directiveHandler(const FpySequencer_StoreRelDirective& directive, DirectiveError& err);
Signal tester_call_directiveHandler(const FpySequencer_CallDirective& directive, DirectiveError& err);
Signal tester_return_directiveHandler(const FpySequencer_ReturnDirective& directive, DirectiveError& err);
Signal tester_loadAbs_directiveHandler(const FpySequencer_LoadAbsDirective& directive, DirectiveError& err);
Signal tester_storeAbs_directiveHandler(const FpySequencer_StoreAbsDirective& directive, DirectiveError& err);
Signal tester_storeAbsConstOffset_directiveHandler(const FpySequencer_StoreAbsConstOffsetDirective& directive,
DirectiveError& err);
Signal tester_pushTime_directiveHandler(const FpySequencer_PushTimeDirective& directive, DirectiveError& err);
Signal tester_setSeed_directiveHandler(const FpySequencer_SetSeedDirective& directive, DirectiveError& err);
Signal tester_pushRand_directiveHandler(const FpySequencer_PushRandDirective& directive, DirectiveError& err);
Signal tester_allocate_directiveHandler(const FpySequencer_AllocateDirective& directive, DirectiveError& err);
Signal tester_loadRel_directiveHandler(const FpySequencer_LoadRelDirective& directive, DirectiveError& err);
Signal tester_storeRelConstOffset_directiveHandler(const FpySequencer_StoreRelConstOffsetDirective& directive,
DirectiveError& err);
Signal tester_pushVal_directiveHandler(const FpySequencer_PushValDirective& directive, DirectiveError& err);
DirectiveError tester_op_or();
DirectiveError tester_op_and();
DirectiveError tester_op_ieq();
DirectiveError tester_op_ine();
DirectiveError tester_op_ult();
DirectiveError tester_op_ule();
DirectiveError tester_op_ugt();
DirectiveError tester_op_uge();
DirectiveError tester_op_slt();
DirectiveError tester_op_sle();
DirectiveError tester_op_sgt();
DirectiveError tester_op_sge();
DirectiveError tester_op_feq();
DirectiveError tester_op_fne();
DirectiveError tester_op_flt();
DirectiveError tester_op_fle();
DirectiveError tester_op_fgt();
DirectiveError tester_op_fge();
DirectiveError tester_op_not();
DirectiveError tester_op_fpext();
DirectiveError tester_op_fptrunc();
DirectiveError tester_op_fptoui();
DirectiveError tester_op_fptosi();
DirectiveError tester_op_sitofp();
DirectiveError tester_op_uitofp();
DirectiveError tester_op_add();
DirectiveError tester_op_sub();
DirectiveError tester_op_mul();
DirectiveError tester_op_udiv();
DirectiveError tester_op_sdiv();
DirectiveError tester_op_umod();
DirectiveError tester_op_smod();
DirectiveError tester_op_fadd();
DirectiveError tester_op_fsub();
DirectiveError tester_op_fmul();
DirectiveError tester_op_fdiv();
DirectiveError tester_op_fpow();
DirectiveError tester_op_flog();
DirectiveError tester_op_fmod();
DirectiveError tester_op_siext_8_64();
DirectiveError tester_op_siext_16_64();
DirectiveError tester_op_siext_32_64();
DirectiveError tester_op_ziext_8_64();
DirectiveError tester_op_ziext_16_64();
DirectiveError tester_op_ziext_32_64();
DirectiveError tester_op_itrunc_64_8();
DirectiveError tester_op_itrunc_64_16();
DirectiveError tester_op_itrunc_64_32();
FpySequencer::Runtime* tester_get_m_runtime_ptr();
Fw::ExternalSerializeBuffer* tester_get_m_sequenceBuffer_ptr();
void tester_set_m_sequencesStarted(U64 val);
void tester_set_m_statementsDispatched(U64 val);
U64 tester_get_m_sequencesStarted();
U64 tester_get_m_statementsDispatched();
Fw::Success tester_deserializeDirective(const Fpy::Statement& stmt,
Svc::FpySequencer::DirectiveUnion& deserializedDirective);
Fpy::Sequence* tester_get_m_sequenceObj_ptr();
Svc::Signal tester_dispatchStatement();
Fw::Success tester_validate();
Fw::String tester_get_m_sequenceFilePath();
void tester_set_m_sequenceFilePath(Fw::String str);
Fw::Success tester_readBytes(Os::File& file,
FwSizeType readLen,
FpySequencer_FileReadStage readStage,
bool updateCrc = true);
Fw::Success tester_readFooter();
Fw::Success tester_readBody();
Fw::Success tester_readHeader();
void tester_set_m_computedCRC(U32 crc);
Svc::FpySequencer::BreakpointInfo* tester_get_m_breakpoint_ptr();
Svc::Signal tester_checkStatementTimeout();
Svc::Signal tester_checkShouldWake();
Svc::FpySequencer::Telemetry* tester_get_m_tlm_ptr();
void tester_doDispatch();
void tester_setState(Svc::FpySequencer_SequencerStateMachineStateMachineBase::State state);
Svc::FpySequencer_SequencerStateMachineStateMachineBase::State tester_getState();
void tester_dispatchDirective(const FpySequencer::DirectiveUnion& directive, const Fpy::DirectiveId& id);
template <typename T>
void tester_push(T val);
template <typename T>
T tester_pop();
public:
// ----------------------------------------------------------------------
// Static methods for accessing protected opcodes
// ----------------------------------------------------------------------
//! Get the OPCODE_RUN value
static FwOpcodeType get_OPCODE_RUN() { return FpySequencerComponentBase::OPCODE_RUN; }
//! Get the OPCODE_VALIDATE value
static FwOpcodeType get_OPCODE_VALIDATE() { return FpySequencerComponentBase::OPCODE_VALIDATE; }
//! Get the OPCODE_RUN_VALIDATED value
static FwOpcodeType get_OPCODE_RUN_VALIDATED() { return FpySequencerComponentBase::OPCODE_RUN_VALIDATED; }
//! Get the OPCODE_CANCEL value
static FwOpcodeType get_OPCODE_CANCEL() { return FpySequencerComponentBase::OPCODE_CANCEL; }
//! Get the OPCODE_CLEAR_BREAKPOINT value
static FwOpcodeType get_OPCODE_CLEAR_BREAKPOINT() { return FpySequencerComponentBase::OPCODE_CLEAR_BREAKPOINT; }
//! Get the OPCODE_SET_BREAKPOINT value
static FwOpcodeType get_OPCODE_SET_BREAKPOINT() { return FpySequencerComponentBase::OPCODE_SET_BREAKPOINT; }
//! Get the OPCODE_BREAK value
static FwOpcodeType get_OPCODE_BREAK() { return FpySequencerComponentBase::OPCODE_BREAK; }
//! Get the OPCODE_SET_FLAG value
static FwOpcodeType get_OPCODE_SET_FLAG() { return FpySequencerComponentBase::OPCODE_SET_FLAG; }
//! Get the OPCODE_CONTINUE value
static FwOpcodeType get_OPCODE_CONTINUE() { return FpySequencerComponentBase::OPCODE_CONTINUE; }
//! Get the OPCODE_STEP value
static FwOpcodeType get_OPCODE_STEP() { return FpySequencerComponentBase::OPCODE_STEP; }
//! Get the OPCODE_DUMP_STACK_TO_FILE value
static FwOpcodeType get_OPCODE_DUMP_STACK_TO_FILE() { return FpySequencerComponentBase::OPCODE_DUMP_STACK_TO_FILE; }
};
class FpySequencer_SequencerStateMachineTester {
// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
public:
//! Construct object FpySequencer_SequencerStateMachineTester
//!
FpySequencer_SequencerStateMachineTester();
//! Destroy object FpySequencer_SequencerStateMachineTester
//!
~FpySequencer_SequencerStateMachineTester();
// ----------------------------------------------------------------------
// Test access to private and protected methods and members
// ----------------------------------------------------------------------
static void setState(FpySequencer_SequencerStateMachineStateMachineBase& sm, State s) { sm.m_state = s; }
};
} // namespace Svc
#endif