Documentation/translations/zh_CN/dev-tools/testing-overview.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/dev-tools/testing-overview.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/dev-tools/testing-overview.rst- Extension
.rst- Size
- 8346 bytes
- Lines
- 164
- Domain
- Support Tooling And Documentation
- Bucket
- Documentation
- Inferred role
- Support Tooling And Documentation: documentation
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/dev-tools/testing-overview.rst
:Translator: 胡皓文 Hu Haowen <2023002089@link.tyut.edu.cn>
============
内核测试指南
============
有许多不同的工具可以用于测试Linux内核,因此了解什么时候使用它们可能
很困难。本文档粗略概述了它们之间的区别,并阐释了它们是怎样糅合在一起
的。
编写和运行测试
==============
大多数内核测试都是用kselftest或KUnit框架之一编写的。它们都让运行测试
更加简化,并为编写新测试提供帮助。
如果你想验证内核的行为——尤其是内核的特定部分——那你就要使用kUnit或
kselftest。
KUnit和kselftest的区别
----------------------
.. note::
由于本文段中部分术语尚无较好的对应中文释义,可能导致与原文含义
存在些许差异,因此建议读者结合原文
(Documentation/dev-tools/testing-overview.rst)辅助阅读。
如对部分翻译有异议或有更好的翻译意见,欢迎联系译者进行修订。
KUnit(Documentation/dev-tools/kunit/index.rst)是用于“白箱”测
试的一个完整的内核内部系统:因为测试代码是内核的一部分,所以它能够访
问用户空间不能访问到的内部结构和功能。
因此,KUnit测试最好针对内核中较小的、自包含的部分,以便能够独立地测
试。“单元”测试的概念亦是如此。
比如,一个KUnit测试可能测试一个单独的内核功能(甚至通过一个函数测试
一个单一的代码路径,例如一个错误处理案例),而不是整个地测试一个特性。
这也使得KUnit测试构建和运行非常地快,从而能够作为开发流程的一部分被
频繁地运行。
有关更详细的介绍,请参阅KUnit测试代码风格指南
Documentation/dev-tools/kunit/style.rst
kselftest(Documentation/dev-tools/kselftest.rst),相对来说,大量用
于用户空间,并且通常测试用户空间的脚本或程序。
这使得编写复杂的测试,或者需要操作更多全局系统状态的测试更加容易(诸
如生成进程之类)。然而,从kselftest直接调用内核函数是不行的。这也就
意味着只有通过某种方式(如系统调用、驱动设备、文件系统等)导出到了用
户空间的内核功能才能使用kselftest来测试。为此,有些测试包含了一个伴
生的内核模块用于导出更多的信息和功能。不过,对于基本上或者完全在内核
中运行的测试,KUnit可能是更佳工具。
kselftest也因此非常适合于全部功能的测试,因为这些功能会将接口暴露到
用户空间,从而能够被测试,而不是展现实现细节。“system”测试和
“end-to-end”测试亦是如此。
比如,一个新的系统调用应该伴随有新的kselftest测试。
代码覆盖率工具
==============
支持两种不同代码之间的覆盖率测量工具。它们可以用来验证一项测试执行的
确切函数或代码行。这有助于决定内核被测试了多少,或用来查找合适的测试
Annotation
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.