File: capabilities.t

package info (click to toggle)
liblinux-prctl-perl 1.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 400 kB
  • sloc: perl: 163; ansic: 19; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,897 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
use strict;
use warnings;

use Test::More tests => 291;
use Linux::Prctl qw(:constants);

use POSIX qw(setlocale LC_ALL);
setlocale(LC_ALL, 'C');

my %new_caps = ("syslog" => 1, "wake_alarm" => 1);

is(defined(tied %Linux::Prctl::cap_permitted), 1, "Have a tied cap_permitted object");
is(defined(tied %Linux::Prctl::cap_effective), 1, "Have a tied cap_effective object");
is(defined(tied %Linux::Prctl::cap_inheritable), 1, "Have a tied cap_inheritable object");
my $R = $< ? 0 : 1;
for(@{$Linux::Prctl::EXPORT_TAGS{capabilities}}) {
    SKIP: {
        s/^CAP_//;
        $_ = lc($_);
        eval {
            my $ign = $Linux::Prctl::cap_permitted{$_};
            1;
        } or do {
            if($@ =~ /Invalid argument|has not defined/ && exists($new_caps{$_})) {
                skip("$_ not defined", 8);
            }
        };
        is($Linux::Prctl::cap_permitted{$_}, $R, "Checking whether $_ is set in cap_permitted");
        is($Linux::Prctl::cap_effective{$_}, $R, "Checking whether $_ is set in cap_effective");
        is($Linux::Prctl::cap_inheritable{$_}, 0, "Checking whether $_ is set in cap_inheritable");

        $Linux::Prctl::cap_inheritable{$_} = 1;
        is($Linux::Prctl::cap_inheritable{$_}, $R, "Checking whether $_ is set to $R in cap_inheritable");

        $Linux::Prctl::cap_effective{$_} = 0;
        is($Linux::Prctl::cap_effective{$_}, 0, "Checking whether $_ is set to 0 in cap_effective");
        $Linux::Prctl::cap_effective{$_} = 1;
        is($Linux::Prctl::cap_effective{$_}, $R, "Checking whether $_ is set to $R in cap_effective");

        $Linux::Prctl::cap_permitted{$_} = 0;
        is($Linux::Prctl::cap_permitted{$_}, $R, "Checking whether $_ is set to $R in cap_permitted");
        $Linux::Prctl::cap_permitted{$_} = 1;
        is($Linux::Prctl::cap_permitted{$_}, $R, "Checking whether $_ is set to $R in cap_permitted");
    }
}