trunk/src/regtests/chdman/chdtest.py
| r20079 | r20080 | |
| 1 | import os |
| 2 | import subprocess |
| 3 | import sys |
| 4 | |
| 5 | def runProcess(cmd): |
| 6 | process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 7 | (stdout, stderr) = process.communicate() |
| 8 | return process.returncode, stdout, stderr |
| 9 | |
| 10 | def compareInfo(info1, info2): |
| 11 | lines1 = info1.splitlines(); |
| 12 | lines2 = info2.splitlines(); |
| 13 | if not len(lines1) == len(lines2): |
| 14 | return False |
| 15 | |
| 16 | mismatch = False |
| 17 | for i in range(len(lines1)): |
| 18 | if lines1[i].startswith("chdman - ") and lines2[i].startswith("chdman - "): |
| 19 | continue |
| 20 | if lines1[i].startswith("Input file:") and lines2[i].startswith("Input file:"): |
| 21 | continue |
| 22 | if not lines1[i] == lines2[i]: |
| 23 | mismatch = True |
| 24 | print lines1[i] + " - " + lines2[i] |
| 25 | |
| 26 | return mismatch == False |
| 27 | |
| 28 | currentDirectory = os.path.dirname(os.path.realpath(__file__)) |
| 29 | inputPath = os.path.join(currentDirectory, 'input') |
| 30 | outputPath = os.path.join(currentDirectory, "output") |
| 31 | tempPath = os.path.join(currentDirectory, "temp") |
| 32 | if os.name == 'nt': |
| 33 | chdmanBin = os.path.normpath(os.path.join(currentDirectory, "..", "..", "..", "chdman.exe")) |
| 34 | else: |
| 35 | chdmanBin = os.path.normpath(os.path.join(currentDirectory, "..", "..", "..", "chdman")) |
| 36 | |
| 37 | if not os.path.exists(chdmanBin): |
| 38 | print chdmanBin + " does not exist" |
| 39 | sys.exit(1) |
| 40 | |
| 41 | if not os.path.exists(inputPath): |
| 42 | print inputPath + " does not exist" |
| 43 | sys.exit(1) |
| 44 | |
| 45 | if not os.path.exists(inputPath): |
| 46 | print inputPath + " does not exist" |
| 47 | sys.exit(1) |
| 48 | |
| 49 | failure = False |
| 50 | |
| 51 | for root, dirs, files in os.walk(inputPath): |
| 52 | for d in dirs: |
| 53 | inFile = os.path.join(root, d, "in") |
| 54 | # TODO: make this better |
| 55 | outFile = os.path.join(root, d, "out.chd").replace("input", "output") |
| 56 | tempFilePath = os.path.join(tempPath, d) |
| 57 | tempFile = os.path.join(tempFilePath, "out.chd") |
| 58 | cmd = "" |
| 59 | if not os.path.exists(tempFilePath): |
| 60 | os.makedirs(tempFilePath) |
| 61 | if d.startswith("createcd"): |
| 62 | ext = d.split("_", 2)[1] |
| 63 | inFile += "." + ext |
| 64 | cmd = chdmanBin + " createcd -f -i " + inFile + " -o " + tempFile |
| 65 | else: |
| 66 | print "unsupported mode" |
| 67 | continue |
| 68 | exitcode, stdout, stderr = runProcess(cmd) |
| 69 | if not exitcode == 0: |
| 70 | print d + " - command failed with " + str(exitcode) + " (" + stderr + ")" |
| 71 | failure = True |
| 72 | exitcode, stdout, stderr = runProcess(chdmanBin + " verify -i " + tempFile) |
| 73 | if not exitcode == 0: |
| 74 | print d + " - verify failed with " + str(exitcode) + " (" + stderr + ")" |
| 75 | failure = True |
| 76 | # TODO: store exected output of reference file as well and compare |
| 77 | exitcode, info1, stderr = runProcess(chdmanBin + " info -v -i " + tempFile) |
| 78 | if not exitcode == 0: |
| 79 | print d + " - info (temp) failed with " + str(exitcode) + " (" + stderr + ")" |
| 80 | failure = True |
| 81 | exitcode, info2, stderr = runProcess(chdmanBin + " info -v -i " + outFile) |
| 82 | if not exitcode == 0: |
| 83 | print d + " - info (output) failed with " + str(exitcode) + " (" + stderr + ")" |
| 84 | failure = True |
| 85 | if not compareInfo(info1, info2): |
| 86 | print d + " - info output differs" |
| 87 | failure = True |
| 88 | # TODO: extract and compare |
| 89 | |
| 90 | if not failure: |
| 91 | print "All tests finished successfully" |
| | No newline at end of file |