X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fnodatacow.t;fp=t%2Fnodatacow.t;h=87b6bdf72142a72a008e3366f301a1e30a0a517f;hb=c106504309621b662ce6c7cd914718f7045edca4;hp=0000000000000000000000000000000000000000;hpb=a3391407c960e4bbd825a34b87d053de6ef3767a;p=public-inbox.git
diff --git a/t/nodatacow.t b/t/nodatacow.t
new file mode 100644
index 00000000..87b6bdf7
--- /dev/null
+++ b/t/nodatacow.t
@@ -0,0 +1,34 @@
+#!perl -w
+# Copyright (C) 2020 all contributors
+# License: AGPL-3.0+
+use strict;
+use Test::More;
+use File::Temp qw(tempfile);
+use PublicInbox::TestCommon;
+use PublicInbox::Spawn qw(which);
+use_ok 'PublicInbox::NDC_PP';
+
+SKIP: {
+ my $nr = 2;
+ skip 'test is Linux-only', $nr if $^O ne 'linux';
+ my $dir = $ENV{BTRFS_TESTDIR};
+ skip 'BTRFS_TESTDIR not defined', $nr unless defined $dir;
+ skip 'chattr(1) not installed', $nr unless which('chattr');
+ my $lsattr = which('lsattr') or skip 'lsattr(1) not installed', $nr;
+ my ($fh, $name) = tempfile(DIR => $dir, UNLINK => 1);
+ BAIL_OUT "tempfile: $!" unless $fh && defined($name);
+ my $pp_sub = \&PublicInbox::NDC_PP::set_nodatacow;
+ $pp_sub->(fileno($fh));
+ my $res = xqx([$lsattr, $name]);
+ like($res, qr/C/, "`C' attribute set with pure Perl");
+
+ my $ic_sub = \&PublicInbox::Spawn::set_nodatacow;
+ $pp_sub == $ic_sub and
+ skip 'Inline::C or Linux kernel headers missing', 1;
+ ($fh, $name) = tempfile(DIR => $dir, UNLINK => 1);
+ $ic_sub->(fileno($fh));
+ $res = xqx([$lsattr, $name]);
+ like($res, qr/C/, "`C' attribute set with Inline::C");
+};
+
+done_testing;