citrun

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

commit 919e5c8625984c1ca371b64ec0dde46d7aea299e
parent 0b7bebd5c9423a5b44b8b95b48680059fc0e28ac
Author: Kyle Milz <kyle@0x30.net>
Date:   Fri, 19 Aug 2016 20:17:32 -0600

t: use .sh extensions

Diffstat:
A.proverc | 2++
At/check_baddir.sh | 13+++++++++++++
Dt/check_baddir.t | 14--------------
At/check_empty.sh | 13+++++++++++++
Dt/check_empty.t | 14--------------
At/inst_basic_link.sh | 40++++++++++++++++++++++++++++++++++++++++
Dt/inst_basic_link.t | 41-----------------------------------------
At/inst_binop.sh | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dt/inst_binop.t | 67-------------------------------------------------------------------
At/inst_correct.sh | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dt/inst_correct.t | 62--------------------------------------------------------------
At/inst_dowhile.sh | 44++++++++++++++++++++++++++++++++++++++++++++
Dt/inst_dowhile.t | 45---------------------------------------------
At/inst_fail.sh | 13+++++++++++++
Dt/inst_fail.t | 14--------------
At/inst_for.sh | 43+++++++++++++++++++++++++++++++++++++++++++
Dt/inst_for.t | 44--------------------------------------------
At/inst_funcdef.sh | 45+++++++++++++++++++++++++++++++++++++++++++++
Dt/inst_funcdef.t | 46----------------------------------------------
At/inst_if.sh | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dt/inst_if.t | 55-------------------------------------------------------
At/inst_link_multiple.sh | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dt/inst_link_multiple.t | 55-------------------------------------------------------
At/inst_log.sh | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dt/inst_log.t | 79-------------------------------------------------------------------------------
At/inst_macro.sh | 43+++++++++++++++++++++++++++++++++++++++++++
Dt/inst_macro.t | 44--------------------------------------------
At/inst_path.sh | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dt/inst_path.t | 58----------------------------------------------------------
At/inst_preamble.sh | 38++++++++++++++++++++++++++++++++++++++
Dt/inst_preamble.t | 39---------------------------------------
At/inst_return.sh | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dt/inst_return.t | 55-------------------------------------------------------
At/inst_src_ext.sh | 27+++++++++++++++++++++++++++
Dt/inst_src_ext.t | 28----------------------------
At/inst_stdout.sh | 38++++++++++++++++++++++++++++++++++++++
Dt/inst_stdout.t | 39---------------------------------------
At/inst_switch.sh | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dt/inst_switch.t | 56--------------------------------------------------------
At/inst_two_src.sh | 38++++++++++++++++++++++++++++++++++++++
Dt/inst_two_src.t | 39---------------------------------------
At/inst_while.sh | 46++++++++++++++++++++++++++++++++++++++++++++++
Dt/inst_while.t | 47-----------------------------------------------
At/rt_dynamic.sh | 24++++++++++++++++++++++++
Dt/rt_dynamic.t | 25-------------------------
At/rt_source.sh | 25+++++++++++++++++++++++++
Dt/rt_source.t | 26--------------------------
At/rt_static.sh | 30++++++++++++++++++++++++++++++
Dt/rt_static.t | 31-------------------------------
At/rt_ver.sh | 28++++++++++++++++++++++++++++
Dt/rt_ver.t | 29-----------------------------
At/wrap_badarg.sh | 6++++++
Dt/wrap_badarg.t | 7-------
At/wrap_exitcode.sh | 8++++++++
Dt/wrap_exitcode.t | 9---------
55 files changed, 1043 insertions(+), 1068 deletions(-)

