Skip to content

Commit 0f2b0d1

Browse files
committed
Fixed greentea tests
1 parent 954f22b commit 0f2b0d1

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

TESTS/mbed_drivers/c_strings/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,15 @@ Case cases[] = {
116116
Case("C strings: %u %d integer formatting", test_case_c_string_u_d, greentea_failure_handler),
117117
Case("C strings: %x %E integer formatting", test_case_c_string_x_X, greentea_failure_handler),
118118
#if !defined(__NEWLIB_NANO)
119-
//In build tools, GCC with Newlib-nano linker option "-u _printf_float" is not configured
120-
//to enable printf floating format. So disabling floating format test case.
119+
// Newlib-nano linker option "-u _printf_float" is not set to enable floating point support.
120+
#if (defined(MBED_MINIMAL_PRINTF) && MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FLOATING_POINT) || !defined(MBED_MINIMAL_PRINTF)
121121
Case("C strings: %f %f float formatting", test_case_c_string_f_f, greentea_failure_handler),
122+
#endif
122123
#ifndef MBED_MINIMAL_PRINTF
123124
Case("C strings: %e %E float formatting", test_case_c_string_e_E, greentea_failure_handler),
124125
Case("C strings: %g %g float formatting", test_case_c_string_g_g, greentea_failure_handler),
125-
#endif
126-
#endif
126+
#endif // MBED_MINIMAL_PRINTF
127+
#endif // !defined(__NEWLIB_NANO)
127128
};
128129

129130
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)

TESTS/mbed_drivers/watchdog_reset/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ bool send_reset_notification(testcase_data *tcdata, uint32_t delay_ms)
9292
{
9393
char msg_value[12];
9494
int str_len = snprintf(msg_value, sizeof msg_value, "%02x,%08lx", tcdata->start_index + tcdata->index, delay_ms);
95-
if (str_len != (sizeof msg_value) - 1) {
95+
if (str_len < 0) {
9696
utest_printf("Failed to compose a value string to be sent to host.");
9797
return false;
9898
}

TESTS/mbed_hal/watchdog_reset/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ bool send_reset_notification(testcase_data *tcdata, uint32_t delay_ms)
9090
{
9191
char msg_value[12];
9292
int str_len = snprintf(msg_value, sizeof msg_value, "%02x,%08lx", tcdata->start_index + tcdata->index, delay_ms);
93-
if (str_len != (sizeof msg_value) - 1) {
93+
if (str_len < 0) {
9494
utest_printf("Failed to compose a value string to be sent to host.");
9595
return false;
9696
}

TESTS/mbed_hal/watchdog_timing/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ bool send_reset_notification(testcase_data *tcdata, uint32_t delay_ms)
5959
{
6060
char msg_value[12];
6161
int str_len = snprintf(msg_value, sizeof msg_value, "%02x,%08lx", tcdata->start_index + tcdata->index, delay_ms);
62-
if (str_len != (sizeof msg_value) - 1) {
62+
if (str_len < 0) {
6363
utest_printf("Failed to compose a value string to be sent to host.");
6464
return false;
6565
}
@@ -110,7 +110,7 @@ void test_timing()
110110

111111
int str_len = snprintf(msg_value, sizeof msg_value, "%02x,%08lx", current_case.start_index + current_case.index,
112112
(uint32_t) current_ts);
113-
if (str_len != (sizeof msg_value) - 1) {
113+
if (str_len < 0) {
114114
utest_printf("Failed to compose a value string to be sent to host.");
115115
return;
116116
}

platform/source/minimal-printf/mbed_printf_implementation.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2017 ARM Limited
2+
* Copyright (c) 2017-2020 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
56
* you may not use this file except in compliance with the License.
@@ -121,17 +122,22 @@ static void mbed_minimal_putchar(char *buffer, size_t length, int *result, char
121122
{
122123
/* only continue if 'result' doesn't overflow */
123124
if ((*result >= 0) && (*result <= INT_MAX - 1)) {
124-
/* write data only if there's enough space */
125-
if ((size_t)*result < length) {
126-
if (buffer) {
125+
if (buffer) {
126+
/* write data only if there's enough space */
127+
if ((size_t)*result < length) {
127128
buffer[*result] = data;
129+
}
130+
131+
/* increment 'result' even if data was not written. This ensures that
132+
'mbed_minimal_formatted_string' returns the correct value. */
133+
*result += 1;
134+
} else {
135+
if (fputc(data, stream) == EOF) {
136+
*result = EOF;
128137
} else {
129-
fputc(data, stream);
138+
*result += 1;
130139
}
131140
}
132-
/* increment 'result' even if data was not written. This ensures that
133-
'mbed_minimal_formatted_string' returns the correct value. */
134-
*result += 1;
135141
}
136142
}
137143

0 commit comments

Comments
 (0)