Whamcloud - gitweb
952dac5007c81aba88aa2cafc375f3c8ef6d3817
[fs/lustre-release.git] / lustre / tests / create.pl
1 #!/usr/bin/perl
2
3 my $mtpt = shift || usage();
4 my $mount_count = shift || usage();
5 my $i = shift || usage();
6 my $files = 5;
7 my $mcreate = 0; # should we use mcreate or open?
8
9 sub usage () {
10     print "Usage: $0 <mount point prefix> <mount count> <iterations>\n";
11     print "example: $0 /mnt/lustre 2 50\n";
12     print "         will test in /mnt/lustre1 and /mnt/lustre2\n";
13     print "         $0 /mnt/lustre -1 50\n";
14     print "         will test in /mnt/lustre only\n";
15     exit;
16 }
17
18 sub do_open($) {
19     my $path = shift;
20
21     if ($mcreate) {
22         my $tmp = `./mcreate $path`;
23         if ($tmp) {
24             $tmp =~ /.*error: (.*)\n/;
25             print "Created  $path: $1\n";
26         } else {
27             print "Created  $path: Success\n";
28         }
29     } else {
30         open(FH, ">$path") || die "open($PATH): $!";
31         print "Opened   $path: Success\n";
32         close(FH) || die;
33     }
34 }
35
36 while ($i--) {
37     my $which = "";
38     if ($mount_count > 0) {
39         $which = int(rand() * $mount_count) + 1;
40     }
41     $d = int(rand() * $files);
42     do_open("$mtpt$which/$d");
43
44     if ($mount_count > 0) {
45         $which = int(rand() * $mount_count) + 1;
46     }
47     $d = int(rand() * $files);
48     $path = "$mtpt$which/$d";
49     if (unlink($path)) {
50         print "Unlinked $path: Success\n";
51     } else {
52         print "Unlinked $path: $!\n";
53     }
54 }
55 print "Done.\n";