aboutsummaryrefslogtreecommitdiff
path: root/docs/testing.md
blob: 62234d6bcad90dd7fd62875f472ea42913c6fdae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Testing
=======

Running `make test` runs most of the integrated tests. You should have
`valgrind` installed.

Running `make pre-push` runs the above builds and tests in different configurations: GCC,
clang, and with ASAN enabled.

There are some [older unit tests](test/unit-tests.c) written in C, but most
tests are now done via Python, in the [test/py](test/py) sub-directory. You can
run just the Python tests via `make pytest` or `make pytest-valgrind`.

The master branch is run through [Coverity](scan.coverity.com) when a new PR
lands.

You can also run `make gcov` to get code coverage reports.

Debugging Test Errors
---------------------

Sometimes debugging Valgrind errors on Python unit tests can be tricky. To
run specific tests use the pytest `-k` option in `PYTESTCMD` in the Makefile.

AFL++
-----

You can run [American Fuzzy Lop](https://github.com/AFLplusplus/AFLplusplus)
against `libvfio-user`. It's easiest to use the Docker container:

```
cd /path/to/libvfio-user/src
docker pull aflplusplus/aflplusplus
docker run -ti -v $(pwd):/src aflplusplus/aflplusplus
```

Set up and build:

```
apt update
apt-get -y install libjson-c-dev libcmocka-dev clang valgrind \
                   python3-pytest debianutils flake8 cmake

cd /src
export AFL_LLVM_LAF_ALL=1
make CC=afl-clang-fast WITH_TRAN_PIPE=1

mkdir inputs
# don't yet have a better starting point
echo "1" >inputs/start
mkdir outputs
```

The `VFU_TRAN_PIPE` is a special `libvfio-user` transport that reads from
`stdin` instead of a socket, we'll use this with the sample server to do our
fuzzing:

```
afl-fuzz -i inputs/ -o outputs/ -- ./build/dbg/samples/server pipe
```