-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtestpyisomd5sum.py
executable file
·87 lines (69 loc) · 2.39 KB
/
testpyisomd5sum.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python3
import os
import subprocess
import sys
import tempfile
import pyisomd5sum
# Pass in the rc, the expected value and the pass_all state
# Returns a PASS/FAIL string and updates pass_all if it fails
def pass_fail(rc, pass_value, pass_all):
if rc == pass_value:
return ("PASS", pass_all)
else:
return ("FAIL", False)
try:
iso_size = int(sys.argv[1])
except (IndexError, ValueError):
# Default to 500K
iso_size = 500
try:
# Python 3
catch_error = FileNotFoundError
except NameError:
# Python 2
catch_error = OSError
# 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)
print("Implanting -> %s" % rstr)
# do it again without forcing, should get error
(rstr, pass_all) = pass_fail(pyisomd5sum.implantisomd5sum("testiso.iso", 1, 0), -1, pass_all)
print("Implanting again w/o forcing -> %s" % rstr)
# do it again with forcing, should work
(rstr, pass_all) = pass_fail(pyisomd5sum.implantisomd5sum("testiso.iso", 1, 1), 0, pass_all)
print("Implanting again forcing -> %s" % rstr)
# check it
(rstr, pass_all) = pass_fail(pyisomd5sum.checkisomd5sum("testiso.iso"), 1, pass_all)
print("Checking -> %s" % rstr)
def callback(offset, total):
print(" %s - %s" % (offset, total))
print("Run with callback, prints offset and total")
(rstr, pass_all) = pass_fail(pyisomd5sum.checkisomd5sum("testiso.iso", callback), 1, pass_all)
print(rstr)
def callback_abort(offset, total):
print(" %s - %s" % (offset, total))
if offset > 100000:
return True
return False
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)
# clean up
os.unlink("testiso.iso")
if pass_all:
exit(0)
else:
exit(1)