citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit b144162e86f574475eaae08b26a71f5b293ae322
parent 1cc51c2ac7e5a55d89eee67826fb5c31e1d8b98c
Author: Kyle Milz <kyle@0x30.net>
Date:   Wed, 31 Aug 2016 17:58:29 -0600

src/check: use getopt

Diffstat:
Msrc/check.in | 53+++++++++++++++++++++++++++++++++++++++--------------
Mt/check_baddir.sh | 2+-
Mt/check_empty.sh | 2+-
Mt/e2e_basic.sh | 5+++--
Mt/e2e_stdout.sh | 5+++--
Mt/inst_basic_link.sh | 5+++--
Mt/inst_binop.sh | 8+++++---
Mt/inst_dowhile.sh | 8+++++---
Mt/inst_fail.sh | 5+++--
Mt/inst_for.sh | 8+++++---
Mt/inst_funcdef.sh | 8+++++---
Mt/inst_if.sh | 8+++++---
Mt/inst_link_multiple.sh | 5+++--
Mt/inst_macro.sh | 8+++++---
Mt/inst_preamble.sh | 6+++---
Mt/inst_return.sh | 8+++++---
Mt/inst_src_ext.sh | 5+++--
Mt/inst_switch.sh | 8+++++---
Mt/inst_two_src.sh | 5+++--
Mt/inst_while.sh | 8+++++---
Mtest/utils.sh | 7++++++-
21 files changed, 116 insertions(+), 61 deletions(-)

