Skip to content

Commit

Permalink
Merge branch 'test/improve_sdmmc_tests' into 'master'
Browse files Browse the repository at this point in the history
sd: improve tests and added on CI

See merge request espressif/esp-idf!27384
  • Loading branch information
Icarus113 committed Nov 30, 2023
2 parents ae4be8e + 1400f35 commit d36fe73
Show file tree
Hide file tree
Showing 43 changed files with 349 additions and 99 deletions.
27 changes: 18 additions & 9 deletions .gitlab/ci/target-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,24 @@ pytest_components_esp32_adc:
artifacts: false
tags: [ esp32, adc ]

pytest_components_esp32_sdmmc:
extends:
- .pytest_components_dir_template
- .rules:test:component_ut-esp32
needs:
- job: build_pytest_components_esp32
artifacts: false
tags: [ esp32, sdcard ]

pytest_components_esp32s3_sdmmc:
extends:
- .pytest_components_dir_template
- .rules:test:component_ut-esp32s3
needs:
- job: build_pytest_components_esp32s3
artifacts: false
tags: [ esp32s3, sdcard ]

pytest_components_esp32_sdio:
extends:
- .pytest_components_dir_template
Expand Down Expand Up @@ -1171,15 +1189,6 @@ pytest_components_esp32c3_flash_multi:
artifacts: false
tags: [ esp32c3, flash_multi ]

pytest_components_esp32_sdmmc:
extends:
- .pytest_components_dir_template
- .rules:test:component_ut-esp32
needs:
- job: build_pytest_components_esp32
artifacts: false
tags: [ esp32, sdcard_sdmode ]

pytest_components_esp32_sdspi:
extends:
- .pytest_components_dir_template
Expand Down
6 changes: 6 additions & 0 deletions components/esp_driver_sdmmc/test_apps/.build-test-rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
components/esp_driver_sdmmc/test_apps/sdmmc:
disable:
- if: SOC_SDMMC_HOST_SUPPORTED != 1
depends_components:
- sdmmc
- esp_driver_sdmmc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(srcs "sdmmc_test_cd_wp_common.c" "sdmmc_test_rw_common.c")

set(public_include "include")

