commit 48b86b8c103c391224efc4eb9fef10d028eeefec
parent bfc80f4983e6c3dd36ec9fac933b7c964d6e7a70
Author: Kyle Milz <kyle@0x30.net>
Date: Mon, 1 Aug 2016 13:32:50 -0600
t: add test for citrun.log file
Diffstat:
2 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/src/inst_main.cc b/src/inst_main.cc
@@ -288,7 +288,7 @@ CitrunInst::fork_compiler()
}
m_log << m_pfx << "Forked '" << m_args[0] << "' "
- << "pid is " << child_pid << ".\n";
+ << "pid is '" << child_pid << "'.\n";
int status;
if (waitpid(child_pid, &status, 0) < 0)
@@ -299,7 +299,7 @@ CitrunInst::fork_compiler()
if (WIFEXITED(status))
exit = WEXITSTATUS(status);
- m_log << m_pfx << child_pid << " exited " << exit << ".\n";
+ m_log << m_pfx << "'" << child_pid << "' exited " << exit << ".\n";
return exit;
}
diff --git a/t/inst_log.t b/t/inst_log.t
@@ -0,0 +1,73 @@
+#!/bin/sh -e
+
+echo "1..6"
+
+tmpdir=`mktemp -d /tmp/citrun.XXXXXXXXXX`
+trap "rm -rf $tmpdir" EXIT
+echo "ok 1 - tmp dir created"
+
+cat <<EOF > $tmpdir/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]);
+ fibonacci(n);
+
+ return 0;
+}
+EOF
+echo "ok 2 - source file wrote"
+
+cat <<EOF > $tmpdir/Jamfile
+Main program : source_0.c ;
+EOF
+echo "ok 3 - Jamfile wrote"
+
+export PATH="`pwd`/src:${PATH}"
+cd $tmpdir && jam
+echo "ok 4 - source compiled"
+
+cd $tmpdir && sed -e "s,^.*: ,," -e "s,'.*',''," -e "s,(.*),()," < citrun.log > citrun.log.proc
+echo "ok 5 - processed citrun.log"
+
+cat <<EOF > $tmpdir/citrun.log.good
+citrun-inst v0.0 () called as ''.
+Processing 5 command line arguments.
+Found source file ''.
+Object arg = 1, compile arg = 1
+Attempting instrumentation on ''.
+Adding search path ''.
+Instrumentation successful.
+Running native compiler on possibly modified source code.
+Forked ''.
+'' exited 0.
+Restored ''.
+Done.
+citrun-inst v0.0 () called as ''.
+Processing 4 command line arguments.
+Object arg = 1, compile arg = 0
+No source files to instrument.
+Link detected, adding ''.
+Running native compiler on possibly modified source code.
+Forked ''.
+'' exited 0.
+Done.
+EOF
+
+cd $tmpdir && diff -u citrun.log.proc citrun.log.good
+echo "ok 6 - diffed processed citrun.log against known good"