citrun

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

commit dad49e743a25488f33743728e66cdf935fa688ba
parent f1478dc4c613b53e4e8c68a3909deb7a624ebab8
Author: Kyle Milz <kyle@0x30.net>
Date:   Wed, 10 Aug 2016 01:43:33 -0600

test: move viewer

Diffstat:
DTest/Viewer.pm | 141-------------------------------------------------------------------------------
Mt/rt_dynamic.t | 4++--
Mt/rt_reconnect.t | 4++--
Mt/rt_static.t | 4++--
Atest/viewer.pm | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtt/ccitrunrun.t | 4++--
Mtt/git.t | 4++--
Mtt/mutt.t | 4++--
Mtt/nvi.t | 4++--
Mtt/openssl.t | 4++--
10 files changed, 157 insertions(+), 157 deletions(-)

diff --git a/Test/Viewer.pm b/Test/Viewer.pm @@ -1,141 +0,0 @@ -package Test::Viewer; - -use strict; -use IO::Socket::UNIX; -use Test::More; - -sub new { - my ($class) = @_; - my $self = {}; - bless ($self, $class); - - $self->{viewer_socket_name} = $ENV{CITRUN_SOCKET}; - my $viewer_socket = IO::Socket::UNIX->new( - Type => SOCK_STREAM(), - Local => $self->{viewer_socket_name}, - Listen => 1 - ); - die "socket error: $!\n" unless ($viewer_socket); - - $self->{viewer_socket} = $viewer_socket; - return $self; -} - -sub accept { - my ($self) = @_; - - my $listen_sock = $self->{viewer_socket}; - my $sock = $listen_sock->accept(); - $self->{client_socket} = $sock; - - # Protocol defined in src/runtime.c function send_static(). - # - ($self->{maj}, $self->{min}) = read_unpack($sock, 2, "C2"); - ($self->{ntus}, $self->{nlines}) = read_unpack($sock, 8, "L2"); - @{ $self->{pids} } = read_unpack($sock, 12, "L3"); - $self->{progname} = read_all($sock, read_unpack($sock, 2, "S")); - $self->{cwd} = read_all($sock, read_unpack($sock, 2, "S")); - - my @tus; - for (1..$self->{ntus}) { - my $comp_file_name = read_all($sock, read_unpack($sock, 2, "S")); - my $abs_file_name = read_all($sock, read_unpack($sock, 2, "S")); - my ($num_lines) = read_unpack($sock, 4, "L"); - - # Keep this in order so it's easy to fetch dynamic data. - push @tus, [ $abs_file_name, $num_lines ]; - } - $self->{tus} = \@tus; -} - -sub get_dynamic_data { - my ($self) = @_; - my $sock = $self->{client_socket}; - - my %data; - for my $tu (@{ $self->{tus} }) { - my ($file_name, $nlines) = @{ $tu }; - - # Protocol defined in src/runtime.c function send_dynamic(). - # - if (read_unpack($sock, 1, "C") == 0) { - $data{$file_name} = [ (0) x $nlines ]; - next; - } - $data{$file_name} = [ read_unpack($sock, 4 * $nlines, "L$nlines") ]; - } - - $sock->syswrite("\x01", 1); - return \%data; -} - -sub cmp_static_data { - my ($self, $known_good) = @_; - is( $self->{ntus}, scalar @$known_good, "translation unit count" ); - - # Sort these alphabetically by file name (field 0). - my @sorted_tus = sort { $a->[0] cmp $b->[0] } @{ $self->{tus} }; - - for my $x (@$known_good) { - my $y = shift @sorted_tus; - - like( $y->[0], qr/.*$x->[0]/, "$x->[0]: filename check" ); - is ( $y->[1], $x->[1], "$x->[0]: total lines check" ); - } -} - -sub cmp_dynamic_data { - my ($self) = @_; - - my $data = $self->get_dynamic_data(); - - # Check that at least a single execution has taken place. - my $good = 0; - for my $key (sort keys %$data) { - my $data_tmp = $data->{$key}; - - for (@$data_tmp) { - $good++ if ($_ > 0); - } - } - cmp_ok( $good, ">", 0, "a single application execution took place" ); - - return $data; -} - -sub read_unpack { - my ($sock, $bytes_total, $unpack_fmt) = @_; - return unpack($unpack_fmt, read_all($sock, $bytes_total)); -} - -sub read_all { - my ($sock, $bytes_total) = @_; - - my $data; - my $bytes_read = 0; - while ($bytes_total > 0) { - my $read = $sock->sysread($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 close { - my ($self) = @_; - close ($self->{client_socket}); -} - -sub DESTROY { - my ($self) = @_; - - close($self->{viewer_socket}); - unlink $self->{viewer_socket_name}; -} - -1; diff --git a/t/rt_dynamic.t b/t/rt_dynamic.t @@ -1,11 +1,11 @@ use strict; use Test::More tests => 107; use test::project; -use Test::Viewer; +use test::viewer; use Time::HiRes qw( usleep ); my $project = test::project->new(); -my $viewer = Test::Viewer->new(); +my $viewer = test::viewer->new(); $project->run(45); diff --git a/t/rt_reconnect.t b/t/rt_reconnect.t @@ -1,7 +1,7 @@ use strict; use Test::More tests => 9; use test::project; -use Test::Viewer; +use test::viewer; my $project = test::project->new(); @@ -10,7 +10,7 @@ $project->run(45); # Give the runtime a chance to reconnect sleep(1); -my $viewer = Test::Viewer->new(); +my $viewer = test::viewer->new(); $viewer->accept(); $viewer->cmp_static_data([ [ "one.c", 20 ], diff --git a/t/rt_static.t b/t/rt_static.t @@ -2,10 +2,10 @@ use strict; use Cwd; use Test::More tests => 22; use test::project; -use Test::Viewer; +use test::viewer; my $project = test::project->new(); -my $viewer = Test::Viewer->new(); +my $viewer = test::viewer->new(); $project->run(45); diff --git a/test/viewer.pm b/test/viewer.pm @@ -0,0 +1,141 @@ +package test::viewer; + +use strict; +use IO::Socket::UNIX; +use Test::More; + +sub new { + my ($class) = @_; + my $self = {}; + bless ($self, $class); + + $self->{viewer_socket_name} = $ENV{CITRUN_SOCKET}; + my $viewer_socket = IO::Socket::UNIX->new( + Type => SOCK_STREAM(), + Local => $self->{viewer_socket_name}, + Listen => 1 + ); + die "socket error: $!\n" unless ($viewer_socket); + + $self->{viewer_socket} = $viewer_socket; + return $self; +} + +sub accept { + my ($self) = @_; + + my $listen_sock = $self->{viewer_socket}; + my $sock = $listen_sock->accept(); + $self->{client_socket} = $sock; + + # Protocol defined in src/runtime.c function send_static(). + # + ($self->{maj}, $self->{min}) = read_unpack($sock, 2, "C2"); + ($self->{ntus}, $self->{nlines}) = read_unpack($sock, 8, "L2"); + @{ $self->{pids} } = read_unpack($sock, 12, "L3"); + $self->{progname} = read_all($sock, read_unpack($sock, 2, "S")); + $self->{cwd} = read_all($sock, read_unpack($sock, 2, "S")); + + my @tus; + for (1..$self->{ntus}) { + my $comp_file_name = read_all($sock, read_unpack($sock, 2, "S")); + my $abs_file_name = read_all($sock, read_unpack($sock, 2, "S")); + my ($num_lines) = read_unpack($sock, 4, "L"); + + # Keep this in order so it's easy to fetch dynamic data. + push @tus, [ $abs_file_name, $num_lines ]; + } + $self->{tus} = \@tus; +} + +sub get_dynamic_data { + my ($self) = @_; + my $sock = $self->{client_socket}; + + my %data; + for my $tu (@{ $self->{tus} }) { + my ($file_name, $nlines) = @{ $tu }; + + # Protocol defined in src/runtime.c function send_dynamic(). + # + if (read_unpack($sock, 1, "C") == 0) { + $data{$file_name} = [ (0) x $nlines ]; + next; + } + $data{$file_name} = [ read_unpack($sock, 4 * $nlines, "L$nlines") ]; + } + + $sock->syswrite("\x01", 1); + return \%data; +} + +sub cmp_static_data { + my ($self, $known_good) = @_; + is( $self->{ntus}, scalar @$known_good, "translation unit count" ); + + # Sort these alphabetically by file name (field 0). + my @sorted_tus = sort { $a->[0] cmp $b->[0] } @{ $self->{tus} }; + + for my $x (@$known_good) { + my $y = shift @sorted_tus; + + like( $y->[0], qr/.*$x->[0]/, "$x->[0]: filename check" ); + is ( $y->[1], $x->[1], "$x->[0]: total lines check" ); + } +} + +sub cmp_dynamic_data { + my ($self) = @_; + + my $data = $self->get_dynamic_data(); + + # Check that at least a single execution has taken place. + my $good = 0; + for my $key (sort keys %$data) { + my $data_tmp = $data->{$key}; + + for (@$data_tmp) { + $good++ if ($_ > 0); + } + } + cmp_ok( $good, ">", 0, "a single application execution took place" ); + + return $data; +} + +sub read_unpack { + my ($sock, $bytes_total, $unpack_fmt) = @_; + return unpack($unpack_fmt, read_all($sock, $bytes_total)); +} + +sub read_all { + my ($sock, $bytes_total) = @_; + + my $data; + my $bytes_read = 0; + while ($bytes_total > 0) { + my $read = $sock->sysread($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 close { + my ($self) = @_; + close ($self->{client_socket}); +} + +sub DESTROY { + my ($self) = @_; + + close($self->{viewer_socket}); + unlink $self->{viewer_socket_name}; +} + +1; diff --git a/tt/ccitrunrun.t b/tt/ccitrunrun.t @@ -4,12 +4,12 @@ use Cwd; use Expect; use Test::More tests => 49; use Test::Package; -use Test::Viewer; +use test::viewer; $ENV{NO_CHECKSUM} = 1; system("rm -rf /usr/ports/devel/ccitrunrun; cp -R bin/openbsd/ccitrunrun /usr/ports/devel/"); my $package = Test::Package->new("devel/ccitrunrun"); -my $viewer = Test::Viewer->new(); +my $viewer = test::viewer->new(); system("./src/citrun-check /usr/ports/pobj/ccitrunrun-*"); diff --git a/tt/git.t b/tt/git.t @@ -4,11 +4,11 @@ use Expect; use Test::More tests => 540 ; use Test::Package; use Test::Report; -use Test::Viewer; +use test::viewer; use Time::HiRes qw( usleep ); my $package = Test::Package->new("devel/git"); -my $viewer = Test::Viewer->new(); +my $viewer = test::viewer->new(); my $exp = Expect->spawn("/usr/ports/pobj/git-2.9.0/git-2.9.0/git", "clone", "http://git.0x30.net/citrun", "/usr/ports/pobj/git-*"); $viewer->accept(); diff --git a/tt/mutt.t b/tt/mutt.t @@ -4,10 +4,10 @@ use warnings; use Expect; use Test::More tests => 204; use Test::Package; -use Test::Viewer; +use test::viewer; my $package = Test::Package->new("mail/mutt"); -my $viewer = Test::Viewer->new(); +my $viewer = test::viewer->new(); my $exp = Expect->spawn("/usr/ports/pobj/mutt-1.6.2/mutt-1.6.2/mutt"); $viewer->accept(); diff --git a/tt/nvi.t b/tt/nvi.t @@ -4,10 +4,10 @@ use Expect; use Test::More tests => 230 ; use Test::Package; use Test::Report; -use Test::Viewer; +use test::viewer; my $package = Test::Package->new("editors/nvi"); -my $viewer = Test::Viewer->new(); +my $viewer = test::viewer->new(); my $exp = Expect->spawn("/usr/ports/pobj/nvi-2.1.3/nvi2-2.1.3/build/nvi"); $viewer->accept(); diff --git a/tt/openssl.t b/tt/openssl.t @@ -4,10 +4,10 @@ use Expect; use Test::More tests => 1368 ; use Test::Package; use Test::Report; -use Test::Viewer; +use test::viewer; my $package = Test::Package->new("security/openssl"); -my $viewer = Test::Viewer->new(); +my $viewer = test::viewer->new(); $ENV{LD_LIBRARY_PATH}="/usr/ports/pobj/openssl-1.0.2h/openssl-1.0.2h"; my $exp = Expect->spawn("/usr/ports/pobj/openssl*/openssl*/apps/openssl");