HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
SpiComprehensiveTest.cpp File Reference

Comprehensive SPI testing suite for ESP32-C6 DevKit-M-1 (noexcept) More...

#include "base/BaseSpi.h"
#include "base/HardwareTypes.h"
#include "mcu/esp32/EspSpi.h"
#include "mcu/esp32/utils/EspTypes_SPI.h"
#include <algorithm>
#include <cstring>
#include <memory>
#include <vector>
#include "TestFramework.h"
Include dependency graph for SpiComprehensiveTest.cpp:

Functions

bool test_spi_bus_initialization () noexcept
 
bool test_spi_bus_deinitialization () noexcept
 
bool test_spi_configuration_validation () noexcept
 
bool test_spi_device_creation () noexcept
 
bool test_spi_device_management () noexcept
 
bool test_spi_transfer_basic () noexcept
 
bool test_spi_transfer_modes () noexcept
 
bool test_spi_transfer_sizes () noexcept
 
bool test_spi_dma_operations () noexcept
 
bool test_spi_clock_speeds () noexcept
 
bool test_spi_multi_device_operations () noexcept
 
bool test_spi_error_handling () noexcept
 
bool test_spi_timeout_handling () noexcept
 
bool test_spi_esp_specific_features () noexcept
 
bool test_spi_iomux_optimization () noexcept
 
bool test_spi_thread_safety () noexcept
 
bool test_spi_performance_benchmarks () noexcept
 
bool test_spi_edge_cases () noexcept
 
bool test_spi_bus_acquisition () noexcept
 
bool test_spi_power_management () noexcept
 
hf_spi_bus_config_t create_test_bus_config (uint32_t speed=MEDIUM_SPEED, bool use_dma=true, spi_host_device_t host=SPI2_HOST) noexcept
 
bool verify_transfer_data (const uint8_t *tx_data, const uint8_t *rx_data, size_t length) noexcept
 
void generate_test_pattern (uint8_t *buffer, size_t length, uint8_t seed=0xAA) noexcept
 
void generate_sequential_pattern (uint8_t *buffer, size_t length, uint8_t start_value=0x01) noexcept
 
void generate_alternating_pattern (uint8_t *buffer, size_t length, uint8_t value1=0x55, uint8_t value2=0xAA) noexcept
 
bool test_spi_espidf_direct_api () noexcept
 Test SPI using ESP-IDF API directly (bypassing our wrapper)
 
bool test_spi_espidf_wrapper_replica () noexcept
 Test SPI using EspSpiBus wrapper (replicating ESP-IDF direct test)
 
void app_main (void)
 

Variables

static const char * TAG = "SPI_Test"
 
static TestResults g_test_results
 
static constexpr bool ENABLE_CORE_TESTS
 
static constexpr bool ENABLE_TRANSFER_TESTS = true
 
static constexpr bool ENABLE_PERFORMANCE_TESTS
 
static constexpr bool ENABLE_ADVANCED_TESTS = true
 
static constexpr bool ENABLE_STRESS_TESTS
 
static constexpr bool ENABLE_ESPIDF_DIRECT_TEST = true
 
static constexpr bool ENABLE_ESPIDF_WRAPPER_REPLICA = true
 
static constexpr hf_pin_num_t TEST_MOSI_PIN = 7
 
static constexpr hf_pin_num_t TEST_MISO_PIN = 2
 
static constexpr hf_pin_num_t TEST_SCLK_PIN = 6
 
static constexpr hf_pin_num_t TEST_CS_PIN = 21
 
static constexpr hf_pin_num_t TEST_CS_PIN_1 = 21
 
static constexpr hf_pin_num_t TEST_CS_PIN_2 = 20
 
static constexpr hf_pin_num_t TEST_CS_PIN_3 = 19
 
static constexpr hf_host_id_t SPI_HOST_NUM
 
static constexpr uint32_t SLOW_SPEED = 1000000
 
static constexpr uint32_t MEDIUM_SPEED = 10000000
 
static constexpr uint32_t FAST_SPEED = 40000000
 
static constexpr uint32_t MAX_SPEED = 80000000
 

Detailed Description

Comprehensive SPI testing suite for ESP32-C6 DevKit-M-1 (noexcept)

This file contains comprehensive testing for the ESP SPI implementation including:

  • Bus initialization and configuration validation
  • Device creation and management
  • Data transfer operations (full-duplex, half-duplex, various modes)
  • DMA operations and performance testing
  • Error handling and recovery
  • Multi-device scenarios with different configurations
  • ESP-specific features (clock sources, IOMUX, advanced timing)
  • Thread safety verification
  • Performance benchmarking and timing tests
  • Edge cases and fault injection
  • SPI modes (0-3) and various transfer sizes

All functions are noexcept - no exception handling used.

Author
Nebiyu Tadesse
Date
2025

Function Documentation

◆ app_main()

void app_main ( void )

◆ create_test_bus_config()

hf_spi_bus_config_t create_test_bus_config ( uint32_t speed = MEDIUM_SPEED,
bool use_dma = true,
spi_host_device_t host = SPI2_HOST )
noexcept

◆ generate_alternating_pattern()

void generate_alternating_pattern ( uint8_t * buffer,
size_t length,
uint8_t value1 = 0x55,
uint8_t value2 = 0xAA )
noexcept

◆ generate_sequential_pattern()

void generate_sequential_pattern ( uint8_t * buffer,
size_t length,
uint8_t start_value = 0x01 )
noexcept

◆ generate_test_pattern()

void generate_test_pattern ( uint8_t * buffer,
size_t length,
uint8_t seed = 0xAA )
noexcept

◆ test_spi_bus_acquisition()

