From a6ad26e1420bdd837b0412ad2c6ff43f746bf7a1 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 29 Apr 2024 14:05:36 -0700 Subject: [PATCH] testpyisomd5sum.py: Use a consistent iso size 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. --- testpyisomd5sum.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/testpyisomd5sum.py b/testpyisomd5sum.py index 082f2e7..c13107c 100755 --- a/testpyisomd5sum.py +++ b/testpyisomd5sum.py @@ -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 @@ -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) @@ -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)