kernel - Regarding tools/testing/ktests or selftests

Greg KH greg at
Tue Oct 10 10:14:33 EDT 2017

On Tue, Oct 10, 2017 at 01:15:11PM +0530, Pintu Kumar wrote:
> Hi All,
> Is anybody familiar with ktests of selftests framework under: tool/testing/ ?
> I have some queries.
> 1) What is the difference between ktests and selftests ? How to choose ?

It depends on what you want to do, but usually new things go in the
selftest section.

> 2) How to invoke a test under ktests?
>     For example:
>     I have some user space C program, that tests some kernel driver IOCTL calls.
>     I have a Makefile to build 2 executable for the tests.
>     I invoke those executable from a bash shell script and execute all
> the tests.
>     How can I do it automatically from ktests ?

Have you read the documentation the kernel has for this:
$ make help | grep test
Kernel selftest:
  kselftest       - Build and run kernel selftest (run as root)
                    running kselftest on it
  kselftest-clean - Remove all generated kselftest files
  kselftest-merge - Merge all the config dependencies of kselftest to existed

> 3) Similarly, how can I do it using selftests?
>     Using selftests looks much better option for me.
>     But the problem is I have some sub directories to execute the tests.
>     Example:
>     Under, tools/testing/selftests , I have created 2 sub folders.
>     selftests/folders/folder1/
>     My test setup is under: folder1
>     How to invoke selftests, for folder1 ?
> If anybody have added new tests under ktests of selftests, please
> provide some reference.

Have you looked at the many patches in the kernel source tree that show
how the existing tests are added?  That's the best thing to use as a

Hope this helps,

greg k-h

More information about the Kernelnewbies mailing list