⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdistcc.py

📁 distcc编译器的源代码.好像是readhat公司开发的.
💻 PY
📖 第 1 页 / 共 3 页
字号:
        while len(pids):            pid, status = os.wait()            if status:                self.fail("child %d failed with status %#x" % (pid, status))            del pids[pid]class BigAssFile_Case(Compilation_Case):    """Test compilation of a really big C file    This will take a while to run"""    def createSource(self):        """Create source file"""        f = open("testtmp.c", 'wt')        # We want a file of many, which will be a few megabytes of        # 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):            f.write("int i%06d = %d;\n" % (i, i))        f.close()    def runtest(self):        self.runcmd("distcc " + _gcc + " -c %s" % "testtmp.c")        self.runcmd("distcc " + _gcc + " -o testtmp testtmp.o")    def daemon_lifetime(self):        return 300class BinFalse_Case(Compilation_Case):    """Compiler that fails without reading input.    This is an interesting case when the server is using fifos,    because it has to cope with the open() on the fifo being    interrupted.    distcc doesn't know that 'false' is not a compiler, but it does    need a command line that looks like a compiler invocation.    We have to use a .i file so that distcc does not try to preprocess it.    """    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 \        sys.platform.startswith ('irix6'):            self.runcmd("distcc false -c testtmp.i", 255)        else:            self.runcmd("distcc false -c testtmp.i", 1)class BinTrue_Case(Compilation_Case):    """Compiler that succeeds without reading input.    This is an interesting case when the server is using fifos,    because it has to cope with the open() on the fifo being    interrupted.    distcc doesn't know that 'true' is not a compiler, but it does    need a command line that looks like a compiler invocation.    We have to use a .i file so that distcc does not try to preprocess it.    """    def createSource(self):        open("testtmp.i", "wt").write("int main() {}")            def runtest(self):        self.runcmd("distcc true -c testtmp.i", 0)class SBeatsC_Case(CompileHello_Case):    """-S overrides -c in gcc.    If both options are given, we have to make sure we imply the    output filename in the same way as gcc."""    # XXX: Are other compilers the same?    def runtest(self):        self.runcmd("distcc " + _gcc + " -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):        self.stripEnvironment()        os.environ['DISTCC_HOSTS'] = 'no.such.host.here'        self.distcc_log = 'distcc.log'        os.environ['DISTCC_LOG'] = self.distcc_log        self.createSource()        def runtest(self):        self.runcmd("distcc " + _gcc + " -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)                            class ImpliedOutput_Case(CompileHello_Case):    """Test handling absence of -o"""    def compileCmd(self):        return "distcc " + _gcc + " -c testtmp.c"class SyntaxError_Case(Compilation_Case):    """Test building a program containing syntax errors, so it won't build    properly."""    def source(self):        return """not C source at all"""    def compile(self):        rc, msgs, errs = self.runcmd_unchecked(self.compileCmd())        self.assert_notequal(rc, 0)        # XXX: Need to also handle "syntax error" from gcc-2.95.3        self.assert_re_match(r'testtmp.c:1: .*error', errs)        self.assert_equal(msgs, '')    def runtest(self):        self.compile()        if os.path.exists("testtmp") or os.path.exists("testtmp.o"):            self.fail("compiler produced output, but should not have done so")class NoHosts_Case(CompileHello_Case):    """Test running with no hosts defined.    We expect compilation to succeed, but with a warning that it was    run locally."""    def runtest(self):        import os                # WithDaemon_Case sets this to point to the local host, but we        # don't want that.  Note that you cannot delete environment        # keys in Python1.5, so we need to just set them to the empty        # string.        os.environ['DISTCC_HOSTS'] = ''        os.environ['DISTCC_LOG'] = ''        self.runcmd('printenv')        msgs, errs = self.runcmd(self.compileCmd())        # We expect only one message, a warning from distcc        self.assert_re_search(r"Warning.*\$DISTCC_HOSTS.*can't distribute work",                              errs)    def compileCmd(self):        """Return command to compile source and run tests"""        return "DISTCC_FALLBACK=1 distcc " + _gcc + \               " -o testtmp.o -c %s" % (self.sourceFilename())class MissingCompiler_Case(CompileHello_Case):    """Test compiler missing from server."""    # Another way to test this would be to break the server's PATH    def sourceFilename(self):        # must be preprocessed, so that we don't need to run the compiler        # on the client        return "testtmp.i"    def source(self):        return """int foo;"""    def runtest(self):        msgs, errs = self.runcmd("DISTCC_FALLBACK=0 distcc nosuchcc -c testtmp.i",                                 expectedResult=EXIT_COMPILER_MISSING)        self.assert_re_search(r'failed to exec', errs)        class RemoteAssemble_Case(WithDaemon_Case):    """Test remote assembly of a .s file."""    # We have a rather tricky method for testing assembly code when we    # don't know what platform we're on.  I think this one will work    # everywhere, though perhaps not.    asm_source = """        .file	"foo.c".globl msg.section	.rodata.LC0:	.string	"hello world".data	.align 4	.type	 msg,@object	.size	 msg,4msg:	.long .LC0"""    asm_filename = 'test2.s'    def setup(self):        WithDaemon_Case.setup(self)        open(self.asm_filename, 'wt').write(self.asm_source)    def compile(self):        # Need to build both the C file and the assembly file        self.runcmd("distcc " + _gcc + " -o test2.o -c test2.s")class PreprocessAsm_Case(WithDaemon_Case):    """Run preprocessor locally on assembly, then compile locally."""    asm_source = """#define MSG "hello world"gcc2_compiled.:.globl msg.section	.rodata.LC0:	.string	 MSG.data	.align 4	.type	 msg,@object	.size	 msg,4msg:	.long .LC0"""    def setup(self):        WithDaemon_Case.setup(self)        open('test2.S', 'wt').write(self.asm_source)        def compile(self):        if sys.platform == 'linux2':            self.runcmd("distcc -o test2.o -c test2.S")    def runtest(self):        self.compile()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)class CheckRoot_Case(comfychair.TestCase):    """Stub case that checks this is run by root.  Not used by default."""    def setup(self):        self.require_root()class EmptySource_Case(Compilation_Case):    """Check compilation of empty source file    It must be treated as preprocessed source, otherwise cpp will    insert a # line, which will give a false pass.  """        def source(self):        return ''    def runtest(self):        self.compile()    def compile(self):        self.runcmd("distcc " + _gcc + " -c %s" % self.sourceFilename())    def sourceFilename(self):        return "testtmp.i"class BadLogFile_Case(comfychair.TestCase):    def runtest(self):        self.runcmd("touch distcc.log")        self.runcmd("chmod 0 distcc.log")        msgs, errs = self.runcmd("DISTCC_LOG=distcc.log distcc " + \                                 _gcc + " -c foo.c", expectedResult=1)        self.assert_re_search("failed to open logfile", errs)class AccessDenied_Case(CompileHello_Case):    """Run the daemon, but don't allow access from this host.    Make sure that compilation falls back to localhost with a warning."""    def daemon_command(self):        return ("distccd --verbose --lifetime=%d --daemon --log-file %s "                "--pid-file %s --port %d --allow 127.0.0.2"                % (self.daemon_lifetime(),                   self.daemon_logfile, self.daemon_pidfile, self.server_port))    def compileCmd(self):        """Return command to compile source and run tests"""        return "DISTCC_FALLBACK=1 distcc " + _gcc + " -o testtmp.o -c %s" % (self.sourceFilename())        def runtest(self):        self.compile()        errs = open('distcc.log').read()        self.assert_re_search(r'failed to distribute', errs)class ParseMask_Case(comfychair.TestCase):    """Test code for matching IP masks."""    values = [        ('127.0.0.1', '127.0.0.1', 0),        ('127.0.0.1', '127.0.0.0', EXIT_ACCESS_DENIED),        ('127.0.0.1', '127.0.0.2', EXIT_ACCESS_DENIED),        ('127.0.0.1/8', '127.0.0.2', 0),        ('10.113.0.0/16', '10.113.45.67', 0),        ('10.113.0.0/16', '10.11.45.67', EXIT_ACCESS_DENIED),        ('10.113.0.0/16', '127.0.0.1', EXIT_ACCESS_DENIED),        ('1.2.3.4/0', '4.3.2.1', 0),        ('1.2.3.4/40', '4.3.2.1', EXIT_BAD_ARGUMENTS),        ('1.2.3.4.5.6.7/8', '127.0.0.1', EXIT_BAD_ARGUMENTS),        ('1.2.3.4/8', '4.3.2.1', EXIT_ACCESS_DENIED),        ('192.168.1.64/28', '192.168.1.70', 0),        ('192.168.1.64/28', '192.168.1.7', EXIT_ACCESS_DENIED),        ]    def runtest(self):        for mask, client, expected in ParseMask_Case.values:            cmd = "h_parsemask %s %s" % (mask, client)            ret, msgs, err = self.runcmd_unchecked(cmd)            if ret != expected:                self.fail("%s gave %d, expected %d" % (cmd, ret, expected))class HostFile_Case(CompileHello_Case):    def setup(self):        CompileHello_Case.setup(self)        del os.environ['DISTCC_HOSTS']        self.save_home = os.environ['HOME']        os.environ['HOME'] = os.getcwd()        # DISTCC_DIR is set to 'distccdir'        open(os.environ['DISTCC_DIR'] + '/hosts', 'w').write('127.0.0.1:%d' % self.server_port)    def teardown(self):        os.environ['HOME'] = self.save_home        CompileHello_Case.teardown(self)# When invoking compiler, use absolute path so distccd can find itfor 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 suitetests = [BadLogFile_Case,         ScanArgs_Case,         ParseMask_Case,         ImplicitCompilerScan_Case,         StripArgs_Case,         StartStopDaemon_Case,         CompileHello_Case,         CompressedCompile_Case,         DashONoSpace_Case,         WriteDevNull_Case,         CppError_Case,         BadInclude_Case,         PreprocessPlainText_Case,         NoDetachDaemon_Case,         SBeatsC_Case,         DashD_Case,         BinFalse_Case,         BinTrue_Case,         VersionOption_Case,         HelpOption_Case,         BogusOption_Case,         MultipleCompile_Case,         GccOptionsPassed_Case,         IsSource_Case,         ExtractExtension_Case,         ImplicitCompiler_Case,         DaemonBadPort_Case,         AccessDenied_Case,         NoServer_Case,         InvalidHostSpec_Case,         ParseHostSpec_Case,         ImpliedOutput_Case,         SyntaxError_Case,         NoHosts_Case,         MissingCompiler_Case,         RemoteAssemble_Case,         PreprocessAsm_Case,         ModeBits_Case,         EmptySource_Case,         HostFile_Case,         # slow tests below here         Concurrent_Case,         ThousandFold_Case,         BigAssFile_Case]if __name__ == '__main__':    comfychair.main(tests)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -