commit 2196d650928eaeb6da6f8489ee4f62307055b8c2
parent 73cb3322b35d395ae213fe0f0416f6baa097ae59
Author: Kyle Milz <kyle@0x30.net>
Date: Wed, 11 Jan 2017 18:10:14 -0700
t: redefine and resuse os allocation size
Diffstat:
4 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/t/lib_size.t b/t/lib_size.t
@@ -3,26 +3,19 @@
#
use strict;
use warnings;
-use POSIX;
use t::shm;
use t::utils;
-plan tests => 4;
+plan tests => 6;
my $dir = setup_projdir();
$dir->run( prog => $dir->workdir . "/program", args => '1', chdir => $dir->curdir );
-is( $? >> 8, 0, "is instrumented program exit code 0" );
+is( $dir->stdout, '1', 'is instrumented program stdout correct' );
+is( $dir->stderr, '', 'is instrumented program stderr silent' );
+is( $? >> 8, 0, 'is instrumented program exit code 0' );
my $shm_file_path = get_one_shmfile( $ENV{CITRUN_PROCDIR} );
my $procfile = t::shm->new( $shm_file_path );
-my $alloc_size;
-if ($^O eq "MSWin32") {
- # Windows allocation granularity.
- $alloc_size = 64 * 1024;
-} else {
- $alloc_size = POSIX::sysconf(POSIX::_SC_PAGESIZE);
-}
-
-is( $procfile->{size}, $alloc_size * 4, "is file 4 allocation units long" );
+is( $procfile->{size}, $t::shm::os_allocsize * 4, 'is file 4 allocation units' );
diff --git a/t/mem_unix.pm b/t/mem_unix.pm
@@ -7,7 +7,7 @@ use POSIX;
use Sys::Mmap;
use autodie;
-our $page_mask = POSIX::sysconf(POSIX::_SC_PAGESIZE) - 1;
+our $os_allocsize = POSIX::sysconf(POSIX::_SC_PAGESIZE);
sub get_mem {
my ($self, $procfile) = @_;
diff --git a/t/mem_win32.pm b/t/mem_win32.pm
@@ -7,7 +7,7 @@ use POSIX; # NULL
use Win32::API;
use autodie;
-our $page_mask = 64 * 1024 - 1;
+our $os_allocsize = 64 * 1024;
use constant GENERIC_READ => 0x80000000;
use constant OPEN_EXISTING => 3;
diff --git a/t/shm.pm b/t/shm.pm
@@ -59,7 +59,8 @@ sub new {
sub get_aligned_size {
my ($unaligned_size) = @_;
- return ($unaligned_size + $t::shm::page_mask) & ~$t::shm::page_mask;
+ my $page_mask = $t::shm::os_allocsize - 1;
+ return ($unaligned_size + $page_mask) & ~$page_mask;
}
sub get_buffers {