Writing Tests

Writing a test case is a lot easier than most people think. Any code that you write to examine how a part of the kernel works can be adapted into a test case. All that is needed is a way to report the result of the action to the rest of the world. There are several ways of doing this, some more involved than others.

Exit Style Tests

Probably the simplest way of reporting the results of a test case is the exit status of your program. If your test program encounters unexpected or incorrect results, exit the test program with a non-zero exit status, i.e. exit(1). Conversely, if your program completes as expected, return a zero exit status, i.e. exit(0). Any test driver should be able to handle this type of error reporting. If a test program has multiple test cases you won't know which test case failed, but you will know the program that failed.

Formatted Output Tests

The next easiest way of reporting the results is to write the results of each test case to standard output. This allows for the testing results to be more understandable to both the tester and the analysis tools. When the results are written in a standard way, tools can be used to analyze the results.