]> Dogcows Code - chaz/p5-Linux-Proc-Maps/blob - t/01-basic.t
initial commit
[chaz/p5-Linux-Proc-Maps] / t / 01-basic.t
1 #!perl
2
3 use warnings;
4 use strict;
5
6 use Path::Tiny;
7 use Test::More tests => 4;
8
9 BEGIN {
10 use_ok('Linux::Proc::Maps');
11 use_ok('Linux::Proc::Maps', qw{read_maps write_maps parse_maps_single_line format_maps_single_line});
12 }
13
14 subtest read_maps => sub {
15 plan tests => 4;
16
17 eval { read_maps() };
18 like($@, qr/filename or pid required/i, 'Die on missing argument');
19
20 eval { read_maps('missing-ebo3d1FHkKEAsGL3ZK89H5') };
21 like($@, qr/open failed/i, 'Die on open failed');
22
23 my $regions = read_maps(path('corpus/maps1')->absolute);
24 isa_ok($regions, 'ARRAY');
25 is(scalar @$regions, 20, 'Number of regions is correct');
26 # note explain $regions;
27 };
28
29 subtest parse_maps_single_line => sub {
30 plan tests => 7;
31
32 {
33 my $line = '00400000-0040c000 r-xp 00000000 08:01 23624 /bin/cat';
34 my $region = parse_maps_single_line($line);
35
36 isa_ok($region, 'HASH');
37 is_deeply($region, {
38 address_end => 4243456,
39 address_start => 4194304,
40 device => '08:01',
41 execute => 1,
42 inode => 23624,
43 offset => 0,
44 pathname => '/bin/cat',
45 read => 1,
46 shared => '',
47 write => '',
48 }, 'Region parses correctly');
49 # note explain $region;
50 }
51
52 {
53 my $line = '021d8000-021f9000 rw-p 00000000 00:00 0 [heap]';
54 my $region = parse_maps_single_line($line);
55
56 isa_ok($region, 'HASH');
57 is($region->{pathname}, '[heap]', 'Heap region identified');
58 }
59
60 {
61 my $line = '7f5d1a490000-7f5d1a494000 rw-p 00000000 00:00 0 ';
62 my $region = parse_maps_single_line($line);
63
64 isa_ok($region, 'HASH');
65 is($region->{pathname}, '', 'Pathname is optional');
66 }
67
68 {
69 my $line = '7f5d1a490000-7f5d1a494000 rw-p 00000000 00:00';
70 my $region = parse_maps_single_line($line);
71
72 is($region, undef, 'Missing inode correctly fails');
73 }
74 };
75
This page took 0.030738 seconds and 4 git commands to generate.