xref: /freebsd-src/contrib/libcbor/doc/source/tests.rst (revision 10ff414c14eef433d8157f0c17904d740693933b)
1*10ff414cSEd MasteTests
2*10ff414cSEd Maste=============
3*10ff414cSEd Maste
4*10ff414cSEd MasteUnit tests
5*10ff414cSEd Maste--------------
6*10ff414cSEd Maste
7*10ff414cSEd MasteThere is a comprehensive test suite employing CMocka_. You can run all of them using ``ctest`` in the build directory. Individual tests are themselves runnable. Please refer to `CTest <http://www.cmake.org/Wiki/CMake/Testing_With_CTest>`_ documentation for detailed information on how to specify particular subset of tests.
8*10ff414cSEd Maste
9*10ff414cSEd Maste.. _CMocka: http://cmocka.org/
10*10ff414cSEd Maste
11*10ff414cSEd MasteTesting for memory leaks
12*10ff414cSEd Maste------------------------
13*10ff414cSEd Maste
14*10ff414cSEd MasteEvery release is tested for memory correctness. You can run these tests by passing the ``-T memcheck`` flag to ``ctest``. [#]_
15*10ff414cSEd Maste
16*10ff414cSEd Maste.. [#] Project should be configured with ``-DCMAKE_BUILD_TYPE=Debug`` to obtain meaningful description of location of the leak. You might also need ``--dsymutil=yes`` on OS X.
17*10ff414cSEd Maste
18*10ff414cSEd Maste
19*10ff414cSEd MasteCode coverage
20*10ff414cSEd Maste-------------------
21*10ff414cSEd Maste
22*10ff414cSEd MasteEvery release is inspected using `GCOV/LCOV <http://ltp.sourceforge.net/coverage/lcov.php>`_. Platform-independent code should be fully covered by the test suite. Simply run
23*10ff414cSEd Maste
24*10ff414cSEd Maste.. code-block:: bash
25*10ff414cSEd Maste
26*10ff414cSEd Maste  make coverage
27*10ff414cSEd Maste
28*10ff414cSEd Maste
29*10ff414cSEd Masteor alternatively run ``lcov`` by hand using
30*10ff414cSEd Maste
31*10ff414cSEd Maste.. code-block:: bash
32*10ff414cSEd Maste
33*10ff414cSEd Maste  lcov --capture --directory . --output-file coverage.info
34*10ff414cSEd Maste  genhtml coverage.info --output-directory out
35*10ff414cSEd Maste
36*10ff414cSEd MasteFuzz testing
37*10ff414cSEd Maste-----------------
38*10ff414cSEd Maste
39*10ff414cSEd MasteEvery release is tested using a fuzz test. In this test, a huge buffer filled with random data is passed to the decoder. We require that it either succeeds or fail with a sensible error, without leaking any memory. This is intended to simulate real-world situations where data received from the network are CBOR-decoded before any further processing.
40