QA updates for testing xfs_copy
[xfstests-dev.git] / src / fill2attr
1 #!/usr/bin/perl -w
2 #
3
4 #
5 #  Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
6 #  
7 #  This program is free software; you can redistribute it and/or modify it
8 #  under the terms of version 2 of the GNU General Public License as
9 #  published by the Free Software Foundation.
10 #  
11 #  This program is distributed in the hope that it would be useful, but
12 #  WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 #  
15 #  Further, this software is distributed without any warranty that it is
16 #  free of the rightful claim of any third person regarding infringement
17 #  or the like.  Any license provided herein, whether implied or
18 #  otherwise, applies only to this software file.  Patent licenses, if
19 #  any, provided herein do not apply to combinations of this program with
20 #  other software, or any other product whatsoever.
21 #  
22 #  You should have received a copy of the GNU General Public License along
23 #  with this program; if not, write the Free Software Foundation, Inc., 59
24 #  Temple Place - Suite 330, Boston MA 02111-1307, USA.
25 #  
26 #  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 #  Mountain View, CA  94043, or:
28 #  
29 #  http://www.sgi.com 
30 #  
31 #  For further information regarding this notice, see: 
32 #  
33 #  http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 #
35 #
36
37 use strict;
38 use File::Basename;
39
40 # returns numbers with a normal distribution
41 sub normal {
42   my($mean) = $_[0];
43   my($stddev) = $_[1];
44   
45   my $x = -6.0;
46   for (my $i = 0; $i < 12; $i++) {
47     $x += rand;
48   }
49   
50   $x = $mean + $stddev * $x;
51   return $x;
52 }
53
54 # location of fill2
55 my $fill2="./src/fill2";
56
57 # for each file attach a random number of attributes
58 # each filled with a random amount of data
59 # attribute name is the checksum of the data stored within
60 # the attribute
61
62 my $status = 0;                 # return status
63 my $file;
64
65 while (<>) {
66   
67   chomp($file = $_);
68   die("Error: $0: $file not found\n") if ( ! -e $file);
69   
70   if ($0 =~ /fill2attr$/) {
71
72     # attach attributes to this file
73     my $num = abs(int(normal(3, 1)));
74     my $seed = 1;
75     my $verbose = 1;
76     my $tmp = "/tmp/fill2attr$$";
77     
78     for (my $i = 0; $i < $num; $i++) {
79       my $size = abs(int(normal(256, 200)));
80       my $cmd = "$fill2 -d nbytes=$size,linelength=72,seed=$seed -b 4k $tmp";
81       $cmd .= " > /dev/null 2>&1" if (! $verbose);
82       
83       if (system($cmd) != 0) {
84         die("Error $0: can't create $tmp\n");
85       }
86       
87       chomp($_ = `sum -r $tmp`);
88       my ($sum) = split(/\s+/);
89       system("cat $tmp | attr -s $sum $file > /dev/null");
90       system("rm $tmp");
91     }
92   }
93   elsif ($0 =~ /fill2attr_check/) {
94
95     # get the attributes for this file
96     my $cmd = "attr -q -l $file |";
97     open LIST, $cmd;
98     my @labels = <LIST>;
99     close LIST or die("Error listing attributes: $!");
100     chomp(@labels);
101
102     # check attribute contents
103     foreach my $label (@labels) {
104       my $sum;
105       ($sum) = split(/\s+/, `attr -q -g $label $file | sum -r`);
106       if ($sum ne $label) {
107         warn("Attribute \"$label\" does not match " .
108              "attribute contents for file $file\n");
109         $status = 1;
110       }
111     }
112   }
113 }
114
115 exit($status);