Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ladislas+mmyster/feature/functional tests #1079

Merged
merged 9 commits into from
Oct 24, 2022
1 change: 1 addition & 0 deletions .vscode/settings.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"editor.formatOnSave": true,
"cmake.ignoreKitEnv": true,
"cmake.configureOnOpen": true,
"cmake.format.allowOptionalArgumentIndentation": true,
"cmake.buildDirectory": "${workspaceFolder}/_build_cmake_tools",
"cmake.mergedCompileCommands": "${workspaceFolder}/compile_commands.json",
"cmake.generator": "Ninja",
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ set(BOOTLOADER_DIR ${ROOT_DIR}/app/bootloader)
# spikes
set(SPIKES_DIR ${ROOT_DIR}/spikes)

# functional tests
set(TESTS_FUNCTIONAL_DIR ${ROOT_DIR}/tests/functional)

#
# MARK: - LekaOS Project
#
Expand Down Expand Up @@ -136,6 +139,9 @@ add_subdirectory(${LIBS_DIR})
# Add spikes
add_subdirectory(${SPIKES_DIR})

# Add functional tests
add_subdirectory(${TESTS_FUNCTIONAL_DIR})

# Add bootloader
add_subdirectory(${BOOTLOADER_DIR})

Expand Down
2 changes: 0 additions & 2 deletions spikes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ add_subdirectory(${SPIKES_DIR}/lk_audio)
add_subdirectory(${SPIKES_DIR}/lk_behavior_kit)
add_subdirectory(${SPIKES_DIR}/lk_ble)
add_subdirectory(${SPIKES_DIR}/lk_bluetooth)
add_subdirectory(${SPIKES_DIR}/lk_boost_ut)
add_subdirectory(${SPIKES_DIR}/lk_cg_animations)
add_subdirectory(${SPIKES_DIR}/lk_color_kit)
add_subdirectory(${SPIKES_DIR}/lk_command_kit)
Expand Down Expand Up @@ -46,7 +45,6 @@ add_custom_target(spikes_leka)
add_dependencies(spikes_leka
spike_lk_ble
spike_lk_bluetooth
spike_lk_boost_ut
spike_lk_cg_animations
spike_lk_color_kit
spike_lk_command_kit
Expand Down
28 changes: 0 additions & 28 deletions spikes/lk_boost_ut/CMakeLists.txt

This file was deleted.

43 changes: 43 additions & 0 deletions tests/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Leka - LekaOS
# Copyright 2022 APF France handicap
# SPDX-License-Identifier: Apache-2.0

set(TESTS_FUNCTIONAL_INCLUDE_DIR ${TESTS_FUNCTIONAL_DIR}/include)
set(TESTS_FUNCTIONAL_SOURCE_DIR ${TESTS_FUNCTIONAL_DIR}/source)
set(TESTS_FUNCTIONAL_TESTS_DIR ${TESTS_FUNCTIONAL_DIR}/tests)

function(register_functional_test)
set(options "")
set(oneValueArgs TARGET)
set(multiValueArgs INCLUDE_DIRECTORIES SOURCES LINK_LIBRARIES)

cmake_parse_arguments(REGISTER_FT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

add_mbed_executable(${REGISTER_FT_TARGET})

target_include_directories(${REGISTER_FT_TARGET}
PRIVATE
${TESTS_FUNCTIONAL_INCLUDE_DIR}
${REGISTER_FT_INCLUDE_DIRECTORIES}
)

target_sources(${REGISTER_FT_TARGET}
PRIVATE
${TESTS_FUNCTIONAL_SOURCE_DIR}/test_main.cpp
${REGISTER_FT_SOURCES}
)

target_link_libraries(${REGISTER_FT_TARGET}
${REGISTER_FT_LINK_LIBRARIES}
)

target_compile_definitions(${REGISTER_FT_TARGET}
PUBLIC
TARGET="${REGISTER_FT_TARGET}"
)
endfunction()

add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/boost_ut)

add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/io_expander)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/qdac)
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ using namespace std::chrono;

inline auto start = rtos::Kernel::Clock::now();
inline auto stop = rtos::Kernel::Clock::now();
inline auto delta = static_cast<int>((stop - start).count());

// namespace time
inline auto delta = [] { return static_cast<int>((stop - start).count()); };

} // namespace utils::time

Expand All @@ -34,8 +32,7 @@ inline auto delta = static_cast<int>((stop - start).count());
// NOLINTNEXTLINE
#define utils_end() \
do { \
utils::time::stop = rtos::Kernel::Clock::now(); \
utils::time::delta = static_cast<int>((utils::time::stop - utils::time::start).count()); \
utils::time::stop = rtos::Kernel::Clock::now(); \
log_ll("\n", 1); \
log_info("End of tests (%i ms total)", utils::time::delta); \
log_info("End of tests (%i ms total)", utils::time::delta()); \
} while (0)
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
#include <iostream>
#include <utility>

#include "./tests/config.h"
#include "./utils.h"
#include "boost/ut.hpp"
#include "tests/config.h"
#include "tests/utils.h"

using namespace leka;
using namespace std::chrono;
namespace ut = boost::ut;

auto main() -> int
{
ut::cfg<ut::override> = {.filter = "*", .colors = {.none = "", .pass = "", .fail = ""}, .dry_run = false};
ut::cfg<ut::override> = {.filter = "*", .dry_run = false};

utils_start("boost::ut example spike");
utils_start(TARGET);

[[maybe_unused]] const auto result = ut::cfg<>.run({.report_errors = true});

Expand Down
22 changes: 22 additions & 0 deletions tests/functional/tests/boost_ut/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Leka - LekaOS
# Copyright 2022 APF France handicap
# SPDX-License-Identifier: Apache-2.0

register_functional_test(
TARGET
functional_ut_boost_ut

INCLUDE_DIRECTORIES

SOURCES
test_array.cpp
test_expect.cpp
test_minimal.cpp
test_mutable.cpp
test_parametrized.cpp
test_should.cpp
test_skip.cpp
test_spec.cpp

LINK_LIBRARIES
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "./tests/config.h"
#include "boost/ut.hpp"
#include "tests/config.h"

using namespace boost::ut;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

#include <memory>

#include "./tests/config.h"
#include "boost/ut.hpp"
#include "tests/config.h"

using namespace boost::ut;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "./tests/config.h"
#include "boost/ut.hpp"
#include "tests/config.h"

using namespace ut;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "./tests/config.h"
#include "boost/ut.hpp"
#include "tests/config.h"

using namespace boost::ut;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

#include <tuple>

#include "./tests/config.h"
#include "boost/ut.hpp"
#include "tests/config.h"

using namespace boost::ut;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "./tests/config.h"
#include "boost/ut.hpp"
#include "tests/config.h"

using namespace boost::ut;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "./tests/config.h"
#include "boost/ut.hpp"
#include "tests/config.h"

using namespace boost::ut;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "./tests/config.h"
#include "boost/ut.hpp"
#include "tests/config.h"

using namespace boost::ut;

Expand Down
17 changes: 17 additions & 0 deletions tests/functional/tests/io_expander/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Leka - LekaOS
# Copyright 2022 APF France handicap
# SPDX-License-Identifier: Apache-2.0

register_functional_test(
TARGET
functional_ut_io_expander

INCLUDE_DIRECTORIES

SOURCES
suite_io_expander.cpp

LINK_LIBRARIES
CoreI2C
CoreIOExpander
)
21 changes: 21 additions & 0 deletions tests/functional/tests/io_expander/suite_io_expander.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "CoreI2C.h"
#include "CoreIOExpander.h"
#include "DigitalOut.h"
#include "tests/config.h"

using namespace leka;
using namespace std::chrono;
using namespace boost::ut;

suite suite_io_expander = [] {
const uint8_t i2c_address {0x4E};
auto corei2c = CoreI2C {PinName::SENSOR_PROXIMITY_MUX_I2C_SDA, PinName::SENSOR_PROXIMITY_MUX_I2C_SCL};
auto io_expander_reset = mbed::DigitalOut {PinName::SENSOR_PROXIMITY_MUX_RESET, 0};
auto io_expander = CoreIOExpanderMCP23017 {corei2c, io_expander_reset};

"Initialization"_test = [&] { expect(neq(&io_expander, nullptr)); };
};
17 changes: 17 additions & 0 deletions tests/functional/tests/qdac/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Leka - LekaOS
# Copyright 2022 APF France handicap
# SPDX-License-Identifier: Apache-2.0

register_functional_test(
TARGET
functional_ut_qdac

INCLUDE_DIRECTORIES

SOURCES
suite_qdac.cpp

LINK_LIBRARIES
CoreI2C
CoreQDAC
)
34 changes: 34 additions & 0 deletions tests/functional/tests/qdac/suite_qdac.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "CoreI2C.h"
#include "CoreQDAC.h"
#include "tests/config.h"

using namespace leka;
using namespace std::chrono;
using namespace boost::ut;

suite suite_qdac = [] {
auto corei2c = CoreI2C {PinName::SENSOR_PROXIMITY_MUX_I2C_SDA, PinName::SENSOR_PROXIMITY_MUX_I2C_SCL};
auto dac = CoreQDACMCP4728 {corei2c, 0xC2};
auto data = uint16_t {};
auto channel = uint8_t {};

"read channel A"_test = [&] {
data = 0x0ABC;
channel = 0x00;
dac.write(channel, data);
auto ret = dac.read(channel);
expect(data == ret) << "Failed to read Channel A";
};

"read channel B"_test = [&] {
data = 0x0DEF;
channel = 0x01;
dac.write(channel, data);
auto ret = dac.read(channel);
expect(data == ret) << "Failed to read Channel B";
};
};
Loading