commit 5914d38f4dba8090441324e774d2af44ab11c51a
parent f1db2b60be4aa2f33b98d20eb4f8bf9e87c8a8a7
Author: Kyle Milz <kyle@0x30.net>
Date: Fri, 2 Sep 2016 00:49:22 -0600
rename test to tlib
Diffstat:
52 files changed, 340 insertions(+), 340 deletions(-)
diff --git a/t/check_baddir.sh b/t/check_baddir.sh
@@ -2,7 +2,7 @@
#
# Verify that passing a bad directory to citrun-check errors out.
#
-. test/utils.sh
+. tlib/utils.sh
plan 1
output_good="citrun-check: some_nonexistent_dir: directory does not exist"
diff --git a/t/check_empty.sh b/t/check_empty.sh
@@ -2,7 +2,7 @@
#
# Verify the output when 0 citrun.log files are found.
#
-. test/utils.sh
+. tlib/utils.sh
plan 1
output_good="No log files found."
diff --git a/t/e2e_basic.sh b/t/e2e_basic.sh
@@ -2,7 +2,7 @@
#
# Check that a simple program can execute successfully with instrumentation.
#
-. test/utils.sh
+. tlib/utils.sh
plan 7
cat <<EOF > fib.c
diff --git a/t/e2e_stdout.sh b/t/e2e_stdout.sh
@@ -2,7 +2,7 @@
#
# Simple program that prints output.
#
-. test/utils.sh
+. tlib/utils.sh
plan 5
cat <<EOF > hello.c
diff --git a/t/inst_basic_link.sh b/t/inst_basic_link.sh
@@ -2,7 +2,7 @@
#
# Check that the most basic of compile command lines works.
#
-. test/utils.sh
+. tlib/utils.sh
plan 4
cat <<EOF > main.c
diff --git a/t/inst_binop.sh b/t/inst_binop.sh
@@ -2,7 +2,7 @@
#
# Test that binary operators in strange cases work. Includes enums and globals.
#
-. test/utils.sh
+. tlib/utils.sh
plan 5
cat <<EOF > enum.c
diff --git a/t/inst_dowhile.sh b/t/inst_dowhile.sh
@@ -2,7 +2,7 @@
#
# Make sure that do while loop condition instrumentation works.
#
-. test/utils.sh
+. tlib/utils.sh
plan 5
cat <<EOF > while.c
diff --git a/t/inst_fail.sh b/t/inst_fail.sh
@@ -2,7 +2,7 @@
#
# Check that a program that won't compile natively is handled properly.
#
-. test/utils.sh
+. tlib/utils.sh
plan 4
echo "int main(void) { return 0; " > bad.c
diff --git a/t/inst_for.sh b/t/inst_for.sh
@@ -2,7 +2,7 @@
#
# Test that for loop condition instrumenting works.
#
-. test/utils.sh
+. tlib/utils.sh
plan 5
cat <<EOF > for.c
diff --git a/t/inst_funcdef.sh b/t/inst_funcdef.sh
@@ -2,7 +2,7 @@
#
# Check that really long function declarations are instrumented properly.
#
-. test/utils.sh
+. tlib/utils.sh
plan 5
cat <<EOF > funcdef.c
diff --git a/t/inst_if.sh b/t/inst_if.sh
@@ -2,7 +2,7 @@
#
# Check that if statement conditions are instrumented properly.
#
-. test/utils.sh
+. tlib/utils.sh
plan 5
cat <<EOF > if.c
diff --git a/t/inst_link_multiple.sh b/t/inst_link_multiple.sh
@@ -2,7 +2,7 @@
#
# Check that linking more than one instrumented object file together works.
#
-. test/utils.sh
+. tlib/utils.sh
plan 4
cat <<EOF > one.c
diff --git a/t/inst_log.sh b/t/inst_log.sh
@@ -3,7 +3,7 @@
# 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.
#
-. test/utils.sh
+. tlib/utils.sh
plan 2
cat <<EOF > source_0.c
diff --git a/t/inst_macro.sh b/t/inst_macro.sh
@@ -3,7 +3,7 @@
# Test for some tricky macro situations. In particular macro expansions at the
# end of binary operators.
#
-. test/utils.sh
+. tlib/utils.sh
plan 5
cat <<EOF > macro.c
diff --git a/t/inst_path.sh b/t/inst_path.sh
@@ -4,7 +4,7 @@
# - not having PATH set errors
# - not having CITRUN_SHARE in PATH when using transparent compile mode errors
#
-. test/utils.sh
+. tlib/utils.sh
plan 2
OLDPATH=${PATH}
diff --git a/t/inst_preamble.sh b/t/inst_preamble.sh
@@ -2,7 +2,7 @@
#
# Test that the instrumentation preamble is what we think it is.
#
-. test/utils.sh
+. tlib/utils.sh
plan 3
touch preamble.c
diff --git a/t/inst_preprocess.sh b/t/inst_preprocess.sh
@@ -2,7 +2,7 @@
#
# Make sure preprocessor flags -E, -MM cause no instrumentation to be done.
#
-. test/utils.sh
+. tlib/utils.sh
plan 3
echo "int main(void) { return 0; }" > prepro.c
diff --git a/t/inst_return.sh b/t/inst_return.sh
@@ -2,7 +2,7 @@
#
# Check that return statement values (if any) are instrumented correctly.
#
-. test/utils.sh
+. tlib/utils.sh
plan 5
cat <<EOF > return.c
diff --git a/t/inst_src_ext.sh b/t/inst_src_ext.sh
@@ -2,7 +2,7 @@
#
# Check that the advertised source file extensions work.
#
-. test/utils.sh
+. tlib/utils.sh
plan 8
touch main.{c,cc,cxx,cpp,C}
diff --git a/t/inst_switch.sh b/t/inst_switch.sh
@@ -2,7 +2,7 @@
#
# Make sure that switch statement condition instrumentation works.
#
-. test/utils.sh
+. tlib/utils.sh
plan 5
cat <<EOF > switch.c
diff --git a/t/inst_two_src.sh b/t/inst_two_src.sh
@@ -3,7 +3,7 @@
# Check that two source files given on the same command line both get
# instrumented fully.
#
-. test/utils.sh
+. tlib/utils.sh
plan 4
cat <<EOF > main.c
diff --git a/t/inst_while.sh b/t/inst_while.sh
@@ -2,7 +2,7 @@
#
# Make sure that while loop condition instrumentation works.
#
-. test/utils.sh
+. tlib/utils.sh
plan 5
cat <<EOF > while.c
diff --git a/t/rt_badver.sh b/t/rt_badver.sh
@@ -3,7 +3,7 @@
# Check that linking object files of one citrun version with libcitrun of
# another errors.
#
-. test/utils.sh
+. tlib/utils.sh
plan 3
cat <<EOF > main.c
diff --git a/t/rt_exectotals.t b/t/rt_exectotals.t
@@ -6,18 +6,18 @@ use warnings;
use POSIX;
use Test::More tests => 100;
use Time::HiRes qw( usleep );
-use test::program;
-use test::shm;
+use tlib::program;
+use tlib::shm;
my $child_pid = fork();
if ($child_pid == 0) {
# Child.
- exec ("test/program/program", "45") or die $!;
+ exec ("tlib/program/program", "45") or die $!;
}
# Give the runtime time to set up.
sleep 1;
-my $shm = test::shm->new();
+my $shm = tlib::shm->new();
my $last_total = 0;
for (0..99) {
diff --git a/t/rt_header.t b/t/rt_header.t
@@ -5,14 +5,14 @@ use strict;
use warnings;
use Test::Cmd;
use Test::More tests => 14;
-use test::program;
-use test::shm;
+use tlib::program;
+use tlib::shm;
-my $test_prog = Test::Cmd->new( prog => 'test/program/program', workdir => '');
+my $test_prog = Test::Cmd->new( prog => 'tlib/program/program', workdir => '');
$test_prog->run( args => "1" );
is $? >> 8, 0, 'did test program exit 0';
-my $shm = test::shm->new();
+my $shm = tlib::shm->new();
is $shm->{major}, 0, "is major correct";
is $shm->{minor}, 0, "is minor correct";
diff --git a/t/rt_size.t b/t/rt_size.t
@@ -1,13 +1,13 @@
use strict;
use warnings;
use Test::More tests => 1;
-use test::program;
-use test::shm;
+use tlib::program;
+use tlib::shm;
#
# Test that the runtime shared file size is what we expect.
#
-system("test/program/program 1");
+system("tlib/program/program 1");
-my $procfile = test::shm->new();
+my $procfile = tlib::shm->new();
is($procfile->{size}, 16384, "size of memory file");
diff --git a/t/rt_translunit.t b/t/rt_translunit.t
@@ -6,14 +6,14 @@ use warnings;
use POSIX;
use Test::Cmd;
use Test::More tests => 7;
-use test::program;
-use test::shm;
+use tlib::program;
+use tlib::shm;
-my $test_prog = Test::Cmd->new( prog => 'test/program/program', workdir => '');
+my $test_prog = Test::Cmd->new( prog => 'tlib/program/program', workdir => '');
$test_prog->run( args => "10" );
is $? >> 8, 0, 'is test program exit code 0';
-my $shm = test::shm->new();
+my $shm = tlib::shm->new();
my ($tu1, $tu2, $tu3) = @{ $shm->{translation_units} };
is $tu1->{size}, 9, "is transl unit 1 9 lines";
diff --git a/t/wrap_badarg.sh b/t/wrap_badarg.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-. test/utils.sh
+. tlib/utils.sh
plan 1
output_good="usage: citrun-wrap <build cmd>"
diff --git a/t/wrap_exitcode.sh b/t/wrap_exitcode.sh
@@ -2,7 +2,7 @@
#
# Make sure that citrun-wrap exits with the same code as the native build.
#
-. test/utils.sh
+. tlib/utils.sh
plan 1
output_good="ls: asdfasdfsaf: No such file or directory"
diff --git a/test/package.sh b/test/package.sh
@@ -1,60 +0,0 @@
-# exports CITRUN_TOOLS and sources libtap.sh.
-. test/utils.sh
-
-function pkg_set
-{
- port="/usr/ports/$1"
- wrkdist=`make -C $port show=WRKDIST`
-
- export TEST_PORT="$port"
- export TEST_WRKDIST="$wrkdist"
-}
-
-function pkg_check_deps
-{
- make -C $TEST_PORT full-build-depends > deps
- make -C $TEST_PORT full-test-depends >> deps
- sort deps | uniq > deps.uniq
- pkg_info -q > installed
- comm -2 -3 deps.uniq installed > deps_needed
-
- ok "build and test dependencies" diff -u /dev/null deps_needed
-}
-
-function pkg_build
-{
- ok "port build" make -C $TEST_PORT PORTPATH="$CITRUN_TOOLS:\${WRKDIR}/bin:$PATH" build
-}
-
-function pkg_test
-{
- #make -C $TEST_PORT PORTPATH="$CITRUN_TOOLS:\${WRKDIR}/bin:$PATH" test || true
-}
-
-function pkg_check
-{
- $CITRUN_TOOLS/citrun-check -o check.out $TEST_WRKDIST
- strip_millis check.out
- ok "citrun-check output diff" diff -u check.good check.out
-}
-
-function pkg_clean
-{
- ok "port clean" make -C $TEST_PORT clean=all
-}
-
-function pkg_write_tus
-{
- cat <<'EOF' > tu_printer.pl
-use strict;
-use warnings;
-use test::shm;
-
-open(my $out, '>', 'filelist.out') or die $!;
-my $shm = test::shm->new();
-
-select $out;
-$shm->print_tus();
-EOF
- ok "is tu printer exit code 0" perl -I $CITRUN_TOOLS/.. tu_printer.pl
-}
diff --git a/test/program.pm b/test/program.pm
@@ -1,8 +0,0 @@
-package test::program;
-use strict;
-use warnings;
-
-# This module builds the test program when it's used.
-system("cd test/program && ../../src/citrun-wrap jam");
-
-1;
diff --git a/test/report.pm b/test/report.pm
@@ -1,97 +0,0 @@
-package test::report;
-use strict;
-
-use List::MoreUtils qw( each_array );
-
-sub new {
- my ($class, $name, $num_tests) = @_;
-
- my $self = {};
- bless($self, $class);
-
- $self->{name} = $name;
- $self->{desc} = [];
- $self->{vanilla} = [];
- $self->{citrun} = [];
-
- $self->{start_time} = time;
- $self->{num_tests} = $num_tests;
-
- return $self;
-}
-
-sub add {
- my ($self, $field, $desc) = @_;
-
- push @{ $self->{$field} }, ($desc);
-}
-
-sub write_header {
-
- open (E2E_HEADER, ">", "tt/report.txt") or die "$!";
-
- format E2E_HEADER =
-E2E TEST REPORT
-===============
-
-SYSTEM INFO
- @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-"started at:", `date`
- @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-"host:", `uname -n`
- @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<
-"os:", `uname -s`
- @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<
-"version:", `uname -r`
- @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<
-"arch:", `uname -m`
- @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<
-"user:", `logname`
- @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<
-"citrun version:", 0
-
-.
- write E2E_HEADER;
- close E2E_HEADER;
-}
-
-sub DESTROY {
- my ($self) = @_;
-
- my @diff;
- my @desc = @{ $self->{desc} };
- my @vanilla = @{ $self->{vanilla} };
- my @citrun = @{ $self->{citrun} };
-
- my $it = each_array( @vanilla, @citrun );
- while ( my ($x, $y) = $it->() ) {
- push @diff, $y * 100.0 / $x - 100.0;
- }
-
- if (! -e "tt/report.txt") {
- write_header();
- }
-
- open (E2E_REPORT, ">>", "tt/report.txt") or die "$!";
-
- format E2E_REPORT =
-@<<<<<<<<<<<<<<<<<<<<<<<<<<
-$self->{name}
- @<<<<<<<<<<<<<< @#### s
-"duration:", time - $self->{start_time}
- @<<<<<<<<<<<<<< @#####
-"tests planned:", $self->{num_tests}
-
- @>>>>>>>>> @>>>>>>>>> @>>>>>>>
-"vanilla", "citrun", "diff (%)"
- ---------------------------------------------------------------------
- @<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>> @>>>> ~~
-shift(@desc), shift(@vanilla), shift(@citrun), shift(@diff)
-
-.
-
- write E2E_REPORT;
- close E2E_REPORT;
-}
-
-1;
diff --git a/test/shm.pm b/test/shm.pm
@@ -1,102 +0,0 @@
-package test::shm;
-use strict;
-use warnings;
-use POSIX;
-
-# Triggers runtime to use alternate shm path.
-$ENV{CITRUN_TOOLS} = 1;
-
-sub new {
- my ($class) = @_;
-
- my $self = {};
- bless($self, $class);
-
- open(my $fh, "<:mmap", "procfile.shm") or die $!;
- $self->{fh} = $fh;
- $self->{size} = (stat "procfile.shm")[7];
-
- ($self->{major}, $self->{minor}) = unpack("C2", xread($fh, 2));
- @{ $self->{pids} } = unpack("L3", xread($fh, 12));
-
- ($self->{prg_sz}) = unpack("S", xread($fh, 2));
- ($self->{progname}) = xread($fh, $self->{prg_sz});
- ($self->{cwd_sz}) = unpack("S", xread($fh, 2));
- ($self->{cwd}) = xread($fh, $self->{cwd_sz});
- $self->next_page();
-
- my @translation_units;
- while (tell $fh < $self->{size}) {
- my %tu;
- ($tu{size}) = unpack("L", xread($fh, 4));
-
- ($tu{cmp_sz}) = unpack("S", xread($fh, 2));
- $tu{comp_file_name} = xread($fh, $tu{cmp_sz});
- ($tu{abs_sz}) = unpack("S", xread($fh, 2));
- $tu{abs_file_path} = xread($fh, $tu{abs_sz});
-
- $tu{exec_buf_pos} = tell $fh;
- xread($fh, $tu{size} * 8);
- $self->next_page();
-
- push @translation_units, (\%tu);
- }
- $self->{translation_units} = \@translation_units;
-
- return $self;
-}
-
-sub next_page {
- my ($self) = @_;
-
- my $pagesize = POSIX::sysconf(POSIX::_SC_PAGESIZE);
- my $cur_pos = tell $self->{fh};
- xread($self->{fh}, $pagesize - ($cur_pos % $pagesize));
-}
-
-sub execs_for {
- my ($self, $tu_num) = @_;
-
- my $tu = $self->{translation_units}->[$tu_num];
- seek $self->{fh}, $tu->{exec_buf_pos}, 0;
- my @execs = unpack("Q$tu->{size}", xread($self->{fh}, $tu->{size} * 8));
- return \@execs;
-}
-
-sub print_tus {
- my ($self) = @_;
-
- my $transl_units = $self->{translation_units};
- for (@$transl_units) {
- my %tu = %$_;
-
- print "$tu{comp_file_name} $tu{size}\n";
- }
-}
-
-#
-# Read an exact amount of bytes.
-#
-sub xread {
- my ($fh, $bytes_total) = @_;
-
- my $data;
- my $bytes_read = 0;
- while ($bytes_total > 0) {
- my $read = read($fh, $data, $bytes_total, $bytes_read);
-
- die "error: read failed: $!" if (!defined $read);
- die "disconnected!\n" if ($read == 0);
-
- $bytes_total -= $read;
- $bytes_read += $read;
- }
-
- return $data;
-}
-
-sub DESTROY {
- unlink "procfile.shm";
-}
-
-1;
diff --git a/test/utils.sh b/test/utils.sh
@@ -1,24 +0,0 @@
-. test/libtap.sh
-
-set -o nounset
-export CITRUN_TOOLS="`pwd`/src"
-
-function strip_preamble
-{
- file="${1}"
- tail -n +24 $file.citrun > $file.citrun_nohdr
-}
-
-function strip_log
-{
- sed -e "s,^.*: ,," \
- -e "s,'.*',''," \
- -e "s,(.*),()," \
- -e "/Milliseconds/d" \
- < ${1} > ${1}.stripped
-}
-
-function strip_millis
-{
- ok "stripping milliseconds" sed -i -e "/Milliseconds spent/d" $1
-}
diff --git a/test/libtap.sh b/tlib/libtap.sh
diff --git a/tlib/package.sh b/tlib/package.sh
@@ -0,0 +1,60 @@
+# exports CITRUN_TOOLS and sources libtap.sh.
+. tlib/utils.sh
+
+function pkg_set
+{
+ port="/usr/ports/$1"
+ wrkdist=`make -C $port show=WRKDIST`
+
+ export TEST_PORT="$port"
+ export TEST_WRKDIST="$wrkdist"
+}
+
+function pkg_check_deps
+{
+ make -C $TEST_PORT full-build-depends > deps
+ make -C $TEST_PORT full-test-depends >> deps
+ sort deps | uniq > deps.uniq
+ pkg_info -q > installed
+ comm -2 -3 deps.uniq installed > deps_needed
+
+ ok "build and test dependencies" diff -u /dev/null deps_needed
+}
+
+function pkg_build
+{
+ ok "port build" make -C $TEST_PORT PORTPATH="$CITRUN_TOOLS:\${WRKDIR}/bin:$PATH" build
+}
+
+function pkg_test
+{
+ #make -C $TEST_PORT PORTPATH="$CITRUN_TOOLS:\${WRKDIR}/bin:$PATH" test || true
+}
+
+function pkg_check
+{
+ $CITRUN_TOOLS/citrun-check -o check.out $TEST_WRKDIST
+ strip_millis check.out
+ ok "citrun-check output diff" diff -u check.good check.out
+}
+
+function pkg_clean
+{
+ ok "port clean" make -C $TEST_PORT clean=all
+}
+
+function pkg_write_tus
+{
+ cat <<'EOF' > tu_printer.pl
+use strict;
+use warnings;
+use tlib::shm;
+
+open(my $out, '>', 'filelist.out') or die $!;
+my $shm = tlib::shm->new();
+
+select $out;
+$shm->print_tus();
+EOF
+ ok "is tu printer exit code 0" perl -I $CITRUN_TOOLS/.. tu_printer.pl
+}
diff --git a/tlib/program.pm b/tlib/program.pm
@@ -0,0 +1,8 @@
+package tlib::program;
+use strict;
+use warnings;
+
+# This module builds the test program when it's used.
+system("cd tlib/program && ../../src/citrun-wrap jam");
+
+1;
diff --git a/test/program/Jamfile b/tlib/program/Jamfile
diff --git a/test/program/one.c b/tlib/program/one.c
diff --git a/test/program/three.c b/tlib/program/three.c
diff --git a/test/program/two.c b/tlib/program/two.c
diff --git a/tlib/report.pm b/tlib/report.pm
@@ -0,0 +1,97 @@
+package tlib::report;
+use strict;
+
+use List::MoreUtils qw( each_array );
+
+sub new {
+ my ($class, $name, $num_tests) = @_;
+
+ my $self = {};
+ bless($self, $class);
+
+ $self->{name} = $name;
+ $self->{desc} = [];
+ $self->{vanilla} = [];
+ $self->{citrun} = [];
+
+ $self->{start_time} = time;
+ $self->{num_tests} = $num_tests;
+
+ return $self;
+}
+
+sub add {
+ my ($self, $field, $desc) = @_;
+
+ push @{ $self->{$field} }, ($desc);
+}
+
+sub write_header {
+
+ open (E2E_HEADER, ">", "tt/report.txt") or die "$!";
+
+ format E2E_HEADER =
+E2E TEST REPORT
+===============
+
+SYSTEM INFO
+ @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+"started at:", `date`
+ @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+"host:", `uname -n`
+ @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<
+"os:", `uname -s`
+ @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<
+"version:", `uname -r`
+ @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<
+"arch:", `uname -m`
+ @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<
+"user:", `logname`
+ @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<
+"citrun version:", 0
+
+.
+ write E2E_HEADER;
+ close E2E_HEADER;
+}
+
+sub DESTROY {
+ my ($self) = @_;
+
+ my @diff;
+ my @desc = @{ $self->{desc} };
+ my @vanilla = @{ $self->{vanilla} };
+ my @citrun = @{ $self->{citrun} };
+
+ my $it = each_array( @vanilla, @citrun );
+ while ( my ($x, $y) = $it->() ) {
+ push @diff, $y * 100.0 / $x - 100.0;
+ }
+
+ if (! -e "tt/report.txt") {
+ write_header();
+ }
+
+ open (E2E_REPORT, ">>", "tt/report.txt") or die "$!";
+
+ format E2E_REPORT =
+@<<<<<<<<<<<<<<<<<<<<<<<<<<
+$self->{name}
+ @<<<<<<<<<<<<<< @#### s
+"duration:", time - $self->{start_time}
+ @<<<<<<<<<<<<<< @#####
+"tests planned:", $self->{num_tests}
+
+ @>>>>>>>>> @>>>>>>>>> @>>>>>>>
+"vanilla", "citrun", "diff (%)"
+ ---------------------------------------------------------------------
+ @<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>> @>>>> ~~
+shift(@desc), shift(@vanilla), shift(@citrun), shift(@diff)
+
+.
+
+ write E2E_REPORT;
+ close E2E_REPORT;
+}
+
+1;
diff --git a/tlib/shm.pm b/tlib/shm.pm
@@ -0,0 +1,102 @@
+package tlib::shm;
+use strict;
+use warnings;
+use POSIX;
+
+# Triggers runtime to use alternate shm path.
+$ENV{CITRUN_TOOLS} = 1;
+
+sub new {
+ my ($class) = @_;
+
+ my $self = {};
+ bless($self, $class);
+
+ open(my $fh, "<:mmap", "procfile.shm") or die $!;
+ $self->{fh} = $fh;
+ $self->{size} = (stat "procfile.shm")[7];
+
+ ($self->{major}, $self->{minor}) = unpack("C2", xread($fh, 2));
+ @{ $self->{pids} } = unpack("L3", xread($fh, 12));
+
+ ($self->{prg_sz}) = unpack("S", xread($fh, 2));
+ ($self->{progname}) = xread($fh, $self->{prg_sz});
+ ($self->{cwd_sz}) = unpack("S", xread($fh, 2));
+ ($self->{cwd}) = xread($fh, $self->{cwd_sz});
+ $self->next_page();
+
+ my @translation_units;
+ while (tell $fh < $self->{size}) {
+ my %tu;
+ ($tu{size}) = unpack("L", xread($fh, 4));
+
+ ($tu{cmp_sz}) = unpack("S", xread($fh, 2));
+ $tu{comp_file_name} = xread($fh, $tu{cmp_sz});
+ ($tu{abs_sz}) = unpack("S", xread($fh, 2));
+ $tu{abs_file_path} = xread($fh, $tu{abs_sz});
+
+ $tu{exec_buf_pos} = tell $fh;
+ xread($fh, $tu{size} * 8);
+ $self->next_page();
+
+ push @translation_units, (\%tu);
+ }
+ $self->{translation_units} = \@translation_units;
+
+ return $self;
+}
+
+sub next_page {
+ my ($self) = @_;
+
+ my $pagesize = POSIX::sysconf(POSIX::_SC_PAGESIZE);
+ my $cur_pos = tell $self->{fh};
+ xread($self->{fh}, $pagesize - ($cur_pos % $pagesize));
+}
+
+sub execs_for {
+ my ($self, $tu_num) = @_;
+
+ my $tu = $self->{translation_units}->[$tu_num];
+ seek $self->{fh}, $tu->{exec_buf_pos}, 0;
+ my @execs = unpack("Q$tu->{size}", xread($self->{fh}, $tu->{size} * 8));
+ return \@execs;
+}
+
+sub print_tus {
+ my ($self) = @_;
+
+ my $transl_units = $self->{translation_units};
+ for (@$transl_units) {
+ my %tu = %$_;
+
+ print "$tu{comp_file_name} $tu{size}\n";
+ }
+}
+
+#
+# Read an exact amount of bytes.
+#
+sub xread {
+ my ($fh, $bytes_total) = @_;
+
+ my $data;
+ my $bytes_read = 0;
+ while ($bytes_total > 0) {
+ my $read = read($fh, $data, $bytes_total, $bytes_read);
+
+ die "error: read failed: $!" if (!defined $read);
+ die "disconnected!\n" if ($read == 0);
+
+ $bytes_total -= $read;
+ $bytes_read += $read;
+ }
+
+ return $data;
+}
+
+sub DESTROY {
+ unlink "procfile.shm";
+}
+
+1;
diff --git a/tlib/utils.sh b/tlib/utils.sh
@@ -0,0 +1,24 @@
+. tlib/libtap.sh
+
+set -o nounset
+export CITRUN_TOOLS="`pwd`/src"
+
+function strip_preamble
+{
+ file="${1}"
+ tail -n +24 $file.citrun > $file.citrun_nohdr
+}
+
+function strip_log
+{
+ sed -e "s,^.*: ,," \
+ -e "s,'.*',''," \
+ -e "s,(.*),()," \
+ -e "/Milliseconds/d" \
+ < ${1} > ${1}.stripped
+}
+
+function strip_millis
+{
+ ok "stripping milliseconds" sed -i -e "/Milliseconds spent/d" $1
+}
diff --git a/tt/bash.sh b/tt/bash.sh
@@ -2,7 +2,7 @@
#
# Check that Bash can be instrumented and still works after.
#
-. test/package.sh
+. tlib/package.sh
plan 5
pkg_set "shells/bash"
diff --git a/tt/ccitrunrun.sh b/tt/ccitrunrun.sh
@@ -2,7 +2,7 @@
#
# Test that citrun run on itself works and the resulting binaries run.
#
-. test/package.sh
+. tlib/package.sh
rm -rf /usr/ports/devel/ccitrunrun
# Port contains some.. "customizations"
diff --git a/tt/git.sh b/tt/git.sh
@@ -3,7 +3,7 @@
# Instruments git, checks logs, and makes sure the resulting program still
# works.
#
-. test/package.sh
+. tlib/package.sh
plan 8
pkg_set "devel/git"
diff --git a/tt/mutt.sh b/tt/mutt.sh
@@ -2,7 +2,7 @@
#
# Test that building Mutt works.
#
-. test/package.sh
+. tlib/package.sh
plan 5
pkg_set "mail/mutt"
diff --git a/tt/nmap.sh b/tt/nmap.sh
@@ -2,7 +2,7 @@
#
# Instruments Nmap and checks that the instrumented program still runs.
#
-. test/package.sh
+. tlib/package.sh
plan 8
pkg_set "net/nmap"
diff --git a/tt/nvi.sh b/tt/nvi.sh
@@ -2,7 +2,7 @@
#
# Tests that nvi works with C It Run.
#
-. test/package.sh
+. tlib/package.sh
plan 10
pkg_set "editors/nvi"
diff --git a/tt/openssl.sh b/tt/openssl.sh
@@ -3,7 +3,7 @@
# Instrument openssl, run its testsuite, check the logs and do a quick runtime
# sanity test on it.
#
-. test/package.sh
+. tlib/package.sh
plan 8
pkg_set "security/openssl"
diff --git a/tt/spidermonkey.sh b/tt/spidermonkey.sh
@@ -2,7 +2,7 @@
#
# Try and instrument spidermonkey.
#
-. test/package.sh
+. tlib/package.sh
plan 6
pkg_set "devel/spidermonkey"