Rework and simplify the "lcov" support for the testsuite.
[sliver-openvswitch.git] / tests / lcov-wrapper.in
1 #! /bin/sh
2
3 abs_top_builddir='@abs_top_builddir@'
4 wrap_program=`basename '@wrap_program@'`
5
6 # Strip the first directory from $PATH that contains $wrap_program,
7 # so that below we run the real $wrap_program, not ourselves.
8 not_found=true
9 new_path=
10 first=true
11 save_IFS=$IFS
12 IFS=:
13 for dir in $PATH; do
14     IFS=$save_IFS
15     if $not_found && test -x "$dir/$wrap_program"; then
16         not_found=false
17     else
18         if $first; then
19             first=false
20             new_path=$dir
21         else
22             new_path=$new_path:$dir
23         fi
24     fi
25 done
26 IFS=$save_IFS
27 if $not_found; then
28     echo "$0: error: cannot find $wrap_program in \$PATH" >&2
29     exit 1
30 fi
31 PATH=$new_path
32 export PATH
33
34 # XXX Probably want some kind of synchronization here to deal with
35 # programs running in parallel.
36 LCOV="lcov -b $abs_top_builddir -d $abs_top_builddir -q"
37 $LCOV -z
38
39 # Run the subprocess and propagate signals to it.
40 for signal in 1 2 3 5 15; do
41     trap "kill -$signal \$!     # Propagate signal
42           trap - $signal        # Reset signal to default
43           wait                  # Wait for child to die
44           kill -$signal $$      # Kill ourselves with same signal
45           exit 1                # Exit in case 'kill' failed" $signal
46 done
47 $wrap_program 0<&0 "$@" &       # 0<&0 prevents shell from closing stdin
48 exec 0</dev/null                # Don't hold stdin open unnecessarily
49 wait $!; rc=$?
50
51 # Run lcov, but only if some .gcda files were produced, since lcov
52 # complains otherwise.
53 for file in `find "$abs_top_builddir" -name '*.gcda'`; do
54     $LCOV -c -o - >> "$abs_top_builddir/tests/coverage.info"
55     break
56 done
57
58 exit $rc