Skip to content

Commit e1a1542

Browse files
author
Jamie Smith
authored
Reactivate tests under drivers/ and fix deprecation warnings (ARMmbed#191)
* Reactivate tests under drivers/ and fix deprecation warnings * Fix missing statement * Oops, fix commented tests
1 parent eee0647 commit e1a1542

File tree

36 files changed

+312
-343
lines changed

36 files changed

+312
-343
lines changed

drivers/include/drivers/Watchdog.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "hal/watchdog_api.h"
2727
#include "platform/NonCopyable.h"
2828
#include <cstdio>
29+
#include <chrono>
2930

3031
namespace mbed {
3132
/**
@@ -92,7 +93,7 @@ class Watchdog : private NonCopyable<Watchdog> {
9293

9394
/** Start the Watchdog timer.
9495
*
95-
* @note Asset that the timeout param is supported by the target
96+
* @note Asserts that the timeout param is supported by the target
9697
* (0 < timeout <= Watchdog::get_max_timeout).
9798
*
9899
* @param timeout Watchdog timeout in milliseconds.
@@ -103,6 +104,22 @@ class Watchdog : private NonCopyable<Watchdog> {
103104
*/
104105
bool start(uint32_t timeout);
105106

107+
/** Start the Watchdog timer.
108+
*
109+
* @note Asserts that the timeout param is supported by the target
110+
* (0 < timeout <= Watchdog::get_max_timeout).
111+
*
112+
* @param timeout Watchdog timeout in chrono milliseconds.
113+
*
114+
* @return true if the Watchdog timer was started successfully;
115+
* false if Watchdog timer was not started or if setting
116+
* a new watchdog timeout was not possible.
117+
*/
118+
bool start(std::chrono::milliseconds timeout)
119+
{
120+
return start(timeout.count());
121+
}
122+
106123
/** Stop the Watchdog timer.
107124
*
108125
* Calling this function disables a running Watchdog

drivers/tests/TESTS/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Copyright (c) 2021 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
add_subdirectory(mbed_drivers/ticker)
4+
add_subdirectory(mbed_drivers)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
add_subdirectory(buffered_serial)
2+
add_subdirectory(c_strings)
3+
add_subdirectory(crc)
4+
add_subdirectory(dev_null)
5+
add_subdirectory(echo)
6+
add_subdirectory(flashiap)
7+
add_subdirectory(generic_tests)
8+
add_subdirectory(lp_ticker)
9+
add_subdirectory(lp_timeout)
10+
add_subdirectory(lp_timer)
11+
add_subdirectory(mem_trace)
12+
add_subdirectory(race_test)
13+
add_subdirectory(reset_reason)
14+
add_subdirectory(sleep_lock)
15+
add_subdirectory(stl_features)
16+
add_subdirectory(ticker)
17+
add_subdirectory(timerevent)
18+
add_subdirectory(unbuffered_serial)
19+
add_subdirectory(watchdog)
20+
add_subdirectory(watchdog_reset)
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5-
6-
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
7-
set(TEST_TARGET mbed-drivers-buffered-serial)
8-
9-
include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)
10-
11-
project(${TEST_TARGET})
4+
if(NOT "DEVICE_SERIAL=1" IN_LIST MBED_TARGET_DEFINITIONS)
5+
set(TEST_SKIPPED "Serial communication not supported for this target")
6+
endif()
127

138
mbed_greentea_add_test(
149
TEST_NAME
15-
${TEST_TARGET}
10+
mbed-drivers-buffered-serial
1611
TEST_SOURCES
1712
main.cpp
13+
HOST_TESTS_DIR
14+
../../host_tests
15+
TEST_SKIPPED
16+
${TEST_SKIPPED}
1817
)
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5-
6-
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
7-
set(TEST_TARGET mbed-drivers-c-strings)
8-
9-
include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)
10-
11-
project(${TEST_TARGET})
12-
134
mbed_greentea_add_test(
145
TEST_NAME
15-
${TEST_TARGET}
6+
mbed-drivers-c-strings
167
TEST_SOURCES
178
main.cpp
189
)
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5-
6-
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
7-
set(TEST_TARGET mbed-drivers-crc)
8-
9-
include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)
10-
11-
project(${TEST_TARGET})
12-
134
mbed_greentea_add_test(
145
TEST_NAME
15-
${TEST_TARGET}
6+
mbed-drivers-crc
167
TEST_SOURCES
178
main.cpp
189
)
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5-
6-
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
7-
set(TEST_TARGET mbed-drivers-dev-null)
8-
9-
include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)
10-
11-
project(${TEST_TARGET})
12-
134
mbed_greentea_add_test(
145
TEST_NAME
15-
${TEST_TARGET}
6+
mbed-drivers-dev-null
167
TEST_SOURCES
178
main.cpp
9+
HOST_TESTS_DIR
10+
../../host_tests
1811
)

drivers/tests/TESTS/mbed_drivers/echo/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ mbed_greentea_add_test(
1515
${TEST_TARGET}
1616
TEST_SOURCES
1717
main.cpp
18+
HOST_TESTS_DIR
19+
../../host_tests
1820
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace utest::v1;
2929
void fill_buffer(char *buffer, unsigned int length, unsigned int index)
3030
{
3131
unsigned int start = length * index;
32-
for (int i = 0; i < length - 1; i++) {
32+
for (unsigned int i = 0; i < length - 1; i++) {
3333
buffer[i] = 'a' + ((start + i) % 26);
3434
}
3535
buffer[length - 1] = '\0';
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5-
6-
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
7-
set(TEST_TARGET mbed-drivers-flashiap)
8-
9-
include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)
10-
11-
project(${TEST_TARGET})
4+
if(NOT "DEVICE_FLASH=1" IN_LIST MBED_TARGET_DEFINITIONS)
5+
set(TEST_SKIPPED "Flash API not supported for this target")
6+
endif()
127

138
mbed_greentea_add_test(
149
TEST_NAME
15-
${TEST_TARGET}
10+
mbed-drivers-flashiap
1611
TEST_SOURCES
1712
main.cpp
13+
TEST_SKIPPED
14+
${TEST_SKIPPED}
1815
)

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

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "FlashIAP.h"
2828
#include "unity.h"
2929
#include <algorithm>
30+
#include <cinttypes>
3031

3132
#include "mbed.h"
3233

@@ -43,6 +44,17 @@
4344

4445
using namespace utest::v1;
4546

47+
// Get the max of two microsecond values
48+
static std::chrono::microseconds us_max(std::chrono::microseconds time1, std::chrono::microseconds time2)
49+
{
50+
return time1 > time2 ? time1 : time2;
51+
}
52+
53+
// Get the min of two microsecond values
54+
static std::chrono::microseconds us_min(std::chrono::microseconds time1, std::chrono::microseconds time2)
55+
{
56+
return time1 < time2 ? time1 : time2;
57+
}
4658

4759
void flashiap_init_test()
4860
{
@@ -54,7 +66,6 @@ void flashiap_init_test()
5466
uint32_t flash_size = flash_device.get_flash_size();
5567
utest_printf("Flash address: 0x%08x, size: %d\n", flash_start, flash_size);
5668
uint32_t address = flash_start;
57-
int num = 0;
5869
while (flash_size) {
5970
uint32_t sector_size = flash_device.get_sector_size(address);
6071
// Make sure all sectors sum up to the total flash size
@@ -234,10 +245,12 @@ void flashiap_timing_test()
234245
uint32_t ret = flash_device.init();
235246
TEST_ASSERT_EQUAL_INT32(0, ret);
236247
mbed::Timer timer;
248+
249+
std::chrono::microseconds curr_time{};
250+
std::chrono::microseconds avg_erase_time{};
237251
unsigned int num_write_sizes;
238-
unsigned int curr_time, byte_usec_ratio;
239-
unsigned int avg_erase_time = 0;
240-
unsigned int max_erase_time = 0, min_erase_time = (unsigned int) -1;
252+
unsigned int byte_usec_ratio;
253+
std::chrono::microseconds max_erase_time(0), min_erase_time(-1);
241254
const unsigned int max_writes = 128;
242255
const unsigned int max_write_sizes = 6;
243256
const unsigned int max_byte_usec_ratio = 200;
@@ -266,42 +279,42 @@ void flashiap_timing_test()
266279
memset(buf, 0x5A, write_size);
267280
timer.reset();
268281
ret = flash_device.erase(base_address, sector_size);
269-
curr_time = timer.read_us();
282+
curr_time = timer.elapsed_time();
270283
avg_erase_time += curr_time;
271284
TEST_ASSERT_EQUAL_INT32(0, ret);
272-
max_erase_time = std::max(max_erase_time, curr_time);
273-
min_erase_time = std::min(min_erase_time, curr_time);
285+
max_erase_time = us_max(max_erase_time, curr_time);
286+
min_erase_time = us_min(min_erase_time, curr_time);
274287
uint32_t address = base_address;
275-
unsigned int avg_write_time = 0;
276-
unsigned int max_write_time = 0, min_write_time = (unsigned int) -1;
288+
std::chrono::microseconds avg_write_time(0);
289+
std::chrono::microseconds max_write_time(0), min_write_time(-1);
277290
unsigned int num_writes;
278291
for (num_writes = 0; num_writes < max_writes; num_writes++) {
279292
if ((address + write_size) > end_address) {
280293
break;
281294
}
282295
timer.reset();
283296
ret = flash_device.program(buf, address, write_size);
284-
curr_time = timer.read_us();
297+
curr_time = timer.elapsed_time();
285298
avg_write_time += curr_time;
286299
TEST_ASSERT_EQUAL_INT32(0, ret);
287-
max_write_time = std::max(max_write_time, curr_time);
288-
min_write_time = std::min(min_write_time, curr_time);
300+
max_write_time = us_max(max_write_time, curr_time);
301+
min_write_time = us_min(min_write_time, curr_time);
289302
address += write_size;
290303
}
291304
delete[] buf;
292305
avg_write_time /= num_writes;
293-
utest_printf("Write size %6u bytes: avg %10u, min %10u, max %10u (usec)\n",
294-
write_size, avg_write_time, min_write_time, max_write_time);
295-
byte_usec_ratio = write_size / avg_write_time;
306+
byte_usec_ratio = write_size / avg_write_time.count();
307+
utest_printf("Write size %6u bytes: avg %10" PRIi64 ", min %10" PRIi64 ", max %10" PRIi64 " (usec), rate %10u bytes/usec\n",
308+
write_size, avg_write_time.count(), min_write_time.count(), max_write_time.count(), byte_usec_ratio);
296309
TEST_ASSERT(byte_usec_ratio < max_byte_usec_ratio);
297310
write_size *= 4;
298311
}
299312

300313
if (num_write_sizes) {
301314
avg_erase_time /= num_write_sizes;
302-
utest_printf("\nErase size %6u bytes: avg %10u, min %10u, max %10u (usec)\n\n",
303-
sector_size, avg_erase_time, min_erase_time, max_erase_time);
304-
byte_usec_ratio = sector_size / avg_erase_time;
315+
byte_usec_ratio = sector_size / avg_erase_time.count();
316+
utest_printf("\nErase size %6u bytes: avg %10" PRIi64 ", min %10" PRIi64 ", max %10" PRIi64" (usec), rate %10u bytes/usec\n\n",
317+
sector_size, avg_erase_time.count(), min_erase_time.count(), max_erase_time.count(), byte_usec_ratio);
305318
TEST_ASSERT(byte_usec_ratio < max_byte_usec_ratio);
306319
}
307320

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5-
6-
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
7-
set(TEST_TARGET mbed-drivers-generic-tests)
8-
9-
include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)
10-
11-
project(${TEST_TARGET})
12-
134
mbed_greentea_add_test(
145
TEST_NAME
15-
${TEST_TARGET}
6+
mbed-drivers-generic-tests
167
TEST_SOURCES
178
main.cpp
189
)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ void test_case_blinky()
8787
}
8888
#endif
8989

90+
// Check C++ start-up initialisation
91+
CppTestCaseHelperClass s("Static");
92+
9093
void test_case_cpp_stack()
9194
{
92-
// Check C++ start-up initialisation
93-
CppTestCaseHelperClass s("Static");
94-
9595
// Global stack object simple test
9696
s.stack_test();
9797
TEST_ASSERT_TRUE_MESSAGE(s.check_init(), "s.check_init() failed");
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5-
6-
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
7-
set(TEST_TARGET mbed-drivers-lp-ticker)
8-
9-
include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)
10-
11-
project(${TEST_TARGET})
4+
if(NOT "DEVICE_LPTICKER=1" IN_LIST MBED_TARGET_DEFINITIONS)
5+
set(TEST_SKIPPED "Low power ticker not supported for this target")
6+
endif()
127

138
mbed_greentea_add_test(
149
TEST_NAME
15-
${TEST_TARGET}
10+
mbed-drivers-lp-ticker
1611
TEST_SOURCES
1712
main.cpp
13+
TEST_SKIPPED
14+
${TEST_SKIPPED}
1815
)
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
4+
if(NOT "DEVICE_LPTICKER=1" IN_LIST MBED_TARGET_DEFINITIONS)
5+
set(TEST_SKIPPED "Low power ticker not supported for this target")
6+
endif()
57

6-
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
7-
set(TEST_TARGET mbed-drivers-lp-timeout)
8-
9-
include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)
10-
11-
project(${TEST_TARGET})
8+
if(MBED_GREENTEA_TEST_BAREMETAL)
9+
set(TEST_SKIPPED "Low power timer not supported for this target")
10+
endif()
1211

1312
mbed_greentea_add_test(
1413
TEST_NAME
15-
${TEST_TARGET}
14+
mbed-drivers-lp-timeout
1615
TEST_SOURCES
1716
main.cpp
17+
HOST_TESTS_DIR
18+
../../host_tests
19+
TEST_SKIPPED
20+
${TEST_SKIPPED}
1821
)

0 commit comments

Comments
 (0)