commit 512016a71bf4547db599c73b0fbfcd636cd62a26
parent ad05e70ac6c01ca8defd360d7b3179a322441d78
Author: Kyle Milz <kyle@0x30.net>
Date: Mon, 29 Aug 2016 17:59:07 -0600
t: change shell tests to use libtap.sh
Diffstat:
28 files changed, 313 insertions(+), 221 deletions(-)
diff --git a/t/check_baddir.sh b/t/check_baddir.sh
@@ -1,13 +1,11 @@
+#!/bin/sh
#
# Verify that passing a bad directory to citrun-check errors out.
#
-echo 1..2
. test/utils.sh
+plan 1
-$CITRUN_TOOLS/citrun-check some_nonexistent_dir > check.out
+output_good="citrun-check: some_nonexistent_dir: no such directory"
-cat <<EOF > check.good
-citrun-check: some_nonexistent_dir: no such directory
-EOF
-
-check_diff 2
+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
@@ -1,13 +1,11 @@
+#!/bin/sh
#
# Verify the output when 0 citrun.log files are found.
#
-echo 1..2
. test/utils.sh
+plan 1
-$CITRUN_TOOLS/citrun-check > check.out
+output_good="No log files found."
-cat <<EOF > check.good
-No log files found.
-EOF
-
-diff -u check.good check.out && echo ok
+ok_program "no logs found message" 1 "$output_good" \
+ $CITRUN_TOOLS/citrun-check
diff --git a/t/e2e_basic.sh b/t/e2e_basic.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+#
+# Check that a simple program can execute successfully with instrumentation.
+#
+. test/utils.sh
+plan 6
+
+cat <<EOF > fib.c
+#include <stdio.h>
+#include <stdlib.h>
+
+int fibonacci(int n) {
+ if (n == 0)
+ return 0;
+ else if (n == 1)
+ return 1;
+
+ return fibonacci(n - 1) + fibonacci(n - 2);
+}
+
+int main(int argc, char *argv[]) {
+ int n;
+
+ if (argc != 2)
+ return 1;
+
+ n = atoi(argv[1]);
+ printf("%i", fibonacci(n));
+
+ return 0;
+}
+EOF
+
+cat <<EOF > check.good
+Summary:
+ 1 Source files used as input
+ 1 Application link commands
+ 1 Rewrite successes
+ 1 Rewritten source compile successes
+
+Totals:
+ 24 Lines of source code
+ 2 Function definitions
+ 3 If statements
+ 5 Return statement values
+ 5 Call expressions
+ 64 Total statements
+ 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 -f
+
+ok "citrun-check diff" diff -u check.good check.out
+
+ok_program "fib with no args" 1 "" fib
+ok_program "fib of 10" 0 "55" fib 10
+ok_program "fib of 20" 0 "6765" fib 20
diff --git a/t/e2e_stdout.sh b/t/e2e_stdout.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# Simple program that prints output.
+#
+. test/utils.sh
+plan 4
+
+cat <<EOF > hello.c
+#include <stdio.h>
+
+int main(void) {
+ printf("hello, world!");
+ return 0;
+}
+EOF
+
+cat <<EOF > check.good
+Summary:
+ 1 Source files used as input
+ 1 Application link commands
+ 1 Rewrite successes
+ 1 Rewritten source compile successes
+
+Totals:
+ 7 Lines of source code
+ 1 Function definitions
+ 1 Return statement values
+ 1 Call expressions
+ 9 Total statements
+EOF
+
+ok "wrapped compile" $CITRUN_TOOLS/citrun-wrap cc -o hello hello.c
+
+ok "citrun-check" $CITRUN_TOOLS/citrun-check -f
+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
@@ -1,16 +1,15 @@
+#!/bin/sh
#
# Check that the most basic of compile command lines works.
#
-echo 1..4
. test/utils.sh
+plan 3
cat <<EOF > main.c
int main(void) { return 0; }
EOF
-echo "ok 2 - source files wrote"
-$CITRUN_TOOLS/citrun-wrap cc main.c
-echo "ok 3 - source compiled"
+ok "wrapping simple build command" $CITRUN_TOOLS/citrun-wrap cc main.c
cat <<EOF > check.good
Summary:
@@ -25,5 +24,6 @@ Totals:
1 Return statement values
3 Total statements
EOF
-$CITRUN_TOOLS/citrun-check > check.out
-check_diff 4
+
+ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f
+ok "citrun-check diff" diff -u check.good check.out
diff --git a/t/inst_binop.sh b/t/inst_binop.sh
@@ -1,8 +1,9 @@
+#!/bin/sh
#
# Test that binary operators in strange cases work. Includes enums and globals.
#
-echo 1..3
. test/utils.sh
+plan 4
cat <<EOF > enum.c
enum ASDF {
@@ -58,8 +59,9 @@ Totals:
1 Binary operators
EOF
-$CITRUN_TOOLS/citrun-inst -c enum.c > citrun.log
-$CITRUN_TOOLS/citrun-check > check.out
+ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c enum.c
+ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f
-inst_diff enum.c 2
-check_diff 3
+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
@@ -1,8 +1,9 @@
+#!/bin/sh
#
# Make sure that do while loop condition instrumentation works.
#
-echo 1..3
. test/utils.sh
+plan 4
cat <<EOF > while.c
int main(int argc, char *argv[]) {
@@ -36,8 +37,9 @@ Totals:
1 Binary operators
EOF
-$CITRUN_TOOLS/citrun-inst -c while.c > citrun.log
-$CITRUN_TOOLS/citrun-check > check.out
+ok "citrun-inst rewrite" $CITRUN_TOOLS/citrun-inst -c while.c
+ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f
-inst_diff while.c 2
-check_diff 3
+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
@@ -1,15 +1,19 @@
+#!/bin/sh
#
# Check that a program that won't compile natively is handled properly.
#
-echo 1..4
. test/utils.sh
+plan 3
echo "int main(void) { return 0; " > bad.c
-$CITRUN_TOOLS/citrun-wrap cc -c bad.c 2> err.out
-[ $? -eq 1 ] && echo ok 2
+output_good="1 error generated.
+Error while processing $tmpdir/bad.c.
+bad.c: In function 'main':
+bad.c:1: error: expected declaration or statement at end of input"
-grep -q "error: expected" err.out && echo ok 3
+ok_program "wrapped failing native compile" 1 "$output_good" \
+ $CITRUN_TOOLS/citrun-wrap cc -c bad.c
cat <<EOF > check.good
Summary:
@@ -24,5 +28,5 @@ Totals:
3 Total statements
EOF
-$CITRUN_TOOLS/citrun-check > check.out
-check_diff 4
+ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f
+ok "citrun-check diff" diff -u check.good check.out
diff --git a/t/inst_for.sh b/t/inst_for.sh
@@ -1,8 +1,9 @@
+#!/bin/sh
#
# Test that for loop condition instrumenting works.
#
-echo 1..3
. test/utils.sh
+plan 4
cat <<EOF > for.c
int main(int argc, char *argv[]) {
@@ -35,8 +36,9 @@ Totals:
2 Binary operators
EOF
-$CITRUN_TOOLS/citrun-inst -c for.c > citrun.log
-$CITRUN_TOOLS/citrun-check > check.out
+ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c for.c
+ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f
-inst_diff for.c 2
-check_diff 3
+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
@@ -1,8 +1,9 @@
+#!/bin/sh
#
# Check that really long function declarations are instrumented properly.
#
-echo 1..3
. test/utils.sh
+plan 4
cat <<EOF > funcdef.c
void
@@ -37,8 +38,9 @@ Totals:
1 Total statements
EOF
-$CITRUN_TOOLS/citrun-inst -c funcdef.c > citrun.log
-$CITRUN_TOOLS/citrun-check > check.out
+ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c funcdef.c
+ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f
-inst_diff funcdef.c 2
-check_diff 3
+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
@@ -1,8 +1,9 @@
+#!/bin/sh
#
# Check that if statement conditions are instrumented properly.
#
-echo 1..3
. test/utils.sh
+plan 4
cat <<EOF > if.c
int main(int argc, char *argv[]) {
@@ -46,8 +47,9 @@ Totals:
2 Binary operators
EOF
-$CITRUN_TOOLS/citrun-inst -c if.c > citrun.log
-$CITRUN_TOOLS/citrun-check > check.out
+ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c if.c
+ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f
-inst_diff if.c 2
-check_diff 3
+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
@@ -1,8 +1,9 @@
+#!/bin/sh
#
# Check that linking more than one instrumented object file together works.
#
-echo 1..4
. test/utils.sh
+plan 3
cat <<EOF > one.c
void second_func();
@@ -32,8 +33,8 @@ cat <<EOF > Jamfile
Main program : one.c two.c three.c ;
EOF
-$CITRUN_TOOLS/citrun-wrap jam && echo "ok - source compiled"
-$CITRUN_TOOLS/citrun-check > check.out && echo ok
+ok "compiling source w/ jam" $CITRUN_TOOLS/citrun-wrap jam
+ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f
cat <<EOF > check.good
Summary:
@@ -50,4 +51,4 @@ Totals:
13 Total statements
EOF
-check_diff 4
+ok "citrun-check diff" diff -u check.good check.out
diff --git a/t/inst_log.sh b/t/inst_log.sh
@@ -1,9 +1,10 @@
+#!/bin/sh
#
# 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.
#
-echo 1..6
. test/utils.sh
+plan 2
cat <<EOF > source_0.c
#include <stdlib.h>
@@ -28,21 +29,14 @@ main(int argc, char *argv[])
return fibonacci(n);
}
EOF
-echo "ok 2 - source file wrote"
cat <<EOF > Jamfile
Main program : source_0.c ;
EOF
-echo "ok 3 - Jamfile wrote"
-$CITRUN_TOOLS/citrun-wrap jam && echo "ok 4 - source compiled"
+ok "source compiled with jam" $CITRUN_TOOLS/citrun-wrap jam
-sed -e "s,^.*: ,," \
- -e "s,'.*',''," \
- -e "s,(.*),()," \
- -e "/Milliseconds/d" \
- < citrun.log > citrun.log.proc \
- && echo "ok 5 - processed citrun.log"
+strip_log citrun.log
cat <<EOF > citrun.log.good
citrun-inst 0.0 () ''
@@ -73,4 +67,4 @@ Link detected, adding '' to command line.
No source files found on command line.
EOF
-diff -u citrun.log.good citrun.log.proc && echo "ok 6 - citrun.log diff"
+ok "log file diff" diff -u citrun.log.good citrun.log.stripped
diff --git a/t/inst_macro.sh b/t/inst_macro.sh
@@ -1,9 +1,10 @@
+#!/bin/sh
#
# Test for some tricky macro situations. In particular macro expansions at the
# end of binary operators.
#
-echo 1..3
. test/utils.sh
+plan 4
cat <<EOF > macro.c
#define MAYBE 1023;
@@ -35,8 +36,9 @@ Totals:
7 Total statements
EOF
-$CITRUN_TOOLS/citrun-inst -c macro.c > citrun.log
-$CITRUN_TOOLS/citrun-check > check.out
+ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c macro.c
+ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f
-inst_diff macro.c 2
-check_diff 3
+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_path.sh b/t/inst_path.sh
@@ -1,40 +1,17 @@
+#!/bin/sh
#
# Test that:
# - not having PATH set errors
# - not having CITRUN_SHARE in PATH when using transparent compile mode errors
#
-echo 1..5
+. test/utils.sh
+plan 3
-#
-# This test is a little special. It unsets PATH and sets it to the empty string,
-# so we must save the locations of standard utilities we use to verify things
-# ahead of time.
-#
-grep=`which grep`
-rm=`which rm`
diff=`which diff`
-sed=`which sed`
-cat=`which cat`
-
-tmpdir=`mktemp -d /tmp/citrun.XXXXXXXXXX`
-trap "$rm -rf $tmpdir" EXIT
-echo "ok 1 - tmp dir created"
-
-export CITRUN_TOOLS="`pwd`/src";
-cd $tmpdir
-
-# Save locations to tools because after unset PATH they are not available.
-grep=`which grep`
-
-unset PATH
-$CITRUN_TOOLS/cc -c nomatter.c
-[ $? -eq 1 ] && echo ok 2
+alias sed=`which sed`
+alias expr=`which expr`
-export PATH=""
-$CITRUN_TOOLS/cc -c nomatter.c 2> /dev/null
-[ $? -eq 1 ] && echo ok 3
-
-$cat <<EOF > citrun.log.good
+cat <<EOF > citrun.log.good
citrun-inst 0.0 () ''
Tool called as ''.
PATH is not set.
@@ -44,10 +21,17 @@ PATH=''
'' not in PATH.
EOF
-$sed -e "s,^.*: ,," \
+unset PATH
+ok_program "run citrun-inst as cc with no PATH" 1 "" \
+ $CITRUN_TOOLS/cc -c nomatter.c
+
+export PATH=""
+ok_program "run citrun-inst as cc with empty PATH" 1 "" \
+ $CITRUN_TOOLS/cc -c nomatter.c 2> /dev/null
+
+sed -e "s,^.*: ,," \
-e "s,'.*',''," \
-e "s,(.*),()," \
- < citrun.log > citrun.log.proc \
- && echo "ok 4 - processed citrun.log"
+ < citrun.log > citrun.log.proc
-$diff -u citrun.log.good citrun.log.proc && echo ok 5
+ok "citrun.log diff" $diff -u citrun.log.good citrun.log.proc
diff --git a/t/inst_preamble.sh b/t/inst_preamble.sh
@@ -1,11 +1,12 @@
+#!/bin/sh
#
# Test that the instrumentation preamble is what we think it is.
#
-echo 1..2
. test/utils.sh
+plan 2
touch preamble.c
-$CITRUN_TOOLS/citrun-inst -c preamble.c > citrun.log
+ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c preamble.c
cat <<EOF > preamble.c.good
#ifdef __cplusplus
@@ -34,4 +35,4 @@ static void citrun_constructor() {
EOF
sed -i -e 's/".*"/""/' preamble.c.citrun
-diff -u preamble.c.good preamble.c.citrun && echo ok 2
+ok "preamble diff" diff -u preamble.c.good preamble.c.citrun
diff --git a/t/inst_preprocess.sh b/t/inst_preprocess.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+#
+# Make sure preprocessor flags -E, -MM cause no instrumentation to be done.
+#
+. test/utils.sh
+plan 3
+
+echo "int main(void) { return 0; }" > prepro.c
+
+ok "wrapping compile w/ preprocessor arg -E" \
+ $CITRUN_TOOLS/citrun-wrap cc -E prepro.c
+
+ok "wrapping compile w/ preprocessor arg -MM" \
+ $CITRUN_TOOLS/citrun-wrap cc -E prepro.c
+
+cat <<EOF > citrun.log.good
+citrun-inst 0.0 () ''
+Tool called as ''.
+PATH=''
+Preprocessor argument found
+citrun-inst 0.0 () ''
+Tool called as ''.
+PATH=''
+Preprocessor argument found
+EOF
+
+strip_log citrun.log
+ok "citrun.log diff" diff -u citrun.log.good citrun.log.stripped
diff --git a/t/inst_return.sh b/t/inst_return.sh
@@ -1,8 +1,9 @@
+#!/bin/sh
#
# Check that return statement values (if any) are instrumented correctly.
#
-echo 1..3
. test/utils.sh
+plan 4
cat <<EOF > return.c
int foo() {
@@ -46,8 +47,9 @@ Totals:
1 Binary operators
EOF
-$CITRUN_TOOLS/citrun-inst -c return.c > citrun.log
-$CITRUN_TOOLS/citrun-check > check.out
+ok "running citrun-inst" $CITRUN_TOOLS/citrun-inst -c return.c
+ok "running citrun-check" $CITRUN_TOOLS/citrun-check -f
-inst_diff return.c 2
-check_diff 3
+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
@@ -1,16 +1,16 @@
+#!/bin/sh
#
# Check that the advertised source file extensions work.
#
-echo 1..2
. test/utils.sh
+plan 7
touch main.{c,cc,cxx,cpp,C}
-$CITRUN_TOOLS/citrun-wrap cc -c main.c
-$CITRUN_TOOLS/citrun-wrap c++ -c main.cc
-$CITRUN_TOOLS/citrun-wrap c++ -c main.cxx
-$CITRUN_TOOLS/citrun-wrap c++ -c main.cpp
-# This one isn't supported
-$CITRUN_TOOLS/citrun-wrap cc -c main.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
cat <<EOF > check.good
Summary:
@@ -22,5 +22,5 @@ Totals:
4 Lines of source code
EOF
-$CITRUN_TOOLS/citrun-check > check.out
-check_diff 2
+ok "citrun-check" $CITRUN_TOOLS/citrun-check -f
+ok "citrun-check diff" diff -u check.good check.out
diff --git a/t/inst_switch.sh b/t/inst_switch.sh
@@ -1,8 +1,9 @@
+#!/bin/sh
#
# Make sure that switch statement condition instrumentation works.
#
-echo 1..3
. test/utils.sh
+plan 4
cat <<EOF > switch.c
int main(void) {
@@ -47,8 +48,9 @@ Totals:
14 Total statements
EOF
-$CITRUN_TOOLS/citrun-inst -c switch.c > citrun.log
-$CITRUN_TOOLS/citrun-check > check.out
+ok "citrun-inst" $CITRUN_TOOLS/citrun-inst -c switch.c
+ok "citrun-check" $CITRUN_TOOLS/citrun-check -f
-inst_diff switch.c 2
-check_diff 3
+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
@@ -1,9 +1,10 @@
+#!/bin/sh
#
# Check that two source files given on the same command line both get
# instrumented fully.
#
-echo 1..3
. test/utils.sh
+plan 3
cat <<EOF > main.c
int main(void) {
@@ -31,7 +32,7 @@ Totals:
6 Total statements
EOF
-$CITRUN_TOOLS/citrun-wrap cc -o main main.c other.c && echo "ok - source compiled"
-$CITRUN_TOOLS/citrun-check > check.out
+ok "citrun-wrap compile" $CITRUN_TOOLS/citrun-wrap cc -o main main.c other.c
+ok "citrun-check" $CITRUN_TOOLS/citrun-check -f
-check_diff 3
+ok "citrun-check diff" diff -u check.good check.out
diff --git a/t/inst_while.sh b/t/inst_while.sh
@@ -1,8 +1,9 @@
+#!/bin/sh
#
# Make sure that while loop condition instrumentation works.
#
-echo 1..3
. test/utils.sh
+plan 4
cat <<EOF > while.c
int main(int argc, char *argv[]) {
@@ -38,8 +39,9 @@ Totals:
2 Binary operators
EOF
-$CITRUN_TOOLS/citrun-inst -c while.c > citrun.log
-$CITRUN_TOOLS/citrun-check > check.out
+ok "citrun-inst" $CITRUN_TOOLS/citrun-inst -c while.c
+ok "citrun-check" $CITRUN_TOOLS/citrun-check -f
-inst_diff while.c 2
-check_diff 3
+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/t/rt_badver.sh b/t/rt_badver.sh
@@ -1,9 +1,10 @@
+#!/bin/sh
#
# Check that linking object files of one citrun version with libcitrun of
# another errors.
#
-echo 1..3
. test/utils.sh
+plan 3
cat <<EOF > main.c
#include <stddef.h>
@@ -15,14 +16,8 @@ main(int argc, char *argv[])
}
EOF
-/usr/bin/cc -include $CITRUN_TOOLS/runtime.h -c main.c
-/usr/bin/cc -o main main.o $CITRUN_TOOLS/libcitrun.a
+ok "compile fake node" cc -include $CITRUN_TOOLS/runtime.h -c main.c
+ok "link fake node to libcitrun.a" cc -o main main.o $CITRUN_TOOLS/libcitrun.a
-./main 2> out
-[ $? -eq 1 ] && echo ok 2 - runtime errored program out
-
-cat <<EOF > good
-main: libcitrun 0.0: incompatible node version 0.255
-EOF
-
-diff -u good out && echo ok 3 - error message
+output_good="main: libcitrun 0.0: incompatible node version 0.255"
+ok_program "running fake node" 1 "$output_good" main
diff --git a/t/rt_exectotals.sh b/t/rt_exectotals.sh
@@ -1,17 +1,37 @@
#
# Test that we can count an executing program as its running.
#
-echo 1..3
-. test/project.sh
+. test/utils.sh
+plan 4
-./program 45 &
-pid=$!
+cat <<EOF > check_totals.cc
+#include "src/process_dir.h"
+#include "test/basic.h"
+
+#include <iostream>
+
+int
+main(void)
+{
+ ProcessDir pdir;
+ pdir.scan();
+
+ ProcessFile f = pdir.m_procfiles[0];
-$CITRUN_TOOLS/citrun-dump -t > execs.out
-[ `grep -c "." execs.out` -eq 60 ] && echo ok 2 - citrun-dump -t output enough lines
+ for (int i = 0; i < 60; i++)
+ std::cout << f.total_execs() << std::endl;
+}
+EOF
+
+ok "tap program compile" clang++ -std=c++11 -c check_totals.cc \
+ -I$CITRUN_TOOLS/..
+ok "tap program link" clang++ -o tap_program check_totals.o \
+ $CITRUN_TOOLS/utils.a $CITRUN_TOOLS/../test/tap.a
+
+program 45 &
+pid=$!
-sort -n execs.out > execs.sorted
-test_diff 3 "executions strictly increasing" execs.sorted execs.out
+ok "tap program run" tap_program
kill $pid
wait
diff --git a/t/rt_header.sh b/t/rt_header.sh
@@ -4,6 +4,8 @@
echo 1..2
. test/project.sh
+env
+
./program 1 &
pid=$!
wait
diff --git a/t/wrap_badarg.sh b/t/wrap_badarg.sh
@@ -1,6 +1,7 @@
-echo 1..2
+#!/bin/sh
-out=`src/citrun-wrap -v`
+. test/utils.sh
+plan 1
-[ $? -eq 1 ] && echo ok 1 - return code
-[ "$out" = "usage: citrun-wrap <build cmd>" ] && echo ok 2 - stdout
+output_good="usage: citrun-wrap <build cmd>"
+ok_program "citrun-wrap -ASD" 1 "$output_good" $CITRUN_TOOLS/citrun-wrap -ASD
diff --git a/t/wrap_exitcode.sh b/t/wrap_exitcode.sh
@@ -1,8 +1,10 @@
+#!/bin/sh
#
# Make sure that citrun-wrap exits with the same code as the native build.
#
-echo 1..1
+. test/utils.sh
+plan 1
-src/citrun-wrap ls asdfasdfsaf 2> /dev/null
-
-[ $? -eq 1 ] && echo ok 1 - return code
+output_good="ls: asdfasdfsaf: No such file or directory"
+ok_program "build command exit code" 1 "$output_good" \
+ $CITRUN_TOOLS/citrun-wrap ls asdfasdfsaf
diff --git a/test/utils.sh b/test/utils.sh
@@ -1,69 +1,19 @@
-#
-# Automatically create a temporary directory and define some differencing
-# functions.
+. test/libtap.sh
set -o nounset
-
-tmpdir=`mktemp -d /tmp/citrun.XXXXXXXXXX`
-trap "rm -rf $tmpdir" EXIT
-
export CITRUN_TOOLS="`pwd`/src"
-cd $tmpdir
-echo "ok 1 - tmp dir created"
-
-#
-# Differences two instrumented files. Knocks the header off of the "*.citrun"
-# file.
-#
-function inst_diff
+function remove_preamble
{
file="${1}"
- test_num="${2}"
- test_desc="instrumented source diff"
-
- tail -n +24 $file.citrun > $file.inst_proc
- test_diff $test_num "$test_desc" $file.inst_good $file.inst_proc
+ tail -n +24 $file.citrun > $file.citrun_nohdr
}
-#
-# Differences two citrun-check outputs. Removes the "Milliseconds spent .." line
-# because it always changes.
-#
-function check_diff
+function strip_log
{
- test_num=${1}
- test_desc="citrun-check diff"
-
- grep -v "Milliseconds" check.out > check.proc
- test_diff $test_num "$test_desc" check.good check.proc
-}
-
-#
-# Difference a file listing output from citrun-dump. Must be sorted first.
-#
-function filelist_diff
-{
- test_num="${1}"
- test_desc="source file (path, length) diff"
-
- sort filelist.out > filelist.proc
- test_diff $test_num "$test_desc" filelist.good filelist.proc
- rm filelist.proc
-}
-
-function test_diff
-{
- test_num=${1}
- test_desc="${2}"
- file_one="${3}"
- file_two="${4}"
-
- if diff -u $file_one $file_two > _diff.out; then
- echo ok $test_num - $test_desc
- else
- echo not ok $test_num - $test_desc
- cat _diff.out
- fi
- rm _diff.out
+ sed -e "s,^.*: ,," \
+ -e "s,'.*',''," \
+ -e "s,(.*),()," \
+ -e "/Milliseconds/d" \
+ < ${1} > ${1}.stripped
}