]> Sergey Matveev's repositories - public-inbox.git/blob - t/nodatacow.t
19247c109b0931b8340f4f75bc4d189bd5a5577a
[public-inbox.git] / t / nodatacow.t
1 #!perl -w
2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict; use v5.10.1; use PublicInbox::TestCommon;
5 use File::Temp 0.19;
6 use_ok 'PublicInbox::NDC_PP';
7
8 SKIP: {
9         my $nr = 2;
10         skip 'test is Linux-only', $nr if $^O ne 'linux';
11         my $dir = $ENV{BTRFS_TESTDIR};
12         skip 'BTRFS_TESTDIR not defined', $nr unless defined $dir;
13         require_cmd('chattr', 1) or skip 'chattr(1) not installed', $nr;
14         my $lsattr = require_cmd('lsattr', 1) or
15                 skip 'lsattr(1) not installed', $nr;
16         my $tmp = File::Temp->newdir('nodatacow-XXXX', DIR => $dir);
17         my $dn = $tmp->dirname;
18
19         my $name = "$dn/pp.f";
20         open my $fh, '>', $name or BAIL_OUT "open($name): $!";
21         my $pp_sub = \&PublicInbox::NDC_PP::nodatacow_fd;
22         $pp_sub->(fileno($fh));
23         my $res = xqx([$lsattr, $name]);
24         like($res, qr/C.*\Q$name\E/, "`C' attribute set on fd with pure Perl");
25
26         $name = "$dn/pp.d";
27         mkdir($name) or BAIL_OUT "mkdir($name) $!";
28         PublicInbox::NDC_PP::nodatacow_dir($name);
29         $res = xqx([$lsattr, '-d', $name]);
30         like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with pure Perl");
31
32         $name = "$dn/ic.f";
33         my $ic_sub = \&PublicInbox::Spawn::nodatacow_fd;
34         $pp_sub == $ic_sub and
35                 skip 'Inline::C or Linux kernel headers missing', 2;
36         open $fh, '>', $name or BAIL_OUT "open($name): $!";
37         $ic_sub->(fileno($fh));
38         $res = xqx([$lsattr, $name]);
39         like($res, qr/C.*\Q$name\E/, "`C' attribute set on fd with Inline::C");
40
41         $name = "$dn/ic.d";
42         mkdir($name) or BAIL_OUT "mkdir($name) $!";
43         PublicInbox::Spawn::nodatacow_dir($name);
44         $res = xqx([$lsattr, '-d', $name]);
45         like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with Inline::C");
46 };
47
48 done_testing;