Skip to content

Commit 9450f98

Browse files
committed
Merge pull request #226 from adbridge/master
Add fixes to Utest to ensure thread safety and thus run when compiled with armcc
2 parents dc84d6a + 774311d commit 9450f98

File tree

22 files changed

+121
-72
lines changed

22 files changed

+121
-72
lines changed

frameworks/greentea-client.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/greentea-client.git/#571cfef17dd0377789532bcd22e388fb84e93a2c
1+
https://github.com/ARMmbed/greentea-client/#646297c0a1aa1afe6ab216aaba26b0c2cdde090b

frameworks/unity.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/unity/#7483099b9df15305b09168e95781e1178372f254
1+
https://github.com/ARMmbed/unity/#14fd303f30f9578b0ef6767c88e2fbc262db5fa1

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

frameworks/utest/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "utest",
3+
"macros": ["UNITY_INCLUDE_CONFIG_H"]
4+
}

frameworks/utest/source/case.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include "utest/case.h"
20+
#include "utest/utest_serial.h"
2021

2122
using namespace utest::v1;
2223

frameworks/utest/source/default_handlers.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "utest/default_handlers.h"
2020
#include "utest/case.h"
2121
#include "utest/stack_trace.h"
22-
22+
#include "utest/utest_serial.h"
2323

2424
using namespace utest::v1;
2525

@@ -40,7 +40,7 @@ static void test_failure_handler(const failure_t failure) {
4040
UTEST_LOG_FUNCTION();
4141
if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN) {
4242
verbose_test_failure_handler(failure);
43-
printf("{{failure}}\n{{end}}\n");
43+
utest_printf("{{failure}}\n{{end}}\n");
4444
while(1) ;
4545
}
4646
}
@@ -49,44 +49,44 @@ static void test_failure_handler(const failure_t failure) {
4949
utest::v1::status_t utest::v1::verbose_test_setup_handler(const size_t number_of_cases)
5050
{
5151
UTEST_LOG_FUNCTION();
52-
printf(">>> Running %u test cases...\n", number_of_cases);
52+
utest_printf(">>> Running %u test cases...\n", number_of_cases);
5353
return STATUS_CONTINUE;
5454
}
5555

5656
void utest::v1::verbose_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure)
5757
{
5858
UTEST_LOG_FUNCTION();
59-
printf("\n>>> Test cases: %u passed, %u failed", passed, failed);
59+
utest_printf("\n>>> Test cases: %u passed, %u failed", passed, failed);
6060
if (failure.reason == REASON_NONE) {
61-
printf("\n");
61+
utest_printf("\n");
6262
} else {
63-
printf(" with reason '%s'\n", stringify(failure.reason));
63+
utest_printf(" with reason '%s'\n", stringify(failure.reason));
6464
}
65-
if (failed) printf(">>> TESTS FAILED!\n");
65+
if (failed) utest_printf(">>> TESTS FAILED!\n");
6666
}
6767

6868
void utest::v1::verbose_test_failure_handler(const failure_t failure)
6969
{
70-
printf(">>> failure with reason '%s' during '%s'\n", stringify(failure.reason), stringify(failure.location));
70+
utest_printf(">>> failure with reason '%s' during '%s'\n", stringify(failure.reason), stringify(failure.location));
7171

7272
}
7373

7474
// --- VERBOSE CASE HANDLERS ---
7575
utest::v1::status_t utest::v1::verbose_case_setup_handler(const Case *const source, const size_t index_of_case)
7676
{
7777
UTEST_LOG_FUNCTION();
78-
printf("\n>>> Running case #%u: '%s'...\n", index_of_case + 1, source->get_description());
78+
utest_printf("\n>>> Running case #%u: '%s'...\n", index_of_case + 1, source->get_description());
7979
return STATUS_CONTINUE;
8080
}
8181

8282
utest::v1::status_t utest::v1::verbose_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
8383
{
8484
UTEST_LOG_FUNCTION();
85-
printf(">>> '%s': %u passed, %u failed", source->get_description(), passed, failed);
85+
utest_printf(">>> '%s': %u passed, %u failed", source->get_description(), passed, failed);
8686
if (failure.reason == REASON_NONE) {
87-
printf("\n");
87+
utest_printf("\n");
8888
} else {
89-
printf(" with reason '%s'\n", stringify(failure.reason));
89+
utest_printf(" with reason '%s'\n", stringify(failure.reason));
9090
}
9191
return STATUS_CONTINUE;
9292
}

frameworks/utest/source/greentea_handlers.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "utest/case.h"
2121
#include "greentea-client/test_env.h"
2222
#include "utest/stack_trace.h"
23+
#include "utest/utest_serial.h"
2324

2425
using namespace utest::v1;
2526

@@ -59,8 +60,8 @@ const handlers_t utest::v1::selftest_handlers = {
5960
// --- SPECIAL HANDLERS ---
6061
static utest::v1::status_t unknown_test_setup_handler(const size_t) {
6162
UTEST_LOG_FUNCTION();
62-
printf(">>> I do not know how to tell greentea that the test started, since\n");
63-
printf(">>> you forgot to override the `test_setup_handler` in your specification.\n");
63+
utest_printf(">>> I do not know how to tell greentea that the test started, since\n");
64+
utest_printf(">>> you forgot to override the `test_setup_handler` in your specification.\n");
6465

6566
return STATUS_ABORT;
6667
}

0 commit comments

Comments
 (0)