Linux内核开发人员在提交代码后如何在本地测试他们的代码?他们是否使用某种单元测试和构建自动化?测试计划?
当前回答
adobriyan提到了Ingo的随机配置构建测试循环。现在,零日测试机器人(又名kbuild测试机器人)几乎涵盖了这一点。这里有一篇关于基础结构的不错的文章:内核构建/引导测试
这种设置背后的想法是尽快通知开发人员,以便他们能够尽快纠正错误(在某些情况下,在补丁进入Linus的树之前,因为kbuild基础设施也会针对维护人员的子系统树进行测试)。
其他回答
自动化内核测试并不容易。大多数Linux开发人员自己进行测试,就像adobriyan提到的那样。
然而,有一些事情可以帮助调试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.
然后,开发人员通常会让其他人检查他们的补丁。一旦补丁在本地被检查,并且没有干扰其他任何东西,并且补丁被测试与来自Linus的最新内核一起工作而没有破坏任何东西,补丁就会被推送到上游。
这里有一个很好的视频,详细介绍了一个补丁在集成到内核之前所经历的过程。
LTP和memtest通常是首选工具。
我曾经做过Linux内核编译,并对Android (Android 6.0 (Marshmallow)和Android 7.0 (Nougat))做过一些修改,其中我使用的是Linux版本3。我在Linux系统上交叉编译它,手动调试错误,然后在Android上运行它的引导映像文件,检查它是否进入了一个漏洞。如果它运行完美,则意味着它根据系统需求进行了完美的编译。
用于MotoG内核编译
注意:Linux内核将根据依赖于系统硬件的需求进行更改
据我所知,英特尔有一个自动性能回归检查工具(名为lkp/0 day)运行/资助。它将测试发送到邮件列表的每个有效补丁,并检查从不同的微基准测试(如hackbench, fio, unixbench, netperf等)更改的分数。
一旦出现性能下降/改进,相应的报告将直接发送给补丁作者和Cc相关的维护者。
除了其他答案外,本文更强调Linux内核的功能测试、硬件认证测试和性能测试。
大量的测试实际上是通过脚本、静态代码分析工具、代码审查等进行的,这对于捕获错误非常有效,否则会破坏应用程序中的某些东西。
稀疏-一个开源工具,旨在发现Linux内核中的错误。
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 for it. 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.