Skip to content

Commit 28f590f

Browse files
authored
Merge pull request #4430 from pan-/utest_cases_romable
utest optimization: Allow case data structure to be put in ROM.
2 parents 6002bdd + f36619b commit 28f590f

File tree

3 files changed

+236
-111
lines changed

3 files changed

+236
-111
lines changed

features/frameworks/utest/source/utest_case.cpp

Lines changed: 106 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,75 @@
2121

2222
using namespace utest::v1;
2323

24+
// case_t factory used by Case contructor
25+
static inline case_t make_case(
26+
const char *description,
27+
const case_handler_t handler,
28+
const case_control_handler_t control_handler,
29+
const case_call_count_handler_t repeat_count_handler,
30+
const case_setup_handler_t setup_handler,
31+
const case_teardown_handler_t teardown_handler,
32+
const case_failure_handler_t failure_handler)
33+
{
34+
case_t result = {
35+
description,
36+
handler,
37+
control_handler,
38+
repeat_count_handler,
39+
setup_handler,
40+
teardown_handler,
41+
failure_handler
42+
};
43+
44+
return result;
45+
}
46+
2447
// normal handler
2548
Case::Case(const char *description,
2649
const case_setup_handler_t setup_handler,
2750
const case_handler_t handler,
2851
const case_teardown_handler_t teardown_handler,
2952
const case_failure_handler_t failure_handler) :
30-
description(description),
31-
handler(handler),
32-
control_handler(ignore_handler),
33-
repeat_count_handler(ignore_handler),
34-
setup_handler(setup_handler),
35-
teardown_handler(teardown_handler),
36-
failure_handler(failure_handler)
53+
case_t(make_case(
54+
description,
55+
handler,
56+
ignore_handler,
57+
ignore_handler,
58+
setup_handler,
59+
teardown_handler,
60+
failure_handler
61+
))
62+
3763
{}
3864

3965
Case::Case(const char *description,
4066
const case_handler_t handler,
4167
const case_teardown_handler_t teardown_handler,
4268
const case_failure_handler_t failure_handler) :
43-
description(description),
44-
handler(handler),
45-
control_handler(ignore_handler),
46-
repeat_count_handler(ignore_handler),
47-
setup_handler(default_handler),
48-
teardown_handler(teardown_handler),
49-
failure_handler(failure_handler)
69+
case_t(make_case(
70+
description,
71+
handler,
72+
ignore_handler,
73+
ignore_handler,
74+
default_handler,
75+
teardown_handler,
76+
failure_handler
77+
))
78+
5079
{}
5180

5281
Case::Case(const char *description,
5382
const case_handler_t handler,
5483
const case_failure_handler_t failure_handler) :
55-
description(description),
56-
handler(handler),
57-
control_handler(ignore_handler),
58-
repeat_count_handler(ignore_handler),
59-
setup_handler(default_handler),
60-
teardown_handler(default_handler),
61-
failure_handler(failure_handler)
84+
case_t(make_case(
85+
description,
86+
handler,
87+
ignore_handler,
88+
ignore_handler,
89+
default_handler,
90+
default_handler,
91+
failure_handler
92+
))
6293
{}
6394

6495
// control handler
@@ -67,38 +98,44 @@ Case::Case(const char *description,
6798
const case_control_handler_t handler,
6899
const case_teardown_handler_t teardown_handler,
69100
const case_failure_handler_t failure_handler) :
70-
description(description),
71-
handler(ignore_handler),
72-
control_handler(handler),
73-
repeat_count_handler(ignore_handler),
74-
setup_handler(setup_handler),
75-
teardown_handler(teardown_handler),
76-
failure_handler(failure_handler)
101+
case_t(make_case(
102+
description,
103+
ignore_handler,
104+
handler,
105+
ignore_handler,
106+
setup_handler,
107+
teardown_handler,
108+
failure_handler
109+
))
77110
{}
78111

79112
Case::Case(const char *description,
80113
const case_control_handler_t handler,
81114
const case_teardown_handler_t teardown_handler,
82115
const case_failure_handler_t failure_handler) :
83-
description(description),
84-
handler(ignore_handler),
85-
control_handler(handler),
86-
repeat_count_handler(ignore_handler),
87-
setup_handler(default_handler),
88-
teardown_handler(teardown_handler),
89-
failure_handler(failure_handler)
116+
case_t(make_case(
117+
description,
118+
ignore_handler,
119+
handler,
120+
ignore_handler,
121+
default_handler,
122+
teardown_handler,
123+
failure_handler
124+
))
90125
{}
91126

92127
Case::Case(const char *description,
93128
const case_control_handler_t handler,
94129
const case_failure_handler_t failure_handler) :
95-
description(description),
96-
handler(ignore_handler),
97-
control_handler(handler),
98-
repeat_count_handler(ignore_handler),
99-
setup_handler(default_handler),
100-
teardown_handler(default_handler),
101-
failure_handler(failure_handler)
130+
case_t(make_case(
131+
description,
132+
ignore_handler,
133+
handler,
134+
ignore_handler,
135+
default_handler,
136+
default_handler,
137+
failure_handler
138+
))
102139
{}
103140

