tests: Replace calls to dd with native writeZeroes

This commit is contained in:
Jakob Unterwurzacher 2014-11-29 13:35:02 +01:00
parent 8620b46d56
commit 7732466277
3 changed files with 23 additions and 2 deletions

View File

@ -72,5 +72,26 @@ sub waitForFile
return 0;
}
# writeZeroes($filename, $size)
# Write zeroes of size $size to file $filename
sub writeZeroes
{
my $filename = shift;
my $size = shift;
open(my $fh, ">", $filename);
my $bs = 4096; # 4 KiB
my $block = "\0" x $bs;
my $remain;
for($remain = $size; $remain >= $bs; $remain -= $bs)
{
print($fh $block) or BAIL_OUT("Could not write to $filename: $!");
}
if($remain > 0)
{
$block = "\0" x $remain;
print($fh $block) or BAIL_OUT("Could not write to $filename: $!");
}
}
# As this file will be require()'d, it needs to return true
return 1;

View File

@ -88,7 +88,7 @@ sub corruption
sub internalModification
{
$ofile = "$workingDir/crypt-internal-$$";
qx(dd if=/dev/urandom of=$ofile bs=2k count=2 2> /dev/null);
writeZeroes($ofile, 2*1024);
ok(copy($ofile, "$crypt/internal"), "copying crypt-internal file");
open(my $out1, "+<", "$crypt/internal");

View File

@ -129,7 +129,7 @@ sub grow {
}
sub largeRead {
system("dd if=/dev/zero of=$plain/largeRead bs=1M count=1 2> /dev/null");
writeZeroes("$plain/largeRead", 1024*1024);
# ciphertext file name
my $cname = encName("largeRead");
# cfh ... ciphertext file handle