citrun

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

commit 34df74ec53b005a36c98daf475a5bb031db2034d
parent ac5a0a4fe627e6da01029b77a3e112704cd4be26
Author: Kyle Milz <kyle@0x30.net>
Date:   Thu, 29 Dec 2016 20:20:28 -0700

t: convert inst_preamble.sh to perl

Diffstat:
Dt/inst_preamble.sh | 54------------------------------------------------------
At/inst_preamble.t | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 54 deletions(-)

diff --git a/t/inst_preamble.sh b/t/inst_preamble.sh @@ -1,54 +0,0 @@ -#!/bin/sh -u -# -# Test that the instrumentation preamble is what we think it is. -# -. t/utils.subr -plan 3 - - -touch preamble.c -ok "running citrun_inst" citrun_inst -c preamble.c - -cat <<EOF > preamble.c.good -#ifdef __cplusplus -extern "" { -#endif -static const unsigned int citrun_major = 0; -static const unsigned int citrun_minor = 0; - -struct citrun_header { - char magic[4]; - unsigned int major; - unsigned int minor; - unsigned int pids[3]; - unsigned int units; - unsigned int loc; - unsigned int exited; - char progname[1024]; - char cwd[1024]; -}; - -struct citrun_node { - unsigned int size; - char comp_file_path[1024]; - char abs_file_path[1024]; - unsigned long long *data; -}; - -void citrun_node_add(unsigned int, unsigned int, struct citrun_node *); -static struct citrun_node _citrun = { - 1, - "", - "", -}; -__attribute__((constructor)) static void -citrun_constructor() { - citrun_node_add(citrun_major, citrun_minor, &_citrun); -} -#ifdef __cplusplus -} -#endif -EOF - -ok "remove os specific paths" sed -i -e 's/".*"/""/' preamble.c.citrun -ok "diff against known good" diff -u preamble.c.good preamble.c.citrun diff --git a/t/inst_preamble.t b/t/inst_preamble.t @@ -0,0 +1,66 @@ +# +# Test that the instrumentation preamble is what we think it is. +# +use strict; +use warnings; +use File::Slurp; +use Test::Cmd; +use Test::Differences; +use Test::More tests => 3; +unified_diff; + + +my $inst = Test::Cmd->new( prog => 'src/citrun_inst', workdir => '' ); + +$inst->write( "empty.c", "" ); +$inst->run( args => "-c empty.c", chdir => $inst->curdir ); + +# Known good output. +my $preamble_good = <<EOF ; +#ifdef __cplusplus +extern "" { +#endif +static const unsigned int citrun_major = 0; +static const unsigned int citrun_minor = 0; + +struct citrun_header { + char magic[4]; + unsigned int major; + unsigned int minor; + unsigned int pids[3]; + unsigned int units; + unsigned int loc; + unsigned int exited; + char progname[1024]; + char cwd[1024]; +}; + +struct citrun_node { + unsigned int size; + char comp_file_path[1024]; + char abs_file_path[1024]; + unsigned long long *data; +}; + +void citrun_node_add(unsigned int, unsigned int, struct citrun_node *); +static struct citrun_node _citrun = { + 1, + "", + "", +}; +__attribute__((constructor)) static void +citrun_constructor() { + citrun_node_add(citrun_major, citrun_minor, &_citrun); +} +#ifdef __cplusplus +} +#endif +EOF + +# Read and sanitize special preamble file created by citrun_inst. +my $preamble = read_file( $inst->workdir . "/empty.c.preamble" ); +$preamble =~ s/".*"/""/gm; + +eq_or_diff( $preamble, $preamble_good, 'is preamble identical', { context => 3 } ); +is( $inst->stderr, '', 'is citrun_inst stderr empty' ); +is( $? >> 8, 0, 'is citrun_inst exit code 0' );