idf_component_register(
SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES sdmmc unity test_utils
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "sdmmc_cmd.h"
#include "sdmmc_test_cd_wp_common.h"


void sdmmc_test_cd_input(int gpio_cd_num, const sdmmc_host_t* config)
{
sdmmc_card_t* card = malloc(sizeof(sdmmc_card_t));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
static void do_single_rw_perf_test(sdmmc_card_t* card, size_t start_block,
size_t block_count, size_t alignment, FILE* performance_log);

static void fill_buffer(uint32_t seed, uint8_t* dst, size_t count) {
static void fill_buffer(uint32_t seed, uint8_t* dst, size_t count)
{
srand(seed);
for (size_t i = 0; i < count; ++i) {
uint32_t val = rand();
Expand All @@ -29,7 +30,8 @@ static void fill_buffer(uint32_t seed, uint8_t* dst, size_t count) {

// Check if the buffer pointed to by 'dst' contains 'count' 32-bit
// ints generated from 'rand' with the starting value of 'seed'
static void check_buffer(uint32_t seed, const uint8_t* src, size_t count) {
static void check_buffer(uint32_t seed, const uint8_t* src, size_t count)
{
srand(seed);
for (size_t i = 0; i < count; ++i) {
uint32_t val;
Expand Down Expand Up @@ -77,7 +79,7 @@ static void do_single_rw_perf_test(sdmmc_card_t* card, size_t start_block,
stdout = performance_log;
static const char wr_speed_str[] = "SDMMC_WR_SPEED";
static const char rd_speed_str[] = "SDMMC_RD_SPEED";
int aligned = ((alignment % 4) == 0)? 1: 0;
int aligned = ((alignment % 4) == 0) ? 1 : 0;
IDF_LOG_PERFORMANCE(wr_speed_str, "%d, blk_n: %d, aligned: %d",
(int)(total_size * 1000 / time_wr), block_count, aligned);
IDF_LOG_PERFORMANCE(rd_speed_str, "%d, blk_n: %d, aligned: %d",
Expand Down Expand Up @@ -142,15 +144,15 @@ void sdmmc_test_rw_with_offset(sdmmc_card_t* card)
do_single_rw_perf_test(card, card->csd.capacity - 64, 32, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity - 64, 64, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity - 8, 1, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity/2, 1, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity/2, 4, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity/2, 8, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity/2, 16, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity/2, 32, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity/2, 64, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity/2, 128, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity / 2, 1, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity / 2, 4, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity / 2, 8, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity / 2, 16, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity / 2, 32, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity / 2, 64, 4, NULL);
do_single_rw_perf_test(card, card->csd.capacity / 2, 128, 4, NULL);
/* unaligned */
do_single_rw_perf_test(card, card->csd.capacity/2, 1, 1, NULL);
do_single_rw_perf_test(card, card->csd.capacity/2, 8, 1, NULL);
do_single_rw_perf_test(card, card->csd.capacity/2, 128, 1, NULL);
do_single_rw_perf_test(card, card->csd.capacity / 2, 1, 1, NULL);
do_single_rw_perf_test(card, card->csd.capacity / 2, 8, 1, NULL);
do_single_rw_perf_test(card, card->csd.capacity / 2, 128, 1, NULL);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
idf_component_register(SRCS sdmmc_test_board.c sdmmc_test_board_defs.c
INCLUDE_DIRS include
PRIV_REQUIRES sdmmc esp_driver_sdmmc esp_driver_sdspi)
REQUIRES esp_driver_sdmmc esp_driver_sdspi esp_driver_gpio)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SDMMC Test Boards

This component is a test utility component for test board info:
- SDMMC test boards (e.g. ESP32_WROVER_KIT, ESP32S3_USB_OTG, etc.)
- eMMC test boards
- SDMMC with SD breakout adapter board
- SDSPI with SD breakout adapter board
- ...
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ typedef struct {
void (*card_power_set)(bool); /*< function to turn card power on or off */
} sdmmc_test_board_info_t;


/**
* @brief Get information about the test board
* @return Pointer to the board information structure
Expand Down Expand Up @@ -92,7 +91,6 @@ void sdmmc_test_board_get_config_sdmmc(int slot_index, sdmmc_host_t *out_host_co
void sdmmc_test_board_get_config_sdspi(int slot_index, sdmmc_host_t *out_host_config,
spi_bus_config_t *out_spi_bus_config, sdspi_device_config_t *out_dev_config);


/**
* @brief Set card power on or off
* For boards with card power control circuit, this function allows powering the card up or down.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "sdkconfig.h"
#include "soc/soc_caps.h"


const sdmmc_test_board_slot_info_t* sdmmc_test_board_get_slot_info(int slot_index)
{
assert(slot_index >= 0 && slot_index < SDMMC_TEST_BOARD_MAX_SLOTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ static const sdmmc_test_board_info_t s_board_info = {

#endif // CONFIG_SDMMC_BOARD_*


const sdmmc_test_board_info_t* sdmmc_test_board_get_info(void)
{
return &s_board_info;
Expand Down
8 changes: 8 additions & 0 deletions components/esp_driver_sdmmc/test_apps/sdmmc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.16)

list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components")
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/components/esp_driver_sdmmc/test_apps/sd_test_utils/components")
set(COMPONENTS main)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(sdmmc_test_console)
2 changes: 2 additions & 0 deletions components/esp_driver_sdmmc/test_apps/sdmmc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| Supported Targets | ESP32 | ESP32-P4 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- |
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set(srcs)


if(CONFIG_SOC_SDMMC_HOST_SUPPORTED)
list(APPEND srcs "sdmmc_test_begin_end_sd.c"
"sdmmc_test_cd_wp_sd.c"
"sdmmc_test_probe_sd.c"
"sdmmc_test_rw_sd.c")
endif()

set(priv_requires "sdmmc"
"esp_driver_sdmmc"
"sdmmc_test_boards"
"common_test_flows"
"unity"
)

idf_component_register(SRCS ${srcs}
PRIV_REQUIRES ${priv_requires}
WHOLE_ARCHIVE TRUE)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "driver/sdmmc_host.h"
#include "sd_protocol_defs.h"
#include "sdmmc_cmd.h"
#include "sdmmc_test_begin_end.h"
#include "sdmmc_test_begin_end_sd.h"
#include "hal/gpio_hal.h"

void sdmmc_test_sd_skip_if_board_incompatible(int slot, int width, int freq_khz, int ddr)
Expand All @@ -33,7 +33,8 @@ void sdmmc_test_sd_skip_if_board_incompatible(int slot, int width, int freq_khz,
TEST_IGNORE_MESSAGE("Board doesn't support required bus width");
}
}
void sdmmc_test_sd_begin(int slot, int width, int freq_khz, int ddr, sdmmc_card_t *out_card) {
void sdmmc_test_sd_begin(int slot, int width, int freq_khz, int ddr, sdmmc_card_t *out_card)
{
sdmmc_host_t config = SDMMC_HOST_DEFAULT();
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();

Expand Down Expand Up @@ -87,18 +88,18 @@ void sdmmc_test_sd_end(sdmmc_card_t *card)
int slot = card->host.slot;
const sdmmc_test_board_slot_info_t *slot_info = sdmmc_test_board_get_slot_info(slot);
const int pins[] = {
slot_info->clk,
slot_info->cmd_mosi,
slot_info->d0_miso,
slot_info->d1,
slot_info->d2,
slot_info->d3_cs,
slot_info->d4,
slot_info->d5,
slot_info->d6,
slot_info->d7,
slot_info->cd,
slot_info->wp,
slot_info->clk,
slot_info->cmd_mosi,
slot_info->d0_miso,
slot_info->d1,
slot_info->d2,
slot_info->d3_cs,
slot_info->d4,
slot_info->d5,
slot_info->d6,
slot_info->d7,
slot_info->cd,
slot_info->wp,
};
const int num_pins = sizeof(pins) / sizeof(pins[0]);
// Silence logging in gpio_reset_pin, which logs at INFO level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ extern "C" {

/* Helper functions to initialize/deinintalize the host (SDMMC/SDSPI) inside the test */


#if SOC_SDMMC_HOST_SUPPORTED
/**
* @brief Skip the test if the board is incompatible with the given slot, width, frequency and DDR mode
Expand Down Expand Up @@ -49,25 +48,6 @@ void sdmmc_test_sd_begin(int slot, int width, int freq_khz, int ddr, sdmmc_card_
void sdmmc_test_sd_end(sdmmc_card_t *card);
#endif

/**
* @brief Skip the test if the board is incompatible with the given slot and frequency, for SPI mode.
* @see sdmmc_test_sd_skip_if_board_incompatible
*/
void sdmmc_test_spi_skip_if_board_incompatible(int slot, int freq_khz);

/**
* @brief Helper function to initialize the SDMMC host and slot for the test using the given settings, for SPI mode
* @see sdmmc_test_sd_begin
*/
void sdmmc_test_spi_begin(int slot, int freq_khz, sdmmc_card_t *out_card);

/**
* @brief Helper function to deinitialize the SDMMC host and slot after the test, for SPI mode
* @see sdmmc_test_sd_end
*/
void sdmmc_test_spi_end(int slot, sdmmc_card_t *card);


#ifdef __cplusplus
};
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "sdmmc_test_cd_wp_common.h"
#include "sdmmc_test_board.h"

//TODO: IDF-8734
#if !CONFIG_IDF_TARGET_ESP32 && !CONFIG_IDF_TARGET_ESP32S3
TEST_CASE("CD input works in SD mode", "[sdmmc]")
{
sdmmc_host_t config = SDMMC_HOST_DEFAULT();
Expand Down Expand Up @@ -43,3 +45,4 @@ TEST_CASE("WP input works in SD mode", "[sdmmc]")
TEST_ESP_OK(sdmmc_host_deinit());
sdmmc_test_board_card_power_set(false);
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stddef.h>
#include "unity.h"
#include "sdmmc_cmd.h"
#include "sdmmc_test_begin_end.h"
#include "sdmmc_test_begin_end_sd.h"

static void do_one_sdmmc_probe_test(int slot, int width, int freq_khz, int ddr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <stddef.h>
#include "unity.h"
#include "sdmmc_cmd.h"
#include "sdmmc_test_begin_end.h"
#include "sdmmc_test_begin_end_sd.h"
#include "sdmmc_test_rw_common.h"

/* ========== Read/write performance tests, SD ========== */
Expand Down
13 changes: 13 additions & 0 deletions components/esp_driver_sdmmc/test_apps/sdmmc/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(srcs "test_app_main.c")

set(priv_requires
# tests reside in this component, also available for `sdmmc_console`
sdmmc_tests
# general
unity
)

idf_component_register(SRCS ${srcs}
INCLUDE_DIRS "."
PRIV_REQUIRES ${priv_requires}
WHOLE_ARCHIVE TRUE)
43 changes: 43 additions & 0 deletions components/esp_driver_sdmmc/test_apps/sdmmc/main/test_app_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/

#include "unity.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "sdkconfig.h"

#define TEST_MEMORY_LEAK_THRESHOLD (300)

void setUp(void)
{
unity_utils_record_free_mem();
}

void tearDown(void)
{
unity_utils_evaluate_leaks_direct(TEST_MEMORY_LEAK_THRESHOLD);
}

void app_main(void)
{
/*
_____ _ ______________ ______ ________
|_ _| | | / ___| _ \ \/ || \/ / __ \
| | ___ ___| |_ \ `--.| | | | . . || . . | / \/
| |/ _ \/ __| __| `--. \ | | | |\/| || |\/| | |
| | __/\__ \ |_ /\__/ / |/ /| | | || | | | \__/\
\_/\___||___/\__| \____/|___/ \_| |_/\_| |_/\____/
*/

printf(" _____ _ ______________ ______ ________\n");
printf("|_ _| | | / ___| _ \\ \\/ || \\/ / __ \\ \n");
printf(" | | ___ ___| |_ \\ `--.| | | | . . || . . | / \\/\n");
printf(" | |/ _ \\/ __| __| `--. \\ | | | |\\/| || |\\/| | |\n");
printf(" | | __/\\__ \\ |_ /\\__/ / |/ /| | | || | | | \\__/\\\n");
printf(" \\_/\\___||___/\\__| \\____/|___/ \\_| |_/\\_| |_/\\____/\n");

unity_run_menu();
}
12 changes: 12 additions & 0 deletions components/esp_driver_sdmmc/test_apps/sdmmc/pytest_sdmmc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0

import pytest
from pytest_embedded_idf import IdfDut


@pytest.mark.esp32
@pytest.mark.esp32s3
@pytest.mark.sdcard
def test_sdmmc(dut: IdfDut) -> None:
dut.run_all_single_board_cases()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP_TASK_WDT_EN=n
Loading

0 comments on commit d36fe73

Please sign in to comment.