File: 18.t

package info (click to toggle)
libcache-fastmmap-perl 1.58-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 356 kB
  • sloc: ansic: 1,399; perl: 628; makefile: 7
file content (63 lines) | stat: -rw-r--r-- 1,287 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

#########################

use Test::More;

BEGIN {
  if ($^O eq "MSWin32") {
    plan skip_all => 'No FD_CLOEXEC tests, running on Windows';
  }
  if (!-d "/proc/$$") {
    plan skip_all => 'No FD_CLOEXEC tests, no /proc filesystem';
  }
}


use strict;
use Fcntl;

#########################

# Test fd's are closed on exec

if (@ARGV) {
  my $PipeFd = shift @ARGV;
  my $FdCount = scalar(() = glob "/proc/$$/fd/*");
  open(my $PipeFh, ">&=$PipeFd")
    || die "Could not reopen fd: $!";
  print($PipeFh "$FdCount\n")
    || die "Could not print to pipe: $!";
  exit(0);
}

require Cache::FastMmap;
my @Caches = map {
  Cache::FastMmap->new(
    page_size => 4096,
    num_pages => 1,
    init_file => 1,
    serializer => '',
  );
} (1 .. 20);
my $CacheCount = @Caches;

my $FdCount = scalar(() = glob "/proc/$$/fd/*");
ok($FdCount > $CacheCount, "More fd's than caches: $FdCount > $CacheCount");

pipe(my $ReadPipeFh, my $WritePipeFh)
  || die "pipe failed: $!";

fcntl($ReadPipeFh, F_SETFD, 0);
fcntl($WritePipeFh, F_SETFD, 0);

if (!fork) {
  exec $^X, $0, fileno($WritePipeFh)
    || die "exec failed: $!";
}

my $ChildFdCount = <$ReadPipeFh>;
chomp $ChildFdCount;
ok($ChildFdCount < $CacheCount, "Less fd's in child than caches: $ChildFdCount < $CacheCount");

done_testing(2);