Documentation/translations/zh_TW/dev-tools/testing-overview.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_TW/dev-tools/testing-overview.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_TW/dev-tools/testing-overview.rst- Extension
.rst- Size
- 8204 bytes
- Lines
- 163
- 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_TW.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.