summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclutton <clutton@zoho.com>2016-03-31 19:16:35 +0300
committerclutton <clutton@zoho.com>2016-03-31 19:16:35 +0300
commit50e5b666d85c92a963ed6c1d4150683e87b8b9a5 (patch)
tree436a9a97e93469f46a98f15897d190493b4f3f06
parentb2fa4e21b4029e13e2c33f7b03ca43346f2cecb8 (diff)
downloaddistcc-git-50e5b666d85c92a963ed6c1d4150683e87b8b9a5.tar.gz
distcc/test python(3) ready #174
-rwxr-xr-xtest/comfychair.py60
-rwxr-xr-xtest/onetest.py2
-rwxr-xr-xtest/testdistcc.py72
3 files changed, 66 insertions, 68 deletions
diff --git a/test/comfychair.py b/test/comfychair.py
index 2e5a111..b5dda91 100755
--- a/test/comfychair.py
+++ b/test/comfychair.py
@@ -105,13 +105,14 @@ class TestCase:
"""
while self._cleanups:
try:
- apply(self._cleanups.pop())
+ clean_task = self._cleanups.pop()
+ clean_task()
except KeyboardInterrupt:
- print "interrupted during cleanups"
+ print("interrupted during cleanups")
_report_error(self, debugger)
return 2
except:
- print "error during cleanups"
+ print("error during cleanups")
_report_error(self, debugger)
return 1
return 0
@@ -130,7 +131,7 @@ class TestCase:
If the predicate value is not true, the test is skipped with a message explaining
why."""
if not predicate:
- raise NotRunError, message
+ raise NotRunError(message)
def require_root(self):
"""Skip this test unless run by root."""
@@ -146,11 +147,11 @@ why."""
def assert_equal(self, a, b):
if not a == b:
- raise AssertionError("assertEquals failed: %s" % `(a, b)`)
+ raise AssertionError("assertEquals failed: %s %s" % (repr(a), repr(b)))
def assert_notequal(self, a, b):
if a == b:
- raise AssertionError("assertNotEqual failed: %s" % `(a, b)`)
+ raise AssertionError("assertNotEqual failed: %s %s" % (repr(a), repr(b)))
def assert_re_match(self, pattern, s):
"""Assert that a string matches a particular pattern
@@ -165,7 +166,7 @@ why."""
if not re.match(pattern, s):
raise AssertionError("string does not match regexp\n"
" string: %s\n"
- " re: %s" % (`s`, `pattern`))
+ " re: %s" % (repr(s), repr(pattern)))
def assert_re_search(self, pattern, s):
"""Assert that a string *contains* a particular pattern
@@ -180,7 +181,7 @@ why."""
if not re.search(pattern, s):
raise AssertionError("string does not contain regexp\n"
" string: %s\n"
- " re: %s" % (`s`, `pattern`))
+ " re: %s" % (repr(s), repr(pattern)))
def assert_no_file(self, filename):
@@ -191,7 +192,7 @@ why."""
# Methods for running programs
def runcmd_background(self, cmd):
- self.test_log = self.test_log + "Run in background:\n" + `cmd` + "\n"
+ self.test_log = self.test_log + "Run in background:\n" + repr(cmd) + "\n"
pid = os.fork()
if pid == 0:
# child
@@ -223,23 +224,22 @@ stderr:
Based in part on popen2.py
Returns (waitstatus, stdout, stderr)."""
- import types
pid = os.fork()
if pid == 0:
# child
- try:
+ try:
pid = os.getpid()
openmode = os.O_WRONLY|os.O_CREAT|os.O_TRUNC
- outfd = os.open('%d.out' % pid, openmode, 0666)
+ outfd = os.open('%d.out' % pid, openmode)
os.dup2(outfd, 1)
os.close(outfd)
- errfd = os.open('%d.err' % pid, openmode, 0666)
+ errfd = os.open('%d.err' % pid, openmode)
os.dup2(errfd, 2)
os.close(errfd)
- if isinstance(cmd, types.StringType):
+ if isinstance(cmd, str):
cmd = ['/bin/sh', '-c', cmd]
os.execvp(cmd[0], cmd)
@@ -257,7 +257,7 @@ stderr:
"""Invoke a command; return (exitcode, stdout, stderr)"""
waitstatus, stdout, stderr = self.run_captured(cmd)
assert not os.WIFSIGNALED(waitstatus), \
- ("%s terminated with signal %d" % (`cmd`, os.WTERMSIG(waitstatus)))
+ ("%s terminated with signal %d" % (repr(cmd), os.WTERMSIG(waitstatus)))
rc = os.WEXITSTATUS(waitstatus)
self.test_log = self.test_log + ("""Run command: %s
Wait status: %#x (exit code %d, signal %d)
@@ -270,13 +270,13 @@ stderr:
# Either we could not execute the command or the command
# returned exit code 127. According to system(3) we can't
# tell the difference.
- raise NotRunError, "could not execute %s" % `cmd`
+ raise NotRunError("could not execute %s" % repr(cmd))
return rc, stdout, stderr
def explain_failure(self, exc_info = None):
- print "test_log:"
- print self.test_log
+ print("test_log:")
+ print(self.test_log)
def log(self, msg):
@@ -300,12 +300,12 @@ def _report_error(case, debugger):
debugger if true, a debugger function to be applied to the traceback
"""
ex = sys.exc_info()
- print "-----------------------------------------------------------------"
+ print("-----------------------------------------------------------------")
if ex:
import traceback
traceback.print_exc(file=sys.stdout)
case.explain_failure()
- print "-----------------------------------------------------------------"
+ print("-----------------------------------------------------------------")
if debugger:
tb = ex[2]
@@ -330,12 +330,12 @@ def runtest(testcase_class, ret, verbose=0, debugger=None, subtest=0):
test progress is not printed.
"""
if not subtest:
- print "%-30s" % _test_name(testcase_class),
+ print("%-30s" % _test_name(testcase_class), end=' ')
def failure_print(message):
- print message
+ print(message)
else:
def failure_print(message):
- print '[%s %s]' % (_test_name(testcase_class), message)
+ print('[%s %s]' % (_test_name(testcase_class), message))
# flush now so that long running tests are easier to follow
sys.stdout.flush()
@@ -348,13 +348,13 @@ def runtest(testcase_class, ret, verbose=0, debugger=None, subtest=0):
obj.setup()
obj.runtest()
if not subtest:
- print "OK"
+ print("OK")
except KeyboardInterrupt:
failure_print("INTERRUPT")
if obj:
_report_error(obj, debugger)
raise
- except NotRunError, msg:
+ except NotRunError as msg:
failure_print("NOTRUN, %s" % msg.value)
except:
failure_print("FAIL")
@@ -399,12 +399,12 @@ def _test_name(test_class):
try:
return test_class.__name__
except:
- return `test_class`
+ return repr(test_class)
def print_help():
"""Help for people running tests"""
- print """%s: software test suite based on ComfyChair
+ print("""%s: software test suite based on ComfyChair
usage:
To run all tests, just run this program. To run particular tests,
@@ -415,13 +415,13 @@ options:
--list list available tests
--verbose, -v show more information while running tests
--post-mortem, -p enter Python debugger on error
-""" % sys.argv[0]
+""" % sys.argv[0])
def print_list(test_list):
"""Show list of available tests"""
for test_class in test_list:
- print " %s" % _test_name(test_class)
+ print(" %s" % _test_name(test_class))
def main(tests, extra_tests=[]):
@@ -478,4 +478,4 @@ Calls sys.exit() on completion.
if __name__ == '__main__':
- print __doc__
+ print(__doc__)
diff --git a/test/onetest.py b/test/onetest.py
index cf33ba3..4ee0c2f 100755
--- a/test/onetest.py
+++ b/test/onetest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.4
+#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
diff --git a/test/testdistcc.py b/test/testdistcc.py
index 69bbc6f..47c89fd 100755
--- a/test/testdistcc.py
+++ b/test/testdistcc.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.2
+#! /usr/bin/env python
# Copyright (C) 2002, 2003, 2004 by Martin Pool <mbp@samba.org>
# Copyright 2007 Google Inc.
@@ -183,7 +183,7 @@ def _ShellSafe(s):
# Some tests only make sense for certain object formats
def _FirstBytes(filename, count):
'''Returns the first count bytes from the given file.'''
- f = open(filename)
+ f = open(filename, 'rb')
try:
return f.read(count)
finally:
@@ -195,7 +195,7 @@ def _IsElf(filename):
taken from /usr/share/file/magic on an ubuntu machine.
'''
contents = _FirstBytes(filename, 5)
- return contents.startswith('\177ELF')
+ return contents.startswith(b'\177ELF')
def _IsMachO(filename):
'''Given a filename, determine if it's an Mach-O object file or
@@ -203,14 +203,14 @@ def _IsMachO(filename):
is taken from /usr/share/file/magic on an ubuntu machine.
'''
contents = _FirstBytes(filename, 10)
- return (contents.startswith('\xCA\xFE\xBA\xBE') or
- contents.startswith('\xFE\xED\xFA\xCE') or
- contents.startswith('\xCE\xFA\xED\xFE') or
+ return (contents.startswith(b'\xCA\xFE\xBA\xBE') or
+ contents.startswith(b'\xFE\xED\xFA\xCE') or
+ contents.startswith(b'\xCE\xFA\xED\xFE') or
# The magic file says '4-bytes (BE) & 0xfeffffff ==
# 0xfeedface' and '4-bytes (LE) & 0xfffffffe ==
# 0xfeedface' are also mach-o.
- contents.startswith('\xFF\xED\xFA\xCE') or
- contents.startswith('\xCE\xFA\xED\xFF'))
+ contents.startswith(b'\xFF\xED\xFA\xCE') or
+ contents.startswith(b'\xCE\xFA\xED\xFF'))
def _IsPE(filename):
'''Given a filename, determine if it's a Microsoft PE object file or
@@ -218,7 +218,7 @@ def _IsPE(filename):
/usr/share/file/magic on an ubuntu machine.
'''
contents = _FirstBytes(filename, 5)
- return contents.startswith('MZ')
+ return contents.startswith(b'MZ')
def _Touch(filename):
'''Update the access and modification time of the given file,
@@ -239,7 +239,7 @@ class SimpleDistCC_Case(comfychair.TestCase):
def stripEnvironment(self):
"""Remove all DISTCC variables from the environment, so that
the test is not affected by the development environment."""
- for key in os.environ.keys():
+ for key in list(os.environ.keys()):
if key[:7] == 'DISTCC_':
# NOTE: This only works properly on Python 2.2: on
# earlier versions, it does not call unsetenv() and so
@@ -313,7 +313,7 @@ as soon as that happens we can go ahead and start the client."""
"""Return command to start the daemon"""
return (self.distccd() +
"--verbose --lifetime=%d --daemon --log-file %s "
- "--pid-file %s --port %d --allow 127.0.0.1"
+ "--pid-file %s --port %d --allow 127.0.0.1 --listen 127.0.0.1"
% (self.daemon_lifetime(),
_ShellSafe(self.daemon_logfile),
_ShellSafe(self.daemon_pidfile),
@@ -369,7 +369,7 @@ class VersionOption_Case(SimpleDistCC_Case):
out, err = self.runcmd("%s --version" % prog)
assert out[-1] == '\n'
out = out[:-1]
- line1,line2,trash = string.split(out, '\n', 2)
+ line1,line2,trash = out.split('\n', 2)
self.assert_re_match(r'^%s [\w.-]+ [.\w-]+$'
% prog, line1)
self.assert_re_match(r'^[ \t]+\(protocol.*\) \(default port 3632\)$'
@@ -404,7 +404,7 @@ class GccOptionsPassed_Case(SimpleDistCC_Case):
+ self.distcc()
+ _gcc + " --help")
if re.search('distcc', out):
- raise ("gcc help contains \"distcc\": \"%s\"" % out)
+ raise AssertionError("gcc help contains \"distcc\": \"%s\"" % out)
self.assert_re_match(r"^Usage: [^ ]*gcc", out)
@@ -461,7 +461,7 @@ class IsSource_Case(SimpleDistCC_Case):
expected = ("%s %s\n" % (issrc, iscpp))
if o != expected:
raise AssertionError("issource %s gave %s, expected %s" %
- (f, `o`, `expected`))
+ (f, repr(o), repr(expected)))
@@ -484,7 +484,6 @@ class ScanArgs_Case(SimpleDistCC_Case):
("gcc -S -c hello.c", "distribute", "hello.c", "hello.s"),
("gcc -M hello.c", "local"),
("gcc -ME hello.c", "local"),
-
("gcc -MD -c hello.c", "distribute", "hello.c", "hello.o"),
("gcc -MMD -c hello.c", "distribute", "hello.c", "hello.o"),
@@ -519,20 +518,20 @@ class ScanArgs_Case(SimpleDistCC_Case):
("gcc -dr -c foo.c", "local"),
]
for tup in cases:
- apply(self.checkScanArgs, tup)
+ self.checkScanArgs(*tup)
def checkScanArgs(self, ccmd, mode, input=None, output=None):
o, err = self.runcmd("h_scanargs %s" % ccmd)
o = o[:-1] # trim \n
- os = string.split(o)
+ os = o.split()
if mode != os[0]:
self.fail("h_scanargs %s gave %s mode, expected %s" %
(ccmd, os[0], mode))
if mode == 'distribute':
- if os[1] <> input:
+ if os[1] != input:
self.fail("h_scanargs %s gave %s input, expected %s" %
(ccmd, os[1], input))
- if os[2] <> output:
+ if os[2] != output:
self.fail("h_scanargs %s gave %s output, expected %s" %
(ccmd, os[2], output))
@@ -733,7 +732,7 @@ foo_bar""",
# Line is non-blank
checked_deps[self.getDep(line)] = 1
deps_list = deps[:]
- checked_deps_list = checked_deps.keys()
+ checked_deps_list = list(checked_deps.keys())
deps_list.sort()
checked_deps_list.sort()
self.assert_equal(checked_deps_list, deps_list)
@@ -759,7 +758,7 @@ class ImplicitCompilerScan_Case(ScanArgs_Case):
for tup in cases:
# NB use "apply" rather than new syntax for compatibility with
# venerable Pythons.
- apply(self.checkScanArgs, tup)
+ self.checkScanArgs(*tup)
class ExtractExtension_Case(SimpleDistCC_Case):
@@ -836,7 +835,7 @@ class ParseHostSpec_Case(SimpleDistCC_Case):
"""
out, err = self.runcmd(("DISTCC_HOSTS=\"%s\" " % spec) + self.valgrind()
+ "h_hosts")
- assert out == expected, "expected %s\ngot %s" % (`expected`, `out`)
+ assert out == expected, "expected %s\ngot %s" % (repr(expected), repr(out))
class Compilation_Case(WithDaemon_Case):
@@ -873,17 +872,17 @@ class Compilation_Case(WithDaemon_Case):
cmd = self.compileCmd()
out, err = self.runcmd(cmd)
if out != '':
- self.fail("compiler command %s produced output:\n%s" % (`cmd`, out))
+ self.fail("compiler command %s produced output:\n%s" % (repr(cmd), out))
if err != '':
- self.fail("compiler command %s produced error:\n%s" % (`cmd`, err))
+ self.fail("compiler command %s produced error:\n%s" % (repr(cmd), err))
def link(self):
cmd = self.linkCmd()
out, err = self.runcmd(cmd)
if out != '':
- self.fail("command %s produced output:\n%s" % (`cmd`, `out`))
+ self.fail("command %s produced output:\n%s" % (repr(cmd), repr(out)))
if err != '':
- self.fail("command %s produced error:\n%s" % (`cmd`, `err`))
+ self.fail("command %s produced error:\n%s" % (repr(cmd), repr(err)))
def compileCmd(self):
"""Return command to compile source"""
@@ -905,9 +904,8 @@ class Compilation_Case(WithDaemon_Case):
return ""
def checkCompileMsgs(self, msgs):
- if msgs <> '':
- self.fail("expected no compiler messages, got \"%s\""
- % msgs)
+ if len(msgs) > 0:
+ self.fail("expected no compiler messages, got \"%s\"" % msgs)
def checkBuiltProgram(self):
'''Check compile/link results. By default, just try to execute.'''
@@ -1236,9 +1234,9 @@ class Gdb_Case(CompileHello_Case):
" -o link/testtmp obj/testtmp.o")
out, err = self.runcmd(cmd)
if out != '':
- self.fail("command %s produced output:\n%s" % (`cmd`, `out`))
+ self.fail("command %s produced output:\n%s" % (repr(cmd), repr(out)))
if err != '':
- self.fail("command %s produced error:\n%s" % (`cmd`, `err`))
+ self.fail("command %s produced error:\n%s" % (repr(cmd), repr(err)))
def runtest(self):
# Don't try to run the test if gdb is not installed
@@ -1633,9 +1631,9 @@ class ScanIncludes_Case(CompileHello_Case):
pump_mode = _server_options.find('cpp') != -1
if pump_mode:
if err != '':
- self.fail("distcc command %s produced stderr:\n%s" % (`cmd`, err))
+ self.fail("distcc command %s produced stderr:\n%s" % (repr(cmd), err))
if rc != 0:
- self.fail("distcc command %s failed:\n%s" % (`cmd`, rc))
+ self.fail("distcc command %s failed:\n%s" % (repr(cmd), rc))
self.assert_re_search(
r"FILE /.*/ScanIncludes_Case/testtmp.c", out);
self.assert_re_search(
@@ -1679,7 +1677,7 @@ class HundredFold_Case(CompileHello_Case):
return 120
def runtest(self):
- for unused_i in xrange(100):
+ for unused_i in range(100):
self.runcmd(self.distcc()
+ _gcc + " -o testtmp.o -c testtmp.c")
@@ -1692,7 +1690,7 @@ class Concurrent_Case(CompileHello_Case):
def runtest(self):
# may take about a minute or so
pids = {}
- for unused_i in xrange(50):
+ for unused_i in range(50):
kid = self.runcmd_background(self.distcc() +
_gcc + " -o testtmp.o -c testtmp.c")
pids[kid] = kid
@@ -1717,7 +1715,7 @@ class BigAssFile_Case(Compilation_Case):
# machines.
f.write("int main() {}\n")
- for i in xrange(200000):
+ for i in range(200000):
f.write("int i%06d = %d;\n" % (i, i))
f.close()
@@ -1951,7 +1949,7 @@ class ModeBits_Case(CompileHello_Case):
"""Check distcc obeys umask"""
def runtest(self):
self.runcmd("umask 0; distcc " + _gcc + " -c testtmp.c")
- self.assert_equal(S_IMODE(os.stat("testtmp.o")[ST_MODE]), 0666)
+ self.assert_equal(S_IMODE(os.stat("testtmp.o")[ST_MODE]), 0o666)
class CheckRoot_Case(SimpleDistCC_Case):