commit 9903a80b2b6b5ce1f606a391ed381ad5bebf1566
parent 79240861a80ea5a0d3a7eb14ee66a66955718210
Author: Kyle Milz <kyle@0x30.net>
Date: Mon, 29 Aug 2016 20:34:44 -0600
t: modify other perl tests to use shm.pm
Diffstat:
5 files changed, 26 insertions(+), 54 deletions(-)
diff --git a/t/rt_header.t b/t/rt_header.t
@@ -5,20 +5,17 @@ use strict;
use warnings;
use Test::Cmd;
use Test::More tests => 14;
-use test::utils;
+use test::shm;
-$ENV{CITRUN_TOOLS} = 1;
my $test_prog = Test::Cmd->new( prog => 'test/program', workdir => '');
$test_prog->run( args => "1" );
is $? >> 8, 0, 'did test program exit 0';
-open(my $fh, "<:mmap", "procfile.shm") or die $!;
+my $shm = test::shm->new();
+is $shm->{major}, 0, "is major correct";
+is $shm->{minor}, 0, "is minor correct";
-my ($major, $minor) = unpack("C2", test::utils::xread($fh, 2));
-is $major, 0, "is major correct";
-is $minor, 0, "is minor correct";
-
-my ($pid, $ppid, $pgrp) = unpack("L3", test::utils::xread($fh, 12));
+my ($pid, $ppid, $pgrp) = @{ $shm->{pids} };
cmp_ok $pid, '<', 100 * 1000, "pid is less than max pid";
cmp_ok $pid, '>', 0, "pid is greater than min pid";
cmp_ok $ppid, '<', 100 * 1000, "ppid is less than max pid";
@@ -26,14 +23,10 @@ cmp_ok $ppid, '>', 0, "ppid is greater than min pid";
cmp_ok $pgrp, '<', 100 * 1000, "pgrp is less than max pid";
cmp_ok $pgrp, '>', 0, "pgrp is greater than min pid";
-my ($prg_sz) = unpack("S", test::utils::xread($fh, 2));
-cmp_ok $prg_sz, '<', 1024, 'is size of program name less than 1024';
-cmp_ok $prg_sz, '>', 0, 'is size of program name greater than 0';
-my ($progname) = unpack("Z$prg_sz", test::utils::xread($fh, $prg_sz));
-is $progname, "program", 'is test program name correct';
+cmp_ok $shm->{prg_sz}, '<', 1024, 'is size of program name less than 1024';
+cmp_ok $shm->{prg_sz}, '>', 0, 'is size of program name greater than 0';
+is $shm->{progname}, "program", 'is test program name correct';
-my ($cwd_sz) = unpack("S", test::utils::xread($fh, 2));
-cmp_ok $cwd_sz, '<', 1024, 'is size of working dir less than 1024';
-cmp_ok $cwd_sz, '>', 0, 'is size of working dir greater than 0';
-my ($cwd) = unpack("Z$cwd_sz", test::utils::xread($fh, $cwd_sz));
+cmp_ok $shm->{cwd_sz}, '<', 1024, 'is size of working dir less than 1024';
+cmp_ok $shm->{cwd_sz}, '>', 0, 'is size of working dir greater than 0';
# is $cwd, "/home/...", 'is working directory believable';
diff --git a/t/rt_size.t b/t/rt_size.t
@@ -1,11 +1,12 @@
use strict;
use warnings;
use Test::More tests => 1;
-
+use test::shm;
#
# Test that the runtime shared file size is what we expect.
#
-$ENV{CITRUN_TOOLS} = 1;
-system("test/program/program 1");
-is((stat "procfile.shm")[7], 16384, "size of memory file");
+system("test/program 1");
+
+my $procfile = test::shm->new();
+is($procfile->{size}, 16384, "size of memory file");
diff --git a/t/rt_translunit.t b/t/rt_translunit.t
@@ -6,29 +6,19 @@ use warnings;
use POSIX;
use Test::Cmd;
use Test::More tests => 7;
-use test::utils;
+use test::shm;
-$ENV{CITRUN_TOOLS} = 1;
my $test_prog = Test::Cmd->new( prog => 'test/program', workdir => '');
$test_prog->run( args => "10" );
is $? >> 8, 0, 'did test program exit 0';
-open(my $fh, "<:mmap", "procfile.shm");
+my $shm = test::shm->new();
-my $pagesize = POSIX::sysconf(POSIX::_SC_PAGESIZE);
-test::utils::xread($fh, $pagesize);
-
-my ($size) = unpack("L", test::utils::xread($fh, 4));
-is $size, 9, 'is line buffer size 100';
-
-my ($cmp_sz) = unpack("S", test::utils::xread($fh, 2));
-cmp_ok $cmp_sz, '<', 1024, 'is size of compiler file name less than 1024';
-cmp_ok $cmp_sz, '>', 0, 'is size of compiler file name greater than 0';
-my $comp_file_name = test::utils::xread($fh, $cmp_sz);
-#is $comp_file_name, 'three.c', 'is compiler file name right';
-
-my ($abs_sz) = unpack("S", test::utils::xread($fh, 2));
-cmp_ok $abs_sz, '<', 1024, 'is size of absolute file path less than 1024';
-cmp_ok $abs_sz, '>', 0, 'is size of absolute file path greater than 0';
-my $abs_file_path = test::utils::xread($fh, $abs_sz);
-like $abs_file_path, qr/.*three.c/, 'is absolute file path believable';
+my (%tu1, %tu2, %tu3) = @{ $shm->{translation_units} };
+is $tu1{size}, 26, "transl unit 1 size";
+cmp_ok $tu1{cmp_sz}, '<', 1024, 'is size of compiler file name less than 1024';
+cmp_ok $tu1{cmp_sz}, '>', 0, 'is size of compiler file name greater than 0';
+#is $tu1{comp_file_name}, 'one.c', 'is compiler file name right';
+cmp_ok $tu1{abs_sz}, '<', 1024, 'is size of absolute file path less than 1024';
+cmp_ok $tu1{abs_sz}, '>', 0, 'is size of absolute file path greater than 0';
+like $tu1{abs_file_path}, qr/.*one.c/, 'is absolute file path believable';
diff --git a/t/rt_ver.sh b/t/rt_ver.sh
@@ -1,12 +0,0 @@
-#
-# Check that the runtime version of the shared memory file is what we expect.
-#
-echo 1..2
-. test/project.sh
-
-./program 2
-
-xxd -p -l 2 runtime/* > hex_version
-echo "0000" > hex_version.good
-
-test_diff 2 "shared memory file version" hex_version.good hex_version
diff --git a/test/shm.pm b/test/shm.pm
@@ -39,7 +39,7 @@ sub new {
xread($fh, $tu{size} * 8);
$self->next_page();
- push @translation_units, (\%tu);
+ push @translation_units, (%tu);
}
$self->{translation_units} = \@translation_units;