trunk/src/regtests/chdman/chdtest.py
| r244806 | r244807 | |
| 7 | 7 | def runProcess(cmd): |
| 8 | 8 | process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 9 | 9 | (stdout, stderr) = process.communicate() |
| 10 | if not isinstance(stdout, str): # python 3 |
| 11 | stdout = stdout.decode('latin-1') |
| 12 | if not isinstance(stderr, str): # python 3 |
| 13 | stderr = stderr.decode('latin-1') |
| 10 | 14 | return process.returncode, stdout, stderr |
| 11 | 15 | |
| 12 | 16 | def compareInfo(info1, info2): |
| r244806 | r244807 | |
| 23 | 27 | continue |
| 24 | 28 | if not lines1[i] == lines2[i]: |
| 25 | 29 | mismatch = True |
| 26 | | print lines1[i] + " - " + lines2[i] |
| 30 | print(lines1[i] + " - " + lines2[i]) |
| 27 | 31 | |
| 28 | 32 | return mismatch == False |
| 29 | 33 | |
| r244806 | r244807 | |
| 54 | 58 | |
| 55 | 59 | exitcode, stdout, stderr = runProcess([chdmanBin, "extractcd", "-f", "-i", outFile, "-o", extractFile]) |
| 56 | 60 | if not exitcode == 0: |
| 57 | | print d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")" |
| 61 | print(d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")") |
| 58 | 62 | failure = True |
| 59 | 63 | |
| 60 | 64 | sha1_extract = sha1sum(extractFile) |
| r244806 | r244807 | |
| 69 | 73 | |
| 70 | 74 | exitcode, stdout, stderr = runProcess([chdmanBin, "extractcd", "-f", "-i", tempFile, "-o", extractFile]) |
| 71 | 75 | if not exitcode == 0: |
| 72 | | print d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")" |
| 76 | print(d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")") |
| 73 | 77 | failure = True |
| 74 | 78 | |
| 75 | 79 | sha1_extract_2 = sha1sum(extractFile) |
| 76 | 80 | sha1_extract_bin_2 = sha1sum(extractFileBin) |
| 77 | 81 | |
| 78 | 82 | if not sha1_extract == sha1_extract_2: |
| 79 | | print "expected: " + sha1_extract + " found: " + sha1_extract_2 |
| 80 | | print d + " - SHA1 mismatch (extractcd - " + type + " - toc)" |
| 83 | print("expected: " + sha1_extract + " found: " + sha1_extract_2) |
| 84 | print(d + " - SHA1 mismatch (extractcd - " + type + " - toc)") |
| 81 | 85 | failure = True |
| 82 | 86 | |
| 83 | 87 | if not sha1_extract_bin == sha1_extract_bin_2: |
| 84 | | print "expected: " + sha1_extract_bin + " found: " + sha1_extract_bin_2 |
| 85 | | print d + " - SHA1 mismatch (extractcd - " + type + " - bin)" |
| 88 | print("expected: " + sha1_extract_bin + " found: " + sha1_extract_bin_2) |
| 89 | print(d + " - SHA1 mismatch (extractcd - " + type + " - bin)") |
| 86 | 90 | failure = True |
| 87 | 91 | |
| 88 | 92 | def extractAndCompare(command, ext): |
| r244806 | r244807 | |
| 95 | 99 | |
| 96 | 100 | exitcode, stdout, stderr = runProcess([chdmanBin, command, "-f", "-i", outFile, "-o", extractFile]) |
| 97 | 101 | if not exitcode == 0: |
| 98 | | print d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")" |
| 102 | print(d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")") |
| 99 | 103 | failure = True |
| 100 | 104 | |
| 101 | 105 | sha1_extract = sha1sum(extractFile) |
| r244806 | r244807 | |
| 108 | 112 | |
| 109 | 113 | exitcode, stdout, stderr = runProcess([chdmanBin, command, "-f", "-i", tempFile, "-o", extractFile]) |
| 110 | 114 | if not exitcode == 0: |
| 111 | | print d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")" |
| 115 | print(d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")") |
| 112 | 116 | failure = True |
| 113 | 117 | |
| 114 | 118 | sha1_extract_2 = sha1sum(extractFile) |
| 115 | 119 | |
| 116 | 120 | if not sha1_extract == sha1_extract_2: |
| 117 | | print "expected: " + sha1_extract + " found: " + sha1_extract_2 |
| 118 | | print d + " - SHA1 mismatch (" + command + " - " + ext + ")" |
| 121 | print("expected: " + sha1_extract + " found: " + sha1_extract_2) |
| 122 | print(d + " - SHA1 mismatch (" + command + " - " + ext + ")") |
| 119 | 123 | failure = True |
| 120 | 124 | |
| 121 | 125 | currentDirectory = os.path.dirname(os.path.realpath(__file__)) |
| r244806 | r244807 | |
| 176 | 180 | elif command == "copy": |
| 177 | 181 | inFile += ".chd" |
| 178 | 182 | else: |
| 179 | | print "unsupported mode '%s'" % command |
| 183 | print("unsupported mode '%s'" % command) |
| 180 | 184 | continue |
| 181 | 185 | if os.path.exists(inFile): |
| 182 | 186 | cmd = [chdmanBin, command, "-f", "-i", inFile, "-o", tempFile] + params |
| r244806 | r244807 | |
| 185 | 189 | |
| 186 | 190 | exitcode, stdout, stderr = runProcess(cmd) |
| 187 | 191 | if not exitcode == 0: |
| 188 | | print d + " - command failed with " + str(exitcode) + " (" + stderr + ")" |
| 192 | print(d + " - command failed with " + str(exitcode) + " (" + stderr + ")") |
| 189 | 193 | failure = True |
| 190 | 194 | |
| 191 | 195 | # verify |
| 192 | 196 | exitcode, stdout, stderr = runProcess([chdmanBin, "verify", "-i", tempFile]) |
| 193 | 197 | if not exitcode == 0: |
| 194 | | print d + " - verify failed with " + str(exitcode) + " (" + stderr + ")" |
| 198 | print(d + " - verify failed with " + str(exitcode) + " (" + stderr + ")") |
| 195 | 199 | failure = True |
| 196 | 200 | |
| 197 | 201 | # compare info |
| 198 | 202 | # TODO: store expected output of reference file as well and compare |
| 199 | 203 | exitcode, info1, stderr = runProcess([chdmanBin, "info", "-v", "-i", tempFile]) |
| 200 | 204 | if not exitcode == 0: |
| 201 | | print d + " - info (temp) failed with " + str(exitcode) + " (" + stderr + ")" |
| 205 | print(d + " - info (temp) failed with " + str(exitcode) + " (" + stderr + ")") |
| 202 | 206 | failure = True |
| 203 | 207 | exitcode, info2, stderr = runProcess([chdmanBin, "info", "-v", "-i", outFile]) |
| 204 | 208 | if not exitcode == 0: |
| 205 | | print d + " - info (output) failed with " + str(exitcode) + " (" + stderr + ")" |
| 209 | print(d + " - info (output) failed with " + str(exitcode) + " (" + stderr + ")") |
| 206 | 210 | failure = True |
| 207 | 211 | if not compareInfo(info1, info2): |
| 208 | | print d + " - info output differs" |
| 212 | print(d + " - info output differs") |
| 209 | 213 | failure = True |
| 210 | 214 | |
| 211 | 215 | # extract and compare |
| r244806 | r244807 | |
| 222 | 226 | sha1_out = sha1sum(outFile) |
| 223 | 227 | sha1_temp = sha1sum(tempFile) |
| 224 | 228 | if not sha1_out == sha1_temp: |
| 225 | | print "expected: " + sha1_out + " found: " + sha1_temp |
| 226 | | print d + " - SHA1 mismatch (output file)" |
| 229 | print("expected: " + sha1_out + " found: " + sha1_temp) |
| 230 | print(d + " - SHA1 mismatch (output file)") |
| 227 | 231 | failure = True |
| 228 | 232 | |
| 229 | 233 | if not failure: |
| 230 | | print "All tests finished successfully" |
| | No newline at end of file |
| 234 | print("All tests finished successfully") |