Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[RFC][utest] Add audio driver test framework #10243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
Loading
from

Conversation

1078249029
Copy link
Contributor

@1078249029 1078249029 commented May 3, 2025

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

Fixed #10046

你的解决方案是什么 (what is your solution)

Achieve driver framework by operating memory to simulate audio peripheral drivers. And it could be as a draft standrad for other drivers test framework.

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/workflows/bsp_buildings.yml 详细请参考链接BSP自查

@1078249029 1078249029 requested a review from Rbb666 as a code owner May 3, 2025 14:32
@1078249029 1078249029 marked this pull request as draft May 3, 2025 14:32
int fd = -1;
int res = 0;
uint8_t *buffer = NULL;
void* player_buffer = NULL;struct rt_audio_caps caps = {0};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意下代码风格,加个换行吧

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

两个文件名称改成drv_xxx是不是更好些?

@1078249029 1078249029 force-pushed the audio_test branch 3 times, most recently from 2655d6a to 71847bc Compare May 10, 2025 04:39
@1078249029 1078249029 closed this May 10, 2025
@1078249029 1078249029 reopened this May 10, 2025
@Rbb666
Copy link
Member

Rbb666 commented May 10, 2025

@1078249029 这个PR准备好了吗?

@1078249029
Copy link
Contributor Author

1078249029 commented May 10, 2025

@1078249029 这个PR准备好了吗?

准备好了,麻烦您review下。
但是ci过不去,应该是utest组件下没有分配reviewer的问题?

@1078249029 1078249029 requested a review from Rbb666 May 10, 2025 09:21
@1078249029
Copy link
Contributor Author

@unicornx 老师,上次跟您说的音频测试框架已经写好了,您有空的话也请review?

@Rbb666 Rbb666 requested a review from unicornx May 12, 2025 02:31
@Rbb666 Rbb666 closed this May 12, 2025
@Rbb666 Rbb666 reopened this May 12, 2025
Copy link

github-actions bot commented May 12, 2025

📌 Code Review Assignment

🏷️ Tag: bsp_cvitek

Path: bsp/cvitek
Reviewers: @unicornx

Changed Files (Click to expand)
  • bsp/cvitek/cv18xx_aarch64/.config
  • bsp/cvitek/cv18xx_aarch64/rtconfig.h
  • bsp/cvitek/cv18xx_aarch64/rtconfig.py

📊 Current Review Status (Last Updated: 2025-05-15 12:43 UTC)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

Copy link
Contributor

@unicornx unicornx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我记得上次开会满老师 @mysterywolf 说建议后面 ut cases 都移到各个模块自己的目录下去,不要放到 examples 下了,本身这个 examples 就很让人迷惑。可以参考 src/klibc/utest 这个是满老师最新作的 utest 例子,貌似就是每个模块下自己维护一个 utest 目录然后在里面加测试代码。然后就是模仿 src/klibc/utest 下的代码写,包括 SConscript 里要 denpend RT_UTEST_USING_ALL_CASES ,还有配置选项名字统一加 'RT_UTEST_TC_USING_' 前缀,参考 'RT_UTEST_TC_USING_KLIBC'。

还有一个问题就是建议在测试代码中以注释的方式写一下测试的设计思想,直接 review 代码一下子不知道你的设计思路理解起来很费劲。这个测试代码需要依赖硬件吗?看注释有模拟的部分,可以说明一下。另外我理解这里测试的对象是 driver audio 的 API,所以 drv_mic.cdrv_player.c 应该是测试的主体,对吧。可以在注释中列一下你覆盖的 API 吗?

代码上,所有全局变量和函数,如果不是 extern 的请全部 static。

Copy link
Contributor

@unicornx unicornx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请每次更新后都和最新的 master 同步一下。

此外,几个问题先提一下,请一并和上面的同步问题一起先改掉。

  • commit 的标题中不要出现 RFC 的字样,PR 可以是 RFC。如果 commit 中含有 RFC,一旦 merge 这个 commit 看上去就怪怪的,除非提交人会及时改 commit,但实践上看做不到这个。PR 里写 RFC 或者设置 draft 状态都很方便,以后要改 PR 的标题也可以在网页上直接操作,但是 commit 一旦合入就很难改了。
  • commit 的标题前缀我觉得不是 utest,但是应该是属于 components: driver: audio 的因为按照现在的做法,utest 是属于子模块的,不再是单独的 utest,除非是涉及 utest 的 framework 的改动。
  • 文件名,我建议有 TC 前缀就够了,不用加 rt 前缀,所有文件默认都是 RTT 的,加 rt 前缀属于多余,而且导致文件名分段太多。另外我比较建议不要大写 TC,文件名全部小写比较好。
  • 只在内部使用的全局变量都要 static,好像没有改全。

