From e15564bd502c0472261cdc7d9081a9c8e683fa1e Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Mon, 28 Nov 2022 14:35:13 +0100 Subject: [PATCH] :white_check_mark: (tests): on device - add more deep sleep core motor tests --- .../suite_core_motor.cpp | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/tests/functional/tests/deep_sleep_core_motor/suite_core_motor.cpp b/tests/functional/tests/deep_sleep_core_motor/suite_core_motor.cpp index 424eef8d0e..764a1328ea 100644 --- a/tests/functional/tests/deep_sleep_core_motor/suite_core_motor.cpp +++ b/tests/functional/tests/deep_sleep_core_motor/suite_core_motor.cpp @@ -32,6 +32,7 @@ suite suite_core_motor = [] { auto speed = CorePwm {MOTOR_LEFT_PWM}; auto motor = CoreMotor {dir_1, dir_2, speed}; + rtos::ThisThread::sleep_for(5ms); expect(neq(&motor, nullptr)); @@ -45,4 +46,131 @@ suite suite_core_motor = [] { }; }; }; + + scenario("motor spin") = [] { + given("motor is in default configuration") = [] { + auto dir_1 = mbed::DigitalOut {MOTOR_LEFT_DIRECTION_1}; + auto dir_2 = mbed::DigitalOut {MOTOR_LEFT_DIRECTION_2}; + auto speed = CorePwm {MOTOR_LEFT_PWM}; + + auto motor = CoreMotor {dir_1, dir_2, speed}; + + expect(neq(&motor, nullptr)); + + when("I spin the motor at 50%") = [&] { + motor.spin(Rotation::clockwise, 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("I spin the motor at 100%") = [&] { + motor.spin(Rotation::clockwise, 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("I spin the motor at 0%") = [&] { + motor.spin(Rotation::clockwise, 0.0); + 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); + }; + }; + }; + }; + + scenario("motor spin, stop, spin, stop") = [] { + given("motor is in default configuration") = [] { + auto dir_1 = mbed::DigitalOut {MOTOR_LEFT_DIRECTION_1}; + auto dir_2 = mbed::DigitalOut {MOTOR_LEFT_DIRECTION_2}; + auto speed = CorePwm {MOTOR_LEFT_PWM}; + + auto motor = CoreMotor {dir_1, dir_2, speed}; + + expect(neq(&motor, nullptr)); + + when("I spin the motor at 50%") = [&] { + motor.spin(Rotation::clockwise, 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("I stop the motor") = [&] { + motor.stop(); + 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("I spin the motor at 100%") = [&] { + motor.spin(Rotation::clockwise, 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("I stop the motor") = [&] { + motor.stop(); + 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("I spin the motor at 100%") = [&] { + motor.spin(Rotation::clockwise, 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("I spin the motor at 0%") = [&] { + motor.spin(Rotation::clockwise, 0.0); + 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); + }; + }; + }; + }; };