Skip to content

Commit

Permalink
✅ (tests): on device - add deep sleep core pwm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Nov 27, 2022
1 parent f918487 commit 249ddb4
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/boost_ut)

add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/core_imu)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_core_buffered_serial)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_core_pwm)
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}/file_manager)
Expand Down
16 changes: 16 additions & 0 deletions tests/functional/tests/deep_sleep_core_pwm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Leka - LekaOS
# Copyright 2022 APF France handicap
# SPDX-License-Identifier: Apache-2.0

register_functional_test(
TARGET
functional_ut_deep_sleep_core_pwm

INCLUDE_DIRECTORIES

SOURCES
suite_core_pwm.cpp

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

#include <cstddef>

#include "CorePwm.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;

suite suite_core_pwm = [] {
scenario("write") = [] {
given("pwm is in default configuration") = [] {
auto pwm = CorePwm(MOTOR_LEFT_PWM);

expect(neq(&pwm, 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.can_deep_sleep);
expect(not status.test_check_ok);
};
};

when("pwm is running at 100%") = [&] {
pwm.write(1.0);

then("I expect deep sleep TO NOT BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(not status.can_deep_sleep);
expect(not status.test_check_ok);
};
};

when("pwm is running at 50%") = [&] {
pwm.write(0.5);

then("I expect deep sleep TO NOT BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(not status.can_deep_sleep);
expect(not status.test_check_ok);
};
};

when("pwm is running at 0%") = [&] {
pwm.write(0.0);

then("I expect deep sleep TO NOT BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(not status.can_deep_sleep);
expect(not status.test_check_ok);
};
};
};
};

scenario("suspend, resume") = [] {
given("pwm is in default configuration") = [] {
auto pwm = CorePwm(MOTOR_LEFT_PWM);

expect(neq(&pwm, 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.can_deep_sleep);
expect(not status.test_check_ok);
};
};

when("pwm is suspended") = [&] {
pwm.suspend();
rtos::ThisThread::sleep_for(5ms);

then("I expect deep sleep TO BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(status.can_deep_sleep);
expect(status.test_check_ok);
};
};

when("pwm is resumed") = [&] {
pwm.resume();

then("I expect deep sleep TO NOT BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(not status.can_deep_sleep);
expect(not status.test_check_ok);
};
};
};
};

scenario("write 100%, suspend, resume") = [] {
given("pwm is in default configuration") = [] {
auto pwm = CorePwm(MOTOR_LEFT_PWM);

expect(neq(&pwm, 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.can_deep_sleep);
expect(not status.test_check_ok);
};
};

when("pwm is running at 100%") = [&] {
pwm.write(1.0);

then("I expect deep sleep TO NOT BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(not status.can_deep_sleep);
expect(not status.test_check_ok);
};
};

when("pwm is suspended") = [&] {
pwm.suspend();
rtos::ThisThread::sleep_for(5ms);

then("I expect deep sleep TO BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(status.can_deep_sleep);
expect(status.test_check_ok);
};
};

when("pwm is resumed") = [&] {
pwm.resume();

then("I expect deep sleep TO BE NOT possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(not status.can_deep_sleep);
expect(not status.test_check_ok);
};
};
};
};

scenario("suspend, write 0%, resume") = [] {
given("pwm is in default configuration") = [] {
auto pwm = CorePwm(MOTOR_LEFT_PWM);

expect(neq(&pwm, 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.can_deep_sleep);
expect(not status.test_check_ok);
};
};

when("pwm is running at 0%") = [&] {
pwm.write(0.0);

then("I expect deep sleep TO NOT BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(not status.can_deep_sleep);
expect(not status.test_check_ok);
};
};

when("pwm is suspended") = [&] {
pwm.suspend();
rtos::ThisThread::sleep_for(5ms);

then("I expect deep sleep TO BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(status.can_deep_sleep);
expect(status.test_check_ok);
};
};

when("pwm is resumed") = [&] {
pwm.resume();

then("I expect deep sleep TO NOT BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(not status.can_deep_sleep);
expect(not status.test_check_ok);
};
};
};
};
};

0 comments on commit 249ddb4

Please sign in to comment.