diff options
author | Martin Whitaker <mageia@martin-whitaker.me.uk> | 2020-05-05 22:42:51 +0100 |
---|---|---|
committer | Martin Whitaker <mageia@martin-whitaker.me.uk> | 2020-05-05 22:42:51 +0100 |
commit | a08300033d2ccaa6f2704535f977fb876da93b65 (patch) | |
tree | 8ea73642300ba5ddb75c7b8eb61ba2bd3dbc9c9e /t/helper.pm | |
parent | 2d28e08b9584e35e9b268f0ddde161e4b899bbd2 (diff) | |
download | perl-Hal-Cdroms-a08300033d2ccaa6f2704535f977fb876da93b65.tar perl-Hal-Cdroms-a08300033d2ccaa6f2704535f977fb876da93b65.tar.gz perl-Hal-Cdroms-a08300033d2ccaa6f2704535f977fb876da93b65.tar.bz2 perl-Hal-Cdroms-a08300033d2ccaa6f2704535f977fb876da93b65.tar.xz perl-Hal-Cdroms-a08300033d2ccaa6f2704535f977fb876da93b65.zip |
Add functional tests.
Diffstat (limited to 't/helper.pm')
-rw-r--r-- | t/helper.pm | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/t/helper.pm b/t/helper.pm new file mode 100644 index 0000000..3890797 --- /dev/null +++ b/t/helper.pm @@ -0,0 +1,44 @@ +use strict; + +sub can_create_fake_media { + system("modprobe -n scsi_debug") == 0; +} + +sub create_fake_media { + my ($o_delay) = @_; + + system("modprobe scsi_debug ptype=0 removable=1 num_tgts=1 add_host=1") == 0 + or die "Failed to load scsi_debug kernel module\n"; + my @paths = glob("/sys/bus/pseudo/drivers/scsi_debug/adapter0/host*/target*/*:*/block/*"); + @paths == 1 + or die "Unexpected number of scsi_debug devices\n"; + my ($prefix, $device) = split("block/", $paths[0]); + if ($o_delay) { + system("echo 'sleep $o_delay; dd if=t/cdroms-test.iso of=/dev/$device conv=nocreat' | at now >& /dev/null") == 0 + or die "Failed to schedule copy of ISO to fake SCSI device\n"; + } else { + system("dd if=t/cdroms-test.iso of=/dev/$device conv=nocreat >& /dev/null") == 0 + or die "Failed to copy ISO to fake SCSI device\n"; + } + $device; +} + +sub remove_fake_media { + my $tries = 0; + while (system("modprobe -r -q scsi_debug") != 0) { + ++$tries < 5 or die "Failed to remove scsi_debug kernel module\n"; + sleep(1); + } +} + +sub find_mount_point { + my ($device) = @_; + open(my $fh, '<', '/proc/mounts') or die "Couldn't read /proc/mounts\n"; + while (<$fh>) { + my ($device_path, $mount_point) = split(' ', $_); + return $mount_point if $device_path eq "/dev/$device"; + } + return undef; +} + +1; |