summaryrefslogtreecommitdiff
path: root/test/testdistcc.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/testdistcc.py')
-rwxr-xr-xtest/testdistcc.py288
1 files changed, 161 insertions, 127 deletions
diff --git a/test/testdistcc.py b/test/testdistcc.py
index 69bbc6f..ef0e351 100755
--- a/test/testdistcc.py
+++ b/test/testdistcc.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.2
+#! /usr/bin/env python3
# Copyright (C) 2002, 2003, 2004 by Martin Pool <mbp@samba.org>
# Copyright 2007 Google Inc.
@@ -169,7 +169,7 @@ EXIT_ACCESS_DENIED = 113
DISTCC_TEST_PORT = 42000
-_gcc = None # full path to gcc
+_cc = None # full path to gcc
_valgrind_command = "" # Command to invoke valgrind (or other
# similar debugging tool).
# e.g. "valgrind --quiet --num-callsers=20 "
@@ -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,22 +203,22 @@ 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
executable. The magic number used ('MZ') is taken from
/usr/share/file/magic on an ubuntu machine.
'''
- contents = _FirstBytes(filename, 5)
- return contents.startswith('MZ')
+ contents = _FirstBytes(filename, 5)
+ return contents.startswith(b'MZ')
def _Touch(filename):
'''Update the access and modification time of the given file,
@@ -235,11 +235,15 @@ class SimpleDistCC_Case(comfychair.TestCase):
'''Abstract base class for distcc tests'''
def setup(self):
self.stripEnvironment()
+ self.initCompiler()
+
+ def initCompiler(self):
+ self._cc = self._get_compiler()
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
@@ -265,6 +269,34 @@ class SimpleDistCC_Case(comfychair.TestCase):
def distcc_without_fallback(self):
return "DISTCC_FALLBACK=0 " + self.distcc()
+ def _get_compiler(self):
+ cc = self._find_compiler("cc")
+ if self.is_clang(cc):
+ return self._find_compiler("clang")
+ elif self.is_gcc(cc):
+ return self._find_compiler("gcc")
+ raise AssertionError("Unknown compiler")
+
+ def _find_compiler(self, compiler):
+ for path in os.environ['PATH'].split (':'):
+ abs_path = os.path.join (path, compiler)
+
+ if os.path.isfile (abs_path):
+ return abs_path
+ return None
+
+ def is_gcc(self, compiler):
+ out, err = self.runcmd(compiler + " --version")
+ if re.search('Free Software Foundation', out):
+ return True
+ return False
+
+ def is_clang(self, compiler):
+ out, err = self.runcmd(compiler + " --version")
+ if re.search('clang', out):
+ return True
+ return False
+
class WithDaemon_Case(SimpleDistCC_Case):
"""Start the daemon, and then run a command locally against it.
@@ -369,7 +401,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\)$'
@@ -390,22 +422,27 @@ class BogusOption_Case(SimpleDistCC_Case):
Now that we support implicit compilers, this is passed to gcc,
which returns a non-zero status."""
def runtest(self):
- error_rc, _, _ = self.runcmd_unchecked(_gcc + " --bogus-option")
+ error_rc, _, _ = self.runcmd_unchecked(self._cc + " --bogus-option")
assert error_rc != 0
- self.runcmd(self.distcc() + _gcc + " --bogus-option", error_rc)
- self.runcmd(self.distccd() + _gcc + " --bogus-option",
+ self.runcmd(self.distcc() + self._cc + " --bogus-option", error_rc)
+ self.runcmd(self.distccd() + self._cc + " --bogus-option",
EXIT_BAD_ARGUMENTS)
-class GccOptionsPassed_Case(SimpleDistCC_Case):
+class CompilerOptionsPassed_Case(SimpleDistCC_Case):
"""Test that options following the compiler name are passed to the compiler."""
def runtest(self):
out, err = self.runcmd("DISTCC_HOSTS=localhost "
+ self.distcc()
- + _gcc + " --help")
+ + self._cc + " --help")
if re.search('distcc', out):
- raise ("gcc help contains \"distcc\": \"%s\"" % out)
- self.assert_re_match(r"^Usage: [^ ]*gcc", out)
+ raise AssertionError("compiler help contains \"distcc\": \"%s\"" % out)
+ if self.is_gcc(self._cc):
+ self.assert_re_match(r"Usage: [^ ]*gcc", out)
+ elif self.is_clang(self._cc):
+ self.assert_re_match(r"OVERVIEW: [^ ]*clang", out)
+ else:
+ raise AssertionError("Unknown compiler found")
class StripArgs_Case(SimpleDistCC_Case):
@@ -461,7 +498,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,11 +521,10 @@ 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"),
- # Assemble to stdout (thanks Alexandre).
+ # Assemble to stdout (thanks Alexandre).
("gcc -S foo.c -o -", "local"),
("-S -o - foo.c", "local"),
("-c -S -o - foo.c", "local"),
@@ -519,20 +555,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))
@@ -554,7 +590,7 @@ class DotD_Case(SimpleDistCC_Case):
#
# - The expected target name (or None).
#
-
+
# The dotd_name is thus divined by examination of the compilation
# directory where we actually run gcc.
@@ -577,7 +613,7 @@ class DotD_Case(SimpleDistCC_Case):
# These C++ cases fail if your gcc installation doesn't support C++.
error_rc, _, _ = self.runcmd_unchecked("touch testtmp.cpp; " +
- _gcc + " -c testtmp.cpp -o /dev/null")
+ self._cc + " -c testtmp.cpp -o /dev/null")
if error_rc == 0:
cases.extend([("foo.cpp -o hello.o", "*.d", 0, None),
("foo.cpp -o hello", "*.d", 0, None)])
@@ -588,7 +624,7 @@ class DotD_Case(SimpleDistCC_Case):
map_out['needs_dotd'],
map_out['sets_dotd_target'],
map_out['dotd_target'])
-
+
for (args, dep_glob, how_many, target) in cases:
# Determine what gcc says.
@@ -601,7 +637,7 @@ int main(void) { return 0; }
def sourceFilename(self):
return args.split()[0]
def compileCmd(self):
- return _gcc + " -c " + args
+ return self._cc + " -c " + args
def runtest(self):
self.compile()
glob_result = glob.glob(dep_glob)
@@ -660,7 +696,7 @@ int main(void) { return 0; }
class Compile_c_Case(SimpleDistCC_Case):
"""Unit tests for source file 'compile.c.'
-
+
Currently, only the functions dcc_fresh_dependency_exists() and
dcc_discrepancy_filename() are tested.
"""
@@ -733,7 +769,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,8 +795,8 @@ 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):
def runtest(self):
@@ -787,7 +823,7 @@ class DaemonBadPort_Case(SimpleDistCC_Case):
class InvalidHostSpec_Case(SimpleDistCC_Case):
def runtest(self):
"""Test various invalid DISTCC_HOSTS
-
+
See also test_parse_host_spec, which tests valid specifications."""
for spec in ["", " ", "\t", " @ ", ":", "mbp@", "angry::", ":4200"]:
self.runcmd(("DISTCC_HOSTS=\"%s\" " % spec) + self.valgrind()
@@ -836,7 +872,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,22 +909,22 @@ 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"""
return self.distcc_without_fallback() + \
- _gcc + " -o testtmp.o " + self.compileOpts() + \
+ self._cc + " -o testtmp.o " + self.compileOpts() + \
" -c %s" % (self.sourceFilename())
def compileOpts(self):
@@ -898,16 +934,15 @@ class Compilation_Case(WithDaemon_Case):
def linkCmd(self):
"""Return command to link object files"""
return self.distcc() + \
- _gcc + " -o testtmp testtmp.o " + self.libraries()
+ self._cc + " -o testtmp testtmp.o " + self.libraries()
def libraries(self):
"""Returns any '-l' options needed to link the program."""
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.'''
@@ -966,8 +1001,8 @@ int main(void) {
class BackslashInMacro_Case(ComputedInclude_Case):
def source(self):
return """
+#include <stdio.h>
#if FALSE
- #include <stdio.h>
#define HEADER MAKE_HEADER(testhdr)
#define MAKE_HEADER(header_name) STRINGIZE(foobar\)
#define STRINGIZE(x) STRINGIZE2(x)
@@ -1016,7 +1051,7 @@ class LanguageSpecific_Case(Compilation_Case):
error_rc, _, _ = self.runcmd_unchecked(
"touch " + source + "; " +
"rm -f testtmp.o; " +
- _gcc + " -x " + lang + " " + self.compileOpts() +
+ self._cc + " -x " + lang + " " + self.compileOpts() +
" -c " + source + " " + self.libraries() + " && " +
"test -f testtmp.o" )
if error_rc != 0:
@@ -1148,7 +1183,7 @@ class SystemIncludeDirectories_Case(Compilation_Case):
def compileOpts(self):
if os.path.exists("/usr/include/sys/types.h"):
- return "-I/usr/include/sys"
+ return "-I/usr/include/"
else:
raise comfychair.NotRunError (
"This test requires /usr/include/sys/types.h")
@@ -1160,12 +1195,13 @@ class SystemIncludeDirectories_Case(Compilation_Case):
def source(self):
return """
-#include "types.h" /* Should resolve to /usr/incude/sys/types.h. */
+#include "sys/types.h" /* Should resolve to /usr/incude/sys/types.h. */
#include <stdio.h>
#include "testhdr.h"
int main(void) {
+ uint val = 1u;
puts(HELLO_WORLD);
- return 0;
+ return val == 1 ? 0 : 1;
}
"""
@@ -1214,7 +1250,7 @@ class Gdb_Case(CompileHello_Case):
def compiler(self):
"""Command for compiling and linking."""
- return _gcc + " -g ";
+ return self._cc + " -g ";
def compileCmd(self):
"""Return command to compile source"""
@@ -1236,9 +1272,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
@@ -1266,7 +1302,7 @@ class Gdb_Case(CompileHello_Case):
if os.path.exists('link/testtmp.exe'):
testtmp_exe = 'testtmp.exe'
else:
- testtmp_exe = 'testtmp'
+ testtmp_exe = 'testtmp'
# Run gdb and verify that it is able to correctly locate the
# testtmp.c source file. We write the gdb commands to a file
@@ -1355,17 +1391,17 @@ class Gdb_Case(CompileHello_Case):
class GdbOpt1_Case(Gdb_Case):
def compiler(self):
"""Command for compiling and linking."""
- return _gcc + " -g -O1 ";
+ return self._cc + " -g -O1 ";
class GdbOpt2_Case(Gdb_Case):
def compiler(self):
"""Command for compiling and linking."""
- return _gcc + " -g -O2 ";
+ return self._cc + " -g -O2 ";
class GdbOpt3_Case(Gdb_Case):
def compiler(self):
"""Command for compiling and linking."""
- return _gcc + " -g -O3 ";
+ return self._cc + " -g -O3 ";
class CompressedCompile_Case(CompileHello_Case):
"""Test compilation with compression.
@@ -1392,7 +1428,7 @@ int main(void) {
class DashONoSpace_Case(CompileHello_Case):
def compileCmd(self):
return self.distcc_without_fallback() + \
- _gcc + " -otesttmp.o -c %s" % (self.sourceFilename())
+ self._cc + " -otesttmp.o -c %s" % (self.sourceFilename())
def runtest(self):
if sys.platform == 'sunos5':
@@ -1406,9 +1442,9 @@ class DashONoSpace_Case(CompileHello_Case):
class WriteDevNull_Case(CompileHello_Case):
def runtest(self):
self.compile()
-
+
def compileCmd(self):
- return self.distcc_without_fallback() + _gcc + \
+ return self.distcc_without_fallback() + self._cc + \
" -c -o /dev/null -c %s" % (self.sourceFilename())
@@ -1425,13 +1461,13 @@ int main(void) {
return 0;
}
""")
-
+
def runtest(self):
self.runcmd(self.distcc()
- + _gcc + " -c test1.c test2.c")
+ + self._cc + " -c test1.c test2.c")
self.runcmd(self.distcc()
- + _gcc + " -o test test1.o test2.o")
-
+ + self._cc + " -o test test1.o test2.o")
+
class CppError_Case(CompileHello_Case):
@@ -1440,7 +1476,7 @@ class CppError_Case(CompileHello_Case):
return '#error "not tonight dear"\n'
def runtest(self):
- cmd = self.distcc() + _gcc + " -c testtmp.c"
+ cmd = self.distcc() + self._cc + " -c testtmp.c"
msgs, errs = self.runcmd(cmd, expectedResult=1)
self.assert_re_search("not tonight dear", errs)
self.assert_equal(msgs, '')
@@ -1465,10 +1501,10 @@ class BadInclude_Case(Compilation_Case):
# is exacerbated by distcc's pump mode because we always
# pass -MMD, even when the user didn't. TODO(klarlund):
# change error_rc back to 1 once that FIXME is fixed.
- error_rc, _, _ = self.runcmd_unchecked(_gcc + " -MMD -E testtmp.c")
+ error_rc, _, _ = self.runcmd_unchecked(self._cc + " -MMD -E testtmp.c")
else:
error_rc = 1
- self.runcmd(self.distcc() + _gcc + " -o testtmp.o -c testtmp.c",
+ self.runcmd(self.distcc() + self._cc + " -o testtmp.o -c testtmp.c",
error_rc)
@@ -1477,6 +1513,7 @@ class PreprocessPlainText_Case(Compilation_Case):
def setup(self):
self.stripEnvironment()
self.createSource()
+ self.initCompiler()
def source(self):
return """#define FOO 3
@@ -1491,7 +1528,7 @@ large foo!
def runtest(self):
# -P means not to emit linemarkers
self.runcmd(self.distcc()
- + _gcc + " -E testtmp.c -o testtmp.out")
+ + self._cc + " -E testtmp.c -o testtmp.out")
out = open("testtmp.out").read()
# It's a bit hard to know the exact value, because different versions of
# GNU cpp seem to handle the whitespace differently.
@@ -1500,7 +1537,7 @@ large foo!
def teardown(self):
# no daemon is run for this test
pass
-
+
class NoDetachDaemon_Case(CompileHello_Case):
"""Test the --no-detach option."""
@@ -1516,7 +1553,7 @@ class NoDetachDaemon_Case(CompileHello_Case):
self.pid = self.runcmd_background(cmd)
self.add_cleanup(self.killDaemon)
# Wait until the server is ready for connections.
- time.sleep(0.2) # Give distccd chance to start listening on the port
+ time.sleep(0.2) # Give distccd chance to start listening on the port
sock = socket.socket()
while sock.connect_ex(('127.0.0.1', self.server_port)) != 0:
time.sleep(0.2)
@@ -1573,7 +1610,9 @@ class DashMD_DashMF_DashMT_Case(CompileHello_Case):
"""Test -MD -MFfoo -MTbar"""
def compileOpts(self):
- return "-MD -MFdotd_filename -MTtarget_name_42"
+ opts = "-MD -MFdotd_filename -MTtarget_name_42"
+ opts += " -Qunused-arguments" if self.is_clang(self._cc) else ""
+ return opts
def runtest(self):
try:
@@ -1589,7 +1628,9 @@ class DashWpMD_Case(CompileHello_Case):
"""Test -Wp,-MD,depfile"""
def compileOpts(self):
- return "-Wp,-MD,depsfile"
+ opts = "-Wp,-MD,depsfile"
+ opts += " -Qunused-arguments" if self.is_clang(self._cc) else ""
+ return opts
def runtest(self):
try:
@@ -1623,7 +1664,7 @@ class ScanIncludes_Case(CompileHello_Case):
def compileCmd(self):
return self.distcc_without_fallback() + "--scan-includes " + \
- _gcc + " -o testtmp.o " + self.compileOpts() + \
+ self._cc + " -o testtmp.o " + self.compileOpts() + \
" -c %s" % (self.sourceFilename())
def runtest(self):
@@ -1633,9 +1674,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(
@@ -1662,10 +1703,10 @@ class AbsSourceFilename_Case(CompileHello_Case):
def compileCmd(self):
return (self.distcc()
- + _gcc
+ + self._cc
+ " -c -o testtmp.o %s/testtmp.c"
% _ShellSafe(os.getcwd()))
-
+
class HundredFold_Case(CompileHello_Case):
"""Try repeated simple compilations.
@@ -1677,24 +1718,24 @@ class HundredFold_Case(CompileHello_Case):
def daemon_lifetime(self):
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")
+ + self._cc + " -o testtmp.o -c testtmp.c")
class Concurrent_Case(CompileHello_Case):
"""Try many compilations at the same time"""
def daemon_lifetime(self):
return 120
-
+
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")
+ self._cc + " -o testtmp.o -c testtmp.c")
pids[kid] = kid
while len(pids):
pid, status = os.wait()
@@ -1715,15 +1756,15 @@ class BigAssFile_Case(Compilation_Case):
# source. Picking the size is kind of hard -- something that
# will properly exercise distcc may be too big for small/old
# 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()
def runtest(self):
- self.runcmd(self.distcc() + _gcc + " -c %s" % "testtmp.c")
- self.runcmd(self.distcc() + _gcc + " -o testtmp testtmp.o")
+ self.runcmd(self.distcc() + self._cc + " -c %s" % "testtmp.c")
+ self.runcmd(self.distcc() + self._cc + " -o testtmp testtmp.o")
def daemon_lifetime(self):
@@ -1745,7 +1786,7 @@ class BinFalse_Case(Compilation_Case):
"""
def createSource(self):
open("testtmp.i", "wt").write("int main() {}")
-
+
def runtest(self):
# On Solaris and IRIX 6, 'false' returns exit status 255
if sys.platform == 'sunos5' or \
@@ -1771,7 +1812,7 @@ class BinTrue_Case(Compilation_Case):
"""
def createSource(self):
open("testtmp.i", "wt").write("int main() {}")
-
+
def runtest(self):
self.runcmd(self.distcc()
+ "true -c testtmp.i", 0)
@@ -1785,13 +1826,13 @@ class SBeatsC_Case(CompileHello_Case):
# XXX: Are other compilers the same?
def runtest(self):
self.runcmd(self.distcc() +
- _gcc + " -c -S testtmp.c")
+ self._cc + " -c -S testtmp.c")
if os.path.exists("testtmp.o"):
self.fail("created testtmp.o but should not have")
if not os.path.exists("testtmp.s"):
self.fail("did not create testtmp.s but should have")
-
+
class NoServer_Case(CompileHello_Case):
"""Invalid server name"""
def setup(self):
@@ -1800,19 +1841,20 @@ class NoServer_Case(CompileHello_Case):
self.distcc_log = 'distcc.log'
os.environ['DISTCC_LOG'] = self.distcc_log
self.createSource()
-
+ self.initCompiler()
+
def runtest(self):
self.runcmd(self.distcc()
- + _gcc + " -c -o testtmp.o testtmp.c")
+ + self._cc + " -c -o testtmp.o testtmp.c")
msgs = open(self.distcc_log, 'r').read()
self.assert_re_search(r'failed to distribute.*running locally instead',
- msgs)
-
-
+ msgs)
+
+
class ImpliedOutput_Case(CompileHello_Case):
"""Test handling absence of -o"""
def compileCmd(self):
- return self.distcc() + _gcc + " -c testtmp.c"
+ return self.distcc() + self._cc + " -c testtmp.c"
class SyntaxError_Case(Compilation_Case):
@@ -1857,7 +1899,7 @@ class NoHosts_Case(CompileHello_Case):
def compileCmd(self):
"""Return command to compile source and run tests"""
return self.distcc_with_fallback() + \
- _gcc + " -o testtmp.o -c %s" % (self.sourceFilename())
+ self._cc + " -o testtmp.o -c %s" % (self.sourceFilename())
@@ -1877,7 +1919,7 @@ class MissingCompiler_Case(CompileHello_Case):
+ "nosuchcc -c testtmp.i",
expectedResult=EXIT_COMPILER_MISSING)
self.assert_re_search(r'failed to exec', errs)
-
+
class RemoteAssemble_Case(WithDaemon_Case):
@@ -1892,13 +1934,13 @@ class RemoteAssemble_Case(WithDaemon_Case):
.globl msg
.section .rodata
.LC0:
- .string "hello world"
+ .string "hello world"
.data
- .align 4
- .type msg,object
- .size msg,4
+ .align 4
+ .type msg,object
+ .size msg,4
msg:
- .long .LC0
+ .long .LC0
"""
asm_filename = 'test2.s'
@@ -1909,7 +1951,7 @@ msg:
def compile(self):
# Need to build both the C file and the assembly file
- self.runcmd(self.distcc() + _gcc + " -o test2.o -c test2.s")
+ self.runcmd(self.distcc() + self._cc + " -o test2.o -c test2.s")
@@ -1921,13 +1963,13 @@ gcc2_compiled.:
.globl msg
.section .rodata
.LC0:
- .string MSG
+ .string MSG
.data
- .align 4
- .type msg,object
- .size msg,4
+ .align 4
+ .type msg,object
+ .size msg,4
msg:
- .long .LC0
+ .long .LC0
"""
def setup(self):
@@ -1950,8 +1992,8 @@ msg:
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.runcmd("umask 0; distcc " + self._cc + " -c testtmp.c")
+ self.assert_equal(S_IMODE(os.stat("testtmp.o")[ST_MODE]), 0o666)
class CheckRoot_Case(SimpleDistCC_Case):
@@ -1980,7 +2022,7 @@ class EmptySource_Case(Compilation_Case):
def compile(self):
rc, out, errs = self.runcmd_unchecked(self.distcc()
- + _gcc + " -c %s" % self.sourceFilename())
+ + self._cc + " -c %s" % self.sourceFilename())
if not re.search("internal compiler error", errs):
self.assert_equal(rc, 0)
@@ -1993,7 +2035,7 @@ class BadLogFile_Case(CompileHello_Case):
self.runcmd("chmod 0 distcc.log")
msgs, errs = self.runcmd("DISTCC_LOG=distcc.log " + \
self.distcc() + \
- _gcc + " -c testtmp.c", expectedResult=0)
+ self._cc + " -c testtmp.c", expectedResult=0)
self.assert_re_search("failed to open logfile", errs)
@@ -2013,9 +2055,9 @@ class AccessDenied_Case(CompileHello_Case):
def compileCmd(self):
"""Return command to compile source and run tests"""
return self.distcc_with_fallback() + \
- _gcc + " -o testtmp.o -c %s" % (self.sourceFilename())
+ self._cc + " -o testtmp.o -c %s" % (self.sourceFilename())
+
-
def runtest(self):
self.compile()
errs = open('distcc.log').read()
@@ -2155,14 +2197,6 @@ class Getline_Case(comfychair.TestCase):
self.assert_equal(msg_parts[3], " line = '%s'" % line);
self.assert_equal(msg_parts[4], " rest = '%s'\n" % rest);
-# When invoking compiler, use absolute path so distccd can find it
-for path in os.environ['PATH'].split (':'):
- abs_path = os.path.join (path, 'gcc')
-
- if os.path.isfile (abs_path):
- _gcc = abs_path
- break
-
# All the tests defined in this suite
tests = [
CompileHello_Case,
@@ -2205,7 +2239,7 @@ tests = [
HelpOption_Case,
BogusOption_Case,
MultipleCompile_Case,
- GccOptionsPassed_Case,
+ CompilerOptionsPassed_Case,
IsSource_Case,
ExtractExtension_Case,
ImplicitCompiler_Case,