From b50d9d7d3df529503ef883276c78f0bbe542376b Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Tue, 6 Feb 2024 11:25:45 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20(functional):=20RFIDKit=20-=20Refac?= =?UTF-8?q?tor=20deep=20sleep=20functional=20tests=20w/=20enable/disable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/functional/CMakeLists.txt | 1 + .../tests/deep_sleep_rfid_kit/CMakeLists.txt | 18 ++++ .../deep_sleep_rfid_kit/suite_rfid_kit.cpp | 90 +++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 tests/functional/tests/deep_sleep_rfid_kit/CMakeLists.txt create mode 100644 tests/functional/tests/deep_sleep_rfid_kit/suite_rfid_kit.cpp diff --git a/tests/functional/CMakeLists.txt b/tests/functional/CMakeLists.txt index c21d136301..35fe44b832 100644 --- a/tests/functional/CMakeLists.txt +++ b/tests/functional/CMakeLists.txt @@ -47,6 +47,7 @@ add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_core_pwm) add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_imu) add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_log_kit) add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_mbed_hal) +add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_rfid_kit) add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/file_manager) add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/firmware_kit) add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/imu_kit) diff --git a/tests/functional/tests/deep_sleep_rfid_kit/CMakeLists.txt b/tests/functional/tests/deep_sleep_rfid_kit/CMakeLists.txt new file mode 100644 index 0000000000..d76ba1f74c --- /dev/null +++ b/tests/functional/tests/deep_sleep_rfid_kit/CMakeLists.txt @@ -0,0 +1,18 @@ +# Leka - LekaOS +# Copyright 2024 APF France handicap +# SPDX-License-Identifier: Apache-2.0 + +register_functional_test( + TARGET + functional_ut_deep_sleep_rfid_kit + + INCLUDE_DIRECTORIES + + SOURCES + suite_rfid_kit.cpp + + LINK_LIBRARIES + CoreBufferedSerial + CoreRFIDReader + RFIDKit +) diff --git a/tests/functional/tests/deep_sleep_rfid_kit/suite_rfid_kit.cpp b/tests/functional/tests/deep_sleep_rfid_kit/suite_rfid_kit.cpp new file mode 100644 index 0000000000..70c341ac60 --- /dev/null +++ b/tests/functional/tests/deep_sleep_rfid_kit/suite_rfid_kit.cpp @@ -0,0 +1,90 @@ +// Leka - LekaOS +// Copyright 2024 APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +#include "CoreBufferedSerial.h" +#include "CoreRFIDReaderCR95HF.h" +#include "RFIDKit.h" +#include "tests/config.h" +#include "tests/utils.h" +#include "tests/utils_sleep.h" + +using namespace leka; +using namespace boost::ut; +using namespace std::chrono; +using namespace boost::ut::bdd; + +auto rfidserial = CoreBufferedSerial(RFID_UART_TX, RFID_UART_RX, 57600); +auto rfidreader = CoreRFIDReaderCR95HF(rfidserial); +auto rfidkit = RFIDKit(rfidreader); + +suite suite_rfid_kit = [] { + scenario("rfid initialization") = [] { + given("rfid is in default configuration") = [] { + rfidkit.init(); + rtos::ThisThread::sleep_for(5ms); + + expect(neq(&rfidkit, nullptr)); + + when("I do nothing") = [&] { + then("I expect deep sleep TO NOT BE possible") = [] { + auto status = utils::sleep::system_deep_sleep_check(); + + expect(not status.test_check_ok); + }; + }; + }; + }; + + scenario("enabled/disable deepsleep") = [] { + given("rfid is in default configuration") = [] { + when("I enable rfid deep sleep") = [&] { + rtos::ThisThread::sleep_for(500ms); + rfidkit.enableDeepSleep(); + rtos::ThisThread::sleep_for(500ms); + + then("I expect deep sleep TO BE possible") = [] { + auto status = utils::sleep::system_deep_sleep_check(); + + expect(status.test_check_ok); + }; + }; + + when("I disable rfid deep sleep") = [&] { + rtos::ThisThread::sleep_for(500ms); + rfidkit.disableDeepSleep(); + rtos::ThisThread::sleep_for(500ms); + + then("I expect deep sleep TO NOT BE possible") = [] { + auto status = utils::sleep::system_deep_sleep_check(); + + expect(not status.test_check_ok); + }; + }; + + when("I enable rfid deep sleep") = [&] { + rtos::ThisThread::sleep_for(500ms); + rfidkit.enableDeepSleep(); + rtos::ThisThread::sleep_for(500ms); + + then("I expect deep sleep TO BE possible") = [] { + auto status = utils::sleep::system_deep_sleep_check(); + + expect(status.test_check_ok); + }; + }; + + when("I disable rfid deep sleep") = [&] { + rtos::ThisThread::sleep_for(500ms); + rfidkit.disableDeepSleep(); + rtos::ThisThread::sleep_for(500ms); + + then("I expect deep sleep TO NOT BE possible") = [] { + auto status = utils::sleep::system_deep_sleep_check(); + + expect(not status.test_check_ok); + }; + }; + }; + }; +};