Skip to content

Commit

Permalink
testpyisomd5sum.py: Use a consistent iso size
Browse files Browse the repository at this point in the history
The test script used to use the directory content for the test.
Depending on the circumstances this could vary in size and fail because
isomd5sum does not work on small isos.

This uses part of the reverted test to make a 500k file/iso to use for
testing. Smaller or larger sizes may be set by passing the size in K on
the cmdline.
  • Loading branch information
bcl committed Apr 29, 2024
1 parent 86c7d97 commit a6ad26e
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions testpyisomd5sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import os
import subprocess
import sys
import tempfile

import pyisomd5sum

# Pass in the rc, the expected value and the pass_all state
Expand All @@ -12,18 +15,35 @@ def pass_fail(rc, pass_value, pass_all):
else:
return ("FAIL", False)

try:
iso_size = int(sys.argv[1])
except (IndexError, ValueError):
# Default to 500K
iso_size = 500

# create iso file
try:
# Python 3
catch_error = FileNotFoundError
except NameError:
# Python 2
catch_error = OSError
try:
subprocess.check_call(["mkisofs", "-o", "testiso.iso", "."])
except catch_error:
subprocess.check_call(["genisoimage", "-o", "testiso.iso", "."])

# create iso file using a clean directory
with tempfile.TemporaryDirectory(prefix="isomd5test-") as tmpdir:
# Write temporary data to iso test dir
with open(tmpdir+"/TEST-DATA", "w") as f:
# Write more data base on cmdline arg
for x in range(0,iso_size):
f.write("A" * 1024)

try:
subprocess.check_call(["mkisofs", "-o", "testiso.iso", tmpdir])
except catch_error:
subprocess.check_call(["genisoimage", "-o", "testiso.iso", tmpdir])

if not os.path.exists("testiso.iso"):
print("Error creating iso")
sys.exit(1)

# implant it
(rstr, pass_all) = pass_fail(pyisomd5sum.implantisomd5sum("testiso.iso", 1, 0), 0, True)
Expand All @@ -50,11 +70,11 @@ def callback(offset, total):

def callback_abort(offset, total):
print(" %s - %s" % (offset, total))
if offset > 500000:
if offset > 100000:
return True
return False

print("Run with callback and abort after offset of 500000")
print("Run with callback and abort after offset of 100000")
(rstr, pass_all) = pass_fail(pyisomd5sum.checkisomd5sum("testiso.iso", callback_abort), 2, pass_all)
print(rstr)

Expand Down

0 comments on commit a6ad26e

Please sign in to comment.