citrun

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

commit dc6f88cdaca33c52d0e7e443fcf0dbda922708b7
parent 819800c6ac10ee553f70e6f1f05aafef76551ee8
Author: kyle <kyle@0x30.net>
Date:   Mon, 21 Nov 2016 00:58:29 -0700

t: split apart libtap and tmp dir creation

Diffstat:
Mt/check_baddir.sh | 10++++++----
Mt/check_empty.sh | 8+++++---
Mt/e2e_ansi.sh | 10+++++++---
Mt/e2e_basic.sh | 10+++++++---
Mt/e2e_stdout.sh | 10+++++++---
Mt/inst_basic_link.sh | 10+++++++---
Mt/inst_binop.sh | 10+++++++---
Mt/inst_dowhile.sh | 10+++++++---
Mt/inst_fail.sh | 10+++++++---
Mt/inst_for.sh | 10+++++++---
Mt/inst_funcdef.sh | 10+++++++---
Mt/inst_if.sh | 10+++++++---
Mt/inst_link_multiple.sh | 10+++++++---
Mt/inst_log.sh | 8++++++--
Mt/inst_macro.sh | 10+++++++---
Mt/inst_path.sh | 18+++++++++++-------
Mt/inst_preamble.sh | 8++++++--
Mt/inst_preprocess.sh | 13+++++++------
Mt/inst_return.sh | 10+++++++---
Mt/inst_src_ext.sh | 18+++++++++++-------
Mt/inst_switch.sh | 10+++++++---
Mt/inst_two_src.sh | 10+++++++---
Mt/inst_while.sh | 10+++++++---
Mt/libtap.subr | 8+++++---
Mt/rt_badver.sh | 11++++++++---
Mt/utils.subr | 17++++++++++++-----
Mt/wrap_badarg.sh | 6+++---
Mt/wrap_exitcode.sh | 8+++++---
28 files changed, 197 insertions(+), 96 deletions(-)

