-
Notifications
You must be signed in to change notification settings - Fork 5.3k
utest: re-org utest framework (initial version) #10534
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
Conversation
@Yaochenger @kurisaW 请 review。 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
🏷️ Tag: kernelReviewers: @GorrayLi @ReviewSun @hamburger-os @lianux-mm @wdfk-prog @xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2025-08-25 16:39 CST)
📝 Review Instructions
|
a15c073
to
84bad87
Compare
改了,但是 ci 又报了其他的错误 :( |
修改建议:
建议修改为:
将rsource "$RTT_DIR替换为source "$(RTT_DIR) |
7be5936
to
d23006e
Compare
1d38849
to
92aa975
Compare
我发现导致 dist 的 ci 失败的原因是在于运行 def bsp_update_kconfig_testcases(dist_dir):
# delete testcases in rt-thread/Kconfig
if not os.path.isfile(os.path.join(dist_dir, 'rt-thread/Kconfig')):
return
with open(os.path.join(dist_dir, 'rt-thread/Kconfig'), 'r') as f:
data = f.readlines()
with open(os.path.join(dist_dir, 'rt-thread/Kconfig'), 'w') as f:
for line in data:
if line.find('examples/utest/testcases/Kconfig') == -1:
f.write(line) 会跳过 cd bsp/stm32/stm32f407-atk-explorer/
scons --dist
cd dist/project/rt-thread/
scons --menuconfig
scons: Reading SConscript files ...
menuconfig: rt-thread/components/utilities/utest/Kconfig:10: 'rt-thread/components/utilities/utest/../../../examples/utest/testcases/utest/Kconfig' not found (in 'rsource "../../../examples/utest/testcases/utest/Kconfig"'). Check that environment variables are set correctly (e.g. $srctree, which is unset or blank). Also note that unset environment variables expand to the empty string. 但具体原因不知道是否有人可以解释一下, dist 中这里这么做的目的是什么,我发现在 dist 后的 这实际上存在一个悖论,就是以后 utest 的内容我们在 dist 中是否需要保留?因为以后的设计思路是 utest 的 testcase 都会放到各个模块自己的目录下,不像现在都是放在 example 的 utest 下,所以我不清楚当时设计 dist 时是怎么考虑这个问题的。如果沿袭原来的思路,utest 的testcase 是不参与 dist 的,但是按照我现在的思路,utest 作为每个模块的组成部分,和 example 不是一回事情。dist 时我理解是需要和模块一起打包的。 此外,我发现和 bsp_update_kconfig_testcases 类似的处理还有一处,就是 tools/env_utility.py 中的 exclude_utestcases 函数。摘录如下: # Exclude utestcases
def exclude_utestcases(RTT_ROOT):
if os.path.isfile(os.path.join(RTT_ROOT, 'examples/utest/testcases/Kconfig')):
return
if not os.path.isfile(os.path.join(RTT_ROOT, 'Kconfig')):
return
with open(os.path.join(RTT_ROOT, 'Kconfig'), 'r') as f:
data = f.readlines()
with open(os.path.join(RTT_ROOT, 'Kconfig'), 'w') as f:
for line in data:
if line.find('examples/utest/testcases/Kconfig') == -1:
f.write(line) 这里也有类似的逻辑,搜索 exclude_utestcases 的调用处,分别是在 tools/env_utility.py 中的 menuconfig/guiconfig/defconfig 三处,目前还不清楚这里是何目的? |
我个人猜测example原本的目的是不应该参与构建的(除了utest目录,其余似乎看起来都没有加构建脚本),仅作为一个参考设计,因此在dist中会被排除构建,所以起初utest被放到example中就是不合理的,建议直接放到如下路径,后面再慢慢推动utest的分布式构建: components/utilities/utest 另外针对你的解决方法,我持赞同意见:
|
我也同意这种改法,将example中的部分逐渐分布到各个目录下面,dist出的工程也可也保留测试用例内容 |
Change the entry of utest's Kconfig from 'examples/utest/testcases/Kconfig' to 'Kconfig.utestcases'. Modified the build scripts where the path name is "examples/utest/testcases/Kconfig" and changed it to 'Kconfig.utestcases', otherwise build operations such 'scons --dist' may fail. In the future, the testcase source code of utest will be placed in each module for maintenance, but the entry of Kconfig will all be placed in Kconfig.utestcases for unified maintenance. In this way, when executing menuconfig, people can enter and configure from one place, avoiding searching for utest configuration switches here and there in the menuconfig interface. For each module, you can maintain unit-test in a unified manner in the following way: - Create a subdirectory named 'utest' in the directory where your module is located. - Store the following files in the utest subdirectory: - Unit test case program source code files for this module. - Kconfig file, add configuration options for the unit test files of this module, the recommended option is named RT_UTEST_TC_USING_XXXX, XXXX is the global unique module name of this module. - SConscript file, note that when adding src files, in addition to relying on RT_UTEST_TC_USING_XXXX, you must also rely on RT_UTEST_USING_ALL_CASES, the two dependencies are in an "or" relationship. The role of RT_UTEST_USING_ALL_CASES is that once this option is turned on, all unit tests will be enabled to avoid selecting one by one. After completing the above steps, add the path of the Kconfig file of utest of this module to the Kconfig.utestcases file. Signed-off-by: Chen Wang <[email protected]>
Signed-off-by: Chen Wang <[email protected]>
Signed-off-by: Chen Wang <[email protected]>
92aa975
to
7f72449
Compare
@kurisaW @Rbb666 @Yaochenger 我改了第二版,请 review, 现在 ci check 没问题了。 |
@Rbb666 merge 时最好保留 3 个 commit,不要压缩,谢谢 |
Kconfig.utestcases放到根目录下看起来感觉会不会不太美观啊,也不规范,我还是保留之前的想法,bsp_update_kconfig_testcases和exclude_utestcases可以删掉或者给注释掉,然后: 'examples/utest/testcases/Kconfig 换成本 PR 中 Kconfig 里的 "components/utilities/utest/Kconfig" 即可。 dist的工程我觉得保留utest是没有影响的,对我来说是希望存在的,唯一来说目前可以看得到的影响就是需要在链接段加入utest的代码段,这个感觉影响不大 |
我原来是放在 每个模块的 Kconfig 应该负责本模块的配置定义,所以 所以我们现在实际上是需要定义一个 RTT 全局的单元测试集合的条目表,这是一个非常 high level 的 Kconfig,所以我觉得放在 RTT 的根目录下其实并不过分,原来我曾经考虑在 RTT 根目录下建一个目录 utestcases 下面放一个 Kconfig 文件,即 另外你说的 |
另外补充一下,将 |
LGTM |
我的意思是这样:由于后续utest采用分布式策略,对应的测试用例都是归属在内核、组件目录下,而example本身是并没有构建系统的(scons脚本),在执行构建时并不会将其加入其中,那么原本在example下的utest彻底剥离出去后,其实也只有一个utest相关的Kconfig文件是需要的,那么这部分可以直接统一放在根目录下的Kconfig里是不是会好些,当然这部分前提是需要将example下的utest全部都剥离完,那么上述工作都做完之后, |
跟汪老师讨论过了,先按照汪老师这种想法去推进,由汪老师来负责主导这部分工作,一点点推进utest分布式,那最终的一个效果就是会剔除掉example下所有的utest相关项,以及 同时默认显示的效果就是menuconfig下在一级目录下显示utest相关配置项,并且对应二级、三级... 我这边没啥问题了 |
LGTM |
After "utest: re-org utest framework (initial version)" (PR RT-Thread#10534) was merged, adding a document to introduce how to add utest-cases for your module. Signed-off-by: Chen Wang <[email protected]>
After "utest: re-org utest framework (initial version)" (PR #10534) was merged, adding a document to introduce how to add utest-cases for your module. Signed-off-by: Chen Wang <[email protected]>
具体需求来源参考:#10513。
本 PR 是本工作的第一步,主要做了如下工作:
将 utest 的 Kconfig 的入口从
examples/utest/testcases/Kconfig
改为Kconfig.utestcases
。单元测试对于内核来说是一个非常重要的模块,放在 examples 下不合适。以后的 utest 的 testcase 源码会分别放到各个模块下自己维护,但是 Kconfig 的入口会放在
Kconfig.utestcases
中统一维护。这样在执行诸如 menuconfig 时可以统一从一个地方进入进行配置,避免在 menuconfig 界面中到处寻找 utest 的配置开关。对于各个模块来说,以后可以按照如下方式统一维护单元测试用例:
utest
的子目录RT_UTEST_TC_USING_XXXX
,XXXX 为本模块的全局唯一模块名。RT_UTEST_TC_USING_XXXX
还要依赖RT_UTEST_USING_ALL_CASES
,两者是 or 的关系。RT_UTEST_USING_ALL_CASES
的作用是一旦打开这个选项,则所有的单元测试都会启用,避免逐个选择。目前整个内核源码树下基于 utest 框架实现的单元测试,除了
examples/utest/testcases
外,只有components/drivers/audio/utest/
和src/klibc/utest/
两处,本 PR 将这两处的 Kconfig 选项也集成到Kconfig.utestcases
下。注意:本 PR 并没有将
examples/utest/testcases
下的 c 源码挪到他们该属于的模块下去,这部分工作将作为后续工作逐渐展开。本 PR 为方便 review,分为三个 commit:
examples/utest/testcases/Kconfig
改为Kconfig.utestcases
。src/klibc/utest/
的 Kconfig 选项也集成到Kconfig.utestcases
下。components/drivers/audio/utest/
的 Kconfig 选项也集成到Kconfig.utestcases
下。