Skip to content

Commit

Permalink
Reactivate tests under drivers/ and fix deprecation warnings (#191)
Browse files Browse the repository at this point in the history
* Reactivate tests under drivers/ and fix deprecation warnings

* Fix missing statement

* Oops, fix commented tests
  • Loading branch information
multiplemonomials authored Oct 4, 2023
1 parent eee0647 commit e1a1542
Show file tree
Hide file tree
Showing 36 changed files with 312 additions and 343 deletions.
19 changes: 18 additions & 1 deletion drivers/include/drivers/Watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "hal/watchdog_api.h"
#include "platform/NonCopyable.h"
#include <cstdio>
#include <chrono>

namespace mbed {
/**
Expand Down Expand Up @@ -92,7 +93,7 @@ class Watchdog : private NonCopyable<Watchdog> {

/** Start the Watchdog timer.
*
* @note Asset that the timeout param is supported by the target
* @note Asserts that the timeout param is supported by the target
* (0 < timeout <= Watchdog::get_max_timeout).
*
* @param timeout Watchdog timeout in milliseconds.
Expand All @@ -103,6 +104,22 @@ class Watchdog : private NonCopyable<Watchdog> {
*/
bool start(uint32_t timeout);

/** Start the Watchdog timer.
*
* @note Asserts that the timeout param is supported by the target
* (0 < timeout <= Watchdog::get_max_timeout).
*
* @param timeout Watchdog timeout in chrono milliseconds.
*
* @return true if the Watchdog timer was started successfully;
* false if Watchdog timer was not started or if setting
* a new watchdog timeout was not possible.
*/
bool start(std::chrono::milliseconds timeout)
{
return start(timeout.count());
}

/** Stop the Watchdog timer.
*
* Calling this function disables a running Watchdog
Expand Down
2 changes: 1 addition & 1 deletion drivers/tests/TESTS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(mbed_drivers/ticker)
add_subdirectory(mbed_drivers)
20 changes: 20 additions & 0 deletions drivers/tests/TESTS/mbed_drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
add_subdirectory(buffered_serial)
add_subdirectory(c_strings)
add_subdirectory(crc)
add_subdirectory(dev_null)
add_subdirectory(echo)
add_subdirectory(flashiap)
add_subdirectory(generic_tests)
add_subdirectory(lp_ticker)
add_subdirectory(lp_timeout)
add_subdirectory(lp_timer)
add_subdirectory(mem_trace)
add_subdirectory(race_test)
add_subdirectory(reset_reason)
add_subdirectory(sleep_lock)
add_subdirectory(stl_features)
add_subdirectory(ticker)
add_subdirectory(timerevent)
add_subdirectory(unbuffered_serial)
add_subdirectory(watchdog)
add_subdirectory(watchdog_reset)
17 changes: 8 additions & 9 deletions drivers/tests/TESTS/mbed_drivers/buffered_serial/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-drivers-buffered-serial)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})
if(NOT "DEVICE_SERIAL=1" IN_LIST MBED_TARGET_DEFINITIONS)
set(TEST_SKIPPED "Serial communication not supported for this target")
endif()

mbed_greentea_add_test(
TEST_NAME
${TEST_TARGET}
mbed-drivers-buffered-serial
TEST_SOURCES
main.cpp
HOST_TESTS_DIR
../../host_tests
TEST_SKIPPED
${TEST_SKIPPED}
)
11 changes: 1 addition & 10 deletions drivers/tests/TESTS/mbed_drivers/c_strings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-drivers-c-strings)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_add_test(
TEST_NAME
${TEST_TARGET}
mbed-drivers-c-strings
TEST_SOURCES
main.cpp
)
11 changes: 1 addition & 10 deletions drivers/tests/TESTS/mbed_drivers/crc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-drivers-crc)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_add_test(
TEST_NAME
${TEST_TARGET}
mbed-drivers-crc
TEST_SOURCES
main.cpp
)
13 changes: 3 additions & 10 deletions drivers/tests/TESTS/mbed_drivers/dev_null/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-drivers-dev-null)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_add_test(
TEST_NAME
${TEST_TARGET}
mbed-drivers-dev-null
TEST_SOURCES
main.cpp
HOST_TESTS_DIR
../../host_tests
)
2 changes: 2 additions & 0 deletions drivers/tests/TESTS/mbed_drivers/echo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ mbed_greentea_add_test(
${TEST_TARGET}
TEST_SOURCES
main.cpp
HOST_TESTS_DIR
../../host_tests
)
2 changes: 1 addition & 1 deletion drivers/tests/TESTS/mbed_drivers/echo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace utest::v1;
void fill_buffer(char *buffer, unsigned int length, unsigned int index)
{
unsigned int start = length * index;
for (int i = 0; i < length - 1; i++) {
for (unsigned int i = 0; i < length - 1; i++) {
buffer[i] = 'a' + ((start + i) % 26);
}
buffer[length - 1] = '\0';
Expand Down
15 changes: 6 additions & 9 deletions drivers/tests/TESTS/mbed_drivers/flashiap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-drivers-flashiap)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})
if(NOT "DEVICE_FLASH=1" IN_LIST MBED_TARGET_DEFINITIONS)
set(TEST_SKIPPED "Flash API not supported for this target")
endif()

mbed_greentea_add_test(
TEST_NAME
${TEST_TARGET}
mbed-drivers-flashiap
TEST_SOURCES
main.cpp
TEST_SKIPPED
${TEST_SKIPPED}
)
49 changes: 31 additions & 18 deletions drivers/tests/TESTS/mbed_drivers/flashiap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "FlashIAP.h"
#include "unity.h"
#include <algorithm>
#include <cinttypes>

#include "mbed.h"

Expand All @@ -43,6 +44,17 @@

using namespace utest::v1;

// Get the max of two microsecond values
static std::chrono::microseconds us_max(std::chrono::microseconds time1, std::chrono::microseconds time2)
{
return time1 > time2 ? time1 : time2;
}

// Get the min of two microsecond values
static std::chrono::microseconds us_min(std::chrono::microseconds time1, std::chrono::microseconds time2)
{
return time1 < time2 ? time1 : time2;
}

void flashiap_init_test()
{
Expand All @@ -54,7 +66,6 @@ void flashiap_init_test()
uint32_t flash_size = flash_device.get_flash_size();
utest_printf("Flash address: 0x%08x, size: %d\n", flash_start, flash_size);
uint32_t address = flash_start;
int num = 0;
while (flash_size) {
uint32_t sector_size = flash_device.get_sector_size(address);
// Make sure all sectors sum up to the total flash size
Expand Down Expand Up @@ -234,10 +245,12 @@ void flashiap_timing_test()
uint32_t ret = flash_device.init();
TEST_ASSERT_EQUAL_INT32(0, ret);
mbed::Timer timer;

std::chrono::microseconds curr_time{};
std::chrono::microseconds avg_erase_time{};
unsigned int num_write_sizes;
unsigned int curr_time, byte_usec_ratio;
unsigned int avg_erase_time = 0;
unsigned int max_erase_time = 0, min_erase_time = (unsigned int) -1;
unsigned int byte_usec_ratio;
std::chrono::microseconds max_erase_time(0), min_erase_time(-1);
const unsigned int max_writes = 128;
const unsigned int max_write_sizes = 6;
const unsigned int max_byte_usec_ratio = 200;
Expand Down Expand Up @@ -266,42 +279,42 @@ void flashiap_timing_test()
memset(buf, 0x5A, write_size);
timer.reset();
ret = flash_device.erase(base_address, sector_size);
curr_time = timer.read_us();
curr_time = timer.elapsed_time();
avg_erase_time += curr_time;
TEST_ASSERT_EQUAL_INT32(0, ret);
max_erase_time = std::max(max_erase_time, curr_time);
min_erase_time = std::min(min_erase_time, curr_time);
max_erase_time = us_max(max_erase_time, curr_time);
min_erase_time = us_min(min_erase_time, curr_time);
uint32_t address = base_address;
unsigned int avg_write_time = 0;
unsigned int max_write_time = 0, min_write_time = (unsigned int) -1;
std::chrono::microseconds avg_write_time(0);
std::chrono::microseconds max_write_time(0), min_write_time(-1);
unsigned int num_writes;
for (num_writes = 0; num_writes < max_writes; num_writes++) {
if ((address + write_size) > end_address) {
break;
}
timer.reset();
ret = flash_device.program(buf, address, write_size);
curr_time = timer.read_us();
curr_time = timer.elapsed_time();
avg_write_time += curr_time;
TEST_ASSERT_EQUAL_INT32(0, ret);
max_write_time = std::max(max_write_time, curr_time);
min_write_time = std::min(min_write_time, curr_time);
max_write_time = us_max(max_write_time, curr_time);
min_write_time = us_min(min_write_time, curr_time);
address += write_size;
}
delete[] buf;
avg_write_time /= num_writes;
utest_printf("Write size %6u bytes: avg %10u, min %10u, max %10u (usec)\n",
write_size, avg_write_time, min_write_time, max_write_time);
byte_usec_ratio = write_size / avg_write_time;
byte_usec_ratio = write_size / avg_write_time.count();
utest_printf("Write size %6u bytes: avg %10" PRIi64 ", min %10" PRIi64 ", max %10" PRIi64 " (usec), rate %10u bytes/usec\n",
write_size, avg_write_time.count(), min_write_time.count(), max_write_time.count(), byte_usec_ratio);
TEST_ASSERT(byte_usec_ratio < max_byte_usec_ratio);
write_size *= 4;
}

if (num_write_sizes) {
avg_erase_time /= num_write_sizes;
utest_printf("\nErase size %6u bytes: avg %10u, min %10u, max %10u (usec)\n\n",
sector_size, avg_erase_time, min_erase_time, max_erase_time);
byte_usec_ratio = sector_size / avg_erase_time;
byte_usec_ratio = sector_size / avg_erase_time.count();
utest_printf("\nErase size %6u bytes: avg %10" PRIi64 ", min %10" PRIi64 ", max %10" PRIi64" (usec), rate %10u bytes/usec\n\n",
sector_size, avg_erase_time.count(), min_erase_time.count(), max_erase_time.count(), byte_usec_ratio);
TEST_ASSERT(byte_usec_ratio < max_byte_usec_ratio);
}

Expand Down
11 changes: 1 addition & 10 deletions drivers/tests/TESTS/mbed_drivers/generic_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-drivers-generic-tests)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_add_test(
TEST_NAME
${TEST_TARGET}
mbed-drivers-generic-tests
TEST_SOURCES
main.cpp
)
6 changes: 3 additions & 3 deletions drivers/tests/TESTS/mbed_drivers/generic_tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ void test_case_blinky()
}
#endif

// Check C++ start-up initialisation
CppTestCaseHelperClass s("Static");

void test_case_cpp_stack()
{
// Check C++ start-up initialisation
CppTestCaseHelperClass s("Static");

// Global stack object simple test
s.stack_test();
TEST_ASSERT_TRUE_MESSAGE(s.check_init(), "s.check_init() failed");
Expand Down
15 changes: 6 additions & 9 deletions drivers/tests/TESTS/mbed_drivers/lp_ticker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-drivers-lp-ticker)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})
if(NOT "DEVICE_LPTICKER=1" IN_LIST MBED_TARGET_DEFINITIONS)
set(TEST_SKIPPED "Low power ticker not supported for this target")
endif()

mbed_greentea_add_test(
TEST_NAME
${TEST_TARGET}
mbed-drivers-lp-ticker
TEST_SOURCES
main.cpp
TEST_SKIPPED
${TEST_SKIPPED}
)
19 changes: 11 additions & 8 deletions drivers/tests/TESTS/mbed_drivers/lp_timeout/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

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

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-drivers-lp-timeout)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})
if(MBED_GREENTEA_TEST_BAREMETAL)
set(TEST_SKIPPED "Low power timer not supported for this target")
endif()

mbed_greentea_add_test(
TEST_NAME
${TEST_TARGET}
mbed-drivers-lp-timeout
TEST_SOURCES
main.cpp
HOST_TESTS_DIR
../../host_tests
TEST_SKIPPED
${TEST_SKIPPED}
)
Loading

0 comments on commit e1a1542

Please sign in to comment.