Demo Codes for CS253A Course, Link
This demo needs g++ installed in your system.
We pass flags to gcc or g++ as shown below for the file we want to test coverage on.
See the code in coverage.cpp file for more information.
$ g++ -fprofile-arcs -ftest-coverage coverage/coverage.cpp -o coverageRunning the binary produced.
$ ./coverage
<num1>
<num2>or
echo -30 -55 | ./coverageRun with more example inputs, fuzz it for better coverage.
Use the gcov tool with required flags for more information.
$ gcov -b -c coverage
Check the file *.gcov produced.
File 'cov/coverage.cpp'
Lines executed:100.00% of 11ma
Branches executed:100.00% of 26
Taken at least once:61.54% of 26
Calls executed:100.00% of 10
Creating 'coverage.cpp.gcov'
File '/usr/include/c++/9/iostream'
No executable lines
No branches
No calls
Removing 'iostream.gcov'See the file in Makefile for more information.
$ make all
$ make cov1
$ make cov2Clean up
$ make clean You need to clone & install googletest from GitHub.
This installation needs cmake & make.
- Clone the repository googletest.
- Use [cmake] to generate
build&makefilesin the cloned repository.
$ cmake .
$ make -j 12Alternately use cmake to add all dependencies, see CMakeLists.txt
You can install googletest framework as described above and then run custom tests using g++/gcc directly without cmake.
We show the run of a sample file example1.cpp
$ g++ src/example1.cpp -lgtest -lgtest_main -pthread
$ ./example1There are three code examples in total.
Make a build directory and from that build directory, run the following commands
Here cmake automatically downloads googletest repository and builds it as a dependency for your cmake project.
Using ninja build.
$ cmake .. -G "Ninja"
$ ninja all
$ ./example1With make.
$ cmake ..
$ make -j $(nproc)
$ ./example1