Make test.py work with Python 3

This commit is contained in:
KentuckyCompass 2012-12-15 02:27:40 -08:00
parent ffdc96a06a
commit e61a7da35b

69
test.py
View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python
# Automated script to run the pspautotests test suite in PPSSPP.
import sys
@ -25,6 +25,7 @@ class Command(object):
def target():
self.process = subprocess.Popen(self.cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
self.output, _ = self.process.communicate()
self.output = self.output.decode("utf-8")
thread = threading.Thread(target=target)
thread.start()
@ -138,12 +139,12 @@ tests_ignored = [
def init():
global PPSSPP_EXE
if not os.path.exists("pspautotests"):
print "Please run git submodule init; git submodule update;"
print("Please run git submodule init; git submodule update;")
sys.exit(1)
if not os.path.exists(TEST_ROOT + "cpu/cpu_alu/cpu_alu.prx"):
print "Please install the pspsdk and run make in common/ and in all the tests"
print "(checked for existence of cpu/cpu_alu/cpu_alu.prx)"
print("Please install the pspsdk and run make in common/ and in all the tests")
print("(checked for existence of cpu/cpu_alu/cpu_alu.prx)")
sys.exit(1)
for p in PPSSPP_EXECUTABLES:
@ -152,28 +153,28 @@ def init():
break
if not PPSSPP_EXE:
print "PPSSPP executable missing, please build one."
print("PPSSPP executable missing, please build one.")
sys.exit(1)
def tcprint(arg):
global teamcity_mode
if teamcity_mode:
print arg
print(arg)
def run_tests(test_list, args):
global PPSSPP_EXE, TIMEOUT
tests_passed = []
tests_failed = []
for test in test_list:
# Try prx first
expected_filename = TEST_ROOT + test + ".expected"
elf_filename = TEST_ROOT + test + ".prx"
print elf_filename
print(elf_filename)
if not os.path.exists(elf_filename):
print "WARNING: no prx, trying elf"
print("WARNING: no prx, trying elf")
elf_filename = TEST_ROOT + test + ".elf"
if not os.path.exists(elf_filename):
@ -189,7 +190,7 @@ def run_tests(test_list, args):
continue
expected_output = open(expected_filename).read().strip()
tcprint("##teamcity[testStarted name='%s' captureStandardOutput='true']" % test)
cmdline = [PPSSPP_EXE, elf_filename]
@ -199,16 +200,16 @@ def run_tests(test_list, args):
c.run(TIMEOUT)
output = c.output.strip()
if c.timeout:
print output
print "Test exceded limit of %d seconds." % TIMEOUT
print(output)
print("Test exceded limit of %d seconds." % TIMEOUT)
tcprint("##teamcity[testFailed name='%s' message='Test timeout']" % test)
tcprint("##teamcity[testFinished name='%s']" % test)
continue
if output.startswith("TESTERROR"):
print "Failed to run test " + elf_filename + "!"
print("Failed to run test " + elf_filename + "!")
tests_failed.append(test)
tcprint("##teamcity[testFailed name='%s' message='Failed to run test']" % test)
tcprint("##teamcity[testFinished name='%s']" % test)
@ -217,48 +218,48 @@ def run_tests(test_list, args):
different = False
expected_lines = [x.strip() for x in expected_output.splitlines()]
output_lines = [x.strip() for x in output.splitlines()]
for i in range(0, min(len(output_lines), len(expected_lines))):
if output_lines[i] != expected_lines[i]:
print "E%i < %s" % (i + 1, expected_lines[i])
print "O%i > %s" % (i + 1, output_lines[i])
print("E%i < %s" % (i + 1, expected_lines[i]))
print("O%i > %s" % (i + 1, output_lines[i]))
different = True
if len(output_lines) != len(expected_lines):
for i in range(len(output_lines), len(expected_lines)):
print "E%i < %s" % (i + 1, expected_lines[i])
print("E%i < %s" % (i + 1, expected_lines[i]))
for i in range(len(expected_lines), len(output_lines)):
print "O%i > %s" % (i + 1, output_lines[i])
print "*** Different number of lines!"
print("O%i > %s" % (i + 1, output_lines[i]))
print("*** Different number of lines!")
different = True
if not different:
if '-v' in args:
print "++++++++++++++ The Equal Output +++++++++++++"
print "\n".join(output_lines)
print "+++++++++++++++++++++++++++++++++++++++++++++"
print " " + test + " - passed!"
print("++++++++++++++ The Equal Output +++++++++++++")
print("\n".join(output_lines))
print("+++++++++++++++++++++++++++++++++++++++++++++")
print(" " + test + " - passed!")
tests_passed.append(test)
tcprint("##teamcity[testFinished name='%s']" % test)
else:
if '-v' in args:
print "============== output from failed " + test + " :"
print output
print "============== expected output:"
print expected_output
print "==============================="
print("============== output from failed " + test + " :")
print(output)
print("============== expected output:")
print(expected_output)
print("===============================")
tests_failed.append(test)
tcprint("##teamcity[testFailed name='%s' message='Output different from expected file']" % test)
tcprint("##teamcity[testFinished name='%s']" % test)
print "%i tests passed, %i tests failed." % (
len(tests_passed), len(tests_failed))
print("%i tests passed, %i tests failed." % (
len(tests_passed), len(tests_failed)))
if len(tests_failed):
print "Failed tests:"
print("Failed tests:")
for t in tests_failed:
print " " + t
print "Ran " + PPSSPP_EXE
print(" " + t)
print("Ran " + PPSSPP_EXE)
def main():