# Linux Kernel Module Cheat

#### 24.14.1. gem5 unit tests

These are just very small GTest tests that test a single class in isolation, they don’t run any executables.

Build the unit tests and run them:

    ./build-gem5 --unit-tests

Running individual unit tests is not yet exposed, but it is easy to do: while running the full tests, GTest prints each test command being run, e.g.:

    /path/to/build/ARM/base/circlebuf.test.opt --gtest_output=xml:/path/to/build/ARM/unittests.opt/base/circlebuf.test.xml
    [==========] Running 4 tests from 1 test case.
    [----------] Global test environment set-up.
    [----------] 4 tests from CircleBufTest
    [ RUN      ] CircleBufTest.BasicReadWriteNoOverflow
    [       OK ] CircleBufTest.BasicReadWriteNoOverflow (0 ms)
    [ RUN      ] CircleBufTest.SingleWriteOverflow
    [       OK ] CircleBufTest.SingleWriteOverflow (0 ms)
    [ RUN      ] CircleBufTest.MultiWriteOverflow
    [       OK ] CircleBufTest.MultiWriteOverflow (0 ms)
    [ RUN      ] CircleBufTest.PointerWrapAround
    [       OK ] CircleBufTest.PointerWrapAround (0 ms)
    [----------] 4 tests from CircleBufTest (0 ms total)

    [----------] Global test environment tear-down
    [==========] 4 tests from 1 test case ran. (0 ms total)
    [  PASSED  ] 4 tests.

so you can just copy paste the command.

Building individual tests is possible with `--unit-test` (singular, no 's'):

    ./build-gem5 --unit-test base/circlebuf.test

This does not run the test however.

Note that the command and it’s corresponding results don’t need to show consecutively on stdout because tests are run in parallel. You just have to match them based on the class name `CircleBufTest` to the file `circlebuf.test.cpp`.