From 586a59e00d00f2b1347f015911545b722f2d1f8b Mon Sep 17 00:00:00 2001 From: Romain d'Alverny Date: Mon, 5 Dec 2011 22:55:33 +0000 Subject: First import, test suite attempt for built ISOs Code heavily taken from previous dams work, reorganized in a test suite to better separate test cases. Does basic things already (in t/). Needs more fixes (esp. in t_install_iso/). --- t/000_test_env.t | 24 ++++++++++++++ t/001_check_file.t | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/003_is_hybrid.t | 82 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 t/000_test_env.t create mode 100644 t/001_check_file.t create mode 100644 t/003_is_hybrid.t (limited to 't') diff --git a/t/000_test_env.t b/t/000_test_env.t new file mode 100644 index 0000000..9484e5b --- /dev/null +++ b/t/000_test_env.t @@ -0,0 +1,24 @@ +# +# These tests check that the testing environment is complete. +# + +use Test::Most; + +bail_on_fail; + +my ($image_path) = @ARGV; + +# FIXME why need to be root? for mounting the ISO only? +# FIXME USER or USERNAME? +is($ENV{USERNAME}, 'root', "Current user is root."); + +# TODO move this elsewhere maybe? +sub pkg_check { my ($pkg) = @_; return system("rpm -q $pkg >/dev/null"); } + +my @packages = qw(cdrkit cdrkit-isotools mono gnupg); + +foreach my $p (@packages) { + is(pkg_check($p), 0, sprintf("%s is installed.", $p)); +} + +done_testing(); diff --git a/t/001_check_file.t b/t/001_check_file.t new file mode 100644 index 0000000..f82b149 --- /dev/null +++ b/t/001_check_file.t @@ -0,0 +1,97 @@ +# +# +# + +use Test::Most; +use File::Basename; +use Tools; + +my ($image_path) = @ARGV; + +my $name = basename($image_path); +my %info = (); + +bail_on_fail; + +note $image_path; +note $name; + +%info = Tools::parse_mageia_iso_name($name); +if (scalar %info) { + pass 'ISO has valid filename.'; + while (my ($k, $v) = each %info) { + note uc($k), "=$v\n"; + } +} else { + fail 'ISO has valid filename.'; + diag 'See https://wiki.mageia.org/en/Product_naming'; +} + +# are files available? +ok -r $image_path, 'ISO file is readable.' + or diag("$image_path: $!"); + +# is file size correct? +my $du = `du --apparent-size --block-size=M $image_path`; +my @size_name = split(/\t/, $du); +my $size = $size_name[0]; + +# FIXME put correct sizes here +my %max_sizes = ( "CD" => "740M", "DVD" => "4200M" ); +ok ($size le $max_sizes{$info{"medium"}}, + sprintf("File has a working size (%s) for its medium type (%s, max %s).", + $size, $info{"medium"}, $max_sizes{$info{"medium"}})); + +# +ok -r $image_path . '.md5', 'MD5 checksum is available.'; +ok -r $image_path . '.sha1', 'SHA1 checkum is available.'; + +TODO: { + local $TODO = ".idx & .lst" if 1; + + ok -r $image_path, '.idx list file is available.'; + ok -r $image_path, '.lst list file is available.'; +} + + +# verify checksums +my $md5file = $image_path . '.md5'; +my $sha1file = $image_path . '.sha1'; + +my @ts = split(/ /, `md5sum $image_path`); +my $md5 = $ts[0]; +@ts = split(/ /, `cat $md5file`); +$md5file = $ts[0]; +is ($md5, $md5file, 'MD5/.md5 checksums match.'); + +@ts = split(/ /, `sha1sum $image_path`); +my $sha1 = $ts[0]; +@ts = split(/ /, `cat $sha1file`); +$sha1file = $ts[0]; +is ($sha1, $sha1file, 'SHA1/.sha1 checksums match.'); + + +# inspect iso definition +my $volume_id = `isoinfo -d -i $image_path | grep "Volume id"`; +my @info = (0, 0, 0, 0); +my @temp = split(/ /, $volume_id); + +note ('TODO, test to check here!'); + + +# bootable? +ok (`isoinfo -d -i $image_path | grep bootable`, 'ISO is bootable.'); + +# TODO check burnable? +my $burner = "/dev/sr0"; + +# FIXME is -eject really needed? +my $_burning = `cdrecord -dummy speed=42 dev=$burner -v -eject -data $image_path 2> is_burnable.log`; +my $result = `cat is_burnable.log | grep overburn | wc -l | tr -d '\n'`; + +-r "is_burnable.log" and system "rm is_burnable.log"; + +is ($result, 0, "ISO can be burnt."); + + +done_testing(); diff --git a/t/003_is_hybrid.t b/t/003_is_hybrid.t new file mode 100644 index 0000000..37ccbcd --- /dev/null +++ b/t/003_is_hybrid.t @@ -0,0 +1,82 @@ +# +# +# +use Test::Most; + +bail_on_fail; + +my ($image_path) = @ARGV; + +ok (is_hybrid($image_path, 0), "Is hybrid"); + +# Verification if the Iso is hybrid +sub is_hybrid { + my ($img, $full) = @_; + + open(my $iso, $img); + my $hybrid = hybrid1($iso); + $hybrid &= hybrid2($iso); + $hybrid &= hybrid3($iso); + if ($full) { + # system "dd if=$img of=/dev/my-pendrive bs=8"; + } + close($iso); + + return $hybrid; +} + + +# Check the first 512 bytes of the iso +sub hybrid1 { + my ($iso) = @_; + my $buffer; + my $hybrid; + + foreach (0 .. 512) { + read($iso, $buffer, 1); + if ($buffer ne '\x00') { + $hybrid = 1; + } + } + + return $hybrid; +} + +#Check the 0x1fe & 0x1ff bytes of the iso +sub hybrid2 { + my ($iso) = @_; + my $hybrid; + my $buffer; + my $byte = "\x55"; + + seek($iso, 0x1fe, 0); + read($iso, $buffer, 1); + if ($buffer eq $byte) { + read($iso, $buffer, 1); + $byte = "\xaa"; + if ($buffer eq $byte) { + $hybrid = 1; + } + } + + return $hybrid; +} + +# check from the 0x200 to the 0x8000 bytes +sub hybrid3 { + my ($iso) = @_; + my $hybrid = 1; + my $buffer; + + seek($iso, 0x200, 0); + foreach (0x200 .. 0x8000) { + read($iso, $buffer, 1); + if ($buffer eq '\x00') { + $hybrid = 0; + } + } + + return $hybrid; +} + +done_testing(); -- cgit v1.2.1