Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 11f53b1

Browse files
committed
Code coverage testing with gcov. Documentation is in the regression test
chapter. Author: Michelle Caisse <Michelle.Caisse@Sun.COM>
1 parent 579d9a5 commit 11f53b1

File tree

7 files changed

+361
-15
lines changed

7 files changed

+361
-15
lines changed

GNUmakefile.in

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# PostgreSQL top level makefile
33
#
4-
# $PostgreSQL: pgsql/GNUmakefile.in,v 1.47 2008/03/18 16:24:50 petere Exp $
4+
# $PostgreSQL: pgsql/GNUmakefile.in,v 1.48 2008/09/05 12:11:17 petere Exp $
55
#
66

77
subdir =
@@ -61,6 +61,25 @@ GNUmakefile: GNUmakefile.in $(top_builddir)/config.status
6161
./config.status $@
6262

6363

64+
##########################################################################
65+
66+
coverage:
67+
$(MAKE) -C src/backend $@
68+
69+
.PHONY: coverage-html
70+
coverage-html: coverage
71+
rm -rf coverage
72+
mkdir coverage
73+
$(GENHTML) --show-details --legend --output-directory=coverage --title=PostgreSQL --num-spaces=4 `find src/backend -name lcov.info -print`
74+
75+
ifeq ($(enable_coverage),yes)
76+
clean distclean maintainer-clean: clean-coverage-local
77+
.PHONY: clean-coverage-local
78+
clean-coverage-local:
79+
rm -rf coverage
80+
endif
81+
82+
6483
##########################################################################
6584

6685
distdir = postgresql-$(VERSION)

configure

+201-6
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,10 @@ enable_shared
672672
enable_rpath
673673
enable_debug
674674
enable_profiling
675+
GCOV
676+
LCOV
677+
GENHTML
678+
enable_coverage
675679
DTRACE
676680
DTRACEFLAGS
677681
enable_dtrace
@@ -1356,6 +1360,7 @@ Optional Features:
13561360
--disable-spinlocks do not use spinlocks
13571361
--enable-debug build with debugging symbols (-g)
13581362
--enable-profiling build with profiling enabled
1363+
--enable-coverage build with coverage testing instrumentation
13591364
--enable-dtrace build with DTrace support
13601365
--enable-depend turn on automatic dependency tracking
13611366
--enable-cassert enable assertion checks (for debugging)
@@ -2468,6 +2473,178 @@ fi
24682473

24692474

24702475