@1078249029
Copy link
Contributor Author

  • 只在内部使用的全局变量都要 static,好像没有改全。

两个flag变量是用于同步驱动与应用层状态机的状态的,只能放在全局。其他方法例如使用全局信号量或者手动延时的效果都不是很好,前者既麻烦又与其他测试模块有依赖,后者太死板,所以这里就没有改。

@1078249029 1078249029 requested a review from unicornx May 15, 2025 04:01
Copy link
Contributor

@unicornx unicornx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#define thread_simulate_intr_create_stacksize 1024
static rt_thread_t thread_simulate_intr_handle;

struct mic_device mic_dev;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么不是 static?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个文件名为啥前后都有 tc,后面那个有什么含义吗?要不要改一个更有意义的名字?
看了你的代码,感觉 tc_audio_tc.c 是测试的主程序,譬如叫 tc_audio_main.c 或者直接叫 tc_audio.c?


struct mic_device mic_dev;

rt_uint8_t mic_flag = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥 mic_flag 定义在 tc_audio_drv_mic.c 里,而 player_flag 定义在 tc_audio_tc.c 里?
我建议统一定义在 tc_audio_tc.c ,甚至我觉得如果 player_testmic_test 不会同时跑的话,只要一个 flag 就好了, 因为这两个变量的作用应该是一回事且不会同时被使用。

另外我理解 mic_flag/player_flag 你是想表达一个类似测试过程中状态机的用于同步主程序和驱动之间的作用吧,flag 这个名字我觉得不能很清楚地表达意思,或许叫 step 更好?

* rt_audio_register or rt_audio_rx_done existing bugs.
*/

#include "TC_rt_audio_common.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你提交前编译过?

@unicornx
Copy link
Contributor

另外这个 PR 的状态为何还是 Draft,可以改成正常的了。

@github-actions github-actions bot added BSP BSP: Cvitek BSP related with cvitek labels May 15, 2025
@1078249029 1078249029 force-pushed the audio_test branch 2 times, most recently from 0270c43 to 977e108 Compare May 15, 2025 13:56
@1078249029 1078249029 requested a review from unicornx May 15, 2025 14:10
@1078249029 1078249029 marked this pull request as ready for review May 15, 2025 14:10
@supperthomas supperthomas requested a review from Copilot May 16, 2025 01:27
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a test framework for audio drivers by simulating audio peripherals using memory operations.

  • Added unit tests for audio player and microphone drivers.
  • Integrated simulation threads to trigger DMA-like behavior.
  • Updated build scripts and configuration options for audio driver tests.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
components/drivers/audio/utest/tc_audio_main.c Added unit tests for audio framework and memory verification logic.
components/drivers/audio/utest/tc_audio_drv_player.c Added player driver simulation and interrupt thread for DMA behavior.
components/drivers/audio/utest/tc_audio_drv_mic.c Added microphone driver simulation and interrupt thread for DMA behavior.
components/drivers/audio/utest/tc_audio_common.h New header with shared definitions and constants for driver tests.
components/drivers/audio/utest/SConscript Updated SConscript to include audio test cases.
components/drivers/audio/SConscript Modified build script to recursively include SConscript files.
components/drivers/audio/Kconfig Added new configuration option for audio driver test cases.
Comments suppressed due to low confidence (1)

components/drivers/audio/utest/tc_audio_drv_player.c:15

  • [nitpick] Consider renaming 'thread_simulate_intr_create_stacksize' to uppercase (e.g., THREAD_SIMULATE_INTR_CREATE_STACKSIZE) for consistency with other macro names.
#define thread_simulate_intr_create_stacksize 1024

Comment on lines 113 to 121
while (1)
{
if(fsm_step == 2)
{
break;
}
rt_thread_mdelay(10);
}

Copy link
Preview

