]> git.sur5r.net Git - bacula/bacula/blob - regress/scripts/functions.pm
regress: Add small perl lib for speed testing
[bacula/bacula] / regress / scripts / functions.pm
1 ################################################################
2 use strict;
3
4 =head1 LICENSE
5
6    Bacula® - The Network Backup Solution
7
8    Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
9
10    The main author of Bacula is Kern Sibbald, with contributions from
11    many others, a complete list can be found in the file AUTHORS.
12
13    This program is Free Software; you can redistribute it and/or
14    modify it under the terms of version two of the GNU General Public
15    License as published by the Free Software Foundation plus additions
16    that are listed in the file LICENSE.
17
18    This program is distributed in the hope that it will be useful, but
19    WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    General Public License for more details.
22
23    You should have received a copy of the GNU General Public License
24    along with this program; if not, write to the Free Software
25    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26    02110-1301, USA.
27
28    Bacula® is a registered trademark of Kern Sibbald.
29    The licensor of Bacula is the Free Software Foundation Europe
30    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
31    Switzerland, email:ftf@fsfeurope.org.
32
33 =cut
34
35 package scripts::functions;
36 use Exporter;
37 our @ISA = qw(Exporter);
38 our @EXPORT =  qw(update_some_files create_many_files);
39
40 sub update_some_files
41 {
42     my ($dest)=@_;
43     my $t=rand();
44     my $f;
45     my $nb=0;
46     print "Update files in $dest\n";
47     opendir(DIR, $dest) || die "$!";
48     map {
49         $f = "$dest/$_";
50         if (-f $f) {
51             open(FP, ">$f") or die "$f $!";
52             print FP "$t update $f\n";
53             close(FP);
54             $nb++;
55         }
56     } readdir(DIR);
57     closedir DIR;
58     print "$nb files updated\n";
59 }
60
61 sub create_many_files
62 {
63     my ($dest, $nb) = @_;
64     my $base;
65     my $dir=$dest;
66     $nb = $nb || 750000;
67     mkdir $dest;
68     $base = chr($nb % 26 + 65);
69
70     # already done
71     if (-f "$dest/$base/a${base}a750000aaa$base") {
72         print "Files already created\n";
73         return;
74     }
75
76     # auto flush stdout for dots
77     $| = 1;
78     print "Create $nb files into $dest\n";
79     for(my $i=0; $i < 26; $i++) {
80         $base = chr($i + 65);
81         mkdir("$dest/$base");
82     }
83     for(my $i=0; $i<=$nb; $i++) {
84         $base = chr($i % 26 + 65);
85         open(FP, ">$dest/$base/a${base}a${i}aaa$base") or die "$dest/$base $!";
86         print FP "$i\n";
87         close(FP);
88         
89         open(FP, ">$dir/b${base}a${i}csq$base") or die "$dir $!";
90         print FP "$base $i\n";
91         close(FP);
92         
93         if (!($i % 100)) {
94             $dir = "$dest/$base/$base$i$base";
95             mkdir $dir;
96         }
97         print "." if (!($i % 10000));
98     }
99     print "\n";
100 }
101
102 1;