00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 import roslib; roslib.load_manifest("test_rosmake")
00031
00032 import sys
00033 import unittest
00034 import rosunit
00035
00036 from rosmake import parallel_build
00037 NAME = "test_rosmake_parallel_build"
00038
00039 class TestDependencyTracker(unittest.TestCase):
00040 def setUp(self):
00041 self.deps = {}
00042 self.deps1 = {}
00043 self.deps["a"] = [ "b", "c", "d","e"]
00044 self.deps1["a"] = ["b"]
00045 self.deps["b"] = ["c"]
00046 self.deps1["b"] = ["c"]
00047 self.deps["d"] = ["c", "e"]
00048 self.deps1["d"] = ["c", "e"]
00049 self.dt = parallel_build.DependencyTracker()
00050 self.dt.load_fake_deps(self.deps, self.deps1)
00051
00052
00053 def test_deps_1(self):
00054 self.assertEquals(self.deps1["a"], self.dt.get_deps_1("a"))
00055 self.assertEquals(self.deps1["b"], self.dt.get_deps_1("b"))
00056 self.assertEquals(self.deps1["d"], self.dt.get_deps_1("d"))
00057
00058 def test_deps(self):
00059 self.assertEquals(self.deps["a"], self.dt.get_deps("a"))
00060 self.assertEquals(self.deps["b"], self.dt.get_deps("b"))
00061 self.assertEquals(self.deps["d"], self.dt.get_deps("d"))
00062
00063 def test_not_package(self):
00064 self.assertEquals([], self.dt.get_deps("This is not a valid package name"))
00065 self.assertEquals([], self.dt.get_deps_1("This is not a valid package name"))
00066
00067
00068 class TestBuildQueue(unittest.TestCase):
00069
00070 def setUp(self):
00071 deps = {}
00072 deps1 = {}
00073 deps1["a"] = ["b"]
00074 deps["a"] = ["b", "c", "d", "e", "f"]
00075 deps1["b"] = ["c"]
00076 deps["b"] = ["c", "d", "e", "f"]
00077 deps1["c"] = ["d"]
00078 deps["c"] = ["d", "e", "f"]
00079 deps1["d"] = ["e"]
00080 deps["d"] = ["e", "f"]
00081 deps["e"] = ["f"]
00082 deps1["e"] = ["f"]
00083 deps["f"] = []
00084 deps1["f"] = []
00085
00086 self.serial_tracker = parallel_build.DependencyTracker()
00087 self.serial_tracker.load_fake_deps(deps, deps1)
00088
00089 deps = {}
00090 deps1 = {}
00091 deps["a"] = ["b", "c", "d", "e", "f"]
00092 deps1["a"] = ["b", "c", "d", "e", "f"]
00093 deps["b"] = []
00094 deps1["b"] = []
00095 deps["c"] = []
00096 deps1["c"] = []
00097 deps["d"] = []
00098 deps1["d"] = []
00099 deps["e"] = []
00100 deps1["e"] = []
00101 deps["f"] = []
00102 deps1["f"] = []
00103
00104 self.parallel_tracker = parallel_build.DependencyTracker()
00105 self.parallel_tracker.load_fake_deps(deps, deps1)
00106
00107
00108 def test_full_build(self):
00109 bq = parallel_build.BuildQueue(["a", "b", "c", "d", "e", "f"], self.serial_tracker)
00110 self.assertFalse(bq.is_done())
00111 self.assertFalse(bq.succeeded())
00112
00113 self.assertEqual("f", bq.get_valid_package())
00114 self.assertEqual(0, len(bq.built))
00115 bq.return_built("f")
00116 self.assertEqual(1, len(bq.built))
00117 self.assertFalse(bq.is_done())
00118 self.assertFalse(bq.succeeded())
00119
00120 self.assertEqual("e", bq.get_valid_package())
00121 bq.return_built("e")
00122 self.assertEqual(2, len(bq.built))
00123 self.assertFalse(bq.is_done())
00124 self.assertFalse(bq.succeeded())
00125
00126 self.assertEqual("d", bq.get_valid_package())
00127 bq.return_built("d")
00128 self.assertEqual(3, len(bq.built))
00129 self.assertFalse(bq.is_done())
00130 self.assertFalse(bq.succeeded())
00131
00132 self.assertEqual("c", bq.get_valid_package())
00133 bq.return_built("c")
00134 self.assertEqual(4, len(bq.built))
00135 self.assertFalse(bq.is_done())
00136 self.assertFalse(bq.succeeded())
00137
00138 self.assertEqual("b", bq.get_valid_package())
00139 bq.return_built("b")
00140 self.assertEqual(5, len(bq.built))
00141 self.assertFalse(bq.is_done())
00142 self.assertFalse(bq.succeeded())
00143
00144 self.assertEqual("a", bq.get_valid_package())
00145 self.assertFalse(bq.is_done())
00146 self.assertFalse(bq.succeeded())
00147 bq.return_built("a")
00148 self.assertEqual(6, len(bq.built))
00149 self.assertTrue (bq.is_done())
00150 self.assertTrue (bq.succeeded())
00151
00152
00153
00154 def test_partial_build(self):
00155 bq = parallel_build.BuildQueue(["d", "e", "f"], self.serial_tracker)
00156 self.assertFalse(bq.is_done())
00157 self.assertFalse(bq.succeeded())
00158
00159 self.assertEqual("f", bq.get_valid_package())
00160 self.assertEqual(0, len(bq.built))
00161 bq.return_built("f")
00162 self.assertEqual(1, len(bq.built))
00163 self.assertFalse(bq.is_done())
00164 self.assertFalse(bq.succeeded())
00165
00166 self.assertEqual("e", bq.get_valid_package())
00167 bq.return_built("e")
00168 self.assertEqual(2, len(bq.built))
00169 self.assertFalse(bq.is_done())
00170 self.assertFalse(bq.succeeded())
00171
00172 self.assertEqual("d", bq.get_valid_package())
00173 self.assertFalse(bq.is_done())
00174 self.assertFalse(bq.succeeded())
00175 bq.return_built("d")
00176 self.assertEqual(3, len(bq.built))
00177 self.assertTrue(bq.is_done())
00178 self.assertTrue(bq.succeeded())
00179
00180
00181
00182 def test_abort_early(self):
00183 bq = parallel_build.BuildQueue(["a", "b", "c", "d", "e", "f"], self.serial_tracker)
00184 self.assertFalse(bq.is_done())
00185 self.assertFalse(bq.succeeded())
00186 self.assertEqual(0, len(bq.built))
00187
00188 self.assertEqual("f", bq.get_valid_package())
00189 bq.return_built("f")
00190 self.assertEqual(1, len(bq.built))
00191 self.assertFalse(bq.is_done())
00192 self.assertFalse(bq.succeeded())
00193
00194 self.assertEqual("e", bq.get_valid_package())
00195 bq.return_built("e")
00196 self.assertEqual(2, len(bq.built))
00197 self.assertFalse(bq.is_done())
00198 self.assertFalse(bq.succeeded())
00199
00200 self.assertEqual("d", bq.get_valid_package())
00201 bq.return_built("d")
00202 self.assertEqual(3, len(bq.built))
00203 self.assertFalse(bq.is_done())
00204 self.assertFalse(bq.succeeded())
00205
00206 bq.stop()
00207 self.assertTrue(bq.is_done())
00208 self.assertFalse(bq.succeeded())
00209
00210 self.assertEqual(None, bq.get_valid_package())
00211
00212
00213 def test_parallel_build(self):
00214 bq = parallel_build.BuildQueue(["a", "b", "c", "d", "e", "f"], self.parallel_tracker)
00215 self.assertFalse(bq.is_done())
00216 self.assertFalse(bq.succeeded())
00217
00218 dependents = ["b", "c", "d", "e", "f"]
00219 count = 0
00220 total = 6
00221 while len(dependents) > 0:
00222 result= bq.get_valid_package()
00223 done = len(bq.built)
00224 pkgs = bq._total_pkgs
00225 self.assertTrue(result in dependents)
00226
00227 dependents.remove(result)
00228 self.assertEqual(count, done)
00229 self.assertEqual(total, pkgs)
00230 self.assertFalse(bq.is_done())
00231 self.assertFalse(bq.succeeded())
00232 bq.return_built(result)
00233 count = count + 1
00234 self.assertFalse(bq.is_done())
00235 self.assertFalse(bq.succeeded())
00236
00237
00238 self.assertEqual("a", bq.get_valid_package())
00239 self.assertFalse(bq.is_done())
00240 self.assertFalse(bq.succeeded())
00241 bq.return_built("a")
00242 self.assertTrue (bq.is_done())
00243 self.assertTrue (bq.succeeded())
00244
00245
00246
00247
00248
00249 if __name__ == '__main__':
00250 rosunit.unitrun('test_rosmake', "dependency_tracker", TestDependencyTracker, sys.argv, coverage_packages=['rosmake'])
00251 rosunit.unitrun('test_rosmake', "build_queue", TestBuildQueue, sys.argv, coverage_packages=['rosmake'])