SysUnit Fakes, Mocks and Stubs
Contents
Note: A number of the libraries here currently implement only a subset of the functions associated with the KPI. Please feel free to extend a library with more functions as test suites require them.
Fakes
fake_atomic
KPIs Provided:
- atomic_add_int
- atomic_fetchadd_int
Notes:
As SysUnit tests are not multithreaded, these implementations are not atomic
fake_malloc
KPIs Provided:
- malloc(9)
- free(9)
Notes:
These symbol names collide with those from malloc(3) in incompatible ways. This incompatibility has been resolved by renaming the KPI symbols to prepend a k (e.g. malloc(9) becomes kmalloc). This is automatically performed by the build infrastructure when building C code for SysUnit.
fake_mbuf
KPIs Provided:
- Everything in mbuf(9)
fake_mib
KPIs Provided:
- All top-level sysctl nodes (e.g. _hw, _dev, _kern, etc)
fake_mutex
KPIs Provided:
- mtx_lock
- mtx_unlock
Notes:
These implementations are not actual mutexes as SysUnit tests are not multithreaded. The tests will detect lock recursion or releasing an unowned mutex and fail the test for it
- The MTX_RECURSE flag is currently not handled
fake_panic
KPIs Provided:
- kassert_panic
- panic
- vpanic
Note:
- Any panic calls will result in the panic message being printed to stderr followed by abort() being called.
fake_uma
KPIs Provided:
- uma_zcreate
- uma_zdestroy
- uma_zalloc
- uma_zalloc_arg
- uma_zfree
- uma_zfree_arg
Notes:
- uma zones will perform leak detection when each test case completes. Tests will fail if memory is leaked from a uma zone
Mocks
MockUpperIfnet
Header:
- #include "mock/UpperIfnet.h"
KPIs Provided:
- if_input
MockUpperIfnet is used to mock ifnet methods that are implemented by the protocol (upper) layer of the ifnet. It should be used when testing code that runs on the network driver side of the stack.
MockTime
Header:
- #include "mock/time.h"
KPIs Provided:
- getmicrotime