blob: b048637e331da679b2816759bf35b75bcf3c0524 (
plain)
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
project(tests C)
set(TEST_EXCEPTION_HANDLER FALSE)
if (HAVE_SIGNAL_H)
set(TEST_EXCEPTION_HANDLER TRUE)
endif()
if (WIN32)
# FIXME: The exception handler doesn't work on Windows
set(TEST_EXCEPTION_HANDLER FALSE)
endif()
if (CMAKE_BUILD_TYPE)
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
if (CMAKE_BUILD_TYPE_LOWER STREQUAL "undefinedsanitizer")
set(TEST_EXCEPTION_HANDLER FALSE)
endif()
endif()
set(CMOCKA_TESTS
test_alloc
test_expect_check
test_expect_u_int_in_set
test_expect_check_fail
test_group_setup_assert
test_group_setup_fail
test_fixtures
test_group_fixtures
test_groups
test_float_macros
test_double_macros
test_assert_true
test_assert_true_fail
test_assert_false
test_assert_false_fail
test_assert_macros
test_assert_macros_fail
test_assert_memory
test_assert_memory_fail
test_assert_ptr
test_assert_ptr_fail
test_assert_u_int
test_assert_u_int_fail
test_assert_range
test_assert_range_fail
test_assert_set
test_assert_set_fail
test_basics
test_skip
test_stop
test_stop_fail
test_strmatch
test_strreplace
test_setup_fail
test_ordering
test_ordering_fail
test_returns
test_returns_fail
test_string
test_wildcard
test_skip_filter
)
if (TEST_EXCEPTION_HANDLER)
list(APPEND CMOCKA_TESTS test_exception_handler)
endif()
foreach(_CMOCKA_TEST ${CMOCKA_TESTS})
add_cmocka_test(${_CMOCKA_TEST}
SOURCES ${_CMOCKA_TEST}.c
COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} -D_GNU_SOURCE -D_XOPEN_SOURCE=700
LINK_LIBRARIES cmocka::static
LINK_OPTIONS ${DEFAULT_LINK_FLAGS})
target_include_directories(${_CMOCKA_TEST} PRIVATE ${cmocka_BINARY_DIR})
add_cmocka_test_environment(${_CMOCKA_TEST})
endforeach()
### Exceptions
# test_skip
set_tests_properties(
test_skip
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ SKIPPED \\] test_check_skip"
)
# test_assert_true
set_tests_properties(
test_assert_true
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ PASSED \\] 1 test\\(s\\)."
)
# test_assert_true_fail
set_tests_properties(
test_assert_true_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"x != 10 is not true"
)
# test_assert_false
set_tests_properties(
test_assert_false
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ PASSED \\] 1 test\\(s\\)."
)
# test_assert_false_fail
set_tests_properties(
test_assert_false_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"x == 10 is not false"
)
# test_assert_macros_fail
set_tests_properties(
test_assert_macros_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] tests: 1 test"
)
set_tests_properties(
test_assert_memory_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] memory_tests: 1 test"
)
set_tests_properties(
test_assert_ptr_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] ptr_tests: 4 test"
)
set_tests_properties(
test_assert_u_int_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] integer_tests: 4 test"
)
set_tests_properties(
test_assert_range_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] range_fail_tests: 6 test"
)
set_tests_properties(
test_assert_set_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] set_fail_tests: 5 test"
)
# test_expect_check_fail
set_tests_properties(
test_expect_check_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] tests: 3 test"
)
# stop_fail
set_tests_properties(
test_stop_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] tests: 3 test"
)
# test_ordering_fail ensure proper failures
set_tests_properties(
test_ordering_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] tests: 8 test"
FAIL_REGULAR_EXPRESSION
"Test failed with exception: (Segmentation fault|Segmentation Fault|11|Illegal instruction)"
)
# test_returns_fail ensure proper failures
set_tests_properties(
test_returns_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] will_return_mock_tests: 6 test"
)
# test_exception_handler
if (TEST_EXCEPTION_HANDLER)
set_tests_properties(test_exception_handler
PROPERTIES
PASS_REGULAR_EXPRESSION
"Test failed with exception")
endif (TEST_EXCEPTION_HANDLER)
set_tests_properties(
test_setup_fail
PROPERTIES
WILL_FAIL
1
)
set_tests_properties(
test_group_setup_assert
PROPERTIES
WILL_FAIL
1
)
set_tests_properties(
test_group_setup_fail
PROPERTIES
WILL_FAIL
1
)
add_test(test_setup_fail_1_failed ${TARGET_SYSTEM_EMULATOR} test_setup_fail)
add_cmocka_test_environment(test_setup_fail_1_failed)
set_tests_properties(
test_setup_fail_1_failed
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ ERROR \\] int_test_ignored"
)
add_test (test_setup_fail_1_passed ${TARGET_SYSTEM_EMULATOR} test_setup_fail)
add_cmocka_test_environment(test_setup_fail_1_passed)
set_tests_properties(
test_setup_fail_1_passed
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ PASSED \\] 1 test\\(s\\)."
)
add_test (test_setup_fail_match_failed ${TARGET_SYSTEM_EMULATOR} test_setup_fail)
add_cmocka_test_environment(test_setup_fail_match_failed)
set_tests_properties(
test_setup_fail_match_failed
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ ERROR \\] int_test_ignored"
)
add_test (test_setup_fail_match_passed ${TARGET_SYSTEM_EMULATOR} test_setup_fail)
add_cmocka_test_environment(test_setup_fail_match_passed)
set_tests_properties(
test_setup_fail_match_passed
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ OK \\] int_test_success"
)
### Output formats
# test output of success, failure, skip, fixture failure
set(OUTPUT_TESTS
test_basics
test_assert_macros_fail
test_groups
test_skip
test_setup_fail)
set(TEST_OUTPUT_FMTS
tap
subunit
xml)
set(test_basics_tap_out
"^TAP version 13"
"1\\.\\.2"
"ok 1 - null_test_success"
"ok 2 - int_test_success"
"# ok - tests")
set(test_assert_macros_fail_tap_out
"^TAP version 13"
"1\\.\\.1"
"not ok 1 - test_assert_return_code_fail"
"#[^\n\r]+[\n\r]#[^\n\r]+[\n\r]# not ok - tests")
set(test_groups_tap_out
"^TAP version 13"
"1\\.\\.1"
"ok 1 - null_test_success"
"# ok - test_group1"
"1\\.\\.1"
"ok 1 - int_test_success"
"# ok - test_group2 num=<'\"2&2'\">")
set(test_skip_tap_out
"ok 1 # SKIP")
set(test_setup_fail_tap_out
"not ok 1 - int_test_ignored Could not run test: Test setup failed")
set(test_basics_subunit_out
"^test: null_test_success"
"success: null_test_success")
set(test_assert_macros_fail_subunit_out
"failure: test_assert_return_code_fail \\[")
set(test_groups_subunit_out
"^test: null_test_success"
"success: null_test_success")
set(test_skip_subunit_out
"^test: test_check_skip"
"skip: test_check_skip")
set(test_setup_fail_subunit_out
"error: int_test_ignored \\[ Could not run test: Test setup failed \\]")
set(test_basics_xml_out
"<testsuite name=\"tests\" time=\"[0-9.]+\" tests=\"2\" failures=\"0\" errors=\"0\" skipped=\"0\" >"
"<testcase name=\"null_test_success\" time=\"[0-9.]+\" >.*</testcase>")
set(test_assert_macros_fail_xml_out
"<testcase name=\"test_assert_return_code_fail\" time=\"[0-9.]+\" >"
"<failure>")
set(test_groups_xml_out
"^<\\?xml version=\"1.0\" encoding=\"UTF-8\" \\?>"
"<testsuites>"
"<testsuite name=\"test_group1\" time=\"[0-9.]+\" tests=\"1\" failures=\"0\" errors=\"0\" skipped=\"0\" >"
"<testcase name=\"null_test_success\" time=\"[0-9.]+\" >"
"</testcase>"
"</testsuite>"
".*<testsuite name=\"test_group2 num=<[;]&apos[;]"[;]2&[;]2&apos[;]"[;]>[;]\" time=\"[0-9.]+\" tests=\"1\" failures=\"0\" errors=\"0\" skipped=\"0\" >"
"<testcase name=\"int_test_success\" time=\"[0-9.]+\" >"
"</testcase>"
"</testsuite>"
"</testsuites>")
set(test_skip_xml_out
"<testcase name=\"test_check_skip\" time=\"[0-9.]+\" >"
"<skipped/>")
set(test_setup_fail_xml_out
"<testcase name=\"int_test_ignored\" time=\"[0-9.]+\" >"
"<failure><!\\[CDATA\\[Test setup failed\\]\\]></failure>")
foreach(_TEST_OUTPUT_FMT ${TEST_OUTPUT_FMTS})
foreach(_OUTPUT_TEST ${OUTPUT_TESTS})
set(TEST_NAME ${_OUTPUT_TEST}_${_TEST_OUTPUT_FMT})
add_test(${TEST_NAME} ${TARGET_SYSTEM_EMULATOR} ${_OUTPUT_TEST})
add_cmocka_test_environment(${TEST_NAME})
set_property(
TEST
${TEST_NAME}
APPEND
PROPERTY
ENVIRONMENT CMOCKA_MESSAGE_OUTPUT=${_TEST_OUTPUT_FMT}
)
list(LENGTH ${TEST_NAME}_out len)
list(GET ${TEST_NAME}_out 0 output)
if(len GREATER 1)
list(REMOVE_AT ${TEST_NAME}_out 0)
foreach(line ${${TEST_NAME}_out})
set(output "${output}[ \n\r]+${line}")
endforeach()
endif()
set_tests_properties(
${TEST_NAME}
PROPERTIES
PASS_REGULAR_EXPRESSION
${output}
)
endforeach()
endforeach()
|