diff options
| author | 2021-01-29 00:10:27 +0100 | |
|---|---|---|
| committer | 2021-01-29 00:11:07 +0100 | |
| commit | 75e81ecb1f540b0734bdcbf3a554e9ec3bb571ef (patch) | |
| tree | df7ab73adf51f7bcd60114e11162d6c42b69f9eb | |
| parent | 832acf5731d68ca411b5fb358ddb4e79ef0faffa (diff) | |
chdtest: make it to properly return a status code != 0 on failures
(experiment for #7716)
| -rw-r--r-- | regtests/chdman/chdtest.py | 206 | ||||
| -rw-r--r-- | regtests/regtests.mak | 17 |
2 files changed, 113 insertions, 110 deletions
diff --git a/regtests/chdman/chdtest.py b/regtests/chdman/chdtest.py index 4b13c176cf9..881f7dd6b75 100644 --- a/regtests/chdman/chdtest.py +++ b/regtests/chdman/chdtest.py @@ -125,113 +125,115 @@ def extractAndCompare(command, ext): print(d + " - SHA1 mismatch (" + command + " - " + ext + ")") failure = True -currentDirectory = os.path.dirname(os.path.realpath(__file__)) -inputPath = os.path.join(currentDirectory, 'input') -outputPath = os.path.join(currentDirectory, "output") -tempPath = os.path.join(currentDirectory, "temp") -if os.name == 'nt': - chdmanBin = os.path.normpath(os.path.join(currentDirectory, "..", "..", "chdman.exe")) -else: - chdmanBin = os.path.normpath(os.path.join(currentDirectory, "..", "..", "chdman")) +if __name__ == "__main__": + currentDirectory = os.path.dirname(os.path.realpath(__file__)) + inputPath = os.path.join(currentDirectory, 'input') + outputPath = os.path.join(currentDirectory, "output") + tempPath = os.path.join(currentDirectory, "temp") + if os.name == 'nt': + chdmanBin = os.path.normpath(os.path.join(currentDirectory, "..", "..", "chdman.exe")) + else: + chdmanBin = os.path.normpath(os.path.join(currentDirectory, "..", "..", "chdman")) -if not os.path.exists(chdmanBin): - sys.stderr.write(chdmanBin + " does not exist\n") - sys.exit(1) + if not os.path.exists(chdmanBin): + sys.stderr.write(chdmanBin + " does not exist\n") + sys.exit(1) -if not os.path.exists(inputPath): - sys.stderr.write(inputPath + " does not exist\n") - sys.exit(1) - -if not os.path.exists(outputPath): - sys.stderr.write(outputPath + " does not exist\n") - sys.exit(1) + if not os.path.exists(inputPath): + sys.stderr.write(inputPath + " does not exist\n") + sys.exit(1) + + if not os.path.exists(outputPath): + sys.stderr.write(outputPath + " does not exist\n") + sys.exit(1) -if os.path.exists(tempPath): - shutil.rmtree(tempPath) - -failure = False + if os.path.exists(tempPath): + shutil.rmtree(tempPath) + + failure = False -for root, dirs, files in os.walk(inputPath): - for d in dirs: - if d.startswith("."): - continue + for root, dirs, files in os.walk(inputPath): + for d in dirs: + if d.startswith("."): + continue - command = ext = d.split("_", 2)[0] - inFile = os.path.join(root, d, "in") - # TODO: make this better - outFile = os.path.join(root, d, "out.chd").replace("input", "output") - tempFilePath = os.path.join(tempPath, d) - tempFile = os.path.join(tempFilePath, "out.chd") - inParams = inFile + ".params" - params = [] - if os.path.exists(inParams): - f = open(inParams, 'r') - paramsstr = f.read() - f.close() - params = paramsstr.split(" ") - if not os.path.exists(tempFilePath): - os.makedirs(tempFilePath) - if command == "createcd": - ext = d.split("_", 2)[1] - inFile += "." + ext - elif command == "createhd": - ext = d.split("_", 2)[1] - inFile += "." + ext - elif command == "createld": - ext = d.split("_", 2)[1] - inFile += "." + ext - elif command == "copy": - inFile += ".chd" - else: - print("unsupported mode '%s'" % command) - continue - if os.path.exists(inFile): - cmd = [chdmanBin, command, "-f", "-i", inFile, "-o", tempFile] + params - else: - cmd = [chdmanBin, command, "-f", "-o", tempFile] + params + command = ext = d.split("_", 2)[0] + inFile = os.path.join(root, d, "in") + # TODO: make this better + outFile = os.path.join(root, d, "out.chd").replace("input", "output") + tempFilePath = os.path.join(tempPath, d) + tempFile = os.path.join(tempFilePath, "out.chd") + inParams = inFile + ".params" + params = [] + if os.path.exists(inParams): + f = open(inParams, 'r') + paramsstr = f.read() + f.close() + params = paramsstr.split(" ") + if not os.path.exists(tempFilePath): + os.makedirs(tempFilePath) + if command == "createcd": + ext = d.split("_", 2)[1] + inFile += "." + ext + elif command == "createhd": + ext = d.split("_", 2)[1] + inFile += "." + ext + elif command == "createld": + ext = d.split("_", 2)[1] + inFile += "." + ext + elif command == "copy": + inFile += ".chd" + else: + print("unsupported mode '%s'" % command) + continue + if os.path.exists(inFile): + cmd = [chdmanBin, command, "-f", "-i", inFile, "-o", tempFile] + params + else: + cmd = [chdmanBin, command, "-f", "-o", tempFile] + params - exitcode, stdout, stderr = runProcess(cmd) - if not exitcode == 0: - print(d + " - command failed with " + str(exitcode) + " (" + stderr + ")") - failure = True - - # verify - exitcode, stdout, stderr = runProcess([chdmanBin, "verify", "-i", tempFile]) - if not exitcode == 0: - print(d + " - verify failed with " + str(exitcode) + " (" + stderr + ")") - failure = True - - # compare info - # TODO: store expected output of reference file as well and compare - exitcode, info1, stderr = runProcess([chdmanBin, "info", "-v", "-i", tempFile]) - if not exitcode == 0: - print(d + " - info (temp) failed with " + str(exitcode) + " (" + stderr + ")") - failure = True - exitcode, info2, stderr = runProcess([chdmanBin, "info", "-v", "-i", outFile]) - if not exitcode == 0: - print(d + " - info (output) failed with " + str(exitcode) + " (" + stderr + ")") - failure = True - if not compareInfo(info1, info2): - print(d + " - info output differs") - failure = True - - # extract and compare - if command == "createcd": - extractcdAndCompare("toc") - extractcdAndCompare("cue") - elif command == "createhd": - extractAndCompare("extracthd", "raw") - elif command == "createld": - extractAndCompare("extractld", "avi") - # TODO: add extraction for "copy" as well + exitcode, stdout, stderr = runProcess(cmd) + if not exitcode == 0: + print(d + " - command failed with " + str(exitcode) + " (" + stderr + ")") + failure = True - # compare SHA1 of output files - sha1_out = sha1sum(outFile) - sha1_temp = sha1sum(tempFile) - if not sha1_out == sha1_temp: - print("expected: " + sha1_out + " found: " + sha1_temp) - print(d + " - SHA1 mismatch (output file)") - failure = True + # verify + exitcode, stdout, stderr = runProcess([chdmanBin, "verify", "-i", tempFile]) + if not exitcode == 0: + print(d + " - verify failed with " + str(exitcode) + " (" + stderr + ")") + failure = True + + # compare info + # TODO: store expected output of reference file as well and compare + exitcode, info1, stderr = runProcess([chdmanBin, "info", "-v", "-i", tempFile]) + if not exitcode == 0: + print(d + " - info (temp) failed with " + str(exitcode) + " (" + stderr + ")") + failure = True + exitcode, info2, stderr = runProcess([chdmanBin, "info", "-v", "-i", outFile]) + if not exitcode == 0: + print(d + " - info (output) failed with " + str(exitcode) + " (" + stderr + ")") + failure = True + if not compareInfo(info1, info2): + print(d + " - info output differs") + failure = True + + # extract and compare + if command == "createcd": + extractcdAndCompare("toc") + extractcdAndCompare("cue") + elif command == "createhd": + extractAndCompare("extracthd", "raw") + elif command == "createld": + extractAndCompare("extractld", "avi") + # TODO: add extraction for "copy" as well + + # compare SHA1 of output files + sha1_out = sha1sum(outFile) + sha1_temp = sha1sum(tempFile) + if not sha1_out == sha1_temp: + print("expected: " + sha1_out + " found: " + sha1_temp) + print(d + " - SHA1 mismatch (output file)") + failure = True -if not failure: - print("All tests finished successfully") + if not failure: + print("All tests finished successfully") + sys.exit(int(failure)) diff --git a/regtests/regtests.mak b/regtests/regtests.mak index 26c5fcc6fc0..bb3d8c9b83b 100644 --- a/regtests/regtests.mak +++ b/regtests/regtests.mak @@ -43,10 +43,18 @@ #------------------------------------------------- REGTESTS += \ - jedutiltest \ chdmantest \ + jedutiltest \ +#------------------------------------------------- +# chdman +#------------------------------------------------- + +chdmantest: + @echo Running chdman unittest + $(PYTHON) regtests/chdman/chdtest.py + #------------------------------------------------- # jedutil @@ -58,10 +66,3 @@ jedutiltest: -#------------------------------------------------- -# chdman -#------------------------------------------------- - -chdmantest: - @echo Running chdman unittest - $(PYTHON) regtests/chdman/chdtest.py |
