From: Márton Németh <[email protected]> Signed-off-by: Márton Németh <[email protected]> --- diff --git a/README b/README index adae4f0..ad93482 100644 --- a/README +++ b/README @@ -116,3 +116,41 @@ powertop --extech=/dev/ttyUSB0
(where ttyUSB0 is the devicenode of the serial-to-usb adapter on my system) +Creating code coverage report for powertop using GCC +---------------------------------------------------- +Code coverage is a method to find out which part of the code was executed and +which was not executed. The gcc compiler supports creating such measurements +on the code by instrumenting the code at compile time when the "--coverage" +option is given. (This was tested with gcc 4.4.6. If you have some older gcc +version you might need to use "-fprofile-arcs -ftest-coverage" instead.) +You can enable this for powertop in the top level Makefile +by uncommenting the line following lines in configure.ac: + + CFLAGS="$CFLAGS --coverage" + CPPFLAGS="$CPPFLAGS --coverage" + LDFLAGS="$LDFLAGS --coverage" + +After this a full recompile is needed. For each single object file a +.gcno file will be created. At this point different test cases can be executed +on powertop binary. Each time powertop exits it will save several .gcda files +containing the measurement data. Once the testing is ready the tools "lcov" +and "genhtml" can be used to generate nice HTML report on the code coverage. + +# (edit Makefile to enable --coverage option) +# make clean +# ./autogen.sh +# ./configure +# make +# cd src/ +# (execute test cases for powertop. May contain multiple powertop runs. The results are accumulated.) +# lcov --base-directory . --directory . -c -o powertop.info +# genhtml -o powertop_coverage powertop.info +# (open powertop_coverage/index.html in a browser) + +If you want to clear coverage data you can delete the .gcda files. You can +run test cases against powertop without powertop binary recompilation. + +Note that the code coverage figures are mainly speaking about the quality +of the testing. It has limitations also, even if you achieve 100% code coverage +you won't be able to detect a missing piece of code (e.g. error handling) only by +looking at the code coverage figures. diff --git a/configure.ac b/configure.ac index 8d36a9e..059e24f 100644 --- a/configure.ac +++ b/configure.ac @@ -64,4 +64,9 @@ AC_CHECK_LIB([resolv], [main], , AC_MSG_ERROR([libresolv is required but was not # FIXME: Replace `main' with a function in `-lncursesw': AC_CHECK_LIB([ncurses], [main], , AC_MSG_ERROR([ncurses is required but was not found])) +# Enable GNU GCC's code coverage +#CFLAGS="$CFLAGS --coverage" +#CPPFLAGS="$CPPFLAGS --coverage" +#LDFLAGS="$LDFLAGS --coverage" _______________________________________________ Power mailing list [email protected] https://bughost.org/mailman/listinfo/power
