citrun

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

commit 1cc2b05e88b6528d2554cbbe7ef178a4de9475c4
parent 1d8c9320eaebda6a01ada445a9c201f43de89179
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Fri, 25 Mar 2016 14:33:30 -0600

t: add new test for preamble only

Diffstat:
MSCV/Project.pm | 15+++++++++++++++
At/inst_preamble.t | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/SCV/Project.pm b/SCV/Project.pm @@ -65,9 +65,24 @@ sub instrumented_src { while (my $line = <$inst_fh>) { $inst_src .= $line; } + close( $inst_fh ); return $inst_src; } +sub inst_src_preamble { + my ($self) = @_; + + open( my $inst_fh, "<", "$self->{tmp_dir}/inst/source_0.c" ); + + my $preamble; + for (1..19) { + my $line = <$inst_fh>; + $preamble .= $line; + } + close( $inst_fh ); + return $preamble; +} + sub run { my ($self, @args) = @_; diff --git a/t/inst_preamble.t b/t/inst_preamble.t @@ -0,0 +1,52 @@ +use strict; +use SCV::Project; +use SCV::Viewer; +use Test::More tests => 4; +use Test::Differences; + +my $project = SCV::Project->new(); +unified_diff; + +$project->add_src(<<EOF); +int +main(void) +{ + return 0; +} +EOF + +$project->compile(); + +my $tmp_dir = $project->get_tmpdir(); + +my $preamble_good = <<EOF; +#include <stdint.h> +struct _scv_node { + uint64_t *lines_ptr; + uint32_t size; + uint32_t inst_sites; + const char *file_name; + struct _scv_node *next; +}; +void libscv_init(); + +static uint64_t _scv_lines[6]; +struct _scv_node _scv_node1; +struct _scv_node _scv_node0 = { + .lines_ptr = _scv_lines, + .size = 6, + .inst_sites = 1, + .file_name = "$tmp_dir/source_0.c", + .next = &_scv_node1, +}; +EOF + +my $preamble = $project->inst_src_preamble(); +ok( $preamble ); + +eq_or_diff $preamble, $preamble_good, "instrumented source comparison"; + +$project->run(); +my ($ret, $err) = $project->wait(); +is($ret, 0, "return code"); +is($err, undef, "stderr empty");