F´ Flight Software - C/C++ Documentation
devel
A framework for building embedded system applications to NASA flight quality standards.
TestUtils.hpp
Go to the documentation of this file.
1
// ======================================================================
2
// \title TestUtils.hpp
3
// \author vwong
4
// \brief hpp file for unit test utility macros
5
//
6
// \copyright
7
//
8
// Copyright (C) 2009-2020 California Institute of Technology.
9
//
10
// ALL RIGHTS RESERVED. United States Government Sponsorship
11
// acknowledged.
12
// ======================================================================
13
14
#ifndef TESTUTILS_HPP
15
#define TESTUTILS_HPP
16
17
// HOW TO USE:
18
//
19
// 1) in Tester.cpp, include this file
20
// e.g.: #include <Utils/TestUtils.hpp>
21
//
22
// 2) in Tester.cpp, set your component name in TEST_COMP macro
23
// e.g.: #define TEST_COMP PwrSwitchManagerComponentImpl
24
//
25
// 3) make sure INSTANCE and CMD_SEQ are also defined in Tester.cpp (they
26
// should be autogenerated)
27
//
28
// List of macros:
29
//
30
// - SEND_CMD(cmd, status, ...)
31
// - SEND_CMD_NO_EXPECT(cmd, ...)
32
// - ASSERT_LAST_CMD(cmd, status)
33
// - ASSERT_LAST_TLM(name, value)
34
// - ASSERT_LAST_EVENT(name, ...)
35
// - ASSERT_LAST_PORT_OUT(port, ...)
36
//
37
// See below for detailed descriptions
38
39
40
// SEND_CMD
41
//
42
// Send a command and expect a response status. This command essentially calls
43
// sendCmd, doDispatch, and asserts a command response. The last command
44
// response received must be for the command sent here for it to validate, i.e.
45
// it may not work well if your component interleaves command responses.
46
//
47
// Example:
48
//
49
// SEND_CMD(PWR_SW_MGR_PWR_ON, Fw::CmdResponse::OK, channel);
50
// SEND_CMD(PWR_SW_MGR_SET_DUTY_CYCLE, Fw::CmdResponse::OK, channel, dutyCycle);
51
// SEND_CMD(PWR_SW_MGR_PWR_ON, Fw::COMMAND_EXECUTION_ERROR, illegalChannel);
52
//
53
#define SEND_CMD(cmd, status, ...) \
54
SEND_CMD_COMP(TEST_COMP, cmd, status, ## __VA_ARGS__)
55
56
#define SEND_CMD_COMP(comp, cmd, status, ...) \
57
this->sendCmd_ ## cmd(INSTANCE, CMD_SEQ, ## __VA_ARGS__); \
58
this->component.doDispatch(); \
59
ASSERT_LAST_CMD(cmd, status);
60
61
// SEND_CMD_NO_EXPECT
62
//
63
// Send a command and performs dispatch, without asserting any command response.
64
//
65
// Example:
66
//
67
// SEND_CMD_NO_EXPECT(FILE_DWN_SEND_APID, 100, 0, 0, 0);
68
// // ...
69
//
70
#define SEND_CMD_NO_EXPECT(cmd, ...) \
71
SEND_CMD_COMP_NO_EXPECT(TEST_COMP, cmd, ## __VA_ARGS__)
72
73
#define SEND_CMD_COMP_NO_EXPECT(comp, cmd, ...) \
74
this->sendCmd_ ## cmd(INSTANCE, CMD_SEQ, ## __VA_ARGS__); \
75
this->component.doDispatch();
76
77
// ASSERT_LAST_CMD
78
//
79
// Assert response status of command. This macro checks both that there was a
80
// response and that the response is as expected and is for the command
81
// specified.
82
//
83
// Example:
84
//
85
// SEND_CMD_NO_EXPECT(FILE_DWN_SEND_APID, 100, 0, 0, 0);
86
// // ...
87
// ASSERT_LAST_CMD(FILE_DWN_SEND_APID, Fw::CmdResponse::OK);
88
//
89
#define ASSERT_LAST_CMD(cmd, status) \
90
ASSERT_LAST_CMD_COMP(TEST_COMP, cmd, status)
91
92
#define ASSERT_LAST_CMD_COMP(comp, cmd, status) \
93
ASSERT_GT(this->cmdResponseHistory->size(), 0); \
94
ASSERT_CMD_RESPONSE(this->cmdResponseHistory->size()-1, comp::OPCODE_ ## cmd, CMD_SEQ, status);
95
96
// ASSERT_LAST_TLM
97
//
98
// Assert the value last received in a given channel.
99
//
100
// Example:
101
//
102
// ASSERT_LAST_TLM(NeaCamManager_ImageDataSize, dataSize);
103
// ASSERT_LAST_TLM(NeaCamManager_PatternDataSize, 0);
104
//
105
#define ASSERT_LAST_TLM(name, value) \
106
ASSERT_GT(this->tlmHistory_ ## name->size(), 0); \
107
ASSERT_TLM_ ## name(this->tlmHistory_ ## name->size()-1, value);
108
109
// ASSERT_LAST_EVENT
110
//
111
// Assert the arguments in the last received EVR of a given name.
112
//
113
// Example:
114
//
115
// SEND_CMD(PWR_SW_MGR_SET_DUTY_CYCLE, Fw::COMMAND_VALIDATION_ERROR, 0, 0);
116
// ASSERT_LAST_EVENT(PwrSwitchManager_DutyCyclingNotEnabled, i);
117
//
118
#define ASSERT_LAST_EVENT(name, ...) \
119
ASSERT_GT(this->eventHistory_ ## name->size(), 0); \
120
ASSERT_EVENTS_ ## name(this->eventHistory_ ## name->size()-1, ## __VA_ARGS__);
121
122
// ASSERT_LAST_PORT_OUT
123
//
124
// Assert the arguments in the last output port call of a given port.
125
//
126
// Example:
127
//
128
// this->invoke_to_PingRecv(0, 0xDEADBEEF);
129
// this->component.doDispatch();
130
// ASSERT_LAST_PORT_OUT(PingResponse, 0, 0xDEADBEEF);
131
//
132
#define ASSERT_LAST_PORT_OUT(port, ...) \
133
ASSERT_GT(this->fromPortHistory_ ## port->size(), 0); \
134
ASSERT_from_ ## port(__VA_ARGS__);
135
136
137
#endif
Utils
TestUtils.hpp
Generated by
1.9.1