From: Márton Németh <[email protected]>

Signed-off-by: Márton Németh <[email protected]>
---
diff --git a/Makefile b/Makefile
index 22096dc..0cc0c02 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ VERSION := 1.98

 CXXFLAGS ?= -O2 -g -fno-omit-frame-pointer -fstack-protector
 CXXFLAGS += -Wall -Wshadow -Wformat
+#CXXFLAGS += --coverage
 CPPFLAGS += -D_FORTIFY_SOURCE=2
 PKG_CONFIG ?= pkg-config

@@ -66,6 +67,8 @@ MANDIR      = $(PREFIX)/share/man/man8

 clean:
        rm -f *.o *~ powertop DEADJOE core.* */*.[ao] */*~ csstoh css.h
+       rm -f *.gcno */*.gcno
+       rm -f *.gcda */*.gcda

 pevents/libparseevent.a:
        $(MAKE) -C pevent
diff --git a/README b/README
index c44f56c..738b3b6 100644
--- a/README
+++ b/README
@@ -109,3 +109,33 @@ 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 "CXXFLAGS += --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
+# make
+# (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.

_______________________________________________
Power mailing list
[email protected]
https://bughost.org/mailman/listinfo/power

Reply via email to