2 # run tests on all Samba subprojects and push to a git tree on success
3 # Copyright Andrew Tridgell 2010
4 # released under GNU GPL v3 or later
6 from subprocess import Popen, PIPE
7 import os, signal, tarfile, sys, time
8 from optparse import OptionParser
14 "source3" : [ "./autogen.sh",
15 "./configure.developer ${PREFIX}",
20 "source4" : [ "./autogen.sh",
21 "./configure.developer ${PREFIX}",
25 "source4/lib/ldb" : [ "./autogen-waf.sh",
26 "./configure --enable-developer -C ${PREFIX}",
30 "lib/tdb" : [ "./autogen-waf.sh",
31 "./configure --enable-developer -C ${PREFIX}",
35 "lib/talloc" : [ "./autogen-waf.sh",
36 "./configure --enable-developer -C ${PREFIX}",
40 "lib/replace" : [ "./autogen-waf.sh",
41 "./configure --enable-developer -C ${PREFIX}",
45 "lib/tevent" : [ "./autogen-waf.sh",
46 "./configure --enable-developer -C ${PREFIX}",
51 def run_cmd(cmd, dir=".", show=None):
55 show = options.verbose
57 print("Running: '%s' in '%s'" % (cmd, dir))
61 raise Exception("FAILED %s: %d" % (cmd, ret))
64 '''handle build of one directory'''
65 def __init__(self, name, sequence):
67 self.tag = self.name.replace('/', '_')
68 self.sequence = sequence
70 self.stdout_path = "%s/%s.stdout" % (testbase, self.tag)
71 self.stderr_path = "%s/%s.stderr" % (testbase, self.tag)
72 cleanup_list.append(self.stdout_path)
73 cleanup_list.append(self.stderr_path)
74 run_cmd("rm -f %s %s" % (self.stdout_path, self.stderr_path))
75 self.stdout = open(self.stdout_path, 'w')
76 self.stderr = open(self.stderr_path, 'w')
77 self.stdin = open("/dev/null", 'r')
78 self.sdir = "%s/%s" % (testbase, self.tag)
79 self.prefix = "%s/prefix/%s" % (testbase, self.tag)
80 run_cmd("rm -rf %s" % self.sdir)
81 cleanup_list.append(self.sdir)
82 cleanup_list.append(self.prefix)
83 os.makedirs(self.sdir)
84 run_cmd("rm -rf %s" % self.sdir)
85 run_cmd("git clone --shared %s %s" % (gitroot, self.sdir))
89 if self.next == len(self.sequence):
90 print '%s: Completed OK' % self.name
93 self.cmd = self.sequence[self.next].replace("${PREFIX}", "--prefix=%s" % self.prefix)
94 print '%s: Running %s' % (self.name, self.cmd)
96 os.chdir("%s/%s" % (self.sdir, self.name))
97 self.proc = Popen(self.cmd, shell=True,
98 stdout=self.stdout, stderr=self.stderr, stdin=self.stdin)
104 '''handle build of multiple directories'''
105 def __init__(self, tasklist, tasknames):
107 self.tail_proc = None
111 b = builder(n, tasks[n])
116 if b.proc is not None:
120 if self.tail_proc is not None:
121 self.tail_proc.terminate()
122 self.tail_proc.wait()
123 self.tail_proc = None
132 b.status = b.proc.poll()
146 if os.WIFSIGNALED(b.status) or os.WEXITSTATUS(b.status) != 0:
148 return (b.status, "%s: failed '%s' with status %d" % (b.name, b.cmd, b.status))
153 def tarlogs(self, fname):
154 tar = tarfile.open(fname, "w:gz")
156 tar.add(b.stdout_path, arcname="%s.stdout" % b.tag)
157 tar.add(b.stderr_path, arcname="%s.stderr" % b.tag)
160 def remove_logs(self):
162 os.unlink(b.stdout_path)
163 os.unlink(b.stderr_path)
165 def start_tail(self):
167 cmd = "tail -f *.stdout *.stderr"
169 self.tail_proc = Popen(cmd, shell=True)
174 print("Cleaning up ....")
175 for d in cleanup_list:
176 run_cmd("rm -rf %s" % d)
180 '''get to the top of the git repo'''
182 while os.getcwd() != '/':
194 def rebase_tree(url):
195 print("Rebasing on %s" % url)
196 run_cmd("git remote add -t master master %s" % url, show=True, dir=test_master)
197 run_cmd("git fetch master", show=True, dir=test_master)
198 run_cmd("git rebase master/master", show=True, dir=test_master)
200 def_testbase = os.getenv("AUTOBUILD_TESTBASE", "/memdisk/%s" % os.getenv('USER'))
201 def_passcmd = os.getenv("AUTOBUILD_PASSCMD",
202 "git push %s/master-passed +HEAD:master" % os.getenv("HOME"))
204 parser = OptionParser()
205 parser.add_option("", "--tail", help="show output while running", default=False, action="store_true")
206 parser.add_option("", "--keeplogs", help="keep logs", default=False, action="store_true")
207 parser.add_option("", "--testbase", help="base directory to run tests in (default %s)" % def_testbase,
208 default=def_testbase)
209 parser.add_option("", "--passcmd", help="command to run on success (default %s)" % def_passcmd,
211 parser.add_option("", "--verbose", help="show all commands as they are run",
212 default=False, action="store_true")
213 parser.add_option("", "--rebase", help="rebase on the given tree before testing",
214 default=None, type='str')
217 (options, args) = parser.parse_args()
219 testbase = "%s/build.%u" % (options.testbase, os.getpid())
220 test_master = "%s/master" % testbase
222 gitroot = find_git_root()
224 raise Exception("Failed to find git root")
227 os.makedirs(testbase)
228 except Exception, reason:
229 raise Exception("Unable to create %s : %s" % (testbase, reason))
230 cleanup_list.append(testbase)
233 run_cmd("rm -rf %s" % test_master)
234 cleanup_list.append(test_master)
235 run_cmd("git clone --shared %s %s" % (gitroot, test_master))
241 if options.rebase is not None:
242 rebase_tree(options.rebase)
243 blist = buildlist(tasks, args)
246 (status, errstr) = blist.run()
253 print("waiting for tail to flush")
258 print("Running passcmd: %s" % options.passcmd)
259 run_cmd(options.passcmd, dir=test_master)
261 blist.tarlogs("logs.tar.gz")
262 print("Logs in logs.tar.gz")
268 # something failed, gather a tar of the logs
269 blist.tarlogs("logs.tar.gz")
273 print("Logs in logs.tar.gz")
274 sys.exit(os.WEXITSTATUS(status))