2476+
#
2477+
# --enable-coverage enables generation of code coverage metrics with gcov
2478+
#
2479+
2480+
pgac_args="$pgac_args enable_coverage"
2481+
2482+
# Check whether --enable-coverage was given.
2483+
if test "${enable_coverage+set}" = set; then
2484+
enableval=$enable_coverage;
2485+
case $enableval in
2486+
yes)
2487+
:
2488+
;;
2489+
no)
2490+
:
2491+
;;
2492+
*)
2493+
{ { echo "$as_me:$LINENO: error: no argument expected for --enable-coverage option" >&5
2494+
echo "$as_me: error: no argument expected for --enable-coverage option" >&2;}
2495+
{ (exit 1); exit 1; }; }
2496+
;;
2497+
esac
2498+
2499+
else
2500+
enable_coverage=no
2501+
2502+
fi
2503+
2504+
2505+
for ac_prog in gcov
2506+
do
2507+
# Extract the first word of "$ac_prog", so it can be a program name with args.
2508+
set dummy $ac_prog; ac_word=$2
2509+
{ echo "$as_me:$LINENO: checking for $ac_word" >&5
2510+
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
2511+
if test "${ac_cv_prog_GCOV+set}" = set; then
2512+
echo $ECHO_N "(cached) $ECHO_C" >&6
2513+
else
2514+
if test -n "$GCOV"; then
2515+
ac_cv_prog_GCOV="$GCOV" # Let the user override the test.
2516+
else
2517+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
2518+
for as_dir in $PATH
2519+
do
2520+
IFS=$as_save_IFS
2521+
test -z "$as_dir" && as_dir=.
2522+
for ac_exec_ext in '' $ac_executable_extensions; do
2523+
if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
2524+
ac_cv_prog_GCOV="$ac_prog"
2525+
echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
2526+
break 2
2527+
fi
2528+
done
2529+
done
2530+
IFS=$as_save_IFS
2531+
2532+
fi
2533+
fi
2534+
GCOV=$ac_cv_prog_GCOV
2535+
if test -n "$GCOV"; then
2536+
{ echo "$as_me:$LINENO: result: $GCOV" >&5
2537+
echo "${ECHO_T}$GCOV" >&6; }
2538+
else
2539+
{ echo "$as_me:$LINENO: result: no" >&5
2540+
echo "${ECHO_T}no" >&6; }
2541+
fi
2542+
2543+
2544+
test -n "$GCOV" && break
2545+
done
2546+
2547+
if test -z "$GCOV"; then
2548+
{ { echo "$as_me:$LINENO: error: gcov not found" >&5
2549+
echo "$as_me: error: gcov not found" >&2;}
2550+
{ (exit 1); exit 1; }; }
2551+
fi
2552+
for ac_prog in lcov
2553+
do
2554+
# Extract the first word of "$ac_prog", so it can be a program name with args.
2555+
set dummy $ac_prog; ac_word=$2
2556+
{ echo "$as_me:$LINENO: checking for $ac_word" >&5
2557+
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
2558+
if test "${ac_cv_prog_LCOV+set}" = set; then
2559+
echo $ECHO_N "(cached) $ECHO_C" >&6
2560+
else
2561+
if test -n "$LCOV"; then
2562+
ac_cv_prog_LCOV="$LCOV" # Let the user override the test.
2563+
else
2564+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
2565+
for as_dir in $PATH
2566+
do
2567+
IFS=$as_save_IFS
2568+
test -z "$as_dir" && as_dir=.
2569+
for ac_exec_ext in '' $ac_executable_extensions; do
2570+
if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
2571+
ac_cv_prog_LCOV="$ac_prog"
2572+
echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
2573+
break 2
2574+
fi
2575+
done
2576+
done
2577+
IFS=$as_save_IFS
2578+
2579+
fi
2580+
fi
2581+
LCOV=$ac_cv_prog_LCOV
2582+
if test -n "$LCOV"; then
2583+
{ echo "$as_me:$LINENO: result: $LCOV" >&5
2584+
echo "${ECHO_T}$LCOV" >&6; }
2585+
else
2586+
{ echo "$as_me:$LINENO: result: no" >&5
2587+
echo "${ECHO_T}no" >&6; }
2588+
fi
2589+
2590+
2591+
test -n "$LCOV" && break
2592+
done
2593+
2594+
if test -z "$LCOV"; then
2595+
{ { echo "$as_me:$LINENO: error: lcov not found" >&5
2596+
echo "$as_me: error: lcov not found" >&2;}
2597+
{ (exit 1); exit 1; }; }
2598+
fi
2599+
for ac_prog in genhtml
2600+
do
2601+
# Extract the first word of "$ac_prog", so it can be a program name with args.
2602+
set dummy $ac_prog; ac_word=$2
2603+
{ echo "$as_me:$LINENO: checking for $ac_word" >&5
2604+
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
2605+
if test "${ac_cv_prog_GENHTML+set}" = set; then
2606+
echo $ECHO_N "(cached) $ECHO_C" >&6
2607+
else
2608+
if test -n "$GENHTML"; then
2609+
ac_cv_prog_GENHTML="$GENHTML" # Let the user override the test.
2610+
else
2611+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
2612+
for as_dir in $PATH
2613+
do
2614+
IFS=$as_save_IFS
2615+
test -z "$as_dir" && as_dir=.
2616+
for ac_exec_ext in '' $ac_executable_extensions; do
2617+
if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
2618+
ac_cv_prog_GENHTML="$ac_prog"
2619+
echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
2620+
break 2
2621+
fi
2622+
done
2623+
done
2624+
IFS=$as_save_IFS
2625+
2626+
fi
2627+
fi
2628+
GENHTML=$ac_cv_prog_GENHTML
2629+
if test -n "$GENHTML"; then
2630+
{ echo "$as_me:$LINENO: result: $GENHTML" >&5
2631+
echo "${ECHO_T}$GENHTML" >&6; }
2632+
else
2633+
{ echo "$as_me:$LINENO: result: no" >&5
2634+
echo "${ECHO_T}no" >&6; }
2635+
fi
2636+
2637+
2638+
test -n "$GENHTML" && break
2639+
done
2640+
2641+
if test -z "$GENHTML"; then
2642+
{ { echo "$as_me:$LINENO: error: genhtml not found" >&5
2643+
echo "$as_me: error: genhtml not found" >&2;}
2644+
{ (exit 1); exit 1; }; }
2645+
fi
2646+
2647+
24712648
#
24722649
# DTrace
24732650
#
@@ -3580,13 +3757,16 @@ unset CFLAGS
35803757
# CFLAGS are selected so:
35813758
# If the user specifies something in the environment, that is used.
35823759
# else: If the template file set something, that is used.
3760+
# else: If coverage was enabled, don't set anything.
35833761
# else: If the compiler is GCC, then we use -O2.
3584-
# else: If the compiler is something else, then we use -0.
3762+
# else: If the compiler is something else, then we use -O.
35853763

35863764
if test "$ac_env_CFLAGS_set" = set; then
35873765
CFLAGS=$ac_env_CFLAGS_value
35883766
elif test "${CFLAGS+set}" = set; then
35893767
: # (keep what template set)
3768+
elif test "$enable_coverage" = yes; then
3769+
: # no optimization by default
35903770
elif test "$GCC" = yes; then
35913771
CFLAGS="-O2"
35923772
else
@@ -3961,6 +4141,17 @@ if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
39614141
CFLAGS="$CFLAGS -g"
39624142
fi
39634143

4144+
# enable code coverage if --enable-coverage
4145+
if test "$enable_coverage" = yes; then
4146+
if test "$GCC" = yes; then
4147+
CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
4148+
else
4149+
{ { echo "$as_me:$LINENO: error: --enable-coverage is supported only when using GCC" >&5
4150+
echo "$as_me: error: --enable-coverage is supported only when using GCC" >&2;}
4151+
{ (exit 1); exit 1; }; }
4152+
fi
4153+
fi
4154+
39644155
# enable profiling if --enable-profiling
39654156
if test "$enable_profiling" = yes && test "$ac_cv_prog_cc_g" = yes; then
39664157
if test "$GCC" = yes; then
@@ -26510,6 +26701,10 @@ enable_shared!$enable_shared$ac_delim
2651026701
enable_rpath!$enable_rpath$ac_delim
2651126702
enable_debug!$enable_debug$ac_delim
2651226703
enable_profiling!$enable_profiling$ac_delim
26704+
GCOV!$GCOV$ac_delim
26705+
LCOV!$LCOV$ac_delim
26706+
GENHTML!$GENHTML$ac_delim
26707+
enable_coverage!$enable_coverage$ac_delim
2651326708
DTRACE!$DTRACE$ac_delim
2651426709
DTRACEFLAGS!$DTRACEFLAGS$ac_delim
2651526710
enable_dtrace!$enable_dtrace$ac_delim
@@ -26549,10 +26744,6 @@ LDFLAGS_SL!$LDFLAGS_SL$ac_delim
2654926744
LD!$LD$ac_delim
2655026745
with_gnu_ld!$with_gnu_ld$ac_delim
2655126746
ld_R_works!$ld_R_works$ac_delim
26552-
RANLIB!$RANLIB$ac_delim
26553-
STRIP!$STRIP$ac_delim
26554-
STRIP_STATIC_LIB!$STRIP_STATIC_LIB$ac_delim
26555-
STRIP_SHARED_LIB!$STRIP_SHARED_LIB$ac_delim
2655626747
_ACEOF
2655726748

2655826749
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -26594,6 +26785,10 @@ _ACEOF
2659426785
ac_delim='%!_!# '
2659526786
for ac_last_try in false false false false false :; do
2659626787
cat >conf$$subs.sed <<_ACEOF
26788+
RANLIB!$RANLIB$ac_delim
26789+
STRIP!$STRIP$ac_delim
26790+
STRIP_STATIC_LIB!$STRIP_STATIC_LIB$ac_delim
26791+
STRIP_SHARED_LIB!$STRIP_SHARED_LIB$ac_delim
2659726792
TAR!$TAR$ac_delim
2659826793
LN_S!$LN_S$ac_delim
2659926794
AWK!$AWK$ac_delim
@@ -26644,7 +26839,7 @@ vpath_build!$vpath_build$ac_delim
2664426839
LTLIBOBJS!$LTLIBOBJS$ac_delim
2664526840
_ACEOF
2664626841

26647-
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 48; then
26842+
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 52; then
2664826843
break
2664926844
elif $ac_last_try; then
2665026845
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5

configure.in

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.565 2008/08/29 13:02:32 petere Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.566 2008/09/05 12:11:18 petere Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -203,6 +203,25 @@ PGAC_ARG_BOOL(enable, profiling, no,
203203
[ --enable-profiling build with profiling enabled ])
204204
AC_SUBST(enable_profiling)
205205

206+
#
207+
# --enable-coverage enables generation of code coverage metrics with gcov
208+
#
209+
PGAC_ARG_BOOL(enable, coverage, no,
210+
[ --enable-coverage build with coverage testing instrumentation])
211+
AC_CHECK_PROGS(GCOV, gcov)
212+
if test -z "$GCOV"; then
213+
AC_MSG_ERROR([gcov not found])
214+
fi
215+
AC_CHECK_PROGS(LCOV, lcov)
216+
if test -z "$LCOV"; then
217+
AC_MSG_ERROR([lcov not found])
218+
fi
219+
AC_CHECK_PROGS(GENHTML, genhtml)
220+
if test -z "$GENHTML"; then
221+
AC_MSG_ERROR([genhtml not found])
222+
fi
223+
AC_SUBST(enable_coverage)
224+
206225
#
207226
# DTrace
208227
#
@@ -370,13 +389,16 @@ unset CFLAGS
370389
# CFLAGS are selected so:
371390
# If the user specifies something in the environment, that is used.
372391
# else: If the template file set something, that is used.
392+
# else: If coverage was enabled, don't set anything.
373393
# else: If the compiler is GCC, then we use -O2.
374-
# else: If the compiler is something else, then we use -0.
394+
# else: If the compiler is something else, then we use -O.
375395

376396
if test "$ac_env_CFLAGS_set" = set; then
377397
CFLAGS=$ac_env_CFLAGS_value
378398
elif test "${CFLAGS+set}" = set; then
379399
: # (keep what template set)
400+
elif test "$enable_coverage" = yes; then
401+
: # no optimization by default
380402
elif test "$GCC" = yes; then
381403
CFLAGS="-O2"
382404
else
@@ -415,6 +437,15 @@ if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
415437
CFLAGS="$CFLAGS -g"
416438
fi
417439

440+
# enable code coverage if --enable-coverage
441+
if test "$enable_coverage" = yes; then
442+
if test "$GCC" = yes; then
443+
CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
444+
else
445+
AC_MSG_ERROR([--enable-coverage is supported only when using GCC])
446+
fi
447+
fi
448+
418449
# enable profiling if --enable-profiling
419450
if test "$enable_profiling" = yes && test "$ac_cv_prog_cc_g" = yes; then
420451
if test "$GCC" = yes; then

0 commit comments

Comments
 (0)