Skip to content

Commit

Permalink
uac: add test_app
Browse files Browse the repository at this point in the history
  • Loading branch information
leeebo committed Mar 25, 2024
1 parent 61e54f6 commit 92b6da1
Show file tree
Hide file tree
Showing 10 changed files with 2,774 additions and 9 deletions.
2 changes: 1 addition & 1 deletion host/class/uac/usb_host_uac/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The following steps outline the typical API call pattern of the UAC Class Driver
- `uac_host_device_start()`
- `uac_host_device_stop()`
6. To control the volume/mute use:
- `uac_class_request_control()`
- `uac_host_device_control()`

7. When UAC device event occurs the driver call an interface callback with events:
- UAC_HOST_DEVICE_EVENT_RX_DONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static esp_err_t _audio_player_mute_fn(AUDIO_PLAYER_MUTE_SETTING setting)
}
ESP_LOGI(TAG, "mute setting: %s", setting == 0 ? "mute" : "unmute");

return uac_class_request_control(s_spk_dev_handle, UAC_CTRL_UAC_MUTE, (void *)(setting == 0 ? 1 : 0));
return uac_host_device_control(s_spk_dev_handle, UAC_CTRL_UAC_MUTE, (void *)(setting == 0 ? 1 : 0));
}

static esp_err_t _audio_player_write_fn(void *audio_buffer, size_t len, size_t *bytes_written, uint32_t timeout_ms)
Expand Down Expand Up @@ -114,7 +114,7 @@ static void _audio_player_callback(audio_player_cb_ctx_t *ctx)
}
case AUDIO_PLAYER_CALLBACK_EVENT_PLAYING:
ESP_ERROR_CHECK(uac_host_device_start(s_spk_dev_handle));
ESP_ERROR_CHECK(uac_class_request_control(s_spk_dev_handle, UAC_CTRL_UAC_VOLUME, (void *)60));
ESP_ERROR_CHECK(uac_host_device_control(s_spk_dev_handle, UAC_CTRL_UAC_VOLUME, (void *)60));
ESP_LOGI(TAG, "AUDIO_PLAYER_REQUEST_PLAY");
break;
case AUDIO_PLAYER_CALLBACK_EVENT_PAUSE:
Expand Down Expand Up @@ -267,7 +267,7 @@ void app_main(void)
assert(s_event_queue != NULL);

static TaskHandle_t uac_task_handle = NULL;
BaseType_t ret = xTaskCreatePinnedToCore(uac_lib_task, "user_events", 4096, NULL,
BaseType_t ret = xTaskCreatePinnedToCore(uac_lib_task, "uac_events", 4096, NULL,
USER_TASK_PRIORITY, &uac_task_handle, 0);
assert(ret == pdTRUE);
ret = xTaskCreatePinnedToCore(usb_lib_task, "usb_events", 4096, (void *)uac_task_handle,
Expand Down
2 changes: 1 addition & 1 deletion host/class/uac/usb_host_uac/include/usb/uac_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ esp_err_t uac_host_device_printf_all_params(uac_host_device_handle_t uac_dev_han
*
* @return esp_err_t
*/
esp_err_t uac_class_request_control(uac_host_device_handle_t uac_dev_handle, uac_host_ctrl_t type, void *value);
esp_err_t uac_host_device_control(uac_host_device_handle_t uac_dev_handle, uac_host_ctrl_t type, void *value);

#ifdef __cplusplus
}
Expand Down
10 changes: 10 additions & 0 deletions host/class/uac/usb_host_uac/test_app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

set(EXTRA_COMPONENT_DIRS
../../usb_host_uac
)

project(test_app_usb_host_uac)
8 changes: 8 additions & 0 deletions host/class/uac/usb_host_uac/test_app/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include($ENV{IDF_PATH}/tools/cmake/version.cmake)

idf_component_register(SRC_DIRS .
INCLUDE_DIRS .
REQUIRES unity usb usb_host_uac)

# force-link test_host_uac.c
set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-u test_uac_setup")
57 changes: 57 additions & 0 deletions host/class/uac/usb_host_uac/test_app/main/test_app_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdio.h>
#include <string.h>
#include "unity.h"
#include "esp_heap_caps.h"

static size_t before_free_8bit;
static size_t before_free_32bit;

#define TEST_MEMORY_LEAK_THRESHOLD (-530)
static void check_leak(size_t before_free, size_t after_free, const char *type)
{
ssize_t delta = after_free - before_free;
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
}

void app_main(void)
{
// ____ ___ ___________________ __ __
// | | \/ _____/\______ \ _/ |_ ____ _______/ |_
// | | /\_____ \ | | _/ \ __\/ __ \ / ___/\ __\.
// | | / / \ | | \ | | \ ___/ \___ \ | |
// |______/ /_______ / |______ / |__| \___ >____ > |__|
// \/ \/ \/ \/
printf(" ____ ___ ___________________ __ __ \r\n");
printf("| | \\/ _____/\\______ \\ _/ |_ ____ _______/ |_ \r\n");
printf("| | /\\_____ \\ | | _/ \\ __\\/ __ \\ / ___/\\ __\\\r\n");
printf("| | / / \\ | | \\ | | \\ ___/ \\___ \\ | | \r\n");
printf("|______/ /_______ / |______ / |__| \\___ >____ > |__| \r\n");
printf(" \\/ \\/ \\/ \\/ \r\n");

UNITY_BEGIN();
unity_run_menu();
UNITY_END();
}

/* setUp runs before every test */
void setUp(void)
{
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
}

/* tearDown runs after every test */
void tearDown(void)
{
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
check_leak(before_free_8bit, after_free_8bit, "8BIT");
check_leak(before_free_32bit, after_free_32bit, "32BIT");
}
Loading

0 comments on commit 92b6da1

Please sign in to comment.