diff --git a/t/check_baddir.sh b/t/check_baddir.sh @@ -1,11 +1,13 @@ -#!/bin/sh +#!/bin/sh -u # # Verify that passing a bad directory to citrun-check errors out. # +. t/libtap.subr . t/utils.subr plan 1 -output_good="citrun-check: some_nonexistent_dir: directory does not exist" +modify_PATH -ok_program "error on bad dir" 1 "$output_good" \ - $CITRUN_TOOLS/citrun-check some_nonexistent_dir +output_good="citrun-check: _nonexistent_dir_: directory does not exist" + +ok_program "error on bad dir" 1 "$output_good" citrun-check _nonexistent_dir_ diff --git a/t/check_empty.sh b/t/check_empty.sh @@ -1,11 +1,13 @@ -#!/bin/sh +#!/bin/sh -u # # Verify the output when 0 citrun.log files are found. # +. t/libtap.subr . t/utils.subr plan 1 +modify_PATH + output_good="No log files found." -ok_program "is no logs found message printed" 1 "$output_good" \ - $CITRUN_TOOLS/citrun-check +ok_program "is no logs found message printed" 1 "$output_good" citrun-check diff --git a/t/e2e_ansi.sh b/t/e2e_ansi.sh @@ -1,11 +1,15 @@ -#!/bin/sh +#!/bin/sh -u # # Check that instrumentation works when the -ansi flag is passed during # compilation. # +. t/libtap.subr . t/utils.subr plan 4 +modify_PATH +enter_tmpdir + cat <<EOF > main.c int main(void) { @@ -27,8 +31,8 @@ Totals: 3 Total statements EOF -ok "is compile successful" $CITRUN_TOOLS/citrun-wrap cc -ansi -o main main.c -ok "is citrun-check exit 0" $CITRUN_TOOLS/citrun-check -o check.out +ok "is compile successful" citrun-wrap cc -ansi -o main main.c +ok "is citrun-check exit 0" citrun-check -o check.out strip_millis check.out ok "is citrun-check output different" diff -u check.good check.out diff --git a/t/e2e_basic.sh b/t/e2e_basic.sh @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Check that a simple program can execute successfully with instrumentation. # +. t/libtap.subr . t/utils.subr plan 7 +modify_PATH +enter_tmpdir + cat <<EOF > fib.c #include <stdio.h> #include <stdlib.h> @@ -48,8 +52,8 @@ Totals: 7 Binary operators EOF -ok "wrapped source compile" $CITRUN_TOOLS/citrun-wrap cc -o fib fib.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "wrapped source compile" citrun-wrap cc -o fib fib.c +ok "running citrun-check" citrun-check -o check.out strip_millis check.out ok "citrun-check diff" diff -u check.good check.out diff --git a/t/e2e_stdout.sh b/t/e2e_stdout.sh @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Simple program that prints output. # +. t/libtap.subr . t/utils.subr plan 5 +modify_PATH +enter_tmpdir + cat <<EOF > hello.c #include <stdio.h> @@ -29,9 +33,9 @@ Totals: 9 Total statements EOF -ok "wrapped compile" $CITRUN_TOOLS/citrun-wrap cc -o hello hello.c +ok "wrapped compile" citrun-wrap cc -o hello hello.c -ok "citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "citrun-check" citrun-check -o check.out strip_millis check.out ok "citrun-check diff" diff -u check.good check.out diff --git a/t/inst_basic_link.sh b/t/inst_basic_link.sh @@ -1,15 +1,19 @@ -#!/bin/sh +#!/bin/sh -u # # Check that the most basic of compile command lines works. # +. t/libtap.subr . t/utils.subr plan 4 +modify_PATH +enter_tmpdir + cat <<EOF > main.c int main(void) { return 0; } EOF -ok "wrapping simple build command" $CITRUN_TOOLS/citrun-wrap cc main.c +ok "wrapping simple build command" citrun-wrap cc main.c cat <<EOF > check.good Summary: @@ -25,6 +29,6 @@ Totals: 3 Total statements EOF -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "running citrun-check" 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 @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Test that binary operators in strange cases work. Includes enums and globals. # +. t/libtap.subr . t/utils.subr plan 5 +modify_PATH +enter_tmpdir + cat <<EOF > enum.c enum ASDF { ONE = (1 << 0), @@ -59,8 +63,8 @@ Totals: 1 Binary operators EOF -ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c enum.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "running citrun-inst" citrun-inst -c enum.c +ok "running citrun-check" citrun-check -o check.out strip_preamble enum.c strip_millis check.out diff --git a/t/inst_dowhile.sh b/t/inst_dowhile.sh @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Make sure that do while loop condition instrumentation works. # +. t/libtap.subr . t/utils.subr plan 5 +modify_PATH +enter_tmpdir + cat <<EOF > while.c int main(int argc, char *argv[]) { do { @@ -37,8 +41,8 @@ Totals: 1 Binary operators EOF -ok "citrun-inst rewrite" $CITRUN_TOOLS/citrun-inst -c while.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "citrun-inst rewrite" citrun-inst -c while.c +ok "running citrun-check" citrun-check -o check.out strip_preamble while.c strip_millis check.out diff --git a/t/inst_fail.sh b/t/inst_fail.sh @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Check that a program that won't compile natively is handled properly. # +. t/libtap.subr . t/utils.subr plan 4 +modify_PATH +enter_tmpdir + echo "int main(void) { return 0; " > bad.c output_good="1 error generated. @@ -13,7 +17,7 @@ bad.c: In function 'main': bad.c:1: error: expected declaration or statement at end of input" ok_program "wrapped failing native compile" 1 "$output_good" \ - $CITRUN_TOOLS/citrun-wrap cc -c bad.c + citrun-wrap cc -c bad.c cat <<EOF > check.good Summary: @@ -28,6 +32,6 @@ Totals: 3 Total statements EOF -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "running citrun-check" 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 @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Test that for loop condition instrumenting works. # +. t/libtap.subr . t/utils.subr plan 5 +modify_PATH +enter_tmpdir + cat <<EOF > for.c int main(int argc, char *argv[]) { for (;;); @@ -36,8 +40,8 @@ Totals: 2 Binary operators EOF -ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c for.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "running citrun-inst" citrun-inst -c for.c +ok "running citrun-check" citrun-check -o check.out strip_preamble for.c strip_millis check.out diff --git a/t/inst_funcdef.sh b/t/inst_funcdef.sh @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Check that really long function declarations are instrumented properly. # +. t/libtap.subr . t/utils.subr plan 5 +modify_PATH +enter_tmpdir + cat <<EOF > funcdef.c void @@ -38,8 +42,8 @@ Totals: 1 Total statements EOF -ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c funcdef.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "running citrun-inst" citrun-inst -c funcdef.c +ok "running citrun-check" citrun-check -o check.out strip_preamble funcdef.c strip_millis check.out diff --git a/t/inst_if.sh b/t/inst_if.sh @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Check that if statement conditions are instrumented properly. # +. t/libtap.subr . t/utils.subr plan 5 +modify_PATH +enter_tmpdir + cat <<EOF > if.c int main(int argc, char *argv[]) { if (argc == 1) @@ -47,8 +51,8 @@ Totals: 2 Binary operators EOF -ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c if.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "running citrun-inst" citrun-inst -c if.c +ok "running citrun-check" citrun-check -o check.out strip_preamble if.c strip_millis check.out diff --git a/t/inst_link_multiple.sh b/t/inst_link_multiple.sh @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Check that linking more than one instrumented object file together works. # +. t/libtap.subr . t/utils.subr plan 4 +modify_PATH +enter_tmpdir + cat <<EOF > one.c void second_func(); @@ -33,8 +37,8 @@ cat <<EOF > Jamfile 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 -o check.out +ok "compiling source w/ jam" citrun-wrap jam +ok "running citrun-check" citrun-check -o check.out cat <<EOF > check.good Summary: diff --git a/t/inst_log.sh b/t/inst_log.sh @@ -1,11 +1,15 @@ -#!/bin/sh +#!/bin/sh -u # # Check that a raw citrun.log file is in good shape. # citrun-check relies on this output, and citrun-check is used quite a bit. # +. t/libtap.subr . t/utils.subr plan 2 +modify_PATH +enter_tmpdir + cat <<EOF > source_0.c #include <stdlib.h> @@ -34,7 +38,7 @@ cat <<EOF > Jamfile Main program : source_0.c ; EOF -ok "source compiled with jam" $CITRUN_TOOLS/citrun-wrap jam +ok "source compiled with jam" citrun-wrap jam strip_log citrun.log diff --git a/t/inst_macro.sh b/t/inst_macro.sh @@ -1,11 +1,15 @@ -#!/bin/sh +#!/bin/sh -u # # Test for some tricky macro situations. In particular macro expansions at the # end of binary operators. # +. t/libtap.subr . t/utils.subr plan 5 +modify_PATH +enter_tmpdir + cat <<EOF > macro.c #define MAYBE 1023; @@ -36,8 +40,8 @@ Totals: 7 Total statements EOF -ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c macro.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "running citrun-inst" citrun-inst -c macro.c +ok "running citrun-check" citrun-check -o check.out strip_preamble macro.c strip_millis check.out diff --git a/t/inst_path.sh b/t/inst_path.sh @@ -1,25 +1,29 @@ -#!/bin/sh +#!/bin/sh -u # # Test that: # - not having PATH set errors # - not having CITRUN_SHARE in PATH when using transparent compile mode errors # -. t/utils.subr +. t/libtap.subr plan 2 -OLDPATH=${PATH} +# We need the absolute path to this faux compiler because we're killing PATH +# below. +cc=`pwd`/src/cc -# Hang onto an absolute reference to 'expr' for libtap.sh +# Hang onto an absolute reference to 'expr' for libtap. alias expr=`which expr` +alias rm=`which rm` unset PATH output_good='citrun-inst: Error: PATH is not set.' ok_program "run citrun-inst as cc with no PATH" 1 "$output_good" \ - $CITRUN_TOOLS/cc -c nomatter.c + $cc -c nomatter.c export PATH="" output_good="citrun-inst: Error: CITRUN_SHARE not in PATH." ok_program "run citrun-inst as cc with empty PATH" 1 "$output_good" \ - $CITRUN_TOOLS/cc -c nomatter.c 2> /dev/null + $cc -c nomatter.c 2> /dev/null -PATH=${OLDPATH} +# XXX: An empty citrun.log file is left behind. +rm citrun.log diff --git a/t/inst_preamble.sh b/t/inst_preamble.sh @@ -1,12 +1,16 @@ -#!/bin/sh +#!/bin/sh -u # # Test that the instrumentation preamble is what we think it is. # +. t/libtap.subr . t/utils.subr plan 3 +modify_PATH +enter_tmpdir + touch preamble.c -ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c preamble.c +ok "running citrun-inst" citrun-inst -c preamble.c cat <<EOF > preamble.c.good #ifdef __cplusplus diff --git a/t/inst_preprocess.sh b/t/inst_preprocess.sh @@ -1,17 +1,18 @@ -#!/bin/sh +#!/bin/sh -u # # Make sure preprocessor flags -E, -MM cause no instrumentation to be done. # +. t/libtap.subr . t/utils.subr plan 3 -echo "int main(void) { return 0; }" > prepro.c +modify_PATH +enter_tmpdir -ok "wrapping compile w/ preprocessor arg -E" \ - $CITRUN_TOOLS/citrun-wrap cc -E prepro.c +echo "int main(void) { return 0; }" > prepro.c -ok "wrapping compile w/ preprocessor arg -MM" \ - $CITRUN_TOOLS/citrun-wrap cc -E prepro.c +ok "wrapping compile w/ preprocessor arg -E" citrun-wrap cc -E prepro.c +ok "wrapping compile w/ preprocessor arg -MM" citrun-wrap cc -E prepro.c cat <<EOF > citrun.log.good citrun-inst 0.0 () '' diff --git a/t/inst_return.sh b/t/inst_return.sh @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Check that return statement values (if any) are instrumented correctly. # +. t/libtap.subr . t/utils.subr plan 5 +modify_PATH +enter_tmpdir + cat <<EOF > return.c int foo() { return 0; @@ -47,8 +51,8 @@ Totals: 1 Binary operators EOF -ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c return.c -ok "running citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "running citrun-inst" citrun-inst -c return.c +ok "running citrun-check" citrun-check -o check.out strip_preamble return.c strip_millis check.out diff --git a/t/inst_src_ext.sh b/t/inst_src_ext.sh @@ -1,16 +1,20 @@ -#!/bin/sh +#!/bin/sh -u # # Check that the advertised source file extensions work. # +. t/libtap.subr . t/utils.subr plan 8 +modify_PATH +enter_tmpdir + touch main.{c,cc,cxx,cpp,C} -ok "extension .c" $CITRUN_TOOLS/citrun-wrap cc -c main.c -ok "extension .cc" $CITRUN_TOOLS/citrun-wrap c++ -c main.cc -ok "extension .cxx" $CITRUN_TOOLS/citrun-wrap c++ -c main.cxx -ok "extension .cpp" $CITRUN_TOOLS/citrun-wrap c++ -c main.cpp -ok "extension .C (not supported)" $CITRUN_TOOLS/citrun-wrap c++ -c main.C +ok "extension .c" citrun-wrap cc -c main.c +ok "extension .cc" citrun-wrap c++ -c main.cc +ok "extension .cxx" citrun-wrap c++ -c main.cxx +ok "extension .cpp" citrun-wrap c++ -c main.cpp +ok "extension .C (not supported)" citrun-wrap c++ -c main.C cat <<EOF > check.good Summary: @@ -22,6 +26,6 @@ Totals: 4 Lines of source code EOF -ok "citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "citrun-check" 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 @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Make sure that switch statement condition instrumentation works. # +. t/libtap.subr . t/utils.subr plan 5 +modify_PATH +enter_tmpdir + cat <<EOF > switch.c int main(void) { int i; @@ -48,8 +52,8 @@ Totals: 14 Total statements EOF -ok "citrun-inst" $CITRUN_TOOLS/citrun-inst -c switch.c -ok "citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "citrun-inst" citrun-inst -c switch.c +ok "citrun-check" citrun-check -o check.out strip_preamble switch.c strip_millis check.out diff --git a/t/inst_two_src.sh b/t/inst_two_src.sh @@ -1,11 +1,15 @@ -#!/bin/sh +#!/bin/sh -u # # Check that two source files given on the same command line both get # instrumented fully. # +. t/libtap.subr . t/utils.subr plan 4 +modify_PATH +enter_tmpdir + cat <<EOF > main.c int main(void) { return 0; @@ -32,8 +36,8 @@ Totals: 6 Total statements EOF -ok "citrun-wrap compile" $CITRUN_TOOLS/citrun-wrap cc -o main main.c other.c -ok "citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "citrun-wrap compile" citrun-wrap cc -o main main.c other.c +ok "citrun-check" 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 @@ -1,10 +1,14 @@ -#!/bin/sh +#!/bin/sh -u # # Make sure that while loop condition instrumentation works. # +. t/libtap.subr . t/utils.subr plan 5 +modify_PATH +enter_tmpdir + cat <<EOF > while.c int main(int argc, char *argv[]) { while (argc < 17) @@ -39,8 +43,8 @@ Totals: 2 Binary operators EOF -ok "citrun-inst" $CITRUN_TOOLS/citrun-inst -c while.c -ok "citrun-check" $CITRUN_TOOLS/citrun-check -o check.out +ok "citrun-inst" citrun-inst -c while.c +ok "citrun-check" citrun-check -o check.out strip_preamble while.c strip_millis check.out diff --git a/t/libtap.subr b/t/libtap.subr @@ -38,9 +38,7 @@ plan () { planned="$1" failed=0 echo "1..$1" - tmpdir=`mktemp -d /tmp/citrun.XXXXXXXXXX` - trap "finish; rm -rf $tmpdir" 0 - cd $tmpdir + trap finish 0 } # Prepare for lazy planning. @@ -89,6 +87,10 @@ finish () { echo "# $planned test successful or skipped" fi fi + # This is sometimes set by the `enter_tmpdir` function in utils.subr. + if [ ! -z ${tmpdir+x} ]; then + rm -rf $tmpdir + fi } # Skip the entire test suite. Should be run instead of plan. diff --git a/t/rt_badver.sh b/t/rt_badver.sh @@ -1,11 +1,16 @@ -#!/bin/sh +#!/bin/sh -u # # Check that linking object files of one citrun version with libcitrun of # another errors. # +. t/libtap.subr . t/utils.subr plan 3 +# Hang onto the source location before entering the temp dir. +src_dir="`pwd`/src" +enter_tmpdir + cat <<EOF > main.c #include <stddef.h> @@ -16,8 +21,8 @@ main(int argc, char *argv[]) } EOF -ok "compile fake node" cc -include $CITRUN_TOOLS/rt.h -c main.c -ok "link fake node to libcitrun.a" cc -o main main.o $CITRUN_TOOLS/libcitrun.a +ok "compile fake node" cc -include $src_dir/rt.h -c main.c +ok "link fake node to libcitrun.a" cc -o main main.o $src_dir/libcitrun.a output_good="main: libcitrun-0.0: incompatible version 0.255, try cleaning and rebuilding your project" ok_program "running fake node" 1 "$output_good" ./main diff --git a/t/utils.subr b/t/utils.subr @@ -1,8 +1,3 @@ -. t/libtap.subr - -set -o nounset -export CITRUN_TOOLS="`pwd`/src" - strip_preamble() { file="${1}" @@ -22,3 +17,15 @@ strip_millis() { ok "stripping milliseconds" sed -i -e "/Milliseconds spent/d" $1 } + +modify_PATH() +{ + export PATH="`pwd`/src:${PATH}" +} + +enter_tmpdir() +{ + tmpdir=`mktemp -d /tmp/citrun.XXXXXXXXXX` + #trap "rm -rf $tmpdir" 0 + cd $tmpdir +} diff --git a/t/wrap_badarg.sh b/t/wrap_badarg.sh @@ -1,7 +1,7 @@ -#!/bin/sh - +#!/bin/sh -u +. t/libtap.subr . t/utils.subr plan 1 output_good="usage: citrun-wrap <build cmd>" -ok_program "citrun-wrap -ASD" 1 "$output_good" $CITRUN_TOOLS/citrun-wrap -ASD +ok_program "citrun-wrap -ASD" 1 "$output_good" src/citrun-wrap -ASD diff --git a/t/wrap_exitcode.sh b/t/wrap_exitcode.sh @@ -1,10 +1,12 @@ -#!/bin/sh +#!/bin/sh -u # # Make sure that citrun-wrap exits with the same code as the native build. # +. t/libtap.subr . t/utils.subr plan 1 +modify_PATH + output_good="ls: asdfasdfsaf: No such file or directory" -ok_program "build command exit code" 1 "$output_good" \ - $CITRUN_TOOLS/citrun-wrap ls asdfasdfsaf +ok_program "build command exit code" 1 "$output_good" citrun-wrap ls asdfasdfsaf