bool test_spi_bus_acquisition ( )
noexcept

◆ test_spi_bus_deinitialization()

bool test_spi_bus_deinitialization ( )
noexcept

◆ test_spi_bus_initialization()

bool test_spi_bus_initialization ( )
noexcept

◆ test_spi_clock_speeds()

bool test_spi_clock_speeds ( )
noexcept

◆ test_spi_configuration_validation()

bool test_spi_configuration_validation ( )
noexcept

◆ test_spi_device_creation()

bool test_spi_device_creation ( )
noexcept

◆ test_spi_device_management()

bool test_spi_device_management ( )
noexcept

◆ test_spi_dma_operations()

bool test_spi_dma_operations ( )
noexcept

◆ test_spi_edge_cases()

bool test_spi_edge_cases ( )
noexcept

◆ test_spi_error_handling()

bool test_spi_error_handling ( )
noexcept

◆ test_spi_esp_specific_features()

bool test_spi_esp_specific_features ( )
noexcept

◆ test_spi_espidf_direct_api()

bool test_spi_espidf_direct_api ( )
noexcept

Test SPI using ESP-IDF API directly (bypassing our wrapper)

Returns
true if successful, false otherwise
Note
This test runs FIRST to verify ESP-IDF SPI driver functionality
Uses identical configuration and test pattern as C++ wrapper replica test

◆ test_spi_espidf_wrapper_replica()

bool test_spi_espidf_wrapper_replica ( )
noexcept

Test SPI using EspSpiBus wrapper (replicating ESP-IDF direct test)

Returns
true if successful, false otherwise
Note
This test runs SECOND to compare EspSpiBus wrapper with ESP-IDF direct API
Uses identical configuration and test pattern as ESP-IDF direct test

◆ test_spi_iomux_optimization()

bool test_spi_iomux_optimization ( )
noexcept

◆ test_spi_multi_device_operations()

bool test_spi_multi_device_operations ( )
noexcept

◆ test_spi_performance_benchmarks()

bool test_spi_performance_benchmarks ( )
noexcept

◆ test_spi_power_management()

bool test_spi_power_management ( )
noexcept

◆ test_spi_thread_safety()

bool test_spi_thread_safety ( )
noexcept

◆ test_spi_timeout_handling()

bool test_spi_timeout_handling ( )
noexcept

◆ test_spi_transfer_basic()

bool test_spi_transfer_basic ( )
noexcept

◆ test_spi_transfer_modes()

bool test_spi_transfer_modes ( )
noexcept

◆ test_spi_transfer_sizes()

bool test_spi_transfer_sizes ( )
noexcept

◆ verify_transfer_data()

bool verify_transfer_data ( const uint8_t * tx_data,
const uint8_t * rx_data,
size_t length )
noexcept

Variable Documentation

◆ ENABLE_ADVANCED_TESTS

constexpr bool ENABLE_ADVANCED_TESTS = true
staticconstexpr

◆ ENABLE_CORE_TESTS

constexpr bool ENABLE_CORE_TESTS
staticconstexpr
Initial value:
=
true

◆ ENABLE_ESPIDF_DIRECT_TEST

constexpr bool ENABLE_ESPIDF_DIRECT_TEST = true
staticconstexpr

◆ ENABLE_ESPIDF_WRAPPER_REPLICA

constexpr bool ENABLE_ESPIDF_WRAPPER_REPLICA = true
staticconstexpr

◆ ENABLE_PERFORMANCE_TESTS

constexpr bool ENABLE_PERFORMANCE_TESTS
staticconstexpr
Initial value:
=
true

◆ ENABLE_STRESS_TESTS

constexpr bool ENABLE_STRESS_TESTS
staticconstexpr
Initial value:
=
true

◆ ENABLE_TRANSFER_TESTS

constexpr bool ENABLE_TRANSFER_TESTS = true
staticconstexpr

◆ FAST_SPEED

constexpr uint32_t FAST_SPEED = 40000000
staticconstexpr

◆ g_test_results

TestResults g_test_results
static

◆ MAX_SPEED

constexpr uint32_t MAX_SPEED = 80000000
staticconstexpr

◆ MEDIUM_SPEED

constexpr uint32_t MEDIUM_SPEED = 10000000
staticconstexpr

◆ SLOW_SPEED

constexpr uint32_t SLOW_SPEED = 1000000
staticconstexpr

◆ SPI_HOST_NUM

constexpr hf_host_id_t SPI_HOST_NUM
staticconstexpr
Initial value:
=
static_cast<hf_host_id_t>(SPI2_HOST)
hf_u32_t hf_host_id_t
Platform-agnostic host/controller identifier type.
Definition HardwareTypes.h:131

◆ TAG

const char* TAG = "SPI_Test"
static

◆ TEST_CS_PIN

constexpr hf_pin_num_t TEST_CS_PIN = 21
staticconstexpr

◆ TEST_CS_PIN_1

constexpr hf_pin_num_t TEST_CS_PIN_1 = 21
staticconstexpr

◆ TEST_CS_PIN_2

constexpr hf_pin_num_t TEST_CS_PIN_2 = 20
staticconstexpr

◆ TEST_CS_PIN_3

constexpr hf_pin_num_t TEST_CS_PIN_3 = 19
staticconstexpr

◆ TEST_MISO_PIN

constexpr hf_pin_num_t TEST_MISO_PIN = 2
staticconstexpr

◆ TEST_MOSI_PIN

constexpr hf_pin_num_t TEST_MOSI_PIN = 7
staticconstexpr

◆ TEST_SCLK_PIN

constexpr hf_pin_num_t TEST_SCLK_PIN = 6
staticconstexpr