InitDeinit tests
This commit is contained in:
parent
5b0af503ae
commit
348a18267f
|
|
@ -575,4 +575,6 @@ class BNO08x
|
||||||
static const constexpr uint8_t TARE_SET_REORIENTATION = 2U; ///< See SH2 Ref. Manual 6.4.4.3
|
static const constexpr uint8_t TARE_SET_REORIENTATION = 2U; ///< See SH2 Ref. Manual 6.4.4.3
|
||||||
|
|
||||||
static const constexpr char* TAG = "BNO08x"; ///< Class tag used for serial print statements
|
static const constexpr char* TAG = "BNO08x"; ///< Class tag used for serial print statements
|
||||||
|
|
||||||
|
friend class BNO08xTestHelper; //allow test helper to access private members for unit tests
|
||||||
};
|
};
|
||||||
|
|
@ -9,20 +9,20 @@ class BNO08xTestHelper
|
||||||
inline static BNO08x* test_imu = nullptr;
|
inline static BNO08x* test_imu = nullptr;
|
||||||
inline static bno08x_config_t imu_cfg;
|
inline static bno08x_config_t imu_cfg;
|
||||||
|
|
||||||
static const constexpr char *TAG = "BNO08xTestHelper";
|
static const constexpr char* TAG = "BNO08xTestHelper";
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void print_test_start_banner(const char *TEST_TAG)
|
static void print_test_start_banner(const char* TEST_TAG)
|
||||||
{
|
{
|
||||||
printf("------------------------BEGIN TEST: %s------------------------\n\r", TEST_TAG);
|
printf("------------------------BEGIN TEST: %s------------------------\n\r", TEST_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_test_end_banner(const char *TEST_TAG)
|
static void print_test_end_banner(const char* TEST_TAG)
|
||||||
{
|
{
|
||||||
printf("------------------------END TEST: %s------------------------\n\r", TEST_TAG);
|
printf("------------------------END TEST: %s------------------------\n\r", TEST_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_test_msg(const char *TEST_TAG, const char *msg)
|
static void print_test_msg(const char* TEST_TAG, const char* msg)
|
||||||
{
|
{
|
||||||
printf("%s: %s: %s\n\r", TAG, TEST_TAG, msg);
|
printf("%s: %s: %s\n\r", TAG, TEST_TAG, msg);
|
||||||
}
|
}
|
||||||
|
|
@ -34,9 +34,9 @@ class BNO08xTestHelper
|
||||||
|
|
||||||
static void create_test_imu()
|
static void create_test_imu()
|
||||||
{
|
{
|
||||||
if(test_imu != nullptr)
|
if (test_imu != nullptr)
|
||||||
destroy_test_imu();
|
destroy_test_imu();
|
||||||
|
|
||||||
test_imu = new BNO08x();
|
test_imu = new BNO08x();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,4 +53,44 @@ class BNO08xTestHelper
|
||||||
{
|
{
|
||||||
return test_imu;
|
return test_imu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static esp_err_t call_init_config_args()
|
||||||
|
{
|
||||||
|
if (test_imu == nullptr)
|
||||||
|
return ESP_FAIL;
|
||||||
|
|
||||||
|
return test_imu->init_config_args();
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t call_init_gpio()
|
||||||
|
{
|
||||||
|
if (test_imu == nullptr)
|
||||||
|
return ESP_FAIL;
|
||||||
|
|
||||||
|
return test_imu->init_gpio();
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t call_init_hint_isr()
|
||||||
|
{
|
||||||
|
if (test_imu == nullptr)
|
||||||
|
return ESP_FAIL;
|
||||||
|
|
||||||
|
return test_imu->init_hint_isr();
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t call_init_spi()
|
||||||
|
{
|
||||||
|
if (test_imu == nullptr)
|
||||||
|
return ESP_FAIL;
|
||||||
|
|
||||||
|
return test_imu->init_spi();
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t call_launch_tasks()
|
||||||
|
{
|
||||||
|
if (test_imu == nullptr)
|
||||||
|
return ESP_FAIL;
|
||||||
|
|
||||||
|
return test_imu->launch_tasks();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -2,11 +2,15 @@
|
||||||
|
|
||||||
void BNO08xTestSuite::run_all_tests()
|
void BNO08xTestSuite::run_all_tests()
|
||||||
{
|
{
|
||||||
run_init_deinit_tests();
|
run_init_deinit_tests();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BNO08xTestSuite::run_init_deinit_tests()
|
void BNO08xTestSuite::run_init_deinit_tests()
|
||||||
{
|
{
|
||||||
|
UNITY_BEGIN();
|
||||||
|
unity_run_tests_by_tag("[Init]", false);
|
||||||
|
UNITY_END();
|
||||||
|
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
unity_run_test_by_name("Full Init & Deinit");
|
unity_run_test_by_name("Full Init & Deinit");
|
||||||
UNITY_END();
|
UNITY_END();
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,103 @@
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "../include/BNO08xTestHelper.hpp"
|
#include "../include/BNO08xTestHelper.hpp"
|
||||||
|
|
||||||
TEST_CASE("Full Init & Deinit", "[InitDenit]")
|
TEST_CASE("Init Config Args", "[Init]")
|
||||||
{
|
{
|
||||||
const constexpr char *TEST_TAG ="Full Init & Deinit";
|
const constexpr char* TEST_TAG = "Init Config Args";
|
||||||
BNO08x* imu;
|
BNO08x* imu = nullptr;
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_start_banner(TEST_TAG);
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_msg(TEST_TAG, "Creating test IMU.");
|
||||||
|
BNO08xTestHelper::create_test_imu();
|
||||||
|
imu = BNO08xTestHelper::get_test_imu();
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, BNO08xTestHelper::call_init_config_args());
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_end_banner(TEST_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Init GPIO", "[Init]")
|
||||||
|
{
|
||||||
|
const constexpr char* TEST_TAG = "Init GPIO";
|
||||||
|
BNO08x* imu = nullptr;
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_start_banner(TEST_TAG);
|
||||||
|
|
||||||
|
imu = BNO08xTestHelper::get_test_imu();
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, BNO08xTestHelper::call_init_gpio());
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_end_banner(TEST_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Init HINT ISR", "[Init]")
|
||||||
|
{
|
||||||
|
const constexpr char* TEST_TAG = "Init HINT_ISR";
|
||||||
|
BNO08x* imu = nullptr;
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_start_banner(TEST_TAG);
|
||||||
|
|
||||||
|
imu = BNO08xTestHelper::get_test_imu();
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, BNO08xTestHelper::call_init_hint_isr());
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_end_banner(TEST_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Init SPI", "[Init]")
|
||||||
|
{
|
||||||
|
const constexpr char* TEST_TAG = "Init SPI";
|
||||||
|
BNO08x* imu = nullptr;
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_start_banner(TEST_TAG);
|
||||||
|
|
||||||
|
imu = BNO08xTestHelper::get_test_imu();
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, BNO08xTestHelper::call_init_spi());
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_end_banner(TEST_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Init Tasks", "[Init]")
|
||||||
|
{
|
||||||
|
const constexpr char* TEST_TAG = "Init Tasks";
|
||||||
|
BNO08x* imu = nullptr;
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_start_banner(TEST_TAG);
|
||||||
|
|
||||||
|
imu = BNO08xTestHelper::get_test_imu();
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, BNO08xTestHelper::call_launch_tasks());
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_end_banner(TEST_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Finish Init", "[Init]")
|
||||||
|
{
|
||||||
|
const constexpr char* TEST_TAG = "Finish Init";
|
||||||
|
BNO08x* imu = nullptr;
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_start_banner(TEST_TAG);
|
||||||
|
|
||||||
|
imu = BNO08xTestHelper::get_test_imu();
|
||||||
|
|
||||||
|
// reset imu
|
||||||
|
TEST_ASSERT_EQUAL(true, imu->hard_reset());
|
||||||
|
|
||||||
|
// check if reason is valid
|
||||||
|
TEST_ASSERT_NOT_EQUAL(IMUResetReason::UNDEFINED, imu->get_reset_reason());
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_msg(TEST_TAG, "Destroying test IMU.");
|
||||||
|
BNO08xTestHelper::destroy_test_imu();
|
||||||
|
|
||||||
|
BNO08xTestHelper::print_test_end_banner(TEST_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Full Init & Deinit", "[FullInitDenit]")
|
||||||
|
{
|
||||||
|
const constexpr char* TEST_TAG = "Full Init & Deinit";
|
||||||
|
BNO08x* imu = nullptr;
|
||||||
|
|
||||||
BNO08xTestHelper::print_test_start_banner(TEST_TAG);
|
BNO08xTestHelper::print_test_start_banner(TEST_TAG);
|
||||||
|
|
||||||
|
|
@ -12,14 +105,14 @@ TEST_CASE("Full Init & Deinit", "[InitDenit]")
|
||||||
BNO08xTestHelper::create_test_imu();
|
BNO08xTestHelper::create_test_imu();
|
||||||
imu = BNO08xTestHelper::get_test_imu();
|
imu = BNO08xTestHelper::get_test_imu();
|
||||||
TEST_ASSERT_EQUAL(true, imu->initialize());
|
TEST_ASSERT_EQUAL(true, imu->initialize());
|
||||||
BNO08xTestHelper::print_test_msg(TEST_TAG, "Success, deinitializing IMU.");
|
BNO08xTestHelper::print_test_msg(TEST_TAG, "Success, deinitializing IMU.");
|
||||||
BNO08xTestHelper::destroy_test_imu();
|
BNO08xTestHelper::destroy_test_imu();
|
||||||
|
|
||||||
BNO08xTestHelper::print_test_msg(TEST_TAG, "Initializing IMU attempt 2.");
|
BNO08xTestHelper::print_test_msg(TEST_TAG, "Initializing IMU attempt 2.");
|
||||||
BNO08xTestHelper::create_test_imu();
|
BNO08xTestHelper::create_test_imu();
|
||||||
imu = BNO08xTestHelper::get_test_imu();
|
imu = BNO08xTestHelper::get_test_imu();
|
||||||
TEST_ASSERT_EQUAL(true, imu->initialize());
|
TEST_ASSERT_EQUAL(true, imu->initialize());
|
||||||
BNO08xTestHelper::print_test_msg(TEST_TAG, "Success, deinitializing IMU.");
|
BNO08xTestHelper::print_test_msg(TEST_TAG, "Success, deinitializing IMU.");
|
||||||
BNO08xTestHelper::destroy_test_imu();
|
BNO08xTestHelper::destroy_test_imu();
|
||||||
|
|
||||||
BNO08xTestHelper::print_test_end_banner(TEST_TAG);
|
BNO08xTestHelper::print_test_end_banner(TEST_TAG);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue