Skip to content

Commit d36fe73

Browse files
committed
Merge branch 'test/improve_sdmmc_tests' into 'master'
sd: improve tests and added on CI See merge request espressif/esp-idf!27384
2 parents ae4be8e + 1400f35 commit d36fe73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+349
-99
lines changed

.gitlab/ci/target-test.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,24 @@ pytest_components_esp32_adc:
715715
artifacts: false
716716
tags: [ esp32, adc ]
717717

718+
pytest_components_esp32_sdmmc:
719+
extends:
720+
- .pytest_components_dir_template
721+
- .rules:test:component_ut-esp32
722+
needs:
723+
- job: build_pytest_components_esp32
724+
artifacts: false
725+
tags: [ esp32, sdcard ]
726+
727+
pytest_components_esp32s3_sdmmc:
728+
extends:
729+
- .pytest_components_dir_template
730+
- .rules:test:component_ut-esp32s3
731+
needs:
732+
- job: build_pytest_components_esp32s3
733+
artifacts: false
734+
tags: [ esp32s3, sdcard ]
735+
718736
pytest_components_esp32_sdio:
719737
extends:
720738
- .pytest_components_dir_template
@@ -1171,15 +1189,6 @@ pytest_components_esp32c3_flash_multi:
11711189
artifacts: false
11721190
tags: [ esp32c3, flash_multi ]
11731191

1174-
pytest_components_esp32_sdmmc:
1175-
extends:
1176-
- .pytest_components_dir_template
1177-
- .rules:test:component_ut-esp32
1178-
needs:
1179-
- job: build_pytest_components_esp32
1180-
artifacts: false
1181-
tags: [ esp32, sdcard_sdmode ]
1182-
11831192
pytest_components_esp32_sdspi:
11841193
extends:
11851194
- .pytest_components_dir_template
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
components/esp_driver_sdmmc/test_apps/sdmmc:
2+
disable:
3+
- if: SOC_SDMMC_HOST_SUPPORTED != 1
4+
depends_components:
5+
- sdmmc
6+
- esp_driver_sdmmc
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(srcs "sdmmc_test_cd_wp_common.c" "sdmmc_test_rw_common.c")
2+
3+
set(public_include "include")
4+
5+
idf_component_register(
6+
SRCS ${srcs}
7+
INCLUDE_DIRS ${public_include}
8+
PRIV_REQUIRES sdmmc unity test_utils
9+
)

tools/test_apps/storage/sdmmc_console/components/sdmmc_tests/sdmmc_test_cd_wp_common.c renamed to components/esp_driver_sdmmc/test_apps/sd_test_utils/components/common_test_flows/sdmmc_test_cd_wp_common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "sdmmc_cmd.h"
1212
#include "sdmmc_test_cd_wp_common.h"
1313

