citrun

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

commit f895e5d9251d317112336760476f1782e3deb6f4
parent b4935642b56ff23dabf1b976fc24c7ef3c60470b
Author: Kyle Milz <kyle@0x30.net>
Date:   Fri, 12 Aug 2016 20:44:17 -0600

src: stop printing number of lines of preamble

Diffstat:
Msrc/check.in | 2+-
Msrc/inst_action.cc | 9++-------
Msrc/inst_log.h | 19++++++++++---------
Msrc/inst_main.cc | 6+++---
Mt/inst_basic_link.t | 1-
Mt/inst_binop.t | 10++++++----
Mt/inst_correct.t | 1-
Mt/inst_dowhile.t | 5++---
Mt/inst_for.t | 5++---
Mt/inst_funcdef.t | 5++---
Mt/inst_if.t | 8++++----
Mt/inst_link_multiple.t | 1-
Mt/inst_log.t | 9++++-----
Mt/inst_macro.t | 5++---
Mt/inst_return.t | 5++---
Mt/inst_stdout.t | 1-
Mt/inst_switch.t | 5++---
Mt/inst_two_src.t | 1-
Mt/inst_while.t | 5++---
Mtest/utils.sh | 9+++++++++
20 files changed, 53 insertions(+), 59 deletions(-)

