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