test: make 'test_common_spi' as a components named 'test_utils_spi'

pull/10165/head
wanlei 2022-10-27 12:42:04 +08:00
rodzic 8fe79ae0cd
commit 312bc6cb3a
7 zmienionych plików z 32 dodań i 19 usunięć

Wyświetl plik

@ -1,7 +1,8 @@
idf_component_register(SRC_DIRS . param_test
PRIV_INCLUDE_DIRS include param_test/include
PRIV_REQUIRES cmock test_utils driver nvs_flash
esp_timer esp_adc esp_event esp_wifi spi_flash)
idf_component_register(
SRC_DIRS .
PRIV_INCLUDE_DIRS include
PRIV_REQUIRES cmock test_utils test_driver_utils driver nvs_flash spi_flash esp_timer esp_adc esp_event esp_wifi
)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
# A local copy of idf-extra-components esp_serial_slave_link, for stabilities of the SDIO test

Wyświetl plik

@ -0,0 +1,5 @@
idf_component_register(
SRCS test_spi_utils.c param_test.c
INCLUDE_DIRS include
REQUIRES driver unity
)

Wyświetl plik

@ -1,8 +1,9 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Parameterized Test Framework
*

Wyświetl plik

@ -7,17 +7,21 @@
#define _TEST_COMMON_SPI_H_
#include <esp_types.h>
#include "driver/spi_master.h"
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/ringbuf.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "freertos/task.h"
#include "unity.h"
#include "test_utils.h"
#include <string.h>
#include "param_test.h"
#include "soc/io_mux_reg.h"
#include "sdkconfig.h"
#include "soc/spi_periph.h"
#include "driver/spi_master.h"
// All the tests using the header should use this definition as much as possible,
// so that the working host can be changed easily in the future.
@ -249,7 +253,7 @@ typedef struct {
void spitest_def_param(void* arg);
// functions for slave task
esp_err_t init_slave_context(spi_slave_task_context_t *context);
esp_err_t init_slave_context(spi_slave_task_context_t *context, spi_host_device_t host);
void deinit_slave_context(spi_slave_task_context_t *context);
void spitest_slave_task(void* arg);

Wyświetl plik

@ -1,12 +1,12 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stddef.h>
#include <stdlib.h>
#include "param_test.h"
#include "esp_log.h"
#include "unity.h"
#include "param_test.h"
void test_serializer(const param_group_t *param_group, const ptest_func_t* test_func)
{

Wyświetl plik

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "test/test_common_spi.h"
#include "test_spi_utils.h"
#include "driver/spi_slave.h"
#include "esp_log.h"
#include "driver/gpio.h"
@ -44,7 +44,7 @@ void spitest_def_param(void* arg)
/**********************************************************************************
* functions for slave task
*********************************************************************************/
esp_err_t init_slave_context(spi_slave_task_context_t *context)
esp_err_t init_slave_context(spi_slave_task_context_t *context, spi_host_device_t host)
{
context->data_to_send = xQueueCreate( 16, sizeof( slave_txdata_t ));
if ( context->data_to_send == NULL ) {
@ -54,7 +54,7 @@ esp_err_t init_slave_context(spi_slave_task_context_t *context)
if ( context->data_received == NULL ) {
return ESP_ERR_NO_MEM;
}
context->spi=TEST_SLAVE_HOST;
context->spi=host;
return ESP_OK;
}
@ -96,7 +96,7 @@ void spitest_slave_task(void* arg)
} while ( t.trans_len <= 2 );
memcpy(recvbuf, &t.trans_len, sizeof(uint32_t));
*(uint8_t**)(recvbuf+4) = (uint8_t*)txdata.start;
ESP_LOGD( SLAVE_TAG, "received: %d", t.trans_len );
ESP_LOGD( SLAVE_TAG, "received: %" PRIu32, (uint32_t)t.trans_len );
xRingbufferSend( ringbuf, recvbuf, 8+(t.trans_len+7)/8, portMAX_DELAY );
}
}
@ -163,7 +163,7 @@ void spitest_master_print_data(spi_transaction_t *t, int rxlength)
void spitest_slave_print_data(slave_rxdata_t *t, bool print_rxdata)
{
int rcv_len = (t->len+7)/8;
ESP_LOGI(SLAVE_TAG, "trans_len: %d", t->len);
ESP_LOGI(SLAVE_TAG, "trans_len: %" PRIu32, t->len);
ESP_LOG_BUFFER_HEX("slave tx", t->tx_start, rcv_len);
if (print_rxdata) ESP_LOG_BUFFER_HEX("slave rx", t->data, rcv_len);
}
@ -188,7 +188,7 @@ esp_err_t spitest_check_data(int len, spi_transaction_t *master_t, slave_rxdata_
ret = ESP_FAIL;
}
if (ret != ESP_OK) {
ESP_LOGI(SLAVE_TAG, "slave_recv_len: %d", rcv_len);
ESP_LOGI(SLAVE_TAG, "slave_recv_len: %" PRIu32, rcv_len);
spitest_master_print_data(master_t, len);
spitest_slave_print_data(slave_t, true);
//already failed, try to use the TEST_ASSERT to output the reason...
@ -250,4 +250,5 @@ void get_tx_buffer(uint32_t seed, uint8_t *master_send_buf, uint8_t *slave_send_
master_send_buf[i] = rand() % 256;
}
}
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)

Wyświetl plik

@ -3,6 +3,7 @@
cmake_minimum_required(VERSION 3.16)
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/examples/cxx/experimental/experimental_cpp_component/")
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/components/driver/test_apps/components")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(unit-test-app)