diff --git a/src/check.in b/src/check.in @@ -3,16 +3,31 @@ # Tries to be POSIX compatible. # function err { - echo "${1}" + echo "$1" exit 1 } -dir=`pwd` -if [ $# -eq 1 ]; then - [[ ${1} = -* ]] && err "Usage: citrun-check [dir]" - dir="${1}" +args=`getopt o: $*` +if [ $? -ne 0 ] +then + err "Usage: citrun-check [-o output file] [dir]" fi -[ -d $dir ] || err "citrun-check: $dir: no such directory" +set -- $args +while [ $# -ne 0 ] +do + case "$1" + in + -o) + # Redirect standard output to argument of -o. + exec 1<&-; exec 1<>"$2"; shift; shift;; + --) + shift; break;; + esac +done + +dir="$1" +[ -z "$1" ] && dir=`pwd` +[ -d $dir ] || err "citrun-check: $dir: directory does not exist" GREP[0]="Found source file" GREP[1]="Link detected" @@ -50,12 +65,14 @@ fine_len=${#FINE[@]} [ -t 1 ] && echo -n Checking \'$dir\' . let log_files=0 -for d in `find $dir -name citrun.log`; do +for d in `find $dir -name citrun.log` +do [ -t 1 ] && echo -n . let log_files++ let i=0 - while [ $i -lt $desc_len ]; do + while [ $i -lt $desc_len ] + do tmp=`grep -c "${GREP[$i]}" $d` let COUNT[$i]+=tmp let i++ @@ -63,9 +80,11 @@ for d in `find $dir -name citrun.log`; do let i=0 typeset -i tmp - while [ $i -lt $fine_len ]; do + while [ $i -lt $fine_len ] + do tmp=`awk "\\$0~/${FINE[$i]}/ { sum += \\$2 } END { print sum }" $d` - if [ "$tmp" = "" ]; then + if [ "$tmp" = "" ] + then let i++ continue fi @@ -79,9 +98,12 @@ done [ -t 1 ] && echo echo Summary: + let i=0 -while [ $i -lt $desc_len ]; do - if [ ${COUNT[$i]} -eq 0 ]; then +while [ $i -lt $desc_len ] +do + if [ ${COUNT[$i]} -eq 0 ] + then let i++ continue fi @@ -91,9 +113,12 @@ done echo echo Totals: + let i=0 -while [ $i -lt $fine_len ]; do - if [ ${FINE_COUNT[$i]} -eq 0 ]; then +while [ $i -lt $fine_len ] +do + if [ ${FINE_COUNT[$i]} -eq 0 ] + then let i++ continue fi diff --git a/t/check_baddir.sh b/t/check_baddir.sh @@ -5,7 +5,7 @@ . test/utils.sh plan 1 -output_good="citrun-check: some_nonexistent_dir: no such directory" +output_good="citrun-check: some_nonexistent_dir: directory does not exist" ok_program "error on bad dir" 1 "$output_good" \ $CITRUN_TOOLS/citrun-check some_nonexistent_dir diff --git a/t/check_empty.sh b/t/check_empty.sh @@ -7,5 +7,5 @@ plan 1 output_good="No log files found." -ok_program "no logs found message" 1 "$output_good" \ +ok_program "is no logs found message printed" 1 "$output_good" \ $CITRUN_TOOLS/citrun-check diff --git a/t/e2e_basic.sh b/t/e2e_basic.sh @@ -3,7 +3,7 @@ # Check that a simple program can execute successfully with instrumentation. # . test/utils.sh -plan 6 +plan 7 cat <<EOF > fib.c #include <stdio.h> @@ -49,8 +49,9 @@ Totals: EOF ok "wrapped source compile" $CITRUN_TOOLS/citrun-wrap cc -o fib fib.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +strip_millis check.out ok "citrun-check diff" diff -u check.good check.out ok_program "fib with no args" 1 "" fib diff --git a/t/e2e_stdout.sh b/t/e2e_stdout.sh @@ -3,7 +3,7 @@ # Simple program that prints output. # . test/utils.sh -plan 4 +plan 5 cat <<EOF > hello.c #include <stdio.h> @@ -31,7 +31,8 @@ EOF ok "wrapped compile" $CITRUN_TOOLS/citrun-wrap cc -o hello hello.c -ok "citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +strip_millis check.out ok "citrun-check diff" diff -u check.good check.out ok_program "stdout compare" 0 "hello, world!" hello diff --git a/t/inst_basic_link.sh b/t/inst_basic_link.sh @@ -3,7 +3,7 @@ # Check that the most basic of compile command lines works. # . test/utils.sh -plan 3 +plan 4 cat <<EOF > main.c int main(void) { return 0; } @@ -25,5 +25,6 @@ Totals: 3 Total statements EOF -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +strip_millis check.out ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_binop.sh b/t/inst_binop.sh @@ -3,7 +3,7 @@ # Test that binary operators in strange cases work. Includes enums and globals. # . test/utils.sh -plan 4 +plan 5 cat <<EOF > enum.c enum ASDF { @@ -60,8 +60,10 @@ Totals: EOF ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c enum.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out + +strip_preamble enum.c +strip_millis check.out -remove_preamble enum.c ok "instrumented src file diff" diff -u enum.c.inst_good enum.c.citrun_nohdr ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_dowhile.sh b/t/inst_dowhile.sh @@ -3,7 +3,7 @@ # Make sure that do while loop condition instrumentation works. # . test/utils.sh -plan 4 +plan 5 cat <<EOF > while.c int main(int argc, char *argv[]) { @@ -38,8 +38,10 @@ Totals: EOF ok "citrun-inst rewrite" $CITRUN_TOOLS/citrun-inst -c while.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out + +strip_preamble while.c +strip_millis check.out -remove_preamble while.c ok "instrumented source diff" diff -u while.c.inst_good while.c.citrun_nohdr ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_fail.sh b/t/inst_fail.sh @@ -3,7 +3,7 @@ # Check that a program that won't compile natively is handled properly. # . test/utils.sh -plan 3 +plan 4 echo "int main(void) { return 0; " > bad.c @@ -28,5 +28,6 @@ Totals: 3 Total statements EOF -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +strip_millis check.out ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_for.sh b/t/inst_for.sh @@ -3,7 +3,7 @@ # Test that for loop condition instrumenting works. # . test/utils.sh -plan 4 +plan 5 cat <<EOF > for.c int main(int argc, char *argv[]) { @@ -37,8 +37,10 @@ Totals: EOF ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c for.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out + +strip_preamble for.c +strip_millis check.out -remove_preamble for.c ok "known good instrumented diff" diff -u for.c.inst_good for.c.citrun_nohdr ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_funcdef.sh b/t/inst_funcdef.sh @@ -3,7 +3,7 @@ # Check that really long function declarations are instrumented properly. # . test/utils.sh -plan 4 +plan 5 cat <<EOF > funcdef.c void @@ -39,8 +39,10 @@ Totals: EOF ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c funcdef.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out + +strip_preamble funcdef.c +strip_millis check.out -remove_preamble funcdef.c ok "known good instrumented diff" diff -u funcdef.c.inst_good funcdef.c.citrun_nohdr ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_if.sh b/t/inst_if.sh @@ -3,7 +3,7 @@ # Check that if statement conditions are instrumented properly. # . test/utils.sh -plan 4 +plan 5 cat <<EOF > if.c int main(int argc, char *argv[]) { @@ -48,8 +48,10 @@ Totals: EOF ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c if.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out + +strip_preamble if.c +strip_millis check.out -remove_preamble if.c ok "known good instrumented diff" diff -u if.c.inst_good if.c.citrun_nohdr ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_link_multiple.sh b/t/inst_link_multiple.sh @@ -3,7 +3,7 @@ # Check that linking more than one instrumented object file together works. # . test/utils.sh -plan 3 +plan 4 cat <<EOF > one.c void second_func(); @@ -34,7 +34,7 @@ Main program : one.c two.c three.c ; EOF ok "compiling source w/ jam" $CITRUN_TOOLS/citrun-wrap jam -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out cat <<EOF > check.good Summary: @@ -51,4 +51,5 @@ Totals: 13 Total statements EOF +strip_millis check.out ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_macro.sh b/t/inst_macro.sh @@ -4,7 +4,7 @@ # end of binary operators. # . test/utils.sh -plan 4 +plan 5 cat <<EOF > macro.c #define MAYBE 1023; @@ -37,8 +37,10 @@ Totals: EOF ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c macro.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out + +strip_preamble macro.c +strip_millis check.out -remove_preamble macro.c ok "known good instrumented diff" diff -u macro.c.inst_good macro.c.citrun_nohdr ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_preamble.sh b/t/inst_preamble.sh @@ -3,7 +3,7 @@ # Test that the instrumentation preamble is what we think it is. # . test/utils.sh -plan 2 +plan 3 touch preamble.c ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c preamble.c @@ -34,5 +34,5 @@ static void citrun_constructor() { #endif EOF -sed -i -e 's/".*"/""/' preamble.c.citrun -ok "preamble diff" diff -u preamble.c.good preamble.c.citrun +ok "remove os specific paths" sed -i -e 's/".*"/""/' preamble.c.citrun +ok "diff against known good" diff -u preamble.c.good preamble.c.citrun diff --git a/t/inst_return.sh b/t/inst_return.sh @@ -3,7 +3,7 @@ # Check that return statement values (if any) are instrumented correctly. # . test/utils.sh -plan 4 +plan 5 cat <<EOF > return.c int foo() { @@ -48,8 +48,10 @@ Totals: EOF ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c return.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out + +strip_preamble return.c +strip_millis check.out -remove_preamble return.c ok "instrumented src diff" diff -u return.c.inst_good return.c.citrun_nohdr ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_src_ext.sh b/t/inst_src_ext.sh @@ -3,7 +3,7 @@ # Check that the advertised source file extensions work. # . test/utils.sh -plan 7 +plan 8 touch main.{c,cc,cxx,cpp,C} ok "extension .c" $CITRUN_TOOLS/citrun-wrap cc -c main.c @@ -22,5 +22,6 @@ Totals: 4 Lines of source code EOF -ok "citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +strip_millis check.out ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_switch.sh b/t/inst_switch.sh @@ -3,7 +3,7 @@ # Make sure that switch statement condition instrumentation works. # . test/utils.sh -plan 4 +plan 5 cat <<EOF > switch.c int main(void) { @@ -49,8 +49,10 @@ Totals: EOF ok "citrun-inst" $CITRUN_TOOLS/citrun-inst -c switch.c -ok "citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "citrun-check" $CITRUN_TOOLS/citrun-check -o check.out + +strip_preamble switch.c +strip_millis check.out -remove_preamble switch.c ok "citrun-inst output diff" diff -u switch.c.inst_good switch.c.citrun_nohdr ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_two_src.sh b/t/inst_two_src.sh @@ -4,7 +4,7 @@ # instrumented fully. # . test/utils.sh -plan 3 +plan 4 cat <<EOF > main.c int main(void) { @@ -33,6 +33,7 @@ Totals: EOF ok "citrun-wrap compile" $CITRUN_TOOLS/citrun-wrap cc -o main main.c other.c -ok "citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +strip_millis check.out ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_while.sh b/t/inst_while.sh @@ -3,7 +3,7 @@ # Make sure that while loop condition instrumentation works. # . test/utils.sh -plan 4 +plan 5 cat <<EOF > while.c int main(int argc, char *argv[]) { @@ -40,8 +40,10 @@ Totals: EOF ok "citrun-inst" $CITRUN_TOOLS/citrun-inst -c while.c -ok "citrun-check" $CITRUN_TOOLS/citrun-check -f +ok "citrun-check" $CITRUN_TOOLS/citrun-check -o check.out + +strip_preamble while.c +strip_millis check.out -remove_preamble while.c ok "citrun-inst diff" diff -u while.c.inst_good while.c.citrun_nohdr ok "citrun-check diff" diff -u check.good check.out diff --git a/test/utils.sh b/test/utils.sh @@ -3,7 +3,7 @@ set -o nounset export CITRUN_TOOLS="`pwd`/src" -function remove_preamble +function strip_preamble { file="${1}" tail -n +24 $file.citrun > $file.citrun_nohdr @@ -17,3 +17,8 @@ function strip_log -e "/Milliseconds/d" \ < ${1} > ${1}.stripped } + +function strip_millis +{ + ok "stripping milliseconds" sed -e "/Milliseconds spent/d" -i $1 +}