Skip to content

Commit

Permalink
✅ (functional): Add imu functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Nov 10, 2022
1 parent 9ab40fd commit 7abd27d
Show file tree
Hide file tree
Showing 3 changed files with 85 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 @@ -39,6 +39,7 @@ endfunction()

add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/boost_ut)

add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/imu)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/io_expander)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/file_manager)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/qdac)
17 changes: 17 additions & 0 deletions tests/functional/tests/imu/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_imu

INCLUDE_DIRECTORIES

SOURCES
suite_lsm6dsox.cpp

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

#include "CoreI2C.h"
#include "CoreLSM6DSOX.h"
#include "ThisThread.h"
#include "tests/config.h"

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

suite suite_lsm6dsox = [] {
auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL);
auto lsm6dsox = CoreLSM6DSOX {i2c};
lsm6dsox.init();
auto default_min_bound_az = 800.f;
auto default_max_bound_az = 1200.f;

"Initialization"_test = [&] { expect(neq(&lsm6dsox, nullptr)); };

"Get imu data "_test = [&] {
auto data = lsm6dsox.getData();
expect(data.xl.x != 0.f) << "Null acceleration on X axis ";
expect(data.xl.y != 0.f) << "Null acceleration on Y axis ";
expect(data.xl.z >= default_min_bound_az) << "Acceleration on Z axis:" << data.xl.z << "axis too low";
expect(data.xl.z <= default_max_bound_az) << "Acceleration on Z axis:" << data.xl.z << "axis too high";
expect(data.gy.x != 0.f) << "Null angular speed on X axis ";
expect(data.gy.y != 0.f) << "Null angular speed on Y axis ";
expect(data.gy.x != 0.f) << "Null angular speed on Z axis ";
};

"Turn off lsm6dsox"_test = [&] {
lsm6dsox.turnOff();
auto data = lsm6dsox.getData();
rtos::ThisThread::sleep_for(40ms);
auto current_data = lsm6dsox.getData();
expect(data.xl.x == current_data.xl.x) << "Lsm6dsox not turned off " << data.xl.x << "!=" << current_data.xl.x;
expect(data.xl.y == current_data.xl.y) << "Lsm6dsox not turned off " << data.xl.y << "!=" << current_data.xl.y;
expect(data.xl.z == current_data.xl.z) << "Lsm6dsox not turned off " << data.xl.z << "!=" << current_data.xl.z;
expect(data.gy.x == current_data.gy.x) << "Lsm6dsox not turned off " << data.gy.x << "!=" << current_data.gy.x;
expect(data.gy.y == current_data.gy.y) << "Lsm6dsox not turned off " << data.gy.y << "!=" << current_data.gy.y;
expect(data.gy.z == current_data.gy.z) << "Lsm6dsox not turned off " << data.gy.z << "!=" << current_data.gy.z;
};

"Assert data are different when lsm6dsox turned on "_test = [&] {
lsm6dsox.turnOn();
auto data = lsm6dsox.getData();
rtos::ThisThread::sleep_for(40ms);
auto current_data = lsm6dsox.getData();
expect(data.gy.z != current_data.gy.z) << "Datas are all the same " << data.gy.z << "!=" << current_data.gy.z;
};

"Turn on lsm6dsox after turned off "_test = [&] {
lsm6dsox.turnOff();
lsm6dsox.turnOn();
auto data = lsm6dsox.getData();
expect(data.xl.x != 0.f) << "Null acceleration on X axis ";
expect(data.xl.y != 0.f) << "Null acceleration on Y axis ";
expect(data.xl.z >= default_min_bound_az) << "Acceleration on Z axis:" << data.xl.z << "axis too low";
expect(data.xl.z <= default_max_bound_az) << "Acceleration on Z axis:" << data.xl.z << "axis too high";
expect(data.gy.x != 0.f) << "Null angular speed on X axis ";
expect(data.gy.y != 0.f) << "Null angular speed on Y axis ";
expect(data.gy.x != 0.f) << "Null angular speed on Z axis ";
};
};

0 comments on commit 7abd27d

Please sign in to comment.