104141
// control flow handler
@@ -107,38 +144,44 @@ Case::Case(const char *description,
107144
const case_call_count_handler_t case_repeat_count_handler,
108145
const case_teardown_handler_t teardown_handler,
109146
const case_failure_handler_t failure_handler) :
110-
description(description),
111-
handler(ignore_handler),
112-
control_handler(ignore_handler),
113-
repeat_count_handler(case_repeat_count_handler),
114-
setup_handler(setup_handler),
115-
teardown_handler(teardown_handler),
116-
failure_handler(failure_handler)
147+
case_t(make_case(
148+
description,
149+
ignore_handler,
150+
ignore_handler,
151+
case_repeat_count_handler,
152+
setup_handler,
153+
teardown_handler,
154+
failure_handler
155+
))
117156
{}
118157

119158
Case::Case(const char *description,
120159
const case_call_count_handler_t case_repeat_count_handler,
121160
const case_failure_handler_t failure_handler) :
122-
description(description),
123-
handler(ignore_handler),
124-
control_handler(ignore_handler),
125-
repeat_count_handler(case_repeat_count_handler),
126-
setup_handler(default_handler),
127-
teardown_handler(default_handler),
128-
failure_handler(failure_handler)
161+
case_t(make_case(
162+
description,
163+
ignore_handler,
164+
ignore_handler,
165+
case_repeat_count_handler,
166+
default_handler,
167+
default_handler,
168+
failure_handler
169+
))
129170
{}
130171

131172
Case::Case(const char *description,
132173
const case_call_count_handler_t case_repeat_count_handler,
133174
const case_teardown_handler_t teardown_handler,
134175
const case_failure_handler_t failure_handler) :
135-
description(description),
136-
handler(ignore_handler),
137-
control_handler(ignore_handler),
138-
repeat_count_handler(case_repeat_count_handler),
139-
setup_handler(default_handler),
140-
teardown_handler(teardown_handler),
141-
failure_handler(failure_handler)
176+
case_t(make_case(
177+
description,
178+
ignore_handler,
179+
ignore_handler,
180+
case_repeat_count_handler,
181+
default_handler,
182+
teardown_handler,
183+
failure_handler
184+
))
142185
{}
143186

144187
const char*

features/frameworks/utest/utest/utest_case.h

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,59 @@ namespace utest {
3030
/** \addtogroup frameworks */
3131
/** @{*/
3232
namespace v1 {
33+
/**
34+
* POD data structure of the Case class.
35+
* Unlike the Case class it can be used as a POD and be put in ROM.
36+
*
37+
* @warning Initialization of handlers with either default_handler or
38+
* ignore_handler helpers will prevent the object to be a POD. Prefer usage
39+
* of NULL in favor of ignore_handler or <handler_type>(1) for default
40+
* handler.
41+
*
42+
* @see Case.
43+
*/
44+
struct case_t
45+
{
46+
/**
47+
* Textual description of the test case
48+
*/
49+
const char *description;
50+
51+
/**
52+
* Primitive test case handler
53+
* This is called only if the case setup succeeded. It is followed by
54+
* the test case teardown handler.
55+
*/
56+
const case_handler_t handler;
57+
58+
/**
59+
* @see case_control_handler_t
60+
*/
61+
const case_control_handler_t control_handler;
62+
63+
/**
64+
* @see case_call_count_handler_t
65+
*/
66+
const case_call_count_handler_t repeat_count_handler;
67+
68+
/**
69+
* Handler called before the execution of the case handler. It sets up
70+
* the case environment.
71+
*/
72+
const case_setup_handler_t setup_handler;
73+
74+
/**
75+
* Handler called after the execution of the case handler. It cleans up
76+
* the case environment.
77+
*/
78+
const case_teardown_handler_t teardown_handler;
79+
80+
/**
81+
* Handler called whenever a faillure occur; at any stage of the case
82+
* execution (including setup and teardown).
83+
*/
84+
const case_failure_handler_t failure_handler;
85+
};
3386

3487
/** Test case wrapper class.
3588
*
@@ -52,7 +105,7 @@ namespace v1 {
52105
* @note While you can specify an empty test case (ie. use `ignore_handler` for all callbacks),
53106
* the harness will abort the test unconditionally.
54107
*/
55-
class Case
108+
class Case : private case_t
56109
{
57110
public:
58111
// overloads for case_handler_t
@@ -111,18 +164,12 @@ namespace v1 {
111164
bool is_empty() const;
112165

113166
private:
114-
const char *description;
115-
116-
const case_handler_t handler;
117-
const case_control_handler_t control_handler;
118-
const case_call_count_handler_t repeat_count_handler;
119-
120-
const case_setup_handler_t setup_handler;
121-
const case_teardown_handler_t teardown_handler;
122-
123-
const case_failure_handler_t failure_handler;
167+
// IMPORTANT: No data members shall be declared inside this class.
168+
// Data members shall be declared in case_t to preserve the layout
169+
// and the compatibility between the two types.
124170

125171
friend class Harness;
172+
friend class Specification;
126173
};
127174

128175
} // namespace v1

0 commit comments

Comments
 (0)