10 print "Usage: ./populator.pl <-seed seed> :\n";
11 print " <-file filename> :\n";
12 print " <-bytes bytes> : Create a file, filename, that\n";
13 print " : is bytes long and populate with\n";
14 print " : random numbers using the given\n";
15 print " : seed. Will use defaults if args\n";
16 print " : not given\n";
22 my $MAX_SIZE = 2147483648;
29 $num = rand $MAX_SIZE;
30 my $tmpstr = sprintf("%d", $num);
32 $len += length $tmpstr;
40 my ($cmdfh, $outfh, $filename, $bytes) = @_;
43 # Allocate the read buffer
44 my $cmd = '$buf = ALLOC 1024'."\n";
45 helper::send_cmd($cmdfh, $outfh, "alloc", $cmd);
47 # Open (create) the new file
48 $cmd = '$fd = CALL open '."$filename O_RDWR|O_CREAT S_IRWXU\n";
49 helper::send_cmd($cmdfh, $outfh, "open", $cmd);
51 # Verify the system call's output
52 helper::verify_cmd($cmdfh, $outfh, "open");
54 my $left_bytes = $bytes;
55 while ($left_bytes > 0) {
56 # Get a buffer filled with random numbers
57 # Buffer will be no less than 512 bytes
58 my ($len, $buf) = get_buf;
59 if ($len > $left_bytes) {
63 # Need to fill $buf with the buffer
64 $cmd = "CALL fill $buf STR $len 0 ".'$buf'."\n";
65 helper::send_cmd($cmdfh, $outfh, "fill", $cmd);
67 # Write out $len bytes to $filename
68 $cmd = 'CALL write $fd $buf '."$len\n";
70 helper::send_cmd($cmdfh, $outfh, "write", $cmd);
72 my $written_bytes = helper::verify_cmd($cmdfh, $outfh, "write");
73 $written_bytes = oct($written_bytes);
74 if ($written_bytes != $len) {
75 helper::print_and_exit($cmdfh, $outfh, 1,
76 "ERROR! Meant to print out $len but only printed $written_bytes\n");
85 my ($filename, $bytes, $is_alpha) = @_;
89 open2(\*OUTFILE, \*CMDFILE, "./test_driver --np");
91 open2(\*OUTFILE, \*CMDFILE,
92 "yod -batch -quiet -sz 1 ./test_driver --np");
98 warn "open2 failed: $!\n$@\n";
105 my $outfh = \*OUTFILE;
106 my $cmdfh = \*CMDFILE;
108 if ($is_alpha == 0) {
109 helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
113 write_file($cmdfh, $outfh, $filename, $bytes);
116 my $cmd = 'CALL close $fd'."\n";
117 helper::send_cmd($cmdfh, $outfh, "close", $cmd);
119 helper::verify_cmd($cmdfh, $outfh, "close");
122 helper::print_and_exit($cmdfh, $outfh, 0, "File $filename successfully created\n");
128 my $filename = "randfile.$seed.$$";
130 for (my $i = 0; $i < @ARGV; $i++)
132 if ($ARGV[$i] eq "-file") {
134 $filename = $ARGV[$i];
135 } elsif ($ARGV[$i] eq "-seed") {
138 } elsif ($ARGV[$i] eq "-alpha") {
140 } elsif ($ARGV[$i] eq "-bytes") {
146 # seed the randome number generator
149 populate_file($filename, $bytes, $is_alpha);