diff --git a/.proverc b/.proverc @@ -0,0 +1,2 @@ +-e '/bin/sh' +--ext '.sh' diff --git a/t/check_baddir.sh b/t/check_baddir.sh @@ -0,0 +1,13 @@ +# +# Verify that passing a bad directory to citrun-check errors out. +# +echo 1..2 +. test/utils.sh + +$TEST_TOOLS/citrun-check some_nonexistent_dir > check.out + +cat <<EOF > check.good +citrun-check: some_nonexistent_dir: no such directory +EOF + +check_diff 2 diff --git a/t/check_baddir.t b/t/check_baddir.t @@ -1,14 +0,0 @@ -#!/bin/sh -# -# Verify that passing a bad directory to citrun-check errors out. -# -echo 1..2 -. test/utils.sh - -$TEST_TOOLS/citrun-check some_nonexistent_dir > check.out - -cat <<EOF > check.good -citrun-check: some_nonexistent_dir: no such directory -EOF - -check_diff 2 diff --git a/t/check_empty.sh b/t/check_empty.sh @@ -0,0 +1,13 @@ +# +# Verify the output when 0 citrun.log files are found. +# +echo 1..2 +. test/utils.sh + +$TEST_TOOLS/citrun-check > check.out + +cat <<EOF > check.good +No log files found. +EOF + +diff -u check.good check.out && echo ok diff --git a/t/check_empty.t b/t/check_empty.t @@ -1,14 +0,0 @@ -#!/bin/sh -# -# Verify the output when 0 citrun.log files are found. -# -echo 1..2 -. test/utils.sh - -$TEST_TOOLS/citrun-check > check.out - -cat <<EOF > check.good -No log files found. -EOF - -diff -u check.good check.out && echo ok diff --git a/t/inst_basic_link.sh b/t/inst_basic_link.sh @@ -0,0 +1,40 @@ +# +# Check that the most basic of compile command lines works. +# +echo 1..5 +. test/utils.sh + +cat <<EOF > main.c +int main(void) { return 0; } +EOF +echo "ok 2 - source files wrote" + +# Check that a command as simple as this works. +# +$TEST_TOOLS/citrun-wrap cc main.c +echo "ok 3 - source compiled" + +$TEST_TOOLS/citrun-check > citrun-check.txt +echo "ok 4 - processed citrun.log" + +cat <<EOF > citrun-check.txt.good +Checking ..done + +Summary: + 1 Log files found + 1 Source files input + 1 Calls to the instrumentation tool + 1 Forked compilers + 1 Instrument successes + 1 Application link commands + +Totals: + 2 Lines of source code + 1 Functions called 'main' + 1 Function definitions + 1 Return statement values + 3 Total statements +EOF + +diff -u citrun-check.txt.good citrun-check.txt +echo "ok 5 - citrun.log diff" diff --git a/t/inst_basic_link.t b/t/inst_basic_link.t @@ -1,41 +0,0 @@ -#!/bin/sh -# -# Check that the most basic of compile command lines works. -# -echo 1..5 -. test/utils.sh - -cat <<EOF > main.c -int main(void) { return 0; } -EOF -echo "ok 2 - source files wrote" - -# Check that a command as simple as this works. -# -$TEST_TOOLS/citrun-wrap cc main.c -echo "ok 3 - source compiled" - -$TEST_TOOLS/citrun-check > citrun-check.txt -echo "ok 4 - processed citrun.log" - -cat <<EOF > citrun-check.txt.good -Checking ..done - -Summary: - 1 Log files found - 1 Source files input - 1 Calls to the instrumentation tool - 1 Forked compilers - 1 Instrument successes - 1 Application link commands - -Totals: - 2 Lines of source code - 1 Functions called 'main' - 1 Function definitions - 1 Return statement values - 3 Total statements -EOF - -diff -u citrun-check.txt.good citrun-check.txt -echo "ok 5 - citrun.log diff" diff --git a/t/inst_binop.sh b/t/inst_binop.sh @@ -0,0 +1,66 @@ +# +# Test that binary operators in strange cases work. Includes enums and globals. +# +echo 1..3 +. test/utils.sh + +cat <<EOF > enum.c +enum ASDF { + ONE = (1 << 0), + TWO = (1 << 1), + THR = (1 << 2) +}; + +static int foo = 5 + 5; + +static const struct { + int i; + unsigned char data[0 + 64 * 6]; +} blah; + +int main(void) { + if (4 + 3) + return 0; +} +EOF + +cat <<EOF > enum.c.inst_good +enum ASDF { + ONE = (1 << 0), + TWO = (1 << 1), + THR = (1 << 2) +}; + +static int foo = 5 + 5; + +static const struct { + int i; + unsigned char data[0 + 64 * 6]; +} blah; + +int main(void) {++_citrun.data[13]; + if ((++_citrun.data[14], (++_citrun.data[14], 4 + 3))) + return (++_citrun.data[15], 0); +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 1 Source files used as input + 1 Rewrite successes + +Totals: + 18 Lines of source code + 1 Function definitions + 1 If statements + 1 Return statement values + 7 Total statements + 1 Binary operators +EOF + +$TEST_TOOLS/citrun-inst -c enum.c > citrun.log +$TEST_TOOLS/citrun-check > check.out + +inst_diff enum.c 2 +check_diff 3 diff --git a/t/inst_binop.t b/t/inst_binop.t @@ -1,67 +0,0 @@ -#!/bin/sh -# -# Test that binary operators in strange cases work. Includes enums and globals. -# -echo 1..3 -. test/utils.sh - -cat <<EOF > enum.c -enum ASDF { - ONE = (1 << 0), - TWO = (1 << 1), - THR = (1 << 2) -}; - -static int foo = 5 + 5; - -static const struct { - int i; - unsigned char data[0 + 64 * 6]; -} blah; - -int main(void) { - if (4 + 3) - return 0; -} -EOF - -cat <<EOF > enum.c.inst_good -enum ASDF { - ONE = (1 << 0), - TWO = (1 << 1), - THR = (1 << 2) -}; - -static int foo = 5 + 5; - -static const struct { - int i; - unsigned char data[0 + 64 * 6]; -} blah; - -int main(void) {++_citrun.data[13]; - if ((++_citrun.data[14], (++_citrun.data[14], 4 + 3))) - return (++_citrun.data[15], 0); -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 1 Source files used as input - 1 Rewrite successes - -Totals: - 18 Lines of source code - 1 Function definitions - 1 If statements - 1 Return statement values - 7 Total statements - 1 Binary operators -EOF - -$TEST_TOOLS/citrun-inst -c enum.c > citrun.log -$TEST_TOOLS/citrun-check > check.out - -inst_diff enum.c 2 -check_diff 3 diff --git a/t/inst_correct.sh b/t/inst_correct.sh @@ -0,0 +1,61 @@ +# +# Check that a simple program can execute successfully with instrumentation. +# +echo 1..5 +. test/utils.sh + +cat <<EOF > fib.c +#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]); + return fibonacci(n); +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 1 Source files used as input + 1 Application link commands + 1 Rewrite successes + 1 Rewritten source compile successes + +Totals: + 21 Lines of source code + 2 Function definitions + 3 If statements + 5 Return statement values + 4 Call expressions + 58 Total statements + 7 Binary operators +EOF + +$TEST_TOOLS/citrun-wrap cc -o fib fib.c +$TEST_TOOLS/citrun-check > check.out + +check_diff 2 + +export CITRUN_SOCKET= +./fib +[ $? -eq 255 ] && echo ok + +./fib 10 # = 55 +[ $? -eq 55 ] && echo ok + +./fib 12 # = 6765 +[ $? -eq 144 ] && echo ok diff --git a/t/inst_correct.t b/t/inst_correct.t @@ -1,62 +0,0 @@ -#!/bin/sh -# -# Check that a simple program can execute successfully with instrumentation. -# -echo 1..5 -. test/utils.sh - -cat <<EOF > fib.c -#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]); - return fibonacci(n); -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 1 Source files used as input - 1 Application link commands - 1 Rewrite successes - 1 Rewritten source compile successes - -Totals: - 21 Lines of source code - 2 Function definitions - 3 If statements - 5 Return statement values - 4 Call expressions - 58 Total statements - 7 Binary operators -EOF - -$TEST_TOOLS/citrun-wrap cc -o fib fib.c -$TEST_TOOLS/citrun-check > check.out - -check_diff 2 - -export CITRUN_SOCKET= -./fib -[ $? -eq 255 ] && echo ok - -./fib 10 # = 55 -[ $? -eq 55 ] && echo ok - -./fib 12 # = 6765 -[ $? -eq 144 ] && echo ok diff --git a/t/inst_dowhile.sh b/t/inst_dowhile.sh @@ -0,0 +1,44 @@ +# +# Make sure that do while loop condition instrumentation works. +# +echo 1..3 +. test/utils.sh + +cat <<EOF > while.c +int main(int argc, char *argv[]) { + do { + argc++; + } while (argc != 10); + return 0; +} +EOF + +cat <<EOF > while.c.inst_good +int main(int argc, char *argv[]) {++_citrun.data[0]; + do { + argc++; + } while ((++_citrun.data[3], (++_citrun.data[3], argc != 10))); + return (++_citrun.data[4], 0); +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 1 Source files used as input + 1 Rewrite successes + +Totals: + 7 Lines of source code + 1 Function definitions + 1 Do while loops + 1 Return statement values + 11 Total statements + 1 Binary operators +EOF + +$TEST_TOOLS/citrun-inst -c while.c > citrun.log +$TEST_TOOLS/citrun-check > check.out + +inst_diff while.c 2 +check_diff 3 diff --git a/t/inst_dowhile.t b/t/inst_dowhile.t @@ -1,45 +0,0 @@ -#!/bin/sh -# -# Make sure that do while loop condition instrumentation works. -# -echo 1..3 -. test/utils.sh - -cat <<EOF > while.c -int main(int argc, char *argv[]) { - do { - argc++; - } while (argc != 10); - return 0; -} -EOF - -cat <<EOF > while.c.inst_good -int main(int argc, char *argv[]) {++_citrun.data[0]; - do { - argc++; - } while ((++_citrun.data[3], (++_citrun.data[3], argc != 10))); - return (++_citrun.data[4], 0); -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 1 Source files used as input - 1 Rewrite successes - -Totals: - 7 Lines of source code - 1 Function definitions - 1 Do while loops - 1 Return statement values - 11 Total statements - 1 Binary operators -EOF - -$TEST_TOOLS/citrun-inst -c while.c > citrun.log -$TEST_TOOLS/citrun-check > check.out - -inst_diff while.c 2 -check_diff 3 diff --git a/t/inst_fail.sh b/t/inst_fail.sh @@ -0,0 +1,13 @@ +# +# Check that a program that won't compile natively is handled properly. +# +echo 1..3 +. test/utils.sh + +echo "int main(void) { return 0; " > bad.c + +$TEST_TOOLS/citrun-wrap gcc -c bad.c 2> err.out +[ $? -eq 1 ] && echo ok 2 +grep -q "error: expected" err.out && echo ok 3 + +$TEST_TOOLS/citrun-check diff --git a/t/inst_fail.t b/t/inst_fail.t @@ -1,14 +0,0 @@ -#!/bin/sh -# -# Check that a program that won't compile natively is handled properly. -# -echo 1..3 -. test/utils.sh - -echo "int main(void) { return 0; " > bad.c - -$TEST_TOOLS/citrun-wrap gcc -c bad.c 2> err.out -[ $? -eq 1 ] && echo ok 2 -grep -q "error: expected" err.out && echo ok 3 - -$TEST_TOOLS/citrun-check diff --git a/t/inst_for.sh b/t/inst_for.sh @@ -0,0 +1,43 @@ +# +# Test that for loop condition instrumenting works. +# +echo 1..3 +. test/utils.sh + +cat <<EOF > for.c +int main(int argc, char *argv[]) { + for (;;); + + for (argc = 0; argc < 10; argc++) + argv++; +} +EOF + +cat <<EOF > for.c.inst_good +int main(int argc, char *argv[]) {++_citrun.data[0]; + for (;;); + + for ((++_citrun.data[3], argc = 0); (++_citrun.data[3], (++_citrun.data[3], argc < 10)); argc++) + argv++; +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 1 Source files used as input + 1 Rewrite successes + +Totals: + 7 Lines of source code + 1 Function definitions + 1 For loops + 15 Total statements + 2 Binary operators +EOF + +$TEST_TOOLS/citrun-inst -c for.c > citrun.log +$TEST_TOOLS/citrun-check > check.out + +inst_diff for.c 2 +check_diff 3 diff --git a/t/inst_for.t b/t/inst_for.t @@ -1,44 +0,0 @@ -#!/bin/sh -e -# -# Test that for loop condition instrumenting works. -# -echo 1..3 -. test/utils.sh - -cat <<EOF > for.c -int main(int argc, char *argv[]) { - for (;;); - - for (argc = 0; argc < 10; argc++) - argv++; -} -EOF - -cat <<EOF > for.c.inst_good -int main(int argc, char *argv[]) {++_citrun.data[0]; - for (;;); - - for ((++_citrun.data[3], argc = 0); (++_citrun.data[3], (++_citrun.data[3], argc < 10)); argc++) - argv++; -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 1 Source files used as input - 1 Rewrite successes - -Totals: - 7 Lines of source code - 1 Function definitions - 1 For loops - 15 Total statements - 2 Binary operators -EOF - -$TEST_TOOLS/citrun-inst -c for.c > citrun.log -$TEST_TOOLS/citrun-check > check.out - -inst_diff for.c 2 -check_diff 3 diff --git a/t/inst_funcdef.sh b/t/inst_funcdef.sh @@ -0,0 +1,45 @@ +# +# Check that really long function declarations are instrumented properly. +# +echo 1..3 +. test/utils.sh + +cat <<EOF > funcdef.c +void + +other(int a, + int b) + + +{ +} +EOF + +cat <<EOF > funcdef.c.inst_good +void + +other(int a, + int b) + + +{++_citrun.data[0];++_citrun.data[1];++_citrun.data[2];++_citrun.data[3];++_citrun.data[4];++_citrun.data[5];++_citrun.data[6]; +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 1 Source files used as input + 1 Rewrite successes + +Totals: + 9 Lines of source code + 1 Function definitions + 1 Total statements +EOF + +$TEST_TOOLS/citrun-inst -c funcdef.c > citrun.log +$TEST_TOOLS/citrun-check > check.out + +inst_diff funcdef.c 2 +check_diff 3 diff --git a/t/inst_funcdef.t b/t/inst_funcdef.t @@ -1,46 +0,0 @@ -#!/bin/sh -# -# Check that really long function declarations are instrumented properly. -# -echo 1..3 -. test/utils.sh - -cat <<EOF > funcdef.c -void - -other(int a, - int b) - - -{ -} -EOF - -cat <<EOF > funcdef.c.inst_good -void - -other(int a, - int b) - - -{++_citrun.data[0];++_citrun.data[1];++_citrun.data[2];++_citrun.data[3];++_citrun.data[4];++_citrun.data[5];++_citrun.data[6]; -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 1 Source files used as input - 1 Rewrite successes - -Totals: - 9 Lines of source code - 1 Function definitions - 1 Total statements -EOF - -$TEST_TOOLS/citrun-inst -c funcdef.c > citrun.log -$TEST_TOOLS/citrun-check > check.out - -inst_diff funcdef.c 2 -check_diff 3 diff --git a/t/inst_if.sh b/t/inst_if.sh @@ -0,0 +1,54 @@ +# +# Check that if statement conditions are instrumented properly. +# +echo 1..3 +. test/utils.sh + +cat <<EOF > if.c +int main(int argc, char *argv[]) { + if (argc == 1) + return 1; + else + return(14); + + if ((argc = 2)) + return 5; + else + return(0); +} +EOF + +cat <<EOF > if.c.inst_good +int main(int argc, char *argv[]) {++_citrun.data[0]; + if ((++_citrun.data[1], (++_citrun.data[1], argc == 1))) + return (++_citrun.data[2], 1); + else + return(++_citrun.data[4], (14)); + + if ((++_citrun.data[6], ((++_citrun.data[6], argc = 2)))) + return (++_citrun.data[7], 5); + else + return(++_citrun.data[9], (0)); +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 1 Source files used as input + 1 Rewrite successes + +Totals: + 12 Lines of source code + 1 Function definitions + 2 If statements + 4 Return statement values + 21 Total statements + 2 Binary operators +EOF + +$TEST_TOOLS/citrun-inst -c if.c > citrun.log +$TEST_TOOLS/citrun-check > check.out + +inst_diff if.c 2 +check_diff 3 diff --git a/t/inst_if.t b/t/inst_if.t @@ -1,55 +0,0 @@ -#!/bin/sh -# -# Check that if statement conditions are instrumented properly. -# -echo 1..3 -. test/utils.sh - -cat <<EOF > if.c -int main(int argc, char *argv[]) { - if (argc == 1) - return 1; - else - return(14); - - if ((argc = 2)) - return 5; - else - return(0); -} -EOF - -cat <<EOF > if.c.inst_good -int main(int argc, char *argv[]) {++_citrun.data[0]; - if ((++_citrun.data[1], (++_citrun.data[1], argc == 1))) - return (++_citrun.data[2], 1); - else - return(++_citrun.data[4], (14)); - - if ((++_citrun.data[6], ((++_citrun.data[6], argc = 2)))) - return (++_citrun.data[7], 5); - else - return(++_citrun.data[9], (0)); -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 1 Source files used as input - 1 Rewrite successes - -Totals: - 12 Lines of source code - 1 Function definitions - 2 If statements - 4 Return statement values - 21 Total statements - 2 Binary operators -EOF - -$TEST_TOOLS/citrun-inst -c if.c > citrun.log -$TEST_TOOLS/citrun-check > check.out - -inst_diff if.c 2 -check_diff 3 diff --git a/t/inst_link_multiple.sh b/t/inst_link_multiple.sh @@ -0,0 +1,54 @@ +# +# Check that linking more than one instrumented object file together works. +# +echo 1..4 +. test/utils.sh + +cat <<EOF > one.c +void second_func(); + +int main(void) { + second_func(); + return 0; +} +EOF + +cat <<EOF > two.c +void third_func(); + +void second_func(void) { + third_func(); + return; +} +EOF + +cat <<EOF > three.c +void third_func(void) { + return; +} +EOF + +cat <<EOF > Jamfile +Main program : one.c two.c three.c ; +EOF + +$TEST_TOOLS/citrun-wrap jam && echo "ok - source compiled" +$TEST_TOOLS/citrun-check > check.out && echo ok + +cat <<EOF > check.good +Summary: + 4 Calls to the rewrite tool + 3 Source files used as input + 1 Application link commands + 3 Rewrite successes + 3 Rewritten source compile successes + +Totals: + 18 Lines of source code + 3 Function definitions + 1 Return statement values + 2 Call expressions + 13 Total statements +EOF + +check_diff 4 diff --git a/t/inst_link_multiple.t b/t/inst_link_multiple.t @@ -1,55 +0,0 @@ -#!/bin/sh -# -# Check that linking more than one instrumented object file together works. -# -echo 1..4 -. test/utils.sh - -cat <<EOF > one.c -void second_func(); - -int main(void) { - second_func(); - return 0; -} -EOF - -cat <<EOF > two.c -void third_func(); - -void second_func(void) { - third_func(); - return; -} -EOF - -cat <<EOF > three.c -void third_func(void) { - return; -} -EOF - -cat <<EOF > Jamfile -Main program : one.c two.c three.c ; -EOF - -$TEST_TOOLS/citrun-wrap jam && echo "ok - source compiled" -$TEST_TOOLS/citrun-check > check.out && echo ok - -cat <<EOF > check.good -Summary: - 4 Calls to the rewrite tool - 3 Source files used as input - 1 Application link commands - 3 Rewrite successes - 3 Rewritten source compile successes - -Totals: - 18 Lines of source code - 3 Function definitions - 1 Return statement values - 2 Call expressions - 13 Total statements -EOF - -check_diff 4 diff --git a/t/inst_log.sh b/t/inst_log.sh @@ -0,0 +1,78 @@ +# +# 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 + +cat <<EOF > source_0.c +#include <stdlib.h> + +long long +fibonacci(long long 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[]) +{ + long long n; + + n = atoi(argv[1]); + return fibonacci(n); +} +EOF +echo "ok 2 - source file wrote" + +cat <<EOF > Jamfile +Main program : source_0.c ; +EOF +echo "ok 3 - Jamfile wrote" + +$TEST_TOOLS/citrun-wrap jam && echo "ok 4 - source compiled" + +sed -e "s,^.*: ,," \ + -e "s,'.*',''," \ + -e "s,(.*),()," \ + -e "/Milliseconds/d" \ + < citrun.log > citrun.log.proc \ + && echo "ok 5 - processed citrun.log" + +cat <<EOF > citrun.log.good +citrun-inst 0.0 () +Tool called as ''. +Resource directory is '' +PATH='' +Found source file ''. +Command line is ''. +Added clangtool argument ''. +Instrumentation of '' finished: + 22 Lines of source code + 2 Function definitions + 2 If statements + 4 Return statement values + 4 Call expressions + 58 Total statements + 6 Binary operators +Modified source written successfully. +Rewriting successful. +Forked ''. +'' exited 0. +Rewritten source compile successful. +Restored ''. +citrun-inst 0.0 () +Tool called as ''. +Resource directory is '' +PATH='' +Command line is ''. +Link detected, adding '' to command line. +No source files found. Executing command line. +EOF + +diff -u citrun.log.good citrun.log.proc && echo "ok 6 - citrun.log diff" diff --git a/t/inst_log.t b/t/inst_log.t @@ -1,79 +0,0 @@ -#!/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 - -cat <<EOF > source_0.c -#include <stdlib.h> - -long long -fibonacci(long long 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[]) -{ - long long n; - - n = atoi(argv[1]); - return fibonacci(n); -} -EOF -echo "ok 2 - source file wrote" - -cat <<EOF > Jamfile -Main program : source_0.c ; -EOF -echo "ok 3 - Jamfile wrote" - -$TEST_TOOLS/citrun-wrap jam && echo "ok 4 - source compiled" - -sed -e "s,^.*: ,," \ - -e "s,'.*',''," \ - -e "s,(.*),()," \ - -e "/Milliseconds/d" \ - < citrun.log > citrun.log.proc \ - && echo "ok 5 - processed citrun.log" - -cat <<EOF > citrun.log.good -citrun-inst 0.0 () -Tool called as ''. -Resource directory is '' -PATH='' -Found source file ''. -Command line is ''. -Added clangtool argument ''. -Instrumentation of '' finished: - 22 Lines of source code - 2 Function definitions - 2 If statements - 4 Return statement values - 4 Call expressions - 58 Total statements - 6 Binary operators -Modified source written successfully. -Rewriting successful. -Forked ''. -'' exited 0. -Rewritten source compile successful. -Restored ''. -citrun-inst 0.0 () -Tool called as ''. -Resource directory is '' -PATH='' -Command line is ''. -Link detected, adding '' to command line. -No source files found. Executing command line. -EOF - -diff -u citrun.log.good citrun.log.proc && echo "ok 6 - citrun.log diff" diff --git a/t/inst_macro.sh b/t/inst_macro.sh @@ -0,0 +1,43 @@ +# +# Test for some tricky macro situations. In particular macro expansions at the +# end of binary operators. +# +echo 1..3 +. test/utils.sh + +cat <<EOF > macro.c +#define MAYBE 1023; + +int main(int argc, char *argv[]) { + int abd = 1023 + MAYBE; + return 0; +} +EOF + +cat <<EOF > macro.c.inst_good +#define MAYBE 1023; + +int main(int argc, char *argv[]) {++_citrun.data[2]; + int abd = 1023 + MAYBE; + return (++_citrun.data[4], 0); +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 1 Source files used as input + 1 Rewrite successes + +Totals: + 7 Lines of source code + 1 Function definitions + 1 Return statement values + 7 Total statements +EOF + +$TEST_TOOLS/citrun-inst -c macro.c > citrun.log +$TEST_TOOLS/citrun-check > check.out + +inst_diff macro.c 2 +check_diff 3 diff --git a/t/inst_macro.t b/t/inst_macro.t @@ -1,44 +0,0 @@ -#!/bin/sh -e -# -# Test for some tricky macro situations. In particular macro expansions at the -# end of binary operators. -# -echo 1..3 -. test/utils.sh - -cat <<EOF > macro.c -#define MAYBE 1023; - -int main(int argc, char *argv[]) { - int abd = 1023 + MAYBE; - return 0; -} -EOF - -cat <<EOF > macro.c.inst_good -#define MAYBE 1023; - -int main(int argc, char *argv[]) {++_citrun.data[2]; - int abd = 1023 + MAYBE; - return (++_citrun.data[4], 0); -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 1 Source files used as input - 1 Rewrite successes - -Totals: - 7 Lines of source code - 1 Function definitions - 1 Return statement values - 7 Total statements -EOF - -$TEST_TOOLS/citrun-inst -c macro.c > citrun.log -$TEST_TOOLS/citrun-check > check.out - -inst_diff macro.c 2 -check_diff 3 diff --git a/t/inst_path.sh b/t/inst_path.sh @@ -0,0 +1,57 @@ +# +# Test that: +# - not having PATH set errors +# - not having CITRUN_SHARE in PATH when using transparent compile mode errors +# +echo 1..5 + +# +# 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 TEST_TOOLS="`pwd`/src"; +cd $tmpdir + +# Save locations to tools because after unset PATH they are not available. +grep=`which grep` + +unset PATH +$TEST_TOOLS/gcc -c nomatter.c +[ $? -eq 1 ] && echo ok 2 + +export PATH="" +$TEST_TOOLS/gcc -c nomatter.c 2> /dev/null +[ $? -eq 1 ] && echo ok 3 + +$cat <<EOF > citrun.log.good +citrun-inst 0.0 () +Tool called as ''. +Resource directory is '' +Changing ''. +PATH is not set. +citrun-inst 0.0 () +Tool called as ''. +Resource directory is '' +Changing ''. +PATH='' +'' not in PATH. +EOF + +$sed -e "s,^.*: ,," \ + -e "s,'.*',''," \ + -e "s,(.*),()," \ + < citrun.log > citrun.log.proc \ + && echo "ok 4 - processed citrun.log" + +$diff -u citrun.log.good citrun.log.proc && echo ok 5 diff --git a/t/inst_path.t b/t/inst_path.t @@ -1,58 +0,0 @@ -#!/bin/sh -# -# Test that: -# - not having PATH set errors -# - not having CITRUN_SHARE in PATH when using transparent compile mode errors -# -echo 1..5 - -# -# 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 TEST_TOOLS="`pwd`/src"; -cd $tmpdir - -# Save locations to tools because after unset PATH they are not available. -grep=`which grep` - -unset PATH -$TEST_TOOLS/gcc -c nomatter.c -[ $? -eq 1 ] && echo ok 2 - -export PATH="" -$TEST_TOOLS/gcc -c nomatter.c 2> /dev/null -[ $? -eq 1 ] && echo ok 3 - -$cat <<EOF > citrun.log.good -citrun-inst 0.0 () -Tool called as ''. -Resource directory is '' -Changing ''. -PATH is not set. -citrun-inst 0.0 () -Tool called as ''. -Resource directory is '' -Changing ''. -PATH='' -'' not in PATH. -EOF - -$sed -e "s,^.*: ,," \ - -e "s,'.*',''," \ - -e "s,(.*),()," \ - < citrun.log > citrun.log.proc \ - && echo "ok 4 - processed citrun.log" - -$diff -u citrun.log.good citrun.log.proc && echo ok 5 diff --git a/t/inst_preamble.sh b/t/inst_preamble.sh @@ -0,0 +1,38 @@ +# +# Test that the instrumentation preamble is what we think it is. +# +echo 1..2 +. test/utils.sh + +touch preamble.c +$TEST_TOOLS/citrun-inst -c preamble.c > citrun.log +$TEST_TOOLS/citrun-check + +cat <<EOF > preamble.c.good +#ifdef __cplusplus +extern "" { +#endif +#include <stdint.h> +struct citrun_node { + uint32_t size; + const char *comp_file_path; + const char *abs_file_path; + uint64_t *data; +}; +void citrun_node_add(uint8_t, uint8_t, struct citrun_node *); +static struct citrun_node _citrun = { + 1, + "", + "", +}; +__attribute__((constructor)) +static void citrun_constructor() { + citrun_node_add(0, 0, &_citrun); +} +#ifdef __cplusplus +} +#endif +EOF + +sed -i "s/\".*\"/\"\"/" preamble.c.citrun +diff -u preamble.c.good preamble.c.citrun && echo ok 2 diff --git a/t/inst_preamble.t b/t/inst_preamble.t @@ -1,39 +0,0 @@ -#!/bin/sh -# -# Test that the instrumentation preamble is what we think it is. -# -echo 1..2 -. test/utils.sh - -touch preamble.c -$TEST_TOOLS/citrun-inst -c preamble.c > citrun.log -$TEST_TOOLS/citrun-check - -cat <<EOF > preamble.c.good -#ifdef __cplusplus -extern "" { -#endif -#include <stdint.h> -struct citrun_node { - uint32_t size; - const char *comp_file_path; - const char *abs_file_path; - uint64_t *data; -}; -void citrun_node_add(uint8_t, uint8_t, struct citrun_node *); -static struct citrun_node _citrun = { - 1, - "", - "", -}; -__attribute__((constructor)) -static void citrun_constructor() { - citrun_node_add(0, 0, &_citrun); -} -#ifdef __cplusplus -} -#endif -EOF - -sed -i "s/\".*\"/\"\"/" preamble.c.citrun -diff -u preamble.c.good preamble.c.citrun && echo ok 2 diff --git a/t/inst_return.sh b/t/inst_return.sh @@ -0,0 +1,54 @@ +# +# Check that return statement values (if any) are instrumented correctly. +# +echo 1..3 +. test/utils.sh + +cat <<EOF > return.c +int foo() { + return 0; +} + +int main(void) { + return 10; + + return 10 + 10; + + return foo(); +} +EOF + +cat <<EOF > return.c.inst_good +int foo() {++_citrun.data[0]; + return (++_citrun.data[1], 0); +} + +int main(void) {++_citrun.data[4]; + return (++_citrun.data[5], 10); + + return (++_citrun.data[7], (++_citrun.data[7], 10 + 10)); + + return (++_citrun.data[9], (++_citrun.data[9], foo())); +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 1 Source files used as input + 1 Rewrite successes + +Totals: + 12 Lines of source code + 2 Function definitions + 4 Return statement values + 1 Call expressions + 14 Total statements + 1 Binary operators +EOF + +$TEST_TOOLS/citrun-inst -c return.c > citrun.log +$TEST_TOOLS/citrun-check > check.out + +inst_diff return.c 2 +check_diff 3 diff --git a/t/inst_return.t b/t/inst_return.t @@ -1,55 +0,0 @@ -#!/bin/sh -# -# Check that return statement values (if any) are instrumented correctly. -# -echo 1..3 -. test/utils.sh - -cat <<EOF > return.c -int foo() { - return 0; -} - -int main(void) { - return 10; - - return 10 + 10; - - return foo(); -} -EOF - -cat <<EOF > return.c.inst_good -int foo() {++_citrun.data[0]; - return (++_citrun.data[1], 0); -} - -int main(void) {++_citrun.data[4]; - return (++_citrun.data[5], 10); - - return (++_citrun.data[7], (++_citrun.data[7], 10 + 10)); - - return (++_citrun.data[9], (++_citrun.data[9], foo())); -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 1 Source files used as input - 1 Rewrite successes - -Totals: - 12 Lines of source code - 2 Function definitions - 4 Return statement values - 1 Call expressions - 14 Total statements - 1 Binary operators -EOF - -$TEST_TOOLS/citrun-inst -c return.c > citrun.log -$TEST_TOOLS/citrun-check > check.out - -inst_diff return.c 2 -check_diff 3 diff --git a/t/inst_src_ext.sh b/t/inst_src_ext.sh @@ -0,0 +1,27 @@ +# +# Check that the advertised source file extensions work. +# +echo 1..2 +. test/utils.sh + +touch main.{c,cc,cxx,cpp,C} +$TEST_TOOLS/citrun-wrap cc -c main.c +$TEST_TOOLS/citrun-wrap c++ -c main.cc +$TEST_TOOLS/citrun-wrap c++ -c main.cxx +$TEST_TOOLS/citrun-wrap c++ -c main.cpp +# This one isn't supported +$TEST_TOOLS/citrun-wrap cc -c main.C + +cat <<EOF > check.good +Summary: + 5 Calls to the rewrite tool + 4 Source files used as input + 4 Rewrite successes + 4 Rewritten source compile successes + +Totals: + 4 Lines of source code +EOF + +$TEST_TOOLS/citrun-check > check.out +check_diff 2 diff --git a/t/inst_src_ext.t b/t/inst_src_ext.t @@ -1,28 +0,0 @@ -#!/bin/sh -# -# Check that the advertised source file extensions work. -# -echo 1..2 -. test/utils.sh - -touch main.{c,cc,cxx,cpp,C} -$TEST_TOOLS/citrun-wrap cc -c main.c -$TEST_TOOLS/citrun-wrap c++ -c main.cc -$TEST_TOOLS/citrun-wrap c++ -c main.cxx -$TEST_TOOLS/citrun-wrap c++ -c main.cpp -# This one isn't supported -$TEST_TOOLS/citrun-wrap cc -c main.C - -cat <<EOF > check.good -Summary: - 5 Calls to the rewrite tool - 4 Source files used as input - 4 Rewrite successes - 4 Rewritten source compile successes - -Totals: - 4 Lines of source code -EOF - -$TEST_TOOLS/citrun-check > check.out -check_diff 2 diff --git a/t/inst_stdout.sh b/t/inst_stdout.sh @@ -0,0 +1,38 @@ +# +# Simple program that prints output. +# +echo 1..3 +. test/utils.sh + +cat <<EOF > hello.c +#include <stdio.h> + +int main(void) { + printf("hello, world!"); + return 0; +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 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 + +$TEST_TOOLS/citrun-wrap cc -o hello hello.c +$TEST_TOOLS/citrun-check > check.out + +export CITRUN_SOCKET= +[ "`./hello`" = "hello, world!" ] && echo ok program prints + +check_diff 3 diff --git a/t/inst_stdout.t b/t/inst_stdout.t @@ -1,39 +0,0 @@ -#!/bin/sh -# -# Simple program that prints output. -# -echo 1..3 -. test/utils.sh - -cat <<EOF > hello.c -#include <stdio.h> - -int main(void) { - printf("hello, world!"); - return 0; -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 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 - -$TEST_TOOLS/citrun-wrap cc -o hello hello.c -$TEST_TOOLS/citrun-check > check.out - -export CITRUN_SOCKET= -[ "`./hello`" = "hello, world!" ] && echo ok program prints - -check_diff 3 diff --git a/t/inst_switch.sh b/t/inst_switch.sh @@ -0,0 +1,55 @@ +# +# Make sure that switch statement condition instrumentation works. +# +echo 1..3 +. test/utils.sh + +cat <<EOF > switch.c +int main(void) { + int i; + + switch (i) { + case 0: + break; + case 1: + break; + } + + return 0; +} +EOF + +cat <<EOF > switch.c.inst_good +int main(void) {++_citrun.data[0]; + int i; + + switch ((++_citrun.data[3], i)) { + case 0: + break; + case 1: + break; + } + + return (++_citrun.data[10], 0); +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 1 Source files used as input + 1 Rewrite successes + +Totals: + 13 Lines of source code + 1 Function definitions + 1 Switch statements + 1 Return statement values + 14 Total statements +EOF + +$TEST_TOOLS/citrun-inst -c switch.c > citrun.log +$TEST_TOOLS/citrun-check > check.out + +inst_diff switch.c 2 +check_diff 3 diff --git a/t/inst_switch.t b/t/inst_switch.t @@ -1,56 +0,0 @@ -#!/bin/sh -# -# Make sure that switch statement condition instrumentation works. -# -echo 1..3 -. test/utils.sh - -cat <<EOF > switch.c -int main(void) { - int i; - - switch (i) { - case 0: - break; - case 1: - break; - } - - return 0; -} -EOF - -cat <<EOF > switch.c.inst_good -int main(void) {++_citrun.data[0]; - int i; - - switch ((++_citrun.data[3], i)) { - case 0: - break; - case 1: - break; - } - - return (++_citrun.data[10], 0); -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 1 Source files used as input - 1 Rewrite successes - -Totals: - 13 Lines of source code - 1 Function definitions - 1 Switch statements - 1 Return statement values - 14 Total statements -EOF - -$TEST_TOOLS/citrun-inst -c switch.c > citrun.log -$TEST_TOOLS/citrun-check > check.out - -inst_diff switch.c 2 -check_diff 3 diff --git a/t/inst_two_src.sh b/t/inst_two_src.sh @@ -0,0 +1,38 @@ +# +# Check that two source files given on the same command line both get +# instrumented fully. +# +echo 1..3 +. test/utils.sh + +cat <<EOF > main.c +int main(void) { + return 0; +} +EOF + +cat <<EOF > other.c +int other(void) { + return 0; +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 2 Source files used as input + 1 Application link commands + 1 Rewrite successes + 1 Rewritten source compile successes + +Totals: + 8 Lines of source code + 2 Function definitions + 2 Return statement values + 6 Total statements +EOF + +$TEST_TOOLS/citrun-wrap cc -o main main.c other.c && echo "ok - source compiled" +$TEST_TOOLS/citrun-check > check.out + +check_diff 3 diff --git a/t/inst_two_src.t b/t/inst_two_src.t @@ -1,39 +0,0 @@ -#!/bin/sh -# -# Check that two source files given on the same command line both get -# instrumented fully. -# -echo 1..3 -. test/utils.sh - -cat <<EOF > main.c -int main(void) { - return 0; -} -EOF - -cat <<EOF > other.c -int other(void) { - return 0; -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 2 Source files used as input - 1 Application link commands - 1 Rewrite successes - 1 Rewritten source compile successes - -Totals: - 8 Lines of source code - 2 Function definitions - 2 Return statement values - 6 Total statements -EOF - -$TEST_TOOLS/citrun-wrap cc -o main main.c other.c && echo "ok - source compiled" -$TEST_TOOLS/citrun-check > check.out - -check_diff 3 diff --git a/t/inst_while.sh b/t/inst_while.sh @@ -0,0 +1,46 @@ +# +# Make sure that while loop condition instrumentation works. +# +echo 1..3 +. test/utils.sh + +cat <<EOF > while.c +int main(int argc, char *argv[]) { + while (argc < 17) + argc++; + + while ((argc && argv)); + return 0; +} +EOF + +cat <<EOF > while.c.inst_good +int main(int argc, char *argv[]) {++_citrun.data[0]; + while ((++_citrun.data[1], (++_citrun.data[1], argc < 17))) + argc++; + + while ((++_citrun.data[4], ((++_citrun.data[4], argc && argv)))); + return (++_citrun.data[5], 0); +} +EOF + +cat <<EOF > check.good +Summary: + 1 Calls to the rewrite tool + 1 Source files used as input + 1 Rewrite successes + +Totals: + 8 Lines of source code + 1 Function definitions + 2 While loops + 1 Return statement values + 18 Total statements + 2 Binary operators +EOF + +$TEST_TOOLS/citrun-inst -c while.c > citrun.log +$TEST_TOOLS/citrun-check > check.out + +inst_diff while.c 2 +check_diff 3 diff --git a/t/inst_while.t b/t/inst_while.t @@ -1,47 +0,0 @@ -#!/bin/sh -e -# -# Make sure that while loop condition instrumentation works. -# -echo 1..3 -. test/utils.sh - -cat <<EOF > while.c -int main(int argc, char *argv[]) { - while (argc < 17) - argc++; - - while ((argc && argv)); - return 0; -} -EOF - -cat <<EOF > while.c.inst_good -int main(int argc, char *argv[]) {++_citrun.data[0]; - while ((++_citrun.data[1], (++_citrun.data[1], argc < 17))) - argc++; - - while ((++_citrun.data[4], ((++_citrun.data[4], argc && argv)))); - return (++_citrun.data[5], 0); -} -EOF - -cat <<EOF > check.good -Summary: - 1 Calls to the rewrite tool - 1 Source files used as input - 1 Rewrite successes - -Totals: - 8 Lines of source code - 1 Function definitions - 2 While loops - 1 Return statement values - 18 Total statements - 2 Binary operators -EOF - -$TEST_TOOLS/citrun-inst -c while.c > citrun.log -$TEST_TOOLS/citrun-check > check.out - -inst_diff while.c 2 -check_diff 3 diff --git a/t/rt_dynamic.sh b/t/rt_dynamic.sh @@ -0,0 +1,24 @@ +# +# Test that we can count an executing program as its running. +# +echo 1..2 +. test/project.sh + +./program 45 & +pid=$! + +let n=0 +let lst=0 +let cur=0 +let bad=0 +while [ $n -lt 60 ]; do + cur=`$TEST_TOOLS/citrun-dump -t` + [ $cur -lt $lst ] && let bad++ + let lst=cur + let n++ +done +[ $bad -eq 0 ] && echo ok 2 - program count increased 60 times + + +kill -USR1 $pid +wait diff --git a/t/rt_dynamic.t b/t/rt_dynamic.t @@ -1,25 +0,0 @@ -#!/bin/sh -# -# Test that we can count an executing program as its running. -# -echo 1..2 -. test/project.sh - -./program 45 & -pid=$! - -let n=0 -let lst=0 -let cur=0 -let bad=0 -while [ $n -lt 60 ]; do - cur=`$TEST_TOOLS/citrun-dump -t` - [ $cur -lt $lst ] && let bad++ - let lst=cur - let n++ -done -[ $bad -eq 0 ] && echo ok 2 - program count increased 60 times - - -kill -USR1 $pid -wait diff --git a/t/rt_source.sh b/t/rt_source.sh @@ -0,0 +1,25 @@ +# +# Test that the source files the runtime passed us and we loaded are identical +# to the original source files on disk. +# +echo 1..4 +. test/project.sh + +./program 45 & +pid=$! + +$TEST_TOOLS/citrun-dump -s one.c > one.c.runtime +$TEST_TOOLS/citrun-dump -s two.c > two.c.runtime +$TEST_TOOLS/citrun-dump -s three.c > three.c.runtime + +kill -USR1 $pid +wait + +# Bug in parsing source line by line in c++ +echo >> one.c +echo >> two.c +echo >> three.c + +test_diff 2 "one.c diff runtime and disk" one.c one.c.runtime +test_diff 3 "two.c diff runtime and disk" two.c two.c.runtime +test_diff 4 "three.c diff runtime and disk" three.c three.c.runtime diff --git a/t/rt_source.t b/t/rt_source.t @@ -1,26 +0,0 @@ -#!/bin/sh -# -# Test that the source files the runtime passed us and we loaded are identical -# to the original source files on disk. -# -echo 1..4 -. test/project.sh - -./program 45 & -pid=$! - -$TEST_TOOLS/citrun-dump -s one.c > one.c.runtime -$TEST_TOOLS/citrun-dump -s two.c > two.c.runtime -$TEST_TOOLS/citrun-dump -s three.c > three.c.runtime - -kill -USR1 $pid -wait - -# Bug in parsing source line by line in c++ -echo >> one.c -echo >> two.c -echo >> three.c - -test_diff 2 "one.c diff runtime and disk" one.c one.c.runtime -test_diff 3 "two.c diff runtime and disk" two.c two.c.runtime -test_diff 4 "three.c diff runtime and disk" three.c three.c.runtime diff --git a/t/rt_static.sh b/t/rt_static.sh @@ -0,0 +1,30 @@ +# +# Test that the basic static structure of the shared memory region is what we +# expect. +# +echo 1..4 +. test/project.sh + +./program 45 & +pid=$! + +$TEST_TOOLS/citrun-dump | grep -e "Versi" -e "Progr" -e "Translat" > dump.out +$TEST_TOOLS/citrun-dump -f > filelist.out + +kill -USR1 $pid +wait +[ $? -eq 0 ] && echo ok 2 - program return code after SIGUSR1 + +cat <<EOF > dump.good +Version: 0.0 +Program name: program +Translation units: 3 +EOF +test_diff 3 "citrun-dump output" dump.out dump.good + +cat <<EOF > filelist.good +one.c 34 +three.c 9 +two.c 11 +EOF +filelist_diff 4 diff --git a/t/rt_static.t b/t/rt_static.t @@ -1,31 +0,0 @@ -#!/bin/sh -# -# Test that the basic static structure of the shared memory region is what we -# expect. -# -echo 1..4 -. test/project.sh - -./program 45 & -pid=$! - -$TEST_TOOLS/citrun-dump | grep -e "Versi" -e "Progr" -e "Translat" > dump.out -$TEST_TOOLS/citrun-dump -f > filelist.out - -kill -USR1 $pid -wait -[ $? -eq 0 ] && echo ok 2 - program return code after SIGUSR1 - -cat <<EOF > dump.good -Version: 0.0 -Program name: program -Translation units: 3 -EOF -test_diff 3 "citrun-dump output" dump.out dump.good - -cat <<EOF > filelist.good -one.c 34 -three.c 9 -two.c 11 -EOF -filelist_diff 4 diff --git a/t/rt_ver.sh b/t/rt_ver.sh @@ -0,0 +1,28 @@ +# +# Check that linking object files of one citrun version with libcitrun of +# another shows a warning message. +# +echo 1..2 +. test/utils.sh + +cat <<EOF > main.c +#include <stddef.h> + +int +main(int argc, char *argv[]) +{ + citrun_node_add(0, 255, NULL); +} +EOF + +/usr/bin/cc -c main.c +/usr/bin/cc -o main main.o $TEST_TOOLS/libcitrun.a + +export CITRUN_SOCKET= +main 2> out + +cat <<EOF > good +main: libcitrun 0.0: node with version 0.255 skipped +EOF + +diff -u good out && echo ok 2 diff --git a/t/rt_ver.t b/t/rt_ver.t @@ -1,29 +0,0 @@ -#!/bin/sh -# -# Check that linking object files of one citrun version with libcitrun of -# another shows a warning message. -# -echo 1..2 -. test/utils.sh - -cat <<EOF > main.c -#include <stddef.h> - -int -main(int argc, char *argv[]) -{ - citrun_node_add(0, 255, NULL); -} -EOF - -/usr/bin/cc -c main.c -/usr/bin/cc -o main main.o $TEST_TOOLS/libcitrun.a - -export CITRUN_SOCKET= -main 2> out - -cat <<EOF > good -main: libcitrun 0.0: node with version 0.255 skipped -EOF - -diff -u good out && echo ok 2 diff --git a/t/wrap_badarg.sh b/t/wrap_badarg.sh @@ -0,0 +1,6 @@ +echo 1..2 + +out=`src/citrun-wrap -v` + +[ $? -eq 1 ] && echo ok 1 - return code +[ "$out" = "usage: citrun-wrap <build cmd>" ] && echo ok 2 - stdout diff --git a/t/wrap_badarg.t b/t/wrap_badarg.t @@ -1,7 +0,0 @@ -#!/bin/sh -echo 1..2 - -out=`src/citrun-wrap -v` - -[ $? -eq 1 ] && echo ok 1 - return code -[ "$out" = "usage: citrun-wrap <build cmd>" ] && echo ok 2 - stdout diff --git a/t/wrap_exitcode.sh b/t/wrap_exitcode.sh @@ -0,0 +1,8 @@ +# +# Make sure that citrun-wrap exits with the same code as the native build. +# +echo 1..1 + +src/citrun-wrap ls asdfasdfsaf 2> /dev/null + +[ $? -eq 1 ] && echo ok 1 - return code diff --git a/t/wrap_exitcode.t b/t/wrap_exitcode.t @@ -1,9 +0,0 @@ -#!/bin/sh -# -# Make sure that citrun-wrap exits with the same code as the native build. -# -echo 1..1 - -src/citrun-wrap ls asdfasdfsaf 2> /dev/null - -[ $? -eq 1 ] && echo ok 1 - return code