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.
24 from buildfarm import data
26 from buildfarm.tests import BuildFarmTestCase
29 class NonexistantTests(unittest.TestCase):
31 def test_nonexistant(self):
33 Exception, data.BuildResultStore, "somedirthatdoesn'texist", None)
36 class ReadTreesFromConfTests(testtools.TestCase):
38 def create_file(self, contents):
39 (fd, path) = tempfile.mkstemp()
40 f = os.fdopen(fd, 'w')
41 self.addCleanup(os.remove, path)
48 def test_read_trees_from_conf_ko(self):
49 name = self.create_file("""
61 Exception, data.read_trees_from_conf, name, None)
63 def test_read_trees_from_conf(self):
64 name = self.create_file("""
76 t = data.read_trees_from_conf(name)
82 class BuildResultStoreTests(BuildFarmTestCase):
85 super(BuildResultStoreTests, self).setUp()
87 self.write_compilers(["cc"])
88 self.write_hosts(["gwenhwyvar", "charis"])
89 self.write_trees({"tdb": {"scm": "git", "repo": "tdb", "branch": "master"}})
91 self.x = data.BuildResultStore(self.path)
93 def test_build_fname(self):
95 self.x.build_fname("mytree", "myhost", "cc"),
96 "%s/data/upload/build.mytree.myhost.cc" % self.path)
98 self.x.build_fname("mytree", "myhost", "cc", 123),
99 "%s/data/oldrevs/build.mytree.myhost.cc-123" % self.path)
101 def test_cache_fname(self):
103 self.x.cache_fname("mytree", "myhost", "cc", 123),
104 "%s/cache/build.mytree.myhost.cc-123" % self.path)
106 self.x.cache_fname("mytree", "myhost", "cc"),
107 "%s/cache/build.mytree.myhost.cc" % self.path)
109 def test_build_age_mtime(self):
110 path = self.create_mock_logfile("tdb", "charis", "cc")
111 # Set mtime to something in the past
112 os.utime(path, (time.time(), time.time() - 990))
113 build = self.x.get_build("tdb", "charis", "cc")
114 age = build.age_mtime()
115 self.assertTrue(age >= 990 and age <= 1000, "age was %d" % age)
117 def test_get_build_nonexistant(self):
118 self.assertRaises(data.NoSuchBuildError, self.x.get_build, "tdb",
121 def test_build_age_ctime(self):
122 path = self.create_mock_logfile("tdb", "charis", "cc")
123 # Set mtime to something in the past
124 build = self.x.get_build("tdb", "charis", "cc")
125 age = build.age_ctime()
126 self.assertTrue(age >= 0 and age <= 10, "age was %d" % age)
128 def test_read_log(self):
129 path = self.create_mock_logfile("tdb", "charis", "cc",
130 contents="This is what a log file looks like.")
131 build = self.x.get_build("tdb", "charis", "cc")
132 self.assertEquals("This is what a log file looks like.", build.read_log())
134 def test_read_err(self):
135 self.create_mock_logfile("tdb", "charis", "cc")
136 path = self.create_mock_logfile("tdb", "charis", "cc",
138 contents="This is what an stderr file looks like.")
139 build = self.x.get_build("tdb", "charis", "cc")
140 self.assertEquals("This is what an stderr file looks like.", build.read_err())
142 def test_revision_details(self):
143 self.create_mock_logfile("tdb", "charis", "cc", contents="""
144 BUILD COMMIT REVISION: 43
147 BUILD COMMIT TIME: 3 August 2010
149 build = self.x.get_build("tdb", "charis", "cc")
150 self.assertEquals(("42", "3 August 2010"), build.revision_details())
152 def test_revision_details_no_timestamp(self):
153 self.create_mock_logfile("tdb", "charis", "cc", contents="""
154 BUILD COMMIT REVISION: 43
158 build = self.x.get_build("tdb", "charis", "cc")
159 self.assertEquals(("42", None), build.revision_details())
161 def test_err_count(self):
162 self.create_mock_logfile("tdb", "charis", "cc")
163 self.create_mock_logfile("tdb", "charis", "cc", kind="stderr", contents="""error1
166 build = self.x.get_build("tdb", "charis", "cc")
167 self.assertEquals(3, build.err_count())
169 def test_has_host(self):
170 self.assertFalse(self.x.has_host("charis"))
171 self.create_mock_logfile("tdb", "charis", "cc")
172 self.assertTrue(self.x.has_host("charis"))
176 class LogParserTests(unittest.TestCase):
178 def test_nothing(self):
179 self.assertEquals(((None, None, None, None, None), set()),
180 data.build_status_from_logs("", ""))
182 def test_disk_full(self):
183 self.assertEquals(((None, None, None, None, None), set(["disk full"])),
184 data.build_status_from_logs("foo\nbar\nNo space left on device\nla\n",
186 self.assertEquals(((None, None, None, None, None), set(["disk full"])),
187 data.build_status_from_logs(
188 "", "foo\nbar\nNo space left on device\nla\n"))
190 def test_timeout(self):
191 self.assertEquals(((None, None, None, None, None), set(["timeout"])),
192 data.build_status_from_logs("foo\nbar\nmaximum runtime exceeded\nla\n",