14-
1514
void sdmmc_test_cd_input(int gpio_cd_num, const sdmmc_host_t* config)
1615
{
1716
sdmmc_card_t* card = malloc(sizeof(sdmmc_card_t));

tools/test_apps/storage/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_common.c renamed to components/esp_driver_sdmmc/test_apps/sd_test_utils/components/common_test_flows/sdmmc_test_rw_common.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
static void do_single_rw_perf_test(sdmmc_card_t* card, size_t start_block,
2020
size_t block_count, size_t alignment, FILE* performance_log);
2121

22-
static void fill_buffer(uint32_t seed, uint8_t* dst, size_t count) {
22+
static void fill_buffer(uint32_t seed, uint8_t* dst, size_t count)
23+
{
2324
srand(seed);
2425
for (size_t i = 0; i < count; ++i) {
2526
uint32_t val = rand();
@@ -29,7 +30,8 @@ static void fill_buffer(uint32_t seed, uint8_t* dst, size_t count) {
2930

3031
// Check if the buffer pointed to by 'dst' contains 'count' 32-bit
3132
// ints generated from 'rand' with the starting value of 'seed'
32-
static void check_buffer(uint32_t seed, const uint8_t* src, size_t count) {
33+
static void check_buffer(uint32_t seed, const uint8_t* src, size_t count)
34+
{
3335
srand(seed);
3436
for (size_t i = 0; i < count; ++i) {
3537
uint32_t val;
@@ -77,7 +79,7 @@ static void do_single_rw_perf_test(sdmmc_card_t* card, size_t start_block,
7779
stdout = performance_log;
7880
static const char wr_speed_str[] = "SDMMC_WR_SPEED";
7981
static const char rd_speed_str[] = "SDMMC_RD_SPEED";
80-
int aligned = ((alignment % 4) == 0)? 1: 0;
82+
int aligned = ((alignment % 4) == 0) ? 1 : 0;
8183
IDF_LOG_PERFORMANCE(wr_speed_str, "%d, blk_n: %d, aligned: %d",
8284
(int)(total_size * 1000 / time_wr), block_count, aligned);
8385
IDF_LOG_PERFORMANCE(rd_speed_str, "%d, blk_n: %d, aligned: %d",
@@ -142,15 +144,15 @@ void sdmmc_test_rw_with_offset(sdmmc_card_t* card)
142144
do_single_rw_perf_test(card, card->csd.capacity - 64, 32, 4, NULL);
143145
do_single_rw_perf_test(card, card->csd.capacity - 64, 64, 4, NULL);
144146
do_single_rw_perf_test(card, card->csd.capacity - 8, 1, 4, NULL);
145-
do_single_rw_perf_test(card, card->csd.capacity/2, 1, 4, NULL);
146-
do_single_rw_perf_test(card, card->csd.capacity/2, 4, 4, NULL);
147-
do_single_rw_perf_test(card, card->csd.capacity/2, 8, 4, NULL);
148-
do_single_rw_perf_test(card, card->csd.capacity/2, 16, 4, NULL);
149-
do_single_rw_perf_test(card, card->csd.capacity/2, 32, 4, NULL);
150-
do_single_rw_perf_test(card, card->csd.capacity/2, 64, 4, NULL);
151-
do_single_rw_perf_test(card, card->csd.capacity/2, 128, 4, NULL);
147+
do_single_rw_perf_test(card, card->csd.capacity / 2, 1, 4, NULL);
148+
do_single_rw_perf_test(card, card->csd.capacity / 2, 4, 4, NULL);
149+
do_single_rw_perf_test(card, card->csd.capacity / 2, 8, 4, NULL);
150+
do_single_rw_perf_test(card, card->csd.capacity / 2, 16, 4, NULL);
151+
do_single_rw_perf_test(card, card->csd.capacity / 2, 32, 4, NULL);
152+
do_single_rw_perf_test(card, card->csd.capacity / 2, 64, 4, NULL);
153+
do_single_rw_perf_test(card, card->csd.capacity / 2, 128, 4, NULL);
152154
/* unaligned */
153-
do_single_rw_perf_test(card, card->csd.capacity/2, 1, 1, NULL);
154-
do_single_rw_perf_test(card, card->csd.capacity/2, 8, 1, NULL);
155-
do_single_rw_perf_test(card, card->csd.capacity/2, 128, 1, NULL);
155+
do_single_rw_perf_test(card, card->csd.capacity / 2, 1, 1, NULL);
156+
do_single_rw_perf_test(card, card->csd.capacity / 2, 8, 1, NULL);
157+
do_single_rw_perf_test(card, card->csd.capacity / 2, 128, 1, NULL);
156158
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
idf_component_register(SRCS sdmmc_test_board.c sdmmc_test_board_defs.c
22
INCLUDE_DIRS include
3-
PRIV_REQUIRES sdmmc esp_driver_sdmmc esp_driver_sdspi)
3+
REQUIRES esp_driver_sdmmc esp_driver_sdspi esp_driver_gpio)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SDMMC Test Boards
2+
3+
This component is a test utility component for test board info:
4+
- SDMMC test boards (e.g. ESP32_WROVER_KIT, ESP32S3_USB_OTG, etc.)
5+
- eMMC test boards
6+
- SDMMC with SD breakout adapter board
7+
- SDSPI with SD breakout adapter board
8+
- ...

tools/test_apps/storage/sdmmc_console/components/sdmmc_test_board/include/sdmmc_test_board.h renamed to components/esp_driver_sdmmc/test_apps/sd_test_utils/components/sdmmc_test_boards/include/sdmmc_test_board.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ typedef struct {
5656
void (*card_power_set)(bool); /*< function to turn card power on or off */
5757
} sdmmc_test_board_info_t;
5858

59-
6059
/**
6160
* @brief Get information about the test board
6261
* @return Pointer to the board information structure
@@ -92,7 +91,6 @@ void sdmmc_test_board_get_config_sdmmc(int slot_index, sdmmc_host_t *out_host_co
9291
void sdmmc_test_board_get_config_sdspi(int slot_index, sdmmc_host_t *out_host_config,
9392
spi_bus_config_t *out_spi_bus_config, sdspi_device_config_t *out_dev_config);
9493

95-
9694
/**
9795
* @brief Set card power on or off
9896
* For boards with card power control circuit, this function allows powering the card up or down.

tools/test_apps/storage/sdmmc_console/components/sdmmc_test_board/sdmmc_test_board.c renamed to components/esp_driver_sdmmc/test_apps/sd_test_utils/components/sdmmc_test_boards/sdmmc_test_board.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "sdkconfig.h"
99
#include "soc/soc_caps.h"
1010

11-
1211
const sdmmc_test_board_slot_info_t* sdmmc_test_board_get_slot_info(int slot_index)
1312
{
1413
assert(slot_index >= 0 && slot_index < SDMMC_TEST_BOARD_MAX_SLOTS);

tools/test_apps/storage/sdmmc_console/components/sdmmc_test_board/sdmmc_test_board_defs.c renamed to components/esp_driver_sdmmc/test_apps/sd_test_utils/components/sdmmc_test_boards/sdmmc_test_board_defs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ static const sdmmc_test_board_info_t s_board_info = {
385385

386386
#endif // CONFIG_SDMMC_BOARD_*
387387

388-
389388
const sdmmc_test_board_info_t* sdmmc_test_board_get_info(void)
390389
{
391390
return &s_board_info;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components")
4+
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/components/esp_driver_sdmmc/test_apps/sd_test_utils/components")
5+
set(COMPONENTS main)
6+
7+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
8+
project(sdmmc_test_console)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| Supported Targets | ESP32 | ESP32-P4 | ESP32-S3 |
2+
| ----------------- | ----- | -------- | -------- |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set(srcs)
2+
3+
4+
if(CONFIG_SOC_SDMMC_HOST_SUPPORTED)
5+
list(APPEND srcs "sdmmc_test_begin_end_sd.c"
6+
"sdmmc_test_cd_wp_sd.c"
7+
"sdmmc_test_probe_sd.c"
8+
"sdmmc_test_rw_sd.c")
9+
endif()
10+
11+
set(priv_requires "sdmmc"
12+
"esp_driver_sdmmc"
13+
"sdmmc_test_boards"
14+
"common_test_flows"
15+
"unity"
16+
)
17+
18+
idf_component_register(SRCS ${srcs}
19+
PRIV_REQUIRES ${priv_requires}
20+
WHOLE_ARCHIVE TRUE)

tools/test_apps/storage/sdmmc_console/components/sdmmc_tests/sdmmc_test_begin_end_sd.c renamed to components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/sdmmc_test_begin_end_sd.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "driver/sdmmc_host.h"
1414
#include "sd_protocol_defs.h"
1515
#include "sdmmc_cmd.h"
16-
#include "sdmmc_test_begin_end.h"
16+
#include "sdmmc_test_begin_end_sd.h"
1717
#include "hal/gpio_hal.h"
1818

1919
void sdmmc_test_sd_skip_if_board_incompatible(int slot, int width, int freq_khz, int ddr)
@@ -33,7 +33,8 @@ void sdmmc_test_sd_skip_if_board_incompatible(int slot, int width, int freq_khz,
3333
TEST_IGNORE_MESSAGE("Board doesn't support required bus width");
3434
}
3535
}
36-
void sdmmc_test_sd_begin(int slot, int width, int freq_khz, int ddr, sdmmc_card_t *out_card) {
36+
void sdmmc_test_sd_begin(int slot, int width, int freq_khz, int ddr, sdmmc_card_t *out_card)
37+
{
3738
sdmmc_host_t config = SDMMC_HOST_DEFAULT();
3839
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
3940

@@ -87,18 +88,18 @@ void sdmmc_test_sd_end(sdmmc_card_t *card)
8788
int slot = card->host.slot;
8889
const sdmmc_test_board_slot_info_t *slot_info = sdmmc_test_board_get_slot_info(slot);
8990
const int pins[] = {
90-
slot_info->clk,
91-
slot_info->cmd_mosi,
92-
slot_info->d0_miso,
93-
slot_info->d1,
94-
slot_info->d2,
95-
slot_info->d3_cs,
96-
slot_info->d4,
97-
slot_info->d5,
98-
slot_info->d6,
99-
slot_info->d7,
100-
slot_info->cd,
101-
slot_info->wp,
91+
slot_info->clk,
92+
slot_info->cmd_mosi,
93+
slot_info->d0_miso,
94+
slot_info->d1,
95+
slot_info->d2,
96+
slot_info->d3_cs,
97+
slot_info->d4,
98+
slot_info->d5,
99+
slot_info->d6,
100+
slot_info->d7,
101+
slot_info->cd,
102+
slot_info->wp,
102103
};
103104
const int num_pins = sizeof(pins) / sizeof(pins[0]);
104105
// Silence logging in gpio_reset_pin, which logs at INFO level

tools/test_apps/storage/sdmmc_console/components/sdmmc_tests/sdmmc_test_begin_end.h renamed to components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/sdmmc_test_begin_end_sd.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ extern "C" {
1919

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

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

52-
/**
53-
* @brief Skip the test if the board is incompatible with the given slot and frequency, for SPI mode.
54-
* @see sdmmc_test_sd_skip_if_board_incompatible
55-
*/
56-
void sdmmc_test_spi_skip_if_board_incompatible(int slot, int freq_khz);
57-
58-
/**
59-
* @brief Helper function to initialize the SDMMC host and slot for the test using the given settings, for SPI mode
60-
* @see sdmmc_test_sd_begin
61-
*/
62-
void sdmmc_test_spi_begin(int slot, int freq_khz, sdmmc_card_t *out_card);
63-
64-
/**
65-
* @brief Helper function to deinitialize the SDMMC host and slot after the test, for SPI mode
66-
* @see sdmmc_test_sd_end
67-
*/
68-
void sdmmc_test_spi_end(int slot, sdmmc_card_t *card);
69-
70-
7151
#ifdef __cplusplus
7252
};
7353
#endif

tools/test_apps/storage/sdmmc_console/components/sdmmc_tests/sdmmc_test_cd_wp_sd.c renamed to components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/sdmmc_test_cd_wp_sd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "sdmmc_test_cd_wp_common.h"
1111
#include "sdmmc_test_board.h"
1212

13+
//TODO: IDF-8734
14+
#if !CONFIG_IDF_TARGET_ESP32 && !CONFIG_IDF_TARGET_ESP32S3
1315
TEST_CASE("CD input works in SD mode", "[sdmmc]")
1416
{
1517
sdmmc_host_t config = SDMMC_HOST_DEFAULT();
@@ -43,3 +45,4 @@ TEST_CASE("WP input works in SD mode", "[sdmmc]")
4345
TEST_ESP_OK(sdmmc_host_deinit());
4446
sdmmc_test_board_card_power_set(false);
4547
}
48+
#endif

tools/test_apps/storage/sdmmc_console/components/sdmmc_tests/sdmmc_test_probe_sd.c renamed to components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/sdmmc_test_probe_sd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <stddef.h>
77
#include "unity.h"
88
#include "sdmmc_cmd.h"
9-
#include "sdmmc_test_begin_end.h"
9+
#include "sdmmc_test_begin_end_sd.h"
1010

1111
static void do_one_sdmmc_probe_test(int slot, int width, int freq_khz, int ddr)
1212
{

tools/test_apps/storage/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_sd.c renamed to components/esp_driver_sdmmc/test_apps/sdmmc/components/sdmmc_tests/sdmmc_test_rw_sd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <stddef.h>
88
#include "unity.h"
99
#include "sdmmc_cmd.h"
10-
#include "sdmmc_test_begin_end.h"
10+
#include "sdmmc_test_begin_end_sd.h"
1111
#include "sdmmc_test_rw_common.h"
1212

1313
/* ========== Read/write performance tests, SD ========== */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set(srcs "test_app_main.c")
2+
3+
set(priv_requires
4+
# tests reside in this component, also available for `sdmmc_console`
5+
sdmmc_tests
6+
# general
7+
unity
8+
)
9+
10+
idf_component_register(SRCS ${srcs}
11+
INCLUDE_DIRS "."
12+
PRIV_REQUIRES ${priv_requires}
13+
WHOLE_ARCHIVE TRUE)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: CC0-1.0
5+
*/
6+
7+
#include "unity.h"
8+
#include "unity_test_utils.h"
9+
#include "esp_heap_caps.h"
10+
#include "sdkconfig.h"
11+
12+
#define TEST_MEMORY_LEAK_THRESHOLD (300)
13+
14+
void setUp(void)
15+
{
16+
unity_utils_record_free_mem();
17+
}
18+
19+
void tearDown(void)
20+
{
21+
unity_utils_evaluate_leaks_direct(TEST_MEMORY_LEAK_THRESHOLD);
22+
}
23+
24+
void app_main(void)
25+
{
26+
/*
27+
_____ _ ______________ ______ ________
28+
|_ _| | | / ___| _ \ \/ || \/ / __ \
29+
| | ___ ___| |_ \ `--.| | | | . . || . . | / \/
30+
| |/ _ \/ __| __| `--. \ | | | |\/| || |\/| | |
31+
| | __/\__ \ |_ /\__/ / |/ /| | | || | | | \__/\
32+
\_/\___||___/\__| \____/|___/ \_| |_/\_| |_/\____/
33+
*/
34+
35+
printf(" _____ _ ______________ ______ ________\n");
36+
printf("|_ _| | | / ___| _ \\ \\/ || \\/ / __ \\ \n");
37+
printf(" | | ___ ___| |_ \\ `--.| | | | . . || . . | / \\/\n");
38+
printf(" | |/ _ \\/ __| __| `--. \\ | | | |\\/| || |\\/| | |\n");
39+
printf(" | | __/\\__ \\ |_ /\\__/ / |/ /| | | || | | | \\__/\\\n");
40+
printf(" \\_/\\___||___/\\__| \\____/|___/ \\_| |_/\\_| |_/\\____/\n");
41+
42+
unity_run_menu();
43+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
import pytest
5+
from pytest_embedded_idf import IdfDut
6+
7+
8+
@pytest.mark.esp32
9+
@pytest.mark.esp32s3
10+
@pytest.mark.sdcard
11+
def test_sdmmc(dut: IdfDut) -> None:
12+
dut.run_all_single_board_cases()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_FREERTOS_HZ=1000
2+
CONFIG_ESP_TASK_WDT_EN=n

0 commit comments

Comments
 (0)