author | Alberto Bertogli
<albertito@blitiri.com.ar> 2010-04-25 06:20:44 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2010-04-25 06:21:45 UTC |
parent | 1ca5dc7c8474af20df8eb2211811a4be50e85b56 |
.gitignore | +2 | -0 |
tests/coverage/README | +21 | -0 |
tests/coverage/coverage | +174 | -0 |
tests/coverage/lcov-start | +21 | -0 |
tests/coverage/lcov-stop | +28 | -0 |
diff --git a/.gitignore b/.gitignore index 0539648..ee35c58 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ .*.swp *.gcno *.gcda +gmon.out # *~ /nmdb/nmdb /utils/nmdb-stats @@ -23,3 +24,4 @@ /tests/perf/out /tests/perf/ag-data /tests/perf/graph +/tests/coverage/lcov diff --git a/tests/coverage/README b/tests/coverage/README new file mode 100644 index 0000000..d6af6e8 --- /dev/null +++ b/tests/coverage/README @@ -0,0 +1,21 @@ + +Here you will find two scripts that can be used to generate code coverage +reports. + + +"coverage" runs the server and all the other tests with different parameters, +trying to maximize code coverage. + +As it does not test for correctness, it is mostly useful to see which code is +not used by the other tests. The output is saved to /tmp/nmdb-lcov.log, to +allow manual verification of the test results. + +It can be combined with gcov, lcov, or other code coverage tools, to generate +friendly reports. + + +"lcov-start" and "lcov-stop" can be used to generate coverage reports with the +lcov tool (http://ltp.sourceforge.net/coverage/lcov.php). The reports are +generated in the "lcov/" subdirectory. + + diff --git a/tests/coverage/coverage b/tests/coverage/coverage new file mode 100755 index 0000000..b6000f6 --- /dev/null +++ b/tests/coverage/coverage @@ -0,0 +1,174 @@ +#!/bin/bash + + +if [ ! -x ./nmdb/nmdb ]; then + # attempt go to the git root + CDUP=$(git rev-parse --show-cdup 2>/dev/null) + if [ "$CDUP" != "" ]; then + cd $CDUP + fi + + if [ ! -x ./nmdb/nmdb ]; then + echo "Error: must be run from the project root" + exit 1 + fi +fi + + +DB="/tmp/nmdb-lcov-db" +LOG="/tmp/nmdb-lcov.log" +rm -f $LOG + +function log() { + echo "$@" >> $LOG +} + +function out() { + echo "$@" + log "$@" +} + +function run() { + log "-- running" "$@" + $@ >> $LOG 2>> $LOG + log +} + +function nmdb() { + log "-- nmdb starting:" "$@" + rm -f $DB + ./nmdb/nmdb -f -d $DB "$@" >> $LOG 2>> $LOG & + sleep 0.2 +} + +function kill_nmdb() { + killall nmdb >> $LOG 2>> $LOG + wait `pidof nmdb` + log "-- nmdb stopped" +} + +function nmdb_and_kill() { + log "-- nmdb_and_kill starting:" "$@" + rm -f $DB + ./nmdb/nmdb -f -d $DB "$@" >> $LOG 2>> $LOG & + sleep 0.2 + killall nmdb >> $LOG 2>> $LOG + wait `pidof nmdb` + log "-- nmdb_and_kill stopped" +} + + +out "+ help" + +# this one by hand so it also runs the "default database" path +run ./nmdb/nmdb -h + +# this one by hand for fork mode +out "+ fork mode" +./nmdb/nmdb >> $LOG; sleep 0.3; +killall nmdb >> $LOG 2>> $LOG; sleep 1.2; killall -9 nmdb >> $LOG 2>> $LOG + +out "+ command line" +nmdb_and_kill +nmdb_and_kill -p +nmdb_and_kill -b blah # supposed to fail + +nmdb_and_kill -l 20 +nmdb_and_kill -L 20 +nmdb_and_kill -t 26020 +nmdb_and_kill -u 26020 +nmdb_and_kill -s 26020 +nmdb_and_kill -T localhost # supposed to fail +nmdb_and_kill -U localhost # supposed to fail +nmdb_and_kill -S localhost # supposed to fail +nmdb_and_kill -T 127.0.0.1 +nmdb_and_kill -U 127.0.0.1 +nmdb_and_kill -S 127.0.0.1 +nmdb_and_kill -c 1 +nmdb_and_kill -o /dev/null +nmdb_and_kill -Z # supposed to fail +nmdb_and_kill -o /root/nmdb-coverage-fail # supposed to fail +nmdb_and_kill -d /dev/null # supposed to fail + + +out "+ signals" +nmdb +run killall -USR1 nmdb +run killall -USR2 nmdb +run killall -TERM nmdb +wait `pidof nmdb` + + +for be in bdb tc qdbm tdb; do + out "+ backend $be" + run rm -f $DB + nmdb -b $be + if ! pidof nmdb > /dev/null; then + out " unsupported" + continue + fi + kill_nmdb + + out " + random" + nmdb -b $be -c 5 + run tests/python/random1.py db 5000 + run tests/python/random1.py cache 5000 + kill_nmdb + + out " + performance" + nmdb -b $be -c 1 + pushd tests/c/ > /dev/null + for p in mult sctp tcp tipc udp; do + for t in cache normal sync; do + run ./1-$p-$t 1200 key val + run ./2-$p-$t 1200 8 8 + run ./3-$p-$t 1200 8 8 + run ./set-$p-$t 1200 8 8 + run ./get-$p-$t 1210 8 + run ./del-$p-$t 1210 8 + run ./incr-$p-$t 1200 10 + done + done + + # stress long tcp requests + run ./2-tcp-normal 1200 30000 30000 + + popd > /dev/null + kill_nmdb +done + +out "+ null backend" +nmdb -b null -c 1 +pushd tests/c/ > /dev/null +for p in mult sctp tcp tipc udp; do + for t in cache normal sync; do + run ./2-$p-$t 1200 8 8 + done +done +popd > /dev/null +kill_nmdb + +out "+ read-only" +nmdb +run tests/c/set-tipc-normal 1200 8 8 +kill_nmdb +nmdb -c 1 -r +pushd tests/c/ > /dev/null +for p in mult sctp tcp tipc udp; do + run ./set-$p-normal 1200 8 8 + run ./get-$p-normal 1210 8 + run ./del-$p-normal 1210 8 + run ./incr-$p-normal 1200 10 +done +popd > /dev/null +kill_nmdb + + +out "+ stats" +nmdb +run utils/nmdb-stats tipc 10 +run utils/nmdb-stats tcp localhost 26010 +run utils/nmdb-stats udp localhost 26010 +run utils/nmdb-stats sctp localhost 26010 +kill_nmdb + diff --git a/tests/coverage/lcov-start b/tests/coverage/lcov-start new file mode 100755 index 0000000..745d22d --- /dev/null +++ b/tests/coverage/lcov-start @@ -0,0 +1,21 @@ +#!/bin/bash + +if [ ! -x ./nmdb/nmdb ]; then + # attempt go to the git root + CDUP=$(git rev-parse --show-cdup 2>/dev/null) + if [ "$CDUP" != "" ]; then + cd $CDUP + fi + + if [ ! -x ./nmdb/nmdb ]; then + echo "Error: must be run from the project root" + exit 1 + fi +fi + +set -e + +LCOV="lcov --directory nmdb/ --base-directory nmdb/" +$LCOV --zerocounters + + diff --git a/tests/coverage/lcov-stop b/tests/coverage/lcov-stop new file mode 100755 index 0000000..da636c8 --- /dev/null +++ b/tests/coverage/lcov-stop @@ -0,0 +1,28 @@ +#!/bin/bash + +if [ ! -x ./nmdb/nmdb ]; then + # attempt go to the git root + CDUP=$(git rev-parse --show-cdup 2>/dev/null) + if [ "$CDUP" != "" ]; then + cd $CDUP + fi + + if [ ! -x ./nmdb/nmdb ]; then + echo "Error: must be run from the project root" + exit 1 + fi +fi + +set -e + +LCOV="lcov --directory nmdb/ --base-directory nmdb/" + +$LCOV -o tests/coverage/test_results.1 \ + --capture -t "Coverage tests" +$LCOV -o tests/coverage/test_results \ + --remove tests/coverage/test_results.1 '/usr/include/*' +rm tests/coverage/test_results.1 +mkdir -p tests/coverage/lcov +genhtml --show-details -o tests/coverage/lcov/ tests/coverage/test_results +rm tests/coverage/test_results +