Skip to content

Commit d4415ee

Browse files
committed
Remove all printfs from test cases which may directly or indirectly run
from an interrupt context. Where required add flags to functions and check the values in the case teardowns. This allows validation that the case callback was invoked without the need for an ASSERT or printf directly in the callback. In cases where a printf is still required in a test case but it is unclear whether the code may or may not get called from interrupt context, a new printf alternative, utest_printf() should be used instead. This just checks whether the code is executing in interrupt context and only passes its arguments to printf if not.
1 parent e64975c commit d4415ee

File tree

8 files changed

+13
-31
lines changed

8 files changed

+13
-31
lines changed

frameworks/utest/TESTS/unit_tests/basic_test/main.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ using namespace utest::v1;
99
void test_simple() {
1010
UTEST_LOG_FUNCTION();
1111
TEST_ASSERT_EQUAL(0, 0);
12-
printf("Simple test called\n");
1312
}
1413

1514
utest::v1::status_t test_repeats_setup(const Case *const source, const size_t index_of_case) {
1615
UTEST_LOG_FUNCTION();
1716
// Call the default handler for proper reporting
1817
utest::v1::status_t status = greentea_case_setup_handler(source, index_of_case);
19-
printf("Setting up for '%s'\n", source->get_description());
18+
utest_printf("Setting up for '%s'\n", source->get_description());
2019
return status;
2120
}
2221
control_t test_repeats(const size_t call_count) {
2322
UTEST_LOG_FUNCTION();
24-
printf("Called for the %u. time\n", call_count);
2523
TEST_ASSERT_NOT_EQUAL(3, call_count);
2624
// Specify how often this test is repeated ie. n total calls
2725
return (call_count < 2) ? CaseRepeatAll : CaseNext;

frameworks/utest/TESTS/unit_tests/case_async_validate/main.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ static Timeout utest_to;
3131
void simple_validation()
3232
{
3333
TEST_ASSERT_EQUAL(1, call_counter++);
34-
printf("Simple validation callback executed.\n");
3534
Harness::validate_callback();
3635
}
3736

3837
control_t simple_validation_case()
3938
{
40-
printf("Simple validation, posting callback\n");
4139
TEST_ASSERT_EQUAL(0, call_counter++);
4240
utest_to.attach_us(simple_validation, 100); // Fire after 100 us
4341

@@ -47,8 +45,6 @@ control_t simple_validation_case()
4745
// Validate: Multiple Validation --------------------------------------------------------------------------------------
4846
void multiple_validation()
4947
{
50-
printf("Multiple validation callback executed.\n");
51-
5248
// make sure validation is side-effect free
5349
TEST_ASSERT_EQUAL(3, call_counter++);
5450
Harness::validate_callback();
@@ -67,7 +63,6 @@ void multiple_validation()
6763
control_t multiple_validation_case()
6864
{
6965
TEST_ASSERT_EQUAL(2, call_counter++);
70-
printf("Multiple validation callback posted.\n");
7166
utest_to.attach_us(multiple_validation, 100000); // Fire after 100 ms
7267
return CaseAwait;
7368
}
@@ -135,15 +130,13 @@ utest::v1::status_t multiple_premature_validation_case_teardown(const Case *cons
135130
void attributed_validation_cancel_repeat()
136131
{
137132
TEST_ASSERT_EQUAL(19, call_counter++);
138-
printf("Validation cancel repeat callback executed.\n");
139133
// cancel all repeats
140134
Harness::validate_callback(CaseNoRepeat);
141135
}
142136

143137
control_t attributed_validation_cancel_repeat_case()
144138
{
145139
TEST_ASSERT_EQUAL(18, call_counter++);
146-
printf("Validation cancel repeat callback posted.\n");
147140

148141
utest_to.attach_us(attributed_validation_cancel_repeat, 100000); // Fire after 100 ms
149142
// the RepeatAll will be cancelled during callback validation
@@ -163,7 +156,6 @@ utest::v1::status_t attributed_validation_cancel_repeat_case_teardown(const Case
163156
// Validate: Attributed Validation: Enable Repeat Handler -------------------------------------------------------------
164157
void attributed_validation_enable_repeat()
165158
{
166-
printf("Validation enable repeat callback executed.\n");
167159
TEST_ASSERT_EQUAL(22, call_counter++);
168160
// cancel all repeats
169161
Harness::validate_callback(CaseRepeatHandler);
@@ -177,7 +169,6 @@ control_t attributed_validation_enable_repeat_case(const size_t call_count)
177169
{
178170
if (call_count == 1) {
179171
TEST_ASSERT_EQUAL(21, call_counter++);
180-
printf("Validation enable repeat callback posted.\n");
181172
utest_to.attach_us(attributed_validation_enable_repeat, 100000); // Fire after 100 ms
182173
// the RepeatAll will be cancelled during callback validation
183174
return CaseAwait;

frameworks/utest/TESTS/unit_tests/case_control_async/main.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class Utest_func_bind {
4646
void await_case_validate(int expected_call_count)
4747
{
4848
UTEST_LOG_FUNCTION();
49-
printf("await_case_validate called with expected call count of %d\n", expected_call_count);
5049
TEST_ASSERT_EQUAL(expected_call_count, call_counter++);
5150
Harness::validate_callback();
5251
}
@@ -142,13 +141,11 @@ utest::v1::status_t repeat_all_on_timeout_case_setup(const Case *const source, c
142141
control_t repeat_all_on_timeout_case(const size_t call_count)
143142
{
144143
UTEST_LOG_FUNCTION();
145-
printf("Running case handler for %u. time\n", call_count);
146144
static int repeat_counter(1);
147145
TEST_ASSERT_EQUAL(repeat_counter++, call_count);
148146
TEST_ASSERT(call_count <= 10);
149147
TEST_ASSERT_EQUAL((call_count-1)*3 + 9, call_counter++);
150148
if (call_count == 10) {
151-
printf("Scheduling await_case_validate with value 37");
152149
utest_to.attach_us(&validate2, &Utest_func_bind::callback, (50*1000)); // Fire after 50ms
153150
}
154151
return CaseRepeatAllOnTimeout(100);
@@ -157,7 +154,6 @@ utest::v1::status_t repeat_all_on_timeout_case_teardown(const Case *const source
157154
{
158155
UTEST_LOG_FUNCTION();
159156
static int repeat_counter(0);
160-
printf("Call counter = %d, passed =%u, failed = %u\n", call_counter, passed, failed);
161157

162158
TEST_ASSERT_EQUAL((call_counter == 38) ? 1 : 0, passed);
163159
TEST_ASSERT_EQUAL(0, failed);
@@ -180,13 +176,11 @@ utest::v1::status_t repeat_handler_on_timeout_case_setup(const Case *const sourc
180176
control_t repeat_handler_on_timeout_case(const size_t call_count)
181177
{
182178
UTEST_LOG_FUNCTION();
183-
printf("Running case handler for %u. time\n", call_count);
184179
static int repeat_counter(1);
185180
TEST_ASSERT_EQUAL(repeat_counter++, call_count);
186181
TEST_ASSERT(call_count <= 10);
187182
TEST_ASSERT_EQUAL(call_count-1 + 40, call_counter++);
188183
if (call_count == 10) {
189-
printf("Scheduling await_case_validate with value 50");
190184
utest_to.attach_us(&validate3, &Utest_func_bind::callback, (50*1000)); // Fire after 50ms
191185
}
192186
return CaseRepeatHandlerOnTimeout(100);

frameworks/utest/TESTS/unit_tests/case_control_repeat/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ utest::v1::status_t repeat_all_case_setup(const Case *const source, const size_t
3434
}
3535
control_t repeat_all_case(const size_t call_count)
3636
{
37-
printf("Running case handler for %u. time\n", call_count);
3837
static int repeat_counter(1);
3938
TEST_ASSERT_EQUAL(repeat_counter++, call_count);
4039
TEST_ASSERT_EQUAL((call_count-1)*3 + 1, call_counter++);
@@ -61,7 +60,6 @@ utest::v1::status_t repeat_handler_case_setup(const Case *const source, const si
6160
}
6261
control_t repeat_handler_case(const size_t call_count)
6362
{
64-
printf("Running case handler for %u. time\n", call_count);
6563
static int repeat_counter(1);
6664
TEST_ASSERT_EQUAL(repeat_counter++, call_count);
6765
TEST_ASSERT_EQUAL((call_count-1) + 31, call_counter++);

frameworks/utest/TESTS/unit_tests/case_selection/main.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323
using namespace utest::v1;
2424

2525
static int call_counter(0);
26+
static bool executed_case_0 = false;
27+
static bool executed_case_1 = false;
28+
static bool executed_case_2 = false;
2629

2730
void handler_case_2()
2831
{
29-
printf("Executing Case 2...\n");
32+
executed_case_2 = true;
3033
}
3134
utest::v1::status_t teardown_case_2(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
3235
{
36+
TEST_ASSERT_TRUE(executed_case_2);
3337
TEST_ASSERT_EQUAL(1, passed);
3438
TEST_ASSERT_EQUAL(0, failed);
3539
TEST_ASSERT_EQUAL(REASON_NONE, failure.reason);
@@ -40,10 +44,11 @@ utest::v1::status_t teardown_case_2(const Case *const source, const size_t passe
4044
}
4145
void handler_case_0()
4246
{
43-
printf("Executing Case 0...\n");
47+
executed_case_0 = true;
4448
}
4549
utest::v1::status_t teardown_case_0(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
4650
{
51+
TEST_ASSERT_TRUE(executed_case_0);
4752
TEST_ASSERT_EQUAL(1, passed);
4853
TEST_ASSERT_EQUAL(0, failed);
4954
TEST_ASSERT_EQUAL(REASON_NONE, failure.reason);
@@ -54,10 +59,11 @@ utest::v1::status_t teardown_case_0(const Case *const source, const size_t passe
5459
}
5560
void handler_case_1()
5661
{
57-
printf("Executing Case 1...\n");
62+
executed_case_1 = true;
5863
}
5964
utest::v1::status_t teardown_case_1(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
6065
{
66+
TEST_ASSERT_TRUE(executed_case_1);
6167
TEST_ASSERT_EQUAL(1, passed);
6268
TEST_ASSERT_EQUAL(0, failed);
6369
TEST_ASSERT_EQUAL(REASON_NONE, failure.reason);

frameworks/utest/TESTS/unit_tests/case_setup_failure/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
using namespace utest::v1;
2323

2424
static int call_counter(0);
25+
static bool never_call = false;
2526

2627
void never_call_case()
2728
{
28-
TEST_FAIL_MESSAGE("Case handler should have never been called!");
29+
never_call = true;
2930
}
3031

3132
utest::v1::status_t abort_case_setup(const Case *const source, const size_t index_of_case)
@@ -38,6 +39,7 @@ utest::v1::status_t abort_case_setup(const Case *const source, const size_t inde
3839

3940
utest::v1::status_t abort_case_teardown(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
4041
{
42+
TEST_ASSERT_FALSE_MESSAGE(never_call, "Case handler should never have been called!");
4143
TEST_ASSERT_EQUAL(1, call_counter);
4244
TEST_ASSERT_EQUAL(0, passed);
4345
TEST_ASSERT_EQUAL(1, failed);

frameworks/utest/TESTS/unit_tests/minimal_async_scheduler/main.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ static Timeout utest_minimal_object;
3838
static void ticker_handler()
3939
{
4040
UTEST_LOG_FUNCTION();
41-
// printf("\t\t>>> Ticker callback fired for %p.\n", ticker_callback);
4241
minimal_callback = ticker_callback;
4342
}
4443

@@ -52,7 +51,6 @@ static int32_t utest_minimal_init()
5251
static void *utest_minimal_post(const utest_v1_harness_callback_t callback, timestamp_t delay_ms)
5352
{
5453
UTEST_LOG_FUNCTION();
55-
// printf("\t\t>>> Schedule %p with %ums delay => %p.\n", callback, (unsigned int)delay_ms, (void*)1);
5654
timestamp_t delay_us = delay_ms *1000;
5755

5856
if (delay_ms) {
@@ -69,7 +67,6 @@ static void *utest_minimal_post(const utest_v1_harness_callback_t callback, tim
6967
static int32_t utest_minimal_cancel(void *handle)
7068
{
7169
UTEST_LOG_FUNCTION();
72-
printf("\t\t>>> Cancel %p => %u\n", handle, (unsigned int)0);
7370
(void) handle;
7471
utest_minimal_object.detach();
7572
return 0;
@@ -86,7 +83,6 @@ static int32_t utest_minimal_run()
8683
// check if a new callback has been set
8784
if (minimal_callback)
8885
{
89-
printf("\t\t>>> Firing callback %p\n", minimal_callback);
9086
// copy the callback
9187
utest_v1_harness_callback_t callback = minimal_callback;
9288
// reset the shared callback
@@ -114,7 +110,6 @@ control_t test_case()
114110
UTEST_LOG_FUNCTION();
115111
static int counter(0);
116112
TEST_ASSERT_EQUAL(counter++, call_counter++);
117-
printf("Running Test #%d\n", counter);
118113
return CaseNext;
119114
}
120115

@@ -124,7 +119,6 @@ control_t test_case_async()
124119
UTEST_LOG_FUNCTION();
125120
static int counter(3);
126121
TEST_ASSERT_EQUAL(counter++, call_counter++);
127-
printf("Running Test #%d\n", counter);
128122
return CaseTimeout(200);
129123
}
130124
utest::v1::status_t test_case_async_failure(const Case *const source, const failure_t reason)

frameworks/utest/TESTS/unit_tests/minimal_scheduler/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ control_t test_case()
8282
{
8383
static int counter(0);
8484
TEST_ASSERT_EQUAL(counter++, call_counter++);
85-
printf("Running Test #%d\n", counter);
8685
return CaseNext;
8786
}
8887

0 commit comments

Comments
 (0)