How is the Linux kernel tested ?

2019-01-08 02:43发布

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?

12条回答
萌系小妹纸
2楼-- · 2019-01-08 03:18

Its not very easy to automate kernel testing. Most Linux developers do the testing on their own, much like adobriyan mentioned.

However, there are a few things that help with debugging the Linux Kernel:

  • 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.

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.

Edit: Here's a nice video detailing the process a patch goes through before it is integrated into the kernel.

查看更多
我只想做你的唯一
3楼-- · 2019-01-08 03:21

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:

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

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/

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.

There are also systems for dynamic analysis of Linux kernel:

Kmemleak is 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.

Kmemcheck traps 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

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.

查看更多
SAY GOODBYE
4楼-- · 2019-01-08 03:27

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

NOTE:- Linux Kernel will change according to requirements which depend on System Hardware

查看更多
Anthone
5楼-- · 2019-01-08 03:28

The linux kernel has a heavy emphasis on community testing.

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.

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 project and the kernel autotest (good overview).

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.

查看更多
forever°为你锁心
6楼-- · 2019-01-08 03:28

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.

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.

查看更多
小情绪 Triste *
7楼-- · 2019-01-08 03:30

In-tree tools

A good way to find test tools in the kernel is to:

In v4.0, this leads me to:

Kernel CI

https://kernelci.org/ is a project that aims to make kernel testing more automated and visible.

It appears to do only build and boot tests (TODO how to test automatically that boot worked Source should be at https://github.com/kernelci/).

Linaro seems to be the main maintainer of the project, with contributions from many big companies: https://kernelci.org/sponsors/

Linaro Lava

http://www.linaro.org/initiatives/lava/ looks like a CI system with focus on development board bringup and the Linux kernel.

ARM LISA

https://github.com/ARM-software/lisa

Not sure what it does in detail, but it is by ARM and Apache Licensed, so likely worth a look.

Demo: https://www.youtube.com/watch?v=yXZzzUEngiU

Step debuggers

Not really unit testing, but may help once your tests start failing:

查看更多
登录 后发表回答