Brief introduction to kselftest

18
Brief Introduction to Kselftest SeongJae Park <[email protected]>

Transcript of Brief introduction to kselftest

Page 1: Brief introduction to kselftest

Brief Introduction to Kselftest

SeongJae Park <[email protected]>

Page 2: Brief introduction to kselftest

This work by SeongJae Park is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To

view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.

Page 3: Brief introduction to kselftest

These slides were presented during 2nd Korea Linux Kernel Community Meetup

(http://onoffmix.com/event/99896)

Page 4: Brief introduction to kselftest

Nice To Meet You

SeongJae Park

[email protected]

Part time programmer at KOSSLAB

Page 5: Brief introduction to kselftest

● Linus Torvalds always want us to test the kernel, but, how?

``Go out and test’’, but, how?

Date: Mon, 19 Jun 2017 23:04:15 +0800

From: Linus Torvalds <[email protected]>

To: Linux Kernel Mailing List <[email protected]>

Subject: Linux 4.12-rc6

...

The good news is that rc6 is smaller than rc5 was, and I think we're

...

Go out and test,

Linus

Page 6: Brief introduction to kselftest

The Way to Test Kernel

● Simplest way: Build, boot, and use the kernel○ It covers many important test cases, but limited and not funny (We do this just for fun, right?)

Page 7: Brief introduction to kselftest

The Ways to Test Linux Kernel Automatically

● Many automatic test suites, framework, and services for the kernel exists○ Linux Test Project (https://linux-test-project.github.io/)○ Zero-day service (https://01.org/lkp/documentation/0-day-test-service)○ Kernel-ci.org (https://kernelci.org/)○ mmtests (https://github.com/gormanm/mmtests)○ More and more...

● However, fetching, configuring, running, and waiting them could be a little difficult to some developers

● Need more developer-friendly tests for more test

https://cdn.meme.am/instances/500x/66745140/y-u-no-jenkins-y-u-no-hate-me.jpg

Page 8: Brief introduction to kselftest

Kselftest: Kernel Self Test

● Set of developer-friendly test framework and tests for the kernel● Goal is to help developers do test more easily and more frequently● May not cover entire case,

but incomplete test is much better than just praying● Discussed from 2014 kernel summit (https://lwn.net/Articles/608959/)● Maintained by Shuah Kahn <[email protected]>

https://vignette4.wikia.nocookie.net/simpsons/images/8/88/Self-Test_Monthly.jpg/revision/latest?cb=20130611172738

Page 9: Brief introduction to kselftest

Kselftest is Contained in The Kernel Source Code

● You have the test if you have the kernel source code○ Under tools/testing/selftests

● For newest selftest, use the git repository at https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/

● Select master, next, devel, or fixes branch for your purpose● next: Content for upcoming merge window● fixes: Fixes to current -rc release are contained● devel: Experimental patches are contained

http://nothingbutpenguins.com/wp-content/uploads/2010/09/test-tube-penguin.jpg

Page 10: Brief introduction to kselftest

Kselftest Runs Quickly

● Many tests require long running time○ Mel Gorman’s test takes thirteen days○ Paul McKenney’s rcutorture takes six hours (https://lwn.net/Articles/608959/)

● Long running tests will not be accepted as default test● Current goal is under 20 minutes● Kselftest default run takes about 9 minutes on my PC

https://lc-www-live-s.legocdn.com/r/www/r/catalogs/-/media/catalogs/characters/dc/mugshots/76012_flash_1488x1984_mugshot_360w_2x.png?l.r2=-1920023313

Page 11: Brief introduction to kselftest

Build and Run

● First, boot with the kernel● Build

○ # make -C tools/testing/selftests

● Run○ # make -C tools/testing/selftests run_tests

○ The command does build if build has not done yet

● Simplest way to build and run:○ # make kselftest

● Some tests require root privilege, but running them without the privilege should not make serious problem

Page 12: Brief introduction to kselftest

Running Subset of Tests Only

● If you have interest in specific tests only, you can build and run them only○ # make TARGETS=<name of tests> kselftest

http://www.futuresmag.com/sites/default/files/styles/300x225/public/futuresmag/article/2014/01/19/cherry%20pick.jpg?itok=1UFRfqCJ

Page 13: Brief introduction to kselftest

Install Kselftest

● The tests can be installed in anywhere (e.g., other system that connected with nfs) you want

○ $ cd tools/testing/selftests; ./kselftest_install.sh [install location]

● To run the installed tests○ # cd [install localtion/]kselftest; ./run_kselftest.sh

Page 14: Brief introduction to kselftest

Packaging kselftest

● The tests can be packaged as tarball○ $ ./gen_kselftest_tar.sh [tar|targz|tarbz2|tarxz]

● The package can be installed and run at anywhere (e.g., tiny testing machine without gcc or make)

○ # tar xf ./kselftest.tar.gz; cd kselftest; ./run_kselftest.sh

https://rcstalon.files.wordpress.com/2013/10/cat-in-a-cat-box.jpg

Page 15: Brief introduction to kselftest

Adding Your New Test

● Insert your test code and Makefile for the test under selftests/<test name>/● The Makefile should include selftests/lib.mk and define your test

program(s) as TEST_PROGS● Add your <test name> to TARGETS in selftests/Makefile

selftests/sjpark$ cat MakefileCFLAGS = -Wall -O2 -g

TEST_PROGS := sjtestTEST_GEN_FILES = sjtest

include ../lib.mk

selftests/sjpark$ cat sjtest.c#include <stdio.h>

int main(void){ printf("hello world\n"); return 0;}

Page 16: Brief introduction to kselftest

Kselftest can be a Start Point to the Kernel

● In many case, test code is a good document to the program○ If you can judge a behavior of an instance as success or fail,

you are understanding the function

● If you are new to the kernel, kselftest can be a good start point

https://www.icas.com/__data/assets/image/0010/4015/varieties/wide-715px.jpg

Page 17: Brief introduction to kselftest

Conclusion

● Kselftest is a developer-friendly test framework and tests for the Linux kernel● The test is contained in the kernel source code itself● The test runs quickly under 20 minutes● The test can be packaged, installed, and run easily● The test code can be a good start point to the Linux kernel

Page 18: Brief introduction to kselftest

Thank You