diff --git a/src/check.in b/src/check.in @@ -12,7 +12,7 @@ fi [ -d $dir ] || err "$dir: no such directory" GREP[1]="Found source file" -GREP[2]="citrun-inst v" +GREP[2]="Tool called as " GREP[3]="Forked " GREP[4]="Instrumentation successful" GREP[5]="And the native compile failed" diff --git a/src/inst_action.cc b/src/inst_action.cc @@ -98,18 +98,13 @@ InstrumentAction::EndSourceFileAction() << "}\n" << "#endif\n"; - std::string header = preamble.str(); - unsigned header_sz = count(header.begin(), header.end(), '\n'); - - if (!m_is_citruninst && m_TheRewriter.InsertTextAfter(start, header)) { - m_log << "Failed inserting " << header_sz - << " lines of instrumentation preabmle."; + if (m_TheRewriter.InsertTextAfter(start, preamble.str())) { + m_log << "Failed to insert the instrumentation preabmle."; return; } m_log << "Instrumentation of '" << m_compiler_file_name << "' finished:\n"; m_log << " " << num_lines << " Lines of source code\n"; - m_log << " " << header_sz << " Lines of instrumentation header\n"; // // Write out statistics from the AST visitor. diff --git a/src/inst_log.h b/src/inst_log.h @@ -9,35 +9,34 @@ class InstrumentLogger { public: InstrumentLogger() : m_pid(getpid()), - m_needs_prefix(true) + m_needs_prefix(true), + m_delete(true) {}; InstrumentLogger(InstrumentLogger &o) : m_pid(o.m_pid), m_output(o.m_output), - m_needs_prefix(o.m_needs_prefix) + m_needs_prefix(o.m_needs_prefix), + m_delete(false) {} - //~InstrumentLogger() - //{ llvm::errs() << "~InstrumentLogger()\n"; }; + ~InstrumentLogger() { if (m_delete) delete m_output; }; void set_output(const bool &is_citruninst) { if (is_citruninst) { m_output = &llvm::outs(); + m_delete = false; return; } else { std::error_code ec; - llvm::raw_fd_ostream *log_file = - new llvm::raw_fd_ostream("citrun.log", ec, llvm::sys::fs::F_Append); + m_output = new llvm::raw_fd_ostream("citrun.log", ec, llvm::sys::fs::F_Append); if (ec.value()) { warnx("citrun.log: %s", ec.message().c_str()); m_output = &llvm::nulls(); + m_delete = false; return; } - m_output = log_file; } - - //m_output = &output; }; template <typename T> @@ -71,6 +70,8 @@ private: if (std::find(rhs.begin(), rhs.end(), '\n') != rhs.end()) m_needs_prefix = true; }; + + bool m_delete; }; #endif // _INST_LOG_H_ diff --git a/src/inst_main.cc b/src/inst_main.cc @@ -93,14 +93,14 @@ print_toolinfo(const char *argv0) struct utsname utsname; if (uname(&utsname) == -1) { warn("uname"); - llog << "(?) "; + llog << "(Unknown OS)\n"; } else { llog << "(" << utsname.sysname << "-" << utsname.release << " " - << utsname.machine << ") "; + << utsname.machine << ")\n"; } - llog << "called as '" << argv0 << "'.\n"; + llog << "Tool called as '" << argv0 << "'.\n"; llog << "Resource directory is '" << STR(CITRUN_SHARE) << "'\n"; } diff --git a/t/inst_basic_link.t b/t/inst_basic_link.t @@ -30,7 +30,6 @@ Summary: Totals: 2 Lines of source code - 32 Lines of instrumentation header 1 Functions called 'main' 1 Function definitions 1 Return statement values diff --git a/t/inst_binop.t b/t/inst_binop.t @@ -1,4 +1,7 @@ -#!/bin/sh -e +#!/bin/sh +# +# Test that binary operators in strange cases work. Includes enums and globals. +# echo 1..3 . test/utils.sh @@ -55,7 +58,6 @@ Summary: Totals: 18 Lines of source code - 32 Lines of instrumentation header 1 Functions called 'main' 1 Function definitions 1 If statements @@ -64,8 +66,8 @@ Totals: 1 Binary operators EOF -$TEST_TOOLS/citrun-inst -c enum.c +$TEST_TOOLS/citrun-inst -c enum.c > citrun.log $TEST_TOOLS/citrun-check > check.out -diff -u enum.c.inst_good enum.c.citrun && echo "ok 2 - instrumented source diff" +inst_diff enum.c 2 diff -u check.good check.out && echo "ok 3 - citrun.log diff" diff --git a/t/inst_correct.t b/t/inst_correct.t @@ -40,7 +40,6 @@ Summary: Totals: 21 Lines of source code - 32 Lines of instrumentation header 1 Functions called 'main' 2 Function definitions 3 If statements diff --git a/t/inst_dowhile.t b/t/inst_dowhile.t @@ -36,7 +36,6 @@ Summary: Totals: 7 Lines of source code - 32 Lines of instrumentation header 1 Functions called 'main' 1 Function definitions 1 Do while loops @@ -45,8 +44,8 @@ Totals: 1 Binary operators EOF -$TEST_TOOLS/citrun-inst -c while.c +$TEST_TOOLS/citrun-inst -c while.c > citrun.log $TEST_TOOLS/citrun-check > check.out -diff -u while.c.inst_good while.c.citrun && echo "ok 2 - instrumented source diff" +inst_diff while.c 2 diff -u check.good check.out && echo "ok 3 - citrun.log diff" diff --git a/t/inst_for.t b/t/inst_for.t @@ -36,7 +36,6 @@ Summary: Totals: 7 Lines of source code - 32 Lines of instrumentation header 1 Functions called 'main' 1 Function definitions 1 For loops @@ -44,8 +43,8 @@ Totals: 2 Binary operators EOF -$TEST_TOOLS/citrun-inst -c for.c +$TEST_TOOLS/citrun-inst -c for.c > citrun.log $TEST_TOOLS/citrun-check > check.out -diff -u for.c.inst_good for.c.citrun && echo "ok 2 - instrumented source diff" +inst_diff for.c 2 diff -u check.good check.out && echo "ok 3 - citrun.log diff" diff --git a/t/inst_funcdef.t b/t/inst_funcdef.t @@ -40,13 +40,12 @@ Summary: Totals: 9 Lines of source code - 32 Lines of instrumentation header 1 Function definitions 1 Total statements EOF -$TEST_TOOLS/citrun-inst -c funcdef.c +$TEST_TOOLS/citrun-inst -c funcdef.c > citrun.log $TEST_TOOLS/citrun-check > check.out -diff -u funcdef.c.inst_good funcdef.c.citrun && echo "ok 2 - instrumented source diff" +inst_diff funcdef.c 2 diff -u check.good check.out && echo "ok 3 - citrun.log diff" diff --git a/t/inst_if.t b/t/inst_if.t @@ -1,4 +1,4 @@ -#!/bin/sh -e +#!/bin/sh echo 1..3 . test/utils.sh @@ -43,7 +43,6 @@ Summary: Totals: 12 Lines of source code - 32 Lines of instrumentation header 1 Functions called 'main' 1 Function definitions 2 If statements @@ -52,8 +51,9 @@ Totals: 2 Binary operators EOF -$TEST_TOOLS/citrun-inst -c if.c +$TEST_TOOLS/citrun-inst -c if.c > citrun.log $TEST_TOOLS/citrun-check > check.out -diff -u if.c.inst_good if.c.citrun && echo "ok 2 - instrumented source diff" +inst_diff if.c 2 +#diff -u if.c.inst_good if.c.citrun && echo "ok 2 - instrumented source diff" diff -u check.good check.out && echo "ok 3 - citrun.log diff" diff --git a/t/inst_link_multiple.t b/t/inst_link_multiple.t @@ -48,7 +48,6 @@ Summary: Totals: 18 Lines of source code - 96 Lines of instrumentation header 1 Functions called 'main' 3 Function definitions 1 Return statement values diff --git a/t/inst_log.t b/t/inst_log.t @@ -43,8 +43,8 @@ sed -e "s,^.*: ,," \ && echo "ok 5 - processed citrun.log" cat <<EOF > citrun.log.good - -citrun-inst v0.0 () called as ''. +citrun-inst 0.0 () +Tool called as ''. Resource directory is '' PATH='' Command line is ''. @@ -53,7 +53,6 @@ Object arg = 1, compile arg = 1 Added clangtool argument ''. Instrumentation of '' finished: 22 Lines of source code - 32 Lines of instrumentation header 1 Functions called '' 2 Function definitions 2 If statements @@ -67,8 +66,8 @@ Running native compiler on modified source code. Forked ''. '' exited 0. Restored ''. - -citrun-inst v0.0 () called as ''. +citrun-inst 0.0 () +Tool called as ''. Resource directory is '' PATH='' Command line is ''. diff --git a/t/inst_macro.t b/t/inst_macro.t @@ -37,15 +37,14 @@ Summary: Totals: 7 Lines of source code - 32 Lines of instrumentation header 1 Functions called 'main' 1 Function definitions 1 Return statement values 7 Total statements EOF -$TEST_TOOLS/citrun-inst -c macro.c +$TEST_TOOLS/citrun-inst -c macro.c > citrun.log $TEST_TOOLS/citrun-check > check.out -diff -u macro.c.inst_good macro.c.citrun && echo "ok 2 - instrumented source diff" +inst_diff macro.c 2 diff -u check.good check.out && echo "ok 3 - citrun.log diff" diff --git a/t/inst_return.t b/t/inst_return.t @@ -43,7 +43,6 @@ Summary: Totals: 12 Lines of source code - 32 Lines of instrumentation header 1 Functions called 'main' 2 Function definitions 4 Return statement values @@ -52,8 +51,8 @@ Totals: 1 Binary operators EOF -$TEST_TOOLS/citrun-inst -c return.c +$TEST_TOOLS/citrun-inst -c return.c > citrun.log $TEST_TOOLS/citrun-check > check.out -diff -u return.c.inst_good return.c.citrun && echo "ok 2 - instrumented source diff" +inst_diff return.c 2 diff -u check.good check.out && echo "ok 3 - citrun.log diff" diff --git a/t/inst_stdout.t b/t/inst_stdout.t @@ -26,7 +26,6 @@ Summary: Totals: 7 Lines of source code - 32 Lines of instrumentation header 1 Functions called 'main' 1 Function definitions 1 Return statement values diff --git a/t/inst_switch.t b/t/inst_switch.t @@ -48,7 +48,6 @@ Summary: Totals: 13 Lines of source code - 32 Lines of instrumentation header 1 Functions called 'main' 1 Function definitions 1 Switch statements @@ -56,8 +55,8 @@ Totals: 14 Total statements EOF -$TEST_TOOLS/citrun-inst -c switch.c +$TEST_TOOLS/citrun-inst -c switch.c > citrun.log $TEST_TOOLS/citrun-check > check.out -diff -u switch.c.inst_good switch.c.citrun && echo "ok 2 - instrumented source diff" +inst_diff switch.c 2 diff -u check.good check.out && echo "ok 3 - citrun.log diff" diff --git a/t/inst_two_src.t b/t/inst_two_src.t @@ -29,7 +29,6 @@ Summary: Totals: 8 Lines of source code - 64 Lines of instrumentation header 1 Functions called 'main' 2 Function definitions 2 Return statement values diff --git a/t/inst_while.t b/t/inst_while.t @@ -38,7 +38,6 @@ Summary: Totals: 8 Lines of source code - 32 Lines of instrumentation header 1 Functions called 'main' 1 Function definitions 2 While loops @@ -47,8 +46,8 @@ Totals: 2 Binary operators EOF -$TEST_TOOLS/citrun-inst -c while.c +$TEST_TOOLS/citrun-inst -c while.c > citrun.log $TEST_TOOLS/citrun-check > check.out -diff -u while.c.inst_good while.c.citrun && echo "ok 2 - instrumented source diff" +inst_diff while.c 2 diff -u check.good check.out && echo "ok 3 - citrun.log diff" diff --git a/test/utils.sh b/test/utils.sh @@ -7,3 +7,12 @@ function setup export TEST_TOOLS="`pwd`/src"; cd $tmpdir } + +function inst_diff +{ + file="${1}" + test_num="${2}" + + tail -n +33 $file.citrun > $file.inst_proc + diff -u $file.inst_good $file.inst_proc && echo "ok $test_num - instrumented source diff" +}