Support extracting subunit files.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 4 Dec 2010 01:49:02 +0000 (02:49 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 4 Dec 2010 01:49:02 +0000 (02:49 +0100)
buildfarm/build.py
buildfarm/tests/test_build.py
tools/fix.py

index a2ea904..9e4b8a6 100644 (file)
@@ -160,13 +160,13 @@ def extract_phase_output(f):
     output = None
     re_action = re.compile("^ACTION (PASSED|FAILED):\s+(.*)$")
     for l in f:
-        if l.startwith("Running action "):
+        if l.startswith("Running action "):
             name = l[len("Running action "):].strip()
             output = []
             continue
         m = re_action.match(l)
         if m:
-            assert name == m.group(1)
+            assert name == m.group(2).strip(), "%r != %r" % (name, m.group(2))
             yield name, output
             name = None
             output = []
@@ -178,7 +178,7 @@ def extract_test_output(f):
     for name, output in extract_phase_output(f):
         if name == "test":
             return output
-    return None
+    raise NoTestOutput()
 
 
 def build_status_from_logs(log, err):
@@ -268,6 +268,10 @@ class NoSuchBuildError(Exception):
         self.rev = rev
 
 
+class NoTestOutput(Exception):
+    """The build did not have any associated test output."""
+
+
 class Build(object):
     """A single build of a tree on a particular host using a particular compiler.
     """
index 4c2d0f0..b3c7a45 100755 (executable)
 from cStringIO import StringIO
 import os
 import testtools
-import unittest
 
 from buildfarm.build import (
     Build,
-    BuildResultStore,
     BuildStatus,
     NoSuchBuildError,
+    NoTestOutput,
     UploadBuildResultStore,
     build_status_from_logs,
+    extract_test_output,
     )
 
 from buildfarm import BuildFarm
@@ -402,3 +402,24 @@ class UploadBuildResultStoreTests(UploadBuildResultStoreTestBase,BuildFarmTestCa
 
         self.x = UploadBuildResultStore(
             os.path.join(self.path, "data", "upload"))
+
+
+class ExtractSubunitTests(testtools.TestCase):
+
+    def extract_test_output(self, log):
+        try:
+            return "".join(extract_test_output(StringIO(log)))
+        except NoTestOutput:
+            return None
+
+    def test_not_present(self):
+        self.assertEquals(None, self.extract_test_output(""))
+
+    def test_simple(self):
+        self.assertEquals("FOO\n", self.extract_test_output("""
+
+Running action test
+FOO
+ACTION PASSED: test
+
+"""))
index 9cec88f..b4cc172 100755 (executable)
@@ -8,11 +8,13 @@ from buildfarm.build import (
     build_status_from_logs,
     LogFileMissing,
     MissingRevisionInfo,
+    NoTestOutput,
     revision_from_log,
+    extract_test_output,
     )
 from buildfarm.hostdb import NoSuchHost
 
-from buildfarm.sqldb import BuildFarm, StormBuild
+from buildfarm import BuildFarm, StormBuild
 
 buildfarm = BuildFarm()
 
@@ -58,4 +60,19 @@ for build in store.find(StormBuild, StormBuild.host_id == None):
     except NoSuchHost, e:
         print "Unable to find host %s" % e.name
 
+
+for build in store.find(StormBuild, StormBuild.basename != None):
+    subunit_path = build.basename + ".subunit"
+    if os.path.exists(subunit_path):
+        continue
+    try:
+        test_output = "".join(extract_test_output(build.read_log()))
+    except (LogFileMissing, NoTestOutput):
+        continue
+    f = open(subunit_path, 'w')
+    try:
+        f.write(test_output)
+    finally:
+        f.close()
+
 buildfarm.commit()