Introduction to unit tests process in SONiC repos - qiluo-msft/SONiC GitHub Wiki

Google Test

Prepare Google Test environment

  1. Install Google Test DEB package. ref: https://stackoverflow.com/questions/13513905/how-to-setup-googletest-as-a-shared-library-on-linux/41954177#41954177
	$ sudo apt-get install cmake libgtest-dev
	$ cd /usr/src/gtest && sudo cmake . && sudo make && sudo mv libg* /usr/lib/; cd -
	$ g++ test.cpp -o test -lgtest -pthread && ./test

2. Use repo local Google Test submodule, eg https://github.com/Azure/sonic-swss-common/tree/v1.0.1

Build with Google Test

$ ./autogen.sh
$ ./configure --enable-debug 'CXXFLAGS=-O0 -g'
$ make clean
$ GCC_COLORS=1 make

Run unit test:

tests/tests

Run unit test with debugger:

LD_LIBRARY_PATH=./common/.libs/ gdb tests/.libs/lt-tests

Memory leak check:

valgrind --log-file="memory_check.out" --tool=memcheck --leak-check=full --show-reachable=yes --num-callers=20 --track-fds=yes tests/.libs/lt-tests

pytest

Doctest

python -m doctest -v src/ax_interface/util.py
python -m doctest -v `git grep -l '>>>' -- '*.py'` | grep failed

Unit test

pytest -s