📄 testdistcc.py
字号:
# dasho syntax ("gcc -ofoo.o foo.c -c", "distribute", "foo.c", "foo.o"), ("gcc -ofoo foo.o", "local"), # tricky this one -- no dashc ("foo.c -o foo.o", "local"), ("foo.c -o foo.o -c", "distribute", "foo.c", "foo.o"), # Produce assembly listings ("gcc -Wa,-alh,-a=foo.lst -c foo.c", "local"), ("gcc -Wa,--MD -c foo.c", "local"), ("gcc -Wa,-xarch=v8 -c foo.c", "distribute", "foo.c", "foo.o"), # Produce .rpo files ("g++ -frepo foo.C", "local"), ("gcc -xassembler-with-cpp -c foo.c", "local"), ("gcc -x assembler-with-cpp -c foo.c", "local"), ("gcc -specs=foo.specs -c foo.c", "local"), ] for tup in cases: apply(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) 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: self.fail("h_scanargs %s gave %s input, expected %s" % (ccmd, os[1], input)) if os[2] <> output: self.fail("h_scanargs %s gave %s output, expected %s" % (ccmd, os[2], output))class ImplicitCompilerScan_Case(ScanArgs_Case): '''Test understanding of commands with no compiler''' def runtest(self): cases = [("-c hello.c", "distribute", "hello.c", "hello.o"), ("hello.c -c", "distribute", "hello.c", "hello.o"), ("-o hello.o -c hello.c", "distribute", "hello.c", "hello.o"), ] for tup in cases: # NB use "apply" rather than new syntax for compatibility with # venerable Pythons. apply(self.checkScanArgs, tup) class ExtractExtension_Case(SimpleDistCC_Case): def runtest(self): """Test extracting extensions from filenames""" for f, e in (("hello.c", ".c"), ("hello.cpp", ".cpp"), ("hello.2.4.4.4.c", ".c"), (".foo", ".foo"), ("gcc", "(NULL)")): out, err = self.runcmd("h_exten '%s'" % f) assert out == eclass DaemonBadPort_Case(SimpleDistCC_Case): def runtest(self): """Test daemon invoked with invalid port number""" self.runcmd("distccd --log-file=distccd.log --lifetime=10 --port 80000", EXIT_BAD_ARGUMENTS) self.assert_no_file("daemonpid.tmp")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\" h_hosts -v" % spec, EXIT_BAD_HOSTSPEC)class ParseHostSpec_Case(SimpleDistCC_Case): def runtest(self): """Check operation of dcc_parse_hosts_env. Passes complex environment variables to h_hosts, which is a C wrapper that calls the appropriate tests.""" spec="""localhost 127.0.0.1 @angry ted@angry \t@angry:/home/mbp/bin/distccd angry:4204 ipv4-localhost angry/44 angry:300/44 angry/44:300 angry,lzo angry:3000,lzo # some comment angry/44,lzo @angry,lzo#asdasd # oh yeah nothing here @angry:/usr/sbin/distccd,lzo localhostbutnotreally """ expected="""16 2 LOCAL 4 TCP 127.0.0.1 3632 4 SSH (no-user) angry (no-command) 4 SSH ted angry (no-command) 4 SSH (no-user) angry /home/mbp/bin/distccd 4 TCP angry 4204 4 TCP ipv4-localhost 3632 44 TCP angry 3632 44 TCP angry 300 44 TCP angry 300 4 TCP angry 3632 4 TCP angry 3000 44 TCP angry 3632 4 SSH (no-user) angry (no-command) 4 SSH (no-user) angry /usr/sbin/distccd 4 TCP localhostbutnotreally 3632""" out, err = self.runcmd("DISTCC_HOSTS=\"%s\" h_hosts" % spec) assert out == expected, "expected %s\ngot %s" % (`expected`, `out`)class Compilation_Case(WithDaemon_Case): '''Test distcc by actually compiling a file''' def setup(self): WithDaemon_Case.setup(self) self.createSource() def runtest(self): self.compile() self.link() self.checkBuiltProgram() def createSource(self): filename = self.sourceFilename() f = open(filename, 'w') f.write(self.source()) f.close() def sourceFilename(self): return "testtmp.c" # default def compile(self): cmd = self.compileCmd() out, err = self.runcmd(cmd) if out != '': self.fail("compiler command %s produced output:\n%s" % (`cmd`, out)) if err != '': self.fail("compiler command %s produced error:\n%s" % (`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`)) if err != '': self.fail("command %s produced error:\n%s" % (`cmd`, `err`)) def compileCmd(self): """Return command to compile source and run tests""" return "DISTCC_FALLBACK=0 distcc " + \ _gcc + " -o testtmp.o -c %s" % (self.sourceFilename()) def linkCmd(self): return "distcc " + _gcc + " -o testtmp testtmp.o" def checkCompileMsgs(self, msgs): if msgs <> '': self.fail("expected no compiler messages, got \"%s\"" % msgs) def checkBuiltProgram(self): '''Check compile results. By default, just try to execute.''' msgs, errs = self.runcmd("./testtmp") self.checkBuiltProgramMsgs(msgs) self.assert_equal(errs, '') def checkBuiltProgramMsgs(self, msgs): passclass CompileHello_Case(Compilation_Case): """Test the simple case of building a program that works properly""" def source(self): return """#include <stdio.h>int main(void) { puts("hello world"); return 0;}""" def checkBuiltProgramMsgs(self, msgs): self.assert_equal(msgs, "hello world\n")class CompressedCompile_Case(Compilation_Case): """Test compilation with compression. The source needs to be moderately large to make sure compression and mmap is turned on.""" def source(self): return """#include <stdio.h>#include <stdlib.h>#include <string.h>int main(void) { printf("hello world\\n"); return 0;}""" def setupEnv(self): Compilation_Case.setupEnv(self) os.environ['DISTCC_HOSTS'] = '127.0.0.1:%d,lzo' % self.server_port def checkBuiltProgramMsgs(self, msgs): self.assert_equal(msgs, "hello world\n")class DashONoSpace_Case(CompileHello_Case): def compileCmd(self): return "DISTCC_FALLBACK=0 distcc " + _gcc + \ " -otesttmp.o -c %s" % (self.sourceFilename()) def runtest(self): if sys.platform == 'sunos5': raise comfychair.NotRunError ('Sun assembler wants space after -o') elif sys.platform.startswith ('osf1'): raise comfychair.NotRunError ('GCC mips-tfile wants space after -o') else: CompileHello_Case.runtest (self)class WriteDevNull_Case(CompileHello_Case): def runtest(self): self.compile() def compileCmd(self): return "DISTCC_FALLBACK=0 distcc " + _gcc + \ " -c -o /dev/null -c %s" % (self.sourceFilename())class MultipleCompile_Case(Compilation_Case): """Test compiling several files from one line""" def setup(self): WithDaemon_Case.setup(self) open("test1.c", "w").write("const char *msg = \"hello foreigner\";") open("test2.c", "w").write("""#include <stdio.h>int main(void) { extern const char *msg; puts(msg); return 0;}""") def runtest(self): self.runcmd("distcc " + _gcc + " -c test1.c test2.c") self.runcmd("distcc " + _gcc + " -o test test1.o test2.o") class CppError_Case(CompileHello_Case): """Test failure of cpp""" def source(self): return '#error "not tonight dear"\n' def runtest(self): cmd = "distcc " + _gcc + " -c testtmp.c" msgs, errs = self.runcmd(cmd, expectedResult=1) self.assert_re_search("not tonight dear", errs) self.assert_equal(msgs, '') class BadInclude_Case(Compilation_Case): """Handling of error running cpp""" def source(self): return """#include <nosuchfilehere.h>""" def runtest(self): self.runcmd("distcc " + _gcc + " -o testtmp.o -c testtmp.c", 1)class PreprocessPlainText_Case(Compilation_Case): """Try using cpp on something that's not C at all""" def setup(self): self.stripEnvironment() self.createSource() def source(self): return """#define FOO 3#if FOO < 10small foo!#elselarge foo!#endif/* comment ca? */""" def runtest(self): # -P means not to emit linemarkers self.runcmd("distcc " + _gcc + " -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. self.assert_re_search("small foo!", out) def teardown(self): # no daemon is run for this test pass class NoDetachDaemon_Case(CompileHello_Case): """Check that without --no-detach the server goes into the background and can be stopped.""" def startDaemon(self): # FIXME: This does not work well if it happens to get the same # port as an existing server, because we can't catch the error. cmd = ("distccd --no-detach --daemon --verbose --log-file %s --pid-file %s --port %d --allow 127.0.0.1" % (self.daemon_logfile, self.daemon_pidfile, self.server_port)) self.pid = self.runcmd_background(cmd) self.add_cleanup(self.killDaemon) time.sleep(.5) # give it a bit of time to bind port def killDaemon(self): import signal os.kill(self.pid, signal.SIGTERM) pid, ret = os.wait() self.assert_equal(self.pid, pid) class ImplicitCompiler_Case(CompileHello_Case): """Test giving no compiler works""" def compileCmd(self): return "distcc -c testtmp.c" def linkCmd(self): # FIXME: Mozilla uses something like "distcc testtmp.o -o testtmp", # but that's broken at the moment. return "distcc -o testtmp testtmp.o " def runtest(self): if sys.platform != 'hp-ux10': CompileHello_Case.runtest (self) else: raise comfychair.NotRunError ('HP-UX bundled C compiler non-ANSI')class DashD_Case(Compilation_Case): """Test preprocessor arguments""" def source(self): return """#include <stdio.h>int main(void) { printf("%s\\n", MESSAGE); return 0;}""" def compileCmd(self): # quoting is hairy because this goes through the shell return "distcc " + _gcc + \ " -c -o testtmp.o '-DMESSAGE=\"hello world\"' testtmp.c" def checkBuiltProgramMsgs(self, msgs): self.assert_equal(msgs, "hello world\n")class ThousandFold_Case(CompileHello_Case): """Try repeated simple compilations""" def daemon_lifetime(self): return 120 def runtest(self): # may take about a minute or so for i in xrange(1000): self.runcmd("distcc " + _gcc + " -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 i in xrange(50): kid = self.runcmd_background("distcc " + _gcc + \ " -o testtmp.o -c testtmp.c") pids[kid] = kid
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -