Skip to content

Commit f0b9d65

Browse files
author
Jamie Smith
authored
Fix lots of Greentea test warnings (#365)
1 parent 828b9f0 commit f0b9d65

File tree

25 files changed

+89
-76
lines changed

25 files changed

+89
-76
lines changed

connectivity/FEATURE_BLE/source/generic/GattClientImpl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ struct GattClient::DiscoveryControlBlock final : public ProcedureControlBlock {
488488
bool done;
489489
};
490490

491+
#undef TRACE_CLASS
491492
#define TRACE_CLASS "ReadControlBlock"
492493
struct GattClient::ReadControlBlock final : public ProcedureControlBlock {
493494
using ProcedureControlBlock::connection_handle;
@@ -701,6 +702,7 @@ struct GattClient::ReadControlBlock final : public ProcedureControlBlock {
701702
/*
702703
* Control block for the write process
703704
*/
705+
#undef TRACE_CLASS
704706
#define TRACE_CLASS "WriteControlBlock"
705707
struct GattClient::WriteControlBlock final : public ProcedureControlBlock {
706708
using ProcedureControlBlock::connection_handle;
@@ -926,6 +928,7 @@ struct GattClient::WriteControlBlock final : public ProcedureControlBlock {
926928
/*
927929
* Control block for the descriptor discovery process
928930
*/
931+
#undef TRACE_CLASS
929932
#define TRACE_CLASS "DescriptorDiscoveryControlBlock"
930933
struct GattClient::DescriptorDiscoveryControlBlock final : public ProcedureControlBlock {
931934
using ProcedureControlBlock::connection_handle;

connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_cert_in_filesystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ void TLSSOCKET_CERT_IN_FILESYSTEM()
3636
TEST_ASSERT_EQUAL(0, fs.mount(&bd));
3737

3838
FILE *fp = fopen("/fs/certs.pem", "wb");
39-
int ret = fwrite(tls_global::cert, strlen(tls_global::cert), 1, fp);
39+
size_t ret = fwrite(tls_global::cert, strlen(tls_global::cert), 1, fp);
40+
TEST_ASSERT_EQUAL(1, ret);
4041
fclose(fp);
4142

4243
TLSSocket sock;

connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void _ifup()
7373
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == MESH
7474
tr_info("Waiting for GLOBAL_UP\n");
7575
while (net->get_connection_status() != NSAPI_STATUS_GLOBAL_UP) {
76-
ThisThread::sleep_for(500);
76+
ThisThread::sleep_for(500ms);
7777
}
7878
#endif
7979
tr_info("MBED: UDPClient IP address is '%s'\n", address ? address.get_ip_address() : "null");

drivers/tests/TESTS/mbed_drivers/reset_reason/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#if DEVICE_WATCHDOG
2828
# include "hal/watchdog_api.h"
2929
# define MSG_VALUE_WATCHDOG_STATUS 1
30-
# define WDG_TIMEOUT_MS 50UL
30+
# define WDG_TIMEOUT_MS 50ms
3131
#else
3232
# define MSG_VALUE_WATCHDOG_STATUS 0
3333
#endif
@@ -60,7 +60,7 @@
6060
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
6161
* To be on the safe side, set the wait time to 150 ms.
6262
*/
63-
#define SERIAL_FLUSH_TIME_MS 150
63+
#define SERIAL_FLUSH_TIME_MS 150ms
6464

6565
typedef enum {
6666
CMD_STATUS_CONTINUE,
@@ -113,7 +113,7 @@ static cmd_status_t handle_command(const char *key, const char *value)
113113
if (strcmp(key, MSG_KEY_DEVICE_RESET) == 0 && strcmp(value, MSG_VALUE_DEVICE_RESET_WATCHDOG) == 0) {
114114
greentea_send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DEVICE_RESET_ACK);
115115
ThisThread::sleep_for(SERIAL_FLUSH_TIME_MS); // Wait for the serial buffers to flush.
116-
watchdog_config_t config = { .timeout_ms = WDG_TIMEOUT_MS };
116+
watchdog_config_t config = { .timeout_ms = WDG_TIMEOUT_MS.count() };
117117
if (hal_watchdog_init(&config) != WATCHDOG_STATUS_OK) {
118118
TEST_ASSERT_MESSAGE(0, "hal_watchdog_init() error.");
119119
return CMD_STATUS_ERROR;

drivers/usb/include/usb/internal/USBDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ class USBDevice: public USBPhyEvents {
547547
void _complete_set_configuration();
548548
void _complete_set_interface();
549549

550+
void _clear_endpoints();
551+
550552
struct endpoint_info_t {
551553
mbed::Callback<void()> callback;
552554
uint16_t max_packet_size;

drivers/usb/source/USBDevice.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void USBDevice::_complete_set_configuration()
402402
if ((_abort_control || !success) && !configured()) {
403403
// The set configuration request was aborted or failed so
404404
// reset any endpoints which may have been added.
405-
memset(_endpoint_info, 0, sizeof(_endpoint_info));
405+
_clear_endpoints();
406406
_device.configuration = 0;
407407
_endpoint_add_remove_allowed = false;
408408
}
@@ -1348,7 +1348,7 @@ USBDevice::USBDevice(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint1
13481348
this->product_id = product_id;
13491349
this->product_release = product_release;
13501350

1351-
memset(_endpoint_info, 0, sizeof(_endpoint_info));
1351+
_clear_endpoints();
13521352
memset(&_transfer, 0, sizeof(_transfer));
13531353
_transfer.user_callback = None;
13541354

@@ -1754,7 +1754,7 @@ void USBDevice::_change_state(DeviceState new_state)
17541754
bool leaving_default_state = (old_state >= Default) && (new_state < Default);
17551755

17561756
if (leaving_configured_state) {
1757-
memset(_endpoint_info, 0, sizeof(_endpoint_info));
1757+
_clear_endpoints();
17581758
_device.configuration = 0;
17591759
_endpoint_add_remove_allowed = false;
17601760
}
@@ -1771,3 +1771,10 @@ void USBDevice::_run_later(void (USBDevice::*function)())
17711771
{
17721772
_post_process = function;
17731773
}
1774+
1775+
void USBDevice::_clear_endpoints()
1776+
{
1777+
for (auto &info : _endpoint_info) {
1778+
info = endpoint_info_t{};
1779+
}
1780+
}

drivers/usb/tests/TESTS/usb_device/msd/main.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void msd_process(USBMSD *msd)
217217
Semaphore proc;
218218
msd->attach(callback(run_processing, &proc));
219219
while (!msd_process_done) {
220-
proc.try_acquire_for(100);
220+
proc.try_acquire_for(100ms);
221221
msd->process();
222222
if (msd->media_removed()) {
223223
media_remove_event.release();
@@ -233,26 +233,27 @@ void msd_process(USBMSD *msd)
233233
for (int x = 0; x < 15; x++) { \
234234
prev_read_counter = usb.get_read_counter();\
235235
prev_program_counter = usb.get_program_counter();\
236-
ThisThread::sleep_for(1000);\
236+
ThisThread::sleep_for(1000ms);\
237237
if ((usb.get_read_counter() == prev_read_counter) && \
238238
(usb.get_program_counter() == prev_program_counter)) {\
239239
break;\
240240
}\
241241
}
242242

243243

244-
#define TEST_ASSERT_EQUAL_STRING_LOOP(expected, actual, loop_index) \
245-
if (strcmp(expected, actual) != 0) { \
246-
char str[128]; \
247-
sprintf(str, "expected %s was %s (loop index: %lu)", expected, actual, loop_index); \
248-
TEST_ASSERT_MESSAGE(false, str); \
244+
char testMessageBuffer[300];
245+
246+
247+
#define TEST_ASSERT_EQUAL_STRING_LOOP(expected, actual, loop_index) \
248+
if (strcmp(expected, actual) != 0) { \
249+
sprintf(testMessageBuffer, "expected %s was %s (loop index: %lu)", expected, actual, loop_index); \
250+
TEST_ASSERT_MESSAGE(false, testMessageBuffer); \
249251
}
250252

251-
#define TEST_ASSERT_EQUAL_LOOP(expected, actual, loop_index) \
252-
if (expected != actual) { \
253-
char str[128]; \
254-
sprintf(str, "expected %d was %d (loop index: %lu)", expected, actual, loop_index); \
255-
TEST_ASSERT_MESSAGE(false, str); \
253+
#define TEST_ASSERT_EQUAL_LOOP(expected, actual, loop_index) \
254+
if (expected != actual) { \
255+
sprintf(testMessageBuffer, "expected %d was %d (loop index: %lu)", expected, actual, loop_index); \
256+
TEST_ASSERT_MESSAGE(false, testMessageBuffer); \
256257
}
257258

258259

@@ -341,7 +342,7 @@ void mount_unmount_test(BlockDevice *bd, FileSystem *fs)
341342
TEST_ASSERT_EQUAL_STRING_LOOP("passed", _key, i);
342343

343344
// wait for unmount event (set 10s timeout)
344-
media_remove_event.try_acquire_for(10000);
345+
media_remove_event.try_acquire_for(10s);
345346
if (!usb.media_removed()) {
346347
TEST_ASSERT_EQUAL_LOOP(true, usb.media_removed(), i);
347348
}
@@ -436,7 +437,7 @@ void mount_unmount_and_data_test(BlockDevice *bd, FileSystem *fs)
436437
TEST_ASSERT_EQUAL_STRING("passed", _key);
437438

438439
do {
439-
ThisThread::sleep_for(1);
440+
ThisThread::sleep_for(1ms);
440441
} while (test_files_exist(fs_root));
441442
TEST_ASSERT_EQUAL(false, test_files_exist(fs_root));
442443

hal/tests/TESTS/mbed_hal/ospi/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static void _ospi_write_read_test(Ospi &ospi, ospi_bus_width_t write_inst_width,
115115
ospi_status_t ret = OSPI_STATUS_OK;
116116

117117
Timer timer;
118-
int erase_time = 0, write_time = 0, read_time = 0;
118+
std::chrono::microseconds erase_time{}, write_time{}, read_time{};
119119
size_t buf_len = data_size;
120120

121121
for (uint32_t tc = 0; tc < test_count; tc++) {
@@ -136,7 +136,7 @@ static void _ospi_write_read_test(Ospi &ospi, ospi_bus_width_t write_inst_width,
136136
WAIT_FOR(SECTOR_ERASE_MAX_TIME, ospi);
137137

138138
timer.stop();
139-
erase_time = timer.read_us();
139+
erase_time = timer.elapsed_time();
140140

141141
// switching to extended-SPI/DPI/QPI mode here for write operation
142142
// for DPI/QPI ospi.cmd is automatically switched to 2_2_2/4_4_4 mode
@@ -167,7 +167,7 @@ static void _ospi_write_read_test(Ospi &ospi, ospi_bus_width_t write_inst_width,
167167
WAIT_FOR(PAGE_PROG_MAX_TIME, ospi);
168168

169169
timer.stop();
170-
write_time = timer.read_us();
170+
write_time = timer.elapsed_time();
171171
}
172172

173173
// switching back to single channel SPI
@@ -193,7 +193,7 @@ static void _ospi_write_read_test(Ospi &ospi, ospi_bus_width_t write_inst_width,
193193
TEST_ASSERT_EQUAL(read_size, buf_len);
194194

195195
timer.stop();
196-
read_time = timer.read_us();
196+
read_time = timer.elapsed_time();
197197
}
198198
ospi.cmd.set_dummy_cycles(0);
199199

@@ -211,13 +211,13 @@ static void _ospi_write_read_test(Ospi &ospi, ospi_bus_width_t write_inst_width,
211211
if (tx_buf[i] != rx_buf[i]) {
212212
log_data("tx data", tx_buf, data_size);
213213
log_data("rx data", rx_buf, data_size);
214-
utest_printf("erase/write/read time: %d/%d/%d [us]\r\n", erase_time, write_time, read_time);
214+
utest_printf("erase/write/read time: %" PRIi64 "/%" PRIi64 "/%" PRIi64 " [us]\r\n", erase_time.count(), write_time.count(), read_time.count());
215215
TEST_ASSERT_EQUAL(tx_buf[i], rx_buf[i]);
216216
}
217217
}
218218

219219
#ifdef OSPI_TEST_LOG_FLASH_TIME
220-
utest_printf("erase/write/read time: %d/%d/%d [us]\r\n", erase_time, write_time, read_time);
220+
utest_printf("erase/write/read time: %" PRIi64 "/%" PRIi64 "/%" PRIi64 " [us]\r\n", erase_time.count(), write_time.count(), read_time.count());
221221
#endif
222222

223223
#ifdef OSPI_TEST_LOG_DATA

hal/tests/TESTS/mbed_hal/sleep_manager_racecondition/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void sleep_manager_locking_thread_test()
3232
{
3333
for (uint32_t i = 0; i < 100; i++) {
3434
sleep_manager_lock_deep_sleep();
35-
ThisThread::sleep_for(25);
35+
ThisThread::sleep_for(25ms);
3636
sleep_manager_unlock_deep_sleep();
3737
}
3838
}
@@ -45,7 +45,7 @@ void sleep_manager_multithread_test()
4545
Thread t2(osPriorityNormal, TEST_STACK_SIZE);
4646

4747
t1.start(callback(cb));
48-
ThisThread::sleep_for(25);
48+
ThisThread::sleep_for(25ms);
4949
t2.start(callback(cb));
5050

5151
// Wait for the threads to finish
@@ -70,13 +70,13 @@ void sleep_manager_irq_test()
7070
Ticker ticker1;
7171
Timer timer;
7272

73-
ticker1.attach_us(&sleep_manager_locking_irq_test, 1000);
73+
ticker1.attach(&sleep_manager_locking_irq_test, 1ms);
7474

7575
// run this for 10 seconds
7676
timer.start();
77-
int start = timer.read();
78-
int end = start + 10;
79-
while (timer.read() < end) {
77+
const auto start = timer.elapsed_time();
78+
const auto end = start + 10s;
79+
while (timer.elapsed_time() < end) {
8080
sleep_manager_locking_irq_test();
8181
}
8282
timer.stop();

hal/tests/TESTS/mbed_hal/ticker/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,7 @@ static void test_match_interval_passed_table()
22512251
{0xfffffffe, 0xffffffff, 0xffffffff, true},
22522252
{0x00000000, 0xffffffff, 0xffffffff, true},
22532253
};
2254-
for (int i = 0; i < MBED_ARRAY_SIZE(test_values); i++) {
2254+
for (size_t i = 0; i < MBED_ARRAY_SIZE(test_values); i++) {
22552255
const uint32_t prev = test_values[i].prev;
22562256
const uint32_t cur = test_values[i].cur;
22572257
const uint32_t match = test_values[i].match;

0 commit comments

Comments
 (0)