2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2010
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 from buildfarm import (
22 from buildfarm.build import NoSuchBuildError
23 from buildfarm.tests import BuildFarmTestCase
26 from testtools import TestCase
30 class ReadTreesFromConfTests(TestCase):
32 def create_file(self, contents):
33 (fd, path) = tempfile.mkstemp()
34 f = os.fdopen(fd, 'w')
35 self.addCleanup(os.remove, path)
42 def test_read_trees_from_conf_ko(self):
43 name = self.create_file("""
55 Exception, read_trees_from_conf, name, None)
57 def test_read_trees_from_conf(self):
58 name = self.create_file("""
70 t = read_trees_from_conf(name)
71 self.assertEquals(t["pidl"].scm, "git")
74 class BuildFarmTests(BuildFarmTestCase):
77 super(BuildFarmTests, self).setUp()
78 self.buildfarm = BuildFarm(self.path)
79 self.write_compilers(["cc"])
80 self.write_hosts({"myhost": "Fedora",
82 self.write_trees({"trivial": {"scm": "git", "repo": "git://foo", "branch": "master"},
83 "other": {"scm": "git", "repo": "other.git", "branch": "HEAD"}})
84 self.buildfarm.commit()
85 self.x = BuildFarm(self.path)
87 def test_get_new_builds_empty(self):
88 self.assertEquals([], list(self.x.get_new_builds()))
90 def test_get_last_builds_empty(self):
91 self.assertEquals([], list(self.x.get_last_builds()))
93 def test_get_tree_builds_empty(self):
94 self.assertEquals([], list(self.x.get_tree_builds("trival")))
96 def test_get_tree_builds(self):
97 path = self.upload_mock_logfile(self.x.builds, "tdb", "myhost", "gcc",
98 stdout_contents="BUILD COMMIT REVISION: 12\n", mtime=1200)
99 path = self.upload_mock_logfile(self.x.builds, "tdb", "myhost", "cc",
100 stdout_contents="BUILD COMMIT REVISION: 13\n", mtime=1300)
101 path = self.upload_mock_logfile(self.x.builds, "tdb", "myhost", "cc",
102 stdout_contents="BUILD COMMIT REVISION: 42\n", mtime=4200)
103 builds = list(self.x.get_tree_builds("tdb"))
104 self.assertEquals(["42", "12"], [x.revision for x in builds])
106 def test_get_last_builds(self):
107 path = self.upload_mock_logfile(self.x.builds, "other", "myhost", "cc",
108 "BUILD COMMIT REVISION: 12\n", mtime=1200)
109 path = self.upload_mock_logfile(self.x.builds, "trivial", "myhost", "cc",
110 "BUILD COMMIT REVISION: 13\n", mtime=1300)
111 path = self.upload_mock_logfile(self.x.builds, "trivial", "myhost", "cc",
112 "BUILD COMMIT REVISION: 42\n", mtime=4200)
113 builds = list(self.x.get_last_builds())
114 self.assertEquals(2, len(builds))
115 self.assertEquals(4200, builds[0].upload_time)
116 self.assertEquals("42", builds[0].revision_details())
117 self.assertEquals("trivial", builds[0].tree)
118 self.assertEquals(1200, builds[1].upload_time)
119 self.assertEquals("12", builds[1].revision_details())
120 self.assertEquals("other", builds[1].tree)
122 def test_get_summary_builds_empty(self):
123 self.assertEquals([], list(self.x.get_summary_builds()))
125 def test_get_summary_builds(self):
126 path = self.upload_mock_logfile(self.x.builds, "other", "myhost", "cc",
127 "BUILD COMMIT REVISION: 12\n", mtime=1200)
128 path = self.upload_mock_logfile(self.x.builds, "trivial", "myhost", "cc",
129 "BUILD COMMIT REVISION: 13\n", mtime=1300)
130 path = self.upload_mock_logfile(self.x.builds, "trivial", "myhost", "cc",
131 "BUILD COMMIT REVISION: 42\n", mtime=4200)
132 builds = list(self.x.get_summary_builds())
133 self.assertEquals(2, len(builds))
134 self.assertEquals(4200, builds[0].upload_time)
135 self.assertEquals("42", builds[0].revision_details())
136 self.assertEquals("trivial", builds[0].tree)
137 self.assertEquals(1200, builds[1].upload_time)
138 self.assertEquals("12", builds[1].revision_details())
139 self.assertEquals("other", builds[1].tree)
140 builds = list(self.x.get_summary_builds(min_age=4000))
141 self.assertEquals(1, len(builds))
142 builds = list(self.x.get_summary_builds(min_age=5000))
143 self.assertEquals(0, len(builds))
145 def test_get_host_builds_empty(self):
146 self.assertEquals([], list(self.x.get_host_builds("myhost")))
148 def test_lcov_status_none(self):
149 self.assertRaises(NoSuchBuildError, self.x.lcov_status, "trivial")
152 self.assertEquals("trivial", self.x.trees["trivial"].name)
153 tree = self.x.trees["trivial"]
154 self.assertEquals("git", tree.scm)
155 self.assertEquals("git://foo", tree.repo)
156 self.assertEquals("master", tree.branch)
158 def test_get_build_rev(self):
159 path = self.upload_mock_logfile(self.x.builds, "tdb", "charis", "cc",
160 stdout_contents="tHIS is what a log file looks like.\n"
161 "BUILD COMMIT REVISION: 12\n")
162 build = self.x.get_build("tdb", "charis", "cc", "12")
163 self.assertEquals("tdb", build.tree)
164 self.assertEquals("charis", build.host)
165 self.assertEquals("cc", build.compiler)
166 self.assertEquals("12", build.revision)
168 def test_get_build_no_rev(self):
169 path = self.create_mock_logfile("tdb", "charis", "cc",
170 contents="This is what a log file looks like.")
171 build = self.x.get_build("tdb", "charis", "cc")
172 self.assertEquals("tdb", build.tree)
173 self.assertEquals("charis", build.host)
174 self.assertEquals("cc", build.compiler)
175 self.assertIs(None, build.revision)