Skip to content

Commit 6d319c5

Browse files
committed
Construct control_t from a POD struct.
Replace const control_t instances by this POD. This save memory and prevent inclusion of the constants in the binary if they are not used.
1 parent 8fa239c commit 6d319c5

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

features/frameworks/utest/source/utest_types.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,20 @@ const char* utest::v1::stringify(utest::v1::status_t status)
116116
}
117117

118118

119-
const utest::v1::control_t utest::v1::CaseNext(REPEAT_NONE, TIMEOUT_NONE);
119+
const utest::v1::base_control_t utest::v1::CaseNext = { REPEAT_NONE, TIMEOUT_NONE };
120120

121-
const utest::v1::control_t utest::v1::CaseNoRepeat(REPEAT_NONE);
121+
const utest::v1::base_control_t utest::v1::CaseNoRepeat = { REPEAT_NONE, TIMEOUT_UNDECLR };
122122

123-
const utest::v1::control_t utest::v1::CaseRepeatAll(REPEAT_ALL);
123+
const utest::v1::base_control_t utest::v1::CaseRepeatAll = { REPEAT_ALL, TIMEOUT_UNDECLR };
124124

125-
const utest::v1::control_t utest::v1::CaseRepeatHandler(REPEAT_HANDLER);
125+
const utest::v1::base_control_t utest::v1::CaseRepeatHandler = { REPEAT_HANDLER, TIMEOUT_UNDECLR };
126126

127-
const utest::v1::control_t utest::v1::CaseNoTimeout(TIMEOUT_NONE);
127+
const utest::v1::base_control_t utest::v1::CaseNoTimeout = { REPEAT_UNDECLR, TIMEOUT_NONE };
128128

129-
const utest::v1::control_t utest::v1::CaseAwait(TIMEOUT_FOREVER);
129+
const utest::v1::base_control_t utest::v1::CaseAwait = { REPEAT_UNDECLR, TIMEOUT_FOREVER };
130130

131-
const utest::v1::control_t utest::v1::CaseRepeat(CaseRepeatAll);
131+
// equal to CaeReapeatAll
132+
const utest::v1::base_control_t utest::v1::CaseRepeat = { REPEAT_ALL, TIMEOUT_UNDECLR };
132133

133-
const utest::v1::control_t utest::v1::CaseRepeatHandlerOnly(CaseRepeatHandler);
134+
// equal to CaseRepeatHandler
135+
const utest::v1::base_control_t utest::v1::CaseRepeatHandlerOnly = { REPEAT_HANDLER, TIMEOUT_UNDECLR };

features/frameworks/utest/utest/utest_types.h

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ namespace v1 {
120120
/// Stringifies a status.
121121
const char* stringify(utest::v1::status_t status);
122122

123+
/** POD version of the class control_t.
124+
* It is used to instantiate const control_t objects as PODs
125+
* and prevent them to be included in the final binary.
126+
* @note: control_pod_t can be converted to control_t by copy construction.
127+
*/
128+
struct base_control_t {
129+
repeat_t repeat;
130+
uint32_t timeout;
131+
};
132+
123133
/** Control class for specifying test case attributes
124134
*
125135
* This class encapsulated control information about test cases which, when returned from
@@ -148,18 +158,21 @@ namespace v1 {
148158
*
149159
* In the future, more control information may be added transparently and backwards compatible.
150160
*/
151-
struct control_t
161+
struct control_t : private base_control_t
152162
{
153-
control_t() : repeat(REPEAT_UNDECLR), timeout(TIMEOUT_UNDECLR) {}
163+
control_t() : base_control_t(make_base_control_t(REPEAT_UNDECLR, TIMEOUT_UNDECLR)) {}
154164

155165
control_t(repeat_t repeat, uint32_t timeout_ms) :
156-
repeat(repeat), timeout(timeout_ms) {}
166+
base_control_t(make_base_control_t(repeat, timeout_ms)) {}
157167

158168
control_t(repeat_t repeat) :
159-
repeat(repeat), timeout(TIMEOUT_UNDECLR) {}
169+
base_control_t(make_base_control_t(repeat, TIMEOUT_UNDECLR)) {}
160170

161171
control_t(uint32_t timeout_ms) :
162-
repeat(REPEAT_UNDECLR), timeout(timeout_ms) {}
172+
base_control_t(make_base_control_t(REPEAT_UNDECLR, timeout_ms)) {}
173+
174+
control_t(base_control_t other) :
175+
base_control_t(other) {}
163176

164177
control_t
165178
inline operator+(const control_t& rhs) const {
@@ -196,25 +209,31 @@ namespace v1 {
196209
}
197210

198211
private:
199-
repeat_t repeat;
200-
uint32_t timeout;
212+
static base_control_t make_base_control_t(repeat_t repeat, uint32_t timeout) {
213+
base_control_t result = {
214+
repeat,
215+
timeout
216+
};
217+
return result;
218+
}
219+
201220
friend class Harness;
202221
};
203222

204223
/// does not repeat this test case and immediately moves on to the next one without timeout
205-
extern const control_t CaseNext;
224+
extern const base_control_t CaseNext;
206225

207226
/// does not repeat this test case, moves on to the next one
208-
extern const control_t CaseNoRepeat;
227+
extern const base_control_t CaseNoRepeat;
209228
/// repeats the test case handler with calling teardown and setup handlers
210-
extern const control_t CaseRepeatAll;
229+
extern const base_control_t CaseRepeatAll;
211230
/// repeats only the test case handler without calling teardown and setup handlers
212-
extern const control_t CaseRepeatHandler;
231+
extern const base_control_t CaseRepeatHandler;
213232

214233
/// No timeout, immediately moves on to the next case, but allows repeats
215-
extern const control_t CaseNoTimeout;
234+
extern const base_control_t CaseNoTimeout;
216235
/// Awaits until the callback is validated and never times out. Use with caution!
217-
extern const control_t CaseAwait;
236+
extern const base_control_t CaseAwait;
218237
/// Alias class for asynchronous timeout control in milliseconds
219238
inline control_t CaseTimeout(uint32_t ms) { return ms; }
220239

@@ -342,10 +361,10 @@ namespace v1 {
342361

343362
// deprecations
344363
__deprecated_message("Use CaseRepeatAll instead.")
345-
extern const control_t CaseRepeat;
364+
extern const base_control_t CaseRepeat;
346365

347366
__deprecated_message("Use CaseRepeatHandler instead.")
348-
extern const control_t CaseRepeatHandlerOnly;
367+
extern const base_control_t CaseRepeatHandlerOnly;
349368

350369
__deprecated_message("Use REASON_NONE instead.") const failure_reason_t FAILURE_NONE = REASON_NONE;
351370
__deprecated_message("Use REASON_UNKNOWN instead.") const failure_reason_t FAILURE_UNKNOWN = REASON_UNKNOWN;

0 commit comments

Comments
 (0)