Copilot AI May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The busy-wait loop here could be improved by using an event-driven mechanism or proper signaling to avoid unnecessary CPU usage during test execution.

Suggested change
while (1)
{
if(fsm_step == 2)
{
break;
}
rt_thread_mdelay(10);
}
rt_sem_t fsm_sem = rt_sem_create("fsm_sem", 0, RT_IPC_FLAG_FIFO);
if (fsm_sem == RT_NULL)
{
rt_kprintf("Failed to create semaphore\n");
uassert_true(0);
goto __exit;
}
/* Wait for fsm_step to be updated to 2 */
rt_sem_take(fsm_sem, RT_WAITING_FOREVER);
/* Clean up semaphore */
rt_sem_delete(fsm_sem);

Copilot uses AI. Check for mistakes.

Positive FeedbackNegative Feedback
Comment on lines 29 to 53
if(fsm_step == 2)
{
/* Send the the data(0x55) from DMA buffer to kernel */
rt_memset((void*)&mic_dev.rx_fifo[RX_DMA_BLOCK_SIZE], 0x55, RX_DMA_BLOCK_SIZE);
rt_audio_rx_done(&mic_dev.audio, &mic_dev.rx_fifo[RX_DMA_BLOCK_SIZE], RX_DMA_BLOCK_SIZE);
fsm_step = 3;
break;
}
if(fsm_step == 4)
{
rt_thread_mdelay(10);
rt_audio_rx_done(&mic_dev.audio, &mic_dev.rx_fifo[RX_DMA_BLOCK_SIZE], RX_DMA_BLOCK_SIZE);
break;
}
rt_thread_mdelay(10);
}

while(1)
{
rt_thread_mdelay(10);
}
}

static void thread_simulate_intr_create(void)
{
Copy link
Preview

Copilot AI May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider replacing the busy-wait loop with an event-driven or signaling mechanism to improve efficiency in the test thread.

Suggested change
if(fsm_step == 2)
{
/* Send the the data(0x55) from DMA buffer to kernel */
rt_memset((void*)&mic_dev.rx_fifo[RX_DMA_BLOCK_SIZE], 0x55, RX_DMA_BLOCK_SIZE);
rt_audio_rx_done(&mic_dev.audio, &mic_dev.rx_fifo[RX_DMA_BLOCK_SIZE], RX_DMA_BLOCK_SIZE);
fsm_step = 3;
break;
}
if(fsm_step == 4)
{
rt_thread_mdelay(10);
rt_audio_rx_done(&mic_dev.audio, &mic_dev.rx_fifo[RX_DMA_BLOCK_SIZE], RX_DMA_BLOCK_SIZE);
break;
}
rt_thread_mdelay(10);
}
while(1)
{
rt_thread_mdelay(10);
}
}
static void thread_simulate_intr_create(void)
{
rt_sem_take(fsm_step_sem, RT_WAITING_FOREVER); // Wait for state change signal
if (fsm_step == 2)
{
/* Send the data(0x55) from DMA buffer to kernel */
rt_memset((void*)&mic_dev.rx_fifo[RX_DMA_BLOCK_SIZE], 0x55, RX_DMA_BLOCK_SIZE);
rt_audio_rx_done(&mic_dev.audio, &mic_dev.rx_fifo[RX_DMA_BLOCK_SIZE], RX_DMA_BLOCK_SIZE);
fsm_step = 3;
}
else if (fsm_step == 4)
{
rt_audio_rx_done(&mic_dev.audio, &mic_dev.rx_fifo[RX_DMA_BLOCK_SIZE], RX_DMA_BLOCK_SIZE);
}
}
}
static void thread_simulate_intr_create(void)
{
fsm_step_sem = rt_sem_create("fsm_step_sem", 0, RT_IPC_FLAG_FIFO); // Create semaphore
if (fsm_step_sem == RT_NULL)
{
rt_kprintf("Error: Failed to create semaphore!\n");
return;
}

Copilot uses AI. Check for mistakes.

Positive FeedbackNegative Feedback
Achieve driver framework by operating memory to simulate audio
peripheral drivers. And it could be as a draft standrad for other
drivers test framework.

Signed-off-by: 1078249029 <1078249029@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] [doxygen] [audio] A plan to achieve audio components doxygen comments
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.