如何测试 Linux 内核?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3177338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How is the Linux kernel tested ?
提问by Ashkan Kh. Nazary
How do the Linux kernel developers test their code locally and after they have it committed? Do they use some kind of unit testing, build automation? test plans?
Linux 内核开发人员如何在本地和提交代码后测试他们的代码?他们是否使用某种单元测试,构建自动化?测试计划?
回答by adobriyan
How do the Linux kernel developers test their code locally and after they have it committed?
Do they use some kind of unit testing, build automation?
Linux 内核开发人员如何在本地和提交代码后测试他们的代码?
他们是否使用某种单元测试,构建自动化?
In classic sense of words, no.
用经典的话来说,不。
E. g. Ingo Molnar is running the following workload: 1. build new kernel with random set of config options 2. boot into it 3. goto 1
例如 Ingo Molnar 正在运行以下工作负载: 1. 构建具有随机配置选项集的新内核 2. 启动它 3. 转到 1
Every build fail, boot fail, BUG or runtime warning is dealt with. 24/7. Multiply by several boxes, and one can uncover quite a lot of problems.
处理每个构建失败、启动失败、BUG 或运行时警告。24/7。乘以几个盒子,可以发现不少问题。
test plans?
测试计划?
No.
不。
There may be misunderstanding that there is central testing facility, there is none. Everyone does what he wants.
可能会有误解,认为有中央测试设施,没有。每个人都做他想做的事。
回答by emcee
I would imagine they use virtualization to do quick tests, something like QEMU, VirtualBox or Xen, and some scripts to perform configurations and automated tests.
我想他们使用虚拟化来进行快速测试,比如 QEMU、VirtualBox 或 Xen,以及一些脚本来执行配置和自动化测试。
Automated testing is probably done by trying either many random configurations or a few specific ones (if they are working with a specific issue). Linux has a lot of low-level tools (such as dmesg) to monitor and log debug data from the kernel, so I imagine that is used as well.
自动化测试可能是通过尝试许多随机配置或一些特定配置(如果他们正在处理特定问题)来完成的。Linux 有很多低级工具(例如 dmesg)来监视和记录来自内核的调试数据,所以我想也可以使用它。
回答by JosephH
The linux kernel has a heavy emphasis on community testing.
linux 内核非常重视社区测试。
Typically any developer will test their own code before submitting, and quite often they will be using a development version of the kernel from Linus, or one of the other unstable/development trees for a project relevant to their work. This means they are often testing both their changes and other people's changes.
通常,任何开发人员都会在提交之前测试他们自己的代码,而且他们经常会使用来自 Linus 的内核的开发版本,或者其他不稳定/开发树之一用于与他们的工作相关的项目。这意味着他们经常同时测试他们的变化和其他人的变化。
There tend not to be much in the way of formal test plans, but extra testing may be asked for before features are merged into upstream trees.
正式测试计划的方式往往不多,但在功能合并到上游树之前可能会要求进行额外的测试。
As Dean pointed out, there's also some automated testing, the linux test projectand the kernel autotest(good overview).
正如 Dean 指出的那样,还有一些自动化测试、linux 测试项目和内核自动测试(很好的概述)。
Developers will often also write automated tests targetted to test their change, but I'm not sure there's a (often used) mechanism to centrally collect these adhoc tests.
开发人员通常也会编写自动化测试来测试他们的更改,但我不确定是否有(经常使用的)机制来集中收集这些临时测试。
It depends a lot on which area of the kernel is being changed of course - the testing you'd do for a new network driver is quite different to the testing you'd do when replacing the core scheduling algorithm.
当然,这很大程度上取决于正在更改内核的哪个区域 - 您对新网络驱动程序所做的测试与替换核心调度算法时所做的测试完全不同。
回答by Vanwaril
Its not very easy to automate kernel testing. Most Linux developers do the testing on their own, much like adobriyan mentioned.
自动化内核测试并不容易。大多数 Linux 开发人员自己进行测试,就像 adobriyan 提到的那样。
However, there are a few things that help with debugging the Linux Kernel:
但是,有一些事情可以帮助调试 Linux 内核:
- kexec:A system call that allows you to put another kernel into memory and reboot without going back to the BIOS, and if it fails, reboot back.
- dmesg:Definitely the place to look for information about what happened during the kernel boot and whether it works/doesn't work.
- Kernel Instrumentation:In addition to printk's (and an option called 'CONFIG_PRINTK_TIME' which allows you to see (to microsecond accuracy) when the kernel output what), the kernel configuration allows you to turn on a LOT of tracers that enable them to debug what is happening.
- kexec:一个系统调用,允许您将另一个内核放入内存并重新启动,而无需返回 BIOS,如果失败,则重新启动。
- dmesg:绝对是查找有关内核启动期间发生的事情以及它是否有效/无效的信息的地方。
- 内核检测:除了 printk(以及一个名为“CONFIG_PRINTK_TIME”的选项,它允许您查看(精确到微秒级)内核何时输出什么),内核配置允许您打开许多跟踪器,使它们能够调试什么正在发生。
Then, developers usually have others review their patches. Once the patches are reviewed locally and seen not to interfere with anything else, and the patches are tested to work with the latest kernel from Linus without breaking anything, the patches are pushed upstream.
然后,开发人员通常会让其他人他们的补丁。一旦补丁在本地进行并且发现不会干扰其他任何东西,并且补丁经过测试可以与来自 Linus 的最新内核一起使用而不会破坏任何东西,补丁就会被推送到上游。
Edit:Here's a nice videodetailing the process a patch goes through before it is integrated into the kernel.
编辑:这是一个很好的视频,详细介绍了补丁在集成到内核之前所经历的过程。
回答by Karen Tsirunyan
Naturally, the kernel itself and its parts are tested prior to the release, but these tests cover only the basic functionality. There are some testing systems which perform testing of Linux Kernel:
自然,内核本身及其部分在发布之前进行了测试,但这些测试仅涵盖基本功能。有一些测试系统可以对 Linux 内核进行测试:
The Linux Test Project (LTP)delivers test suites to the open source community that validate the reliability and stability of Linux. The LTP test suite contains a collection of tools for testing the Linux kernel and related features. https://github.com/linux-test-project/ltp
Linux 测试项目 (LTP)向开源社区提供测试套件,以验证 Linux 的可靠性和稳定性。LTP 测试套件包含一组用于测试 Linux 内核和相关功能的工具。https://github.com/linux-test-project/ltp
Autotest-- a framework for fully automated testing. It is designed primarily to test the Linux kernel, though it is useful for many other purposes such as qualifying new hardware, virtualization testing, and other general user space program testing under Linux platforms. It's an open-source project under the GPL and is used and developed by a number of organizations, including Google, IBM, Red Hat, and many others. http://autotest.github.io/
Autotest——一个完全自动化测试的框架。它主要用于测试 Linux 内核,但它也可用于许多其他目的,例如验证新硬件、虚拟化测试和 Linux 平台下的其他一般用户空间程序测试。它是 GPL 下的一个开源项目,被许多组织使用和开发,包括 Google、IBM、Red Hat 和许多其他组织。http://autotest.github.io/
Also there are certification systems developed by some major GNU/Linux distribution companies. These systems usually check complete GNU/Linux distributions for compatibility with hardware. There are certification systems developed by Novell, Red Hat, Oracle, Canonical, Google.
还有一些主要的 GNU/Linux 发行公司开发的认证系统。这些系统通常会检查完整的 GNU/Linux 发行版是否与硬件兼容。有Novell、Red Hat、Oracle、Canonical、Google开发的认证系统。
There are also systems for dynamic analysis of Linux kernel:
Linux内核的动态分析也有系统:
Kmemleakis a memory leak detector included in the Linux kernel. It provides a way of detecting possible kernel memory leaks in a way similar to a tracing garbage collector with the difference that the orphan objects are not freed but only reported via /sys/kernel/debug/kmemleak.
Kmemleak是包含在 Linux 内核中的内存泄漏检测器。它提供了一种以类似于跟踪垃圾收集器的方式检测可能的内核内存泄漏的方法,不同之处在于孤儿对象不会被释放,而是仅通过 /sys/kernel/debug/kmemleak 报告。
Kmemchecktraps every read and write to memory that was allocated dynamically (i.e. with kmalloc()). If a memory address is read that has not previously been written to, a message is printed to the kernel log. Also is a part of Linux Kernel
Kmemcheck捕获对动态分配的内存(即使用 kmalloc())的每次读取和写入。如果读取了先前未写入的内存地址,则会在内核日志中打印一条消息。也是 Linux 内核的一部分
Fault Injection Framework(included in Linux kernel) allows for infusing errors and exceptions into an application's logic to achieve a higher coverage and fault tolerance of the system.
故障注入框架(包含在 Linux 内核中)允许将错误和异常注入应用程序的逻辑中,以实现更高的系统覆盖率和容错能力。
回答by metan
There also are:
还有:
MMTestswhich is collection of benchmarks and scripts to analyze the results
MMTests是用于分析结果的基准测试和脚本的集合
https://github.com/gormanm/mmtests
https://github.com/gormanm/mmtests
Trinitywhich is Linux system call fuzz tester
Trinity是 Linux 系统调用模糊测试器
http://codemonkey.org.uk/projects/trinity/
http://codemonkey.org.uk/projects/trinity/
Also the LTPpages at the sourceforge are quite outdated and the project has moved to GitHub https://github.com/linux-test-project/ltp
此外,sourceforge 上的LTP页面已经过时,该项目已移至 GitHub https://github.com/linux-test-project/ltp
回答by askb
In addition to above/below points, which emphasis more on the functionality testing, hardware certification testing and performance testing the Linux kernel.
除了以上/以下几点之外,更强调Linux内核的功能测试、硬件认证测试和性能测试。
A lot a testing actually happen through, actually scripts, static code analysis tools, code reviews etc. which is very efficient in catching bugs, which would otherwise break something in the application.
许多测试实际上是通过脚本、静态代码分析工具、代码等实际发生的,这在捕获错误方面非常有效,否则会破坏应用程序中的某些内容。
Sparse– An open-source tool designed to find faults in the Linux kernel.
Sparse– 一种开源工具,旨在查找 Linux 内核中的故障。
Coccinelleis another program does matching and transformation engine which provides the language SmPL (Semantic Patch Language) for specifying desired matches and transformations in C code.
Coccinelle是另一个执行匹配和转换引擎的程序,它提供语言 SmPL(语义补丁语言),用于在 C 代码中指定所需的匹配和转换。
checkpatch.pl and other scripts- coding style issues can be found in the file Documentation/CodingStyle in the kernel source tree. The important thing to remember when reading it is not that this style is somehow better than any other style, just that it is consistent. this helps developers easily find and fix coding style issues, the script scripts/checkpatch.pl in the kernel source tree has been developed. This script can point out problems easily, and should always be run by a developer on their changes, instead of having a reviewer waste their time by pointing out problems later on.
checkpatch.pl 和其他脚本- 编码风格问题可以在内核源代码树中的文件 Documentation/CodingStyle 中找到。阅读时要记住的重要一点不是这种风格在某种程度上比任何其他风格都好,只是它是一致的。这有助于开发人员轻松查找和修复编码风格问题,内核源代码树中的脚本脚本/checkpatch.pl 已开发。这个脚本可以很容易地指出问题,并且应该始终由开发人员根据他们的更改运行,而不是让审阅者稍后指出问题来浪费他们的时间。
回答by Pradeep Goswami
LTP and Memtests are generally preferred tools.
LTP 和 Memtests 通常是首选工具。
回答by krisharav
adobriyan mentioned Ingo's loop of random config build testing. That is pretty much now covered by the 0-day test bot (aka kbuild test bot). A nice article about the infrastructure is presented here:Kernel Build/boot testing
adobriyan 提到了 Ingo 的随机配置构建测试循环。现在 0 天测试机器人(又名 kbuild 测试机器人)几乎涵盖了这一点。这里提供了一篇关于基础设施的好文章:内核构建/启动测试
The idea behind this set-up is to notify the developers ASAP so that they can rectify the errors soon enough. (before the patches make it into Linus' tree in some cases as the kbuild infrastructure also tests against maintainer's subsystem trees)
此设置背后的想法是尽快通知开发人员,以便他们能够尽快纠正错误。(在某些情况下,在补丁进入 Linus 的树之前,因为 kbuild 基础设施还针对维护者的子系统树进行测试)
回答by Vineet Jain
I had done linux kernel compilation and done some Modifications for android(Marshmallow and Nougat) in which I use linux version 3. I cross-compiled it in linux system, debug the errors manually and then run its boot image file in Android and check if it was going in loop-hole or not. If it runs perfect then it means it is compiled perfectly according to system requirements.
For MotoG kernel Compilation
我已经完成了 linux 内核编译并为 android(棉花糖和牛轧糖)做了一些修改,其中我使用了 linux 版本 3。我在 linux 系统中交叉编译它,手动调试错误,然后在 Android 中运行它的启动映像文件并检查是否它是否进入了漏洞。如果它运行完美,则意味着它是根据系统要求完美编译的。
MotoG内核编译
NOTE:-Linux Kernel will change according to requirements which depend on System Hardware
注意:-Linux 内核会根据系统硬件的要求而改变