summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/bldviewer
diff options
context:
space:
mode:
authorAndreea Proca <andreea.b.proca@intel.com>2014-01-14 16:01:08 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-01-27 21:01:05 +0000
commitbaaab36f41636e571d021dba5496c29d2224937c (patch)
tree814d90e1c9d54c8e0b228c61ad5a9253c253591c /bitbake/lib/toaster/bldviewer
parentb0b1acbe623c1c126af2abc1cc332d993dcaf15c (diff)
downloadpoky-baaab36f41636e571d021dba5496c29d2224937c.tar.gz
bitbake: toaster: Add initial tests
This adds the initial api tests for toaster, using Django's unittest modules. (Bitbake rev: daf9a61fbf69a46b7afd781a6175b05b05fd452f) Signed-off-by: Andreea Proca <andreea.b.proca@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/bldviewer')
-rw-r--r--bitbake/lib/toaster/bldviewer/api.py7
-rw-r--r--bitbake/lib/toaster/bldviewer/tests.py342
-rw-r--r--bitbake/lib/toaster/bldviewer/views.py6
3 files changed, 350 insertions, 5 deletions
diff --git a/bitbake/lib/toaster/bldviewer/api.py b/bitbake/lib/toaster/bldviewer/api.py
index 596e6a93c6..654864e1e8 100644
--- a/bitbake/lib/toaster/bldviewer/api.py
+++ b/bitbake/lib/toaster/bldviewer/api.py
@@ -27,10 +27,11 @@ urlpatterns = patterns('bldviewer.views',
27 url(r'^targets$', 'model_explorer', {'model_name':'target'}, name='targets'), 27 url(r'^targets$', 'model_explorer', {'model_name':'target'}, name='targets'),
28 url(r'^tasks$', 'model_explorer', {'model_name':'task'}, name='task'), 28 url(r'^tasks$', 'model_explorer', {'model_name':'task'}, name='task'),
29 url(r'^task_dependencies$', 'model_explorer', {'model_name':'task_dependency'}, name='task_dependencies'), 29 url(r'^task_dependencies$', 'model_explorer', {'model_name':'task_dependency'}, name='task_dependencies'),
30 url(r'^packages$', 'model_explorer', {'model_name':'build_package'}, name='build_packages'), 30 url(r'^packages$', 'model_explorer', {'model_name':'package'}, name='package'),
31 url(r'^package_dependencies$', 'model_explorer', {'model_name':'build_package_dependency'}, name='build_package_dependencies'), 31 url(r'^package_dependencies$', 'model_explorer', {'model_name':'package_dependency'}, name='package_dependency'),
32 url(r'^target_packages$', 'model_explorer', {'model_name':'target_package'}, name='target_packages'), 32 url(r'^target_packages$', 'model_explorer', {'model_name':'target_package'}, name='target_packages'),
33 url(r'^package_files$', 'model_explorer', {'model_name':'build_file'}, name='build_files'), 33 url(r'^target_installed_packages$', 'model_explorer', {'model_name':'target_installed_package'}, name='target_installed_package'),
34 url(r'^package_files$', 'model_explorer', {'model_name':'build_file'}, name='build_file'),
34 url(r'^layers$', 'model_explorer', {'model_name':'layer'}, name='layer'), 35 url(r'^layers$', 'model_explorer', {'model_name':'layer'}, name='layer'),
35 url(r'^layerversions$', 'model_explorer', {'model_name':'layerversion'}, name='layerversion'), 36 url(r'^layerversions$', 'model_explorer', {'model_name':'layerversion'}, name='layerversion'),
36 url(r'^recipes$', 'model_explorer', {'model_name':'recipe'}, name='recipe'), 37 url(r'^recipes$', 'model_explorer', {'model_name':'recipe'}, name='recipe'),
diff --git a/bitbake/lib/toaster/bldviewer/tests.py b/bitbake/lib/toaster/bldviewer/tests.py
new file mode 100644
index 0000000000..761165b8a4
--- /dev/null
+++ b/bitbake/lib/toaster/bldviewer/tests.py
@@ -0,0 +1,342 @@
1"""
2This file demonstrates writing tests using the unittest module. These will pass
3when you run "manage.py test".
4
5Replace this with more appropriate tests for your application.
6"""
7from django.test import TestCase
8from django.test.client import Client
9from django.db.models import Count, Q
10from orm.models import Target, Recipe, Recipe_Dependency, Layer_Version, Target_Installed_Package
11from orm.models import Build, Task, Layer, Package, Package_File, LogMessage, Variable, VariableHistory
12import json, os, re, urllib, shlex
13
14
15class Tests(TestCase):
16 fixtures = ['orm_views_testdata.json']
17
18 def test_builds(self):
19 client = Client()
20 resp = client.get('http://localhost:8000/api/1.0/builds')
21 self.assertEqual(resp.status_code, 200)
22 response = json.loads(resp.content)
23 self.assertTrue(len(json.loads(response['list'])) > 0)
24 for item in json.loads(response['list']):
25 fields = item['fields']
26 self.assertTrue(fields["machine"] == "qemux86")
27 self.assertTrue(fields["distro"] == "poky")
28 self.assertTrue(fields["image_fstypes"] == "tar.bz2 ext3")
29 self.assertTrue(fields["bitbake_version"] == "1.21.1")
30 self.assertTrue("1.5+snapshot-" in fields["distro_version"])
31 self.assertEqual(fields["outcome"], 0)
32 self.assertEqual(fields["errors_no"], 0)
33 log_path = "/tmp/log/cooker/qemux86/"
34 self.assertTrue(log_path in fields["cooker_log_path"])
35 self.assertTrue(".log" in fields["cooker_log_path"])
36
37 def test_targets(self):
38 client = Client()
39 resp = client.get('http://localhost:8000/api/1.0/targets')
40 self.assertEqual(resp.status_code, 200)
41 response = json.loads(resp.content)
42 self.assertTrue(len(json.loads(response['list'])) > 0)
43 for item in json.loads(response['list']):
44 fields = item['fields']
45 self.assertTrue(fields["is_image"] == True)
46 self.assertTrue(fields["target"] == "core-image-minimal")
47
48 def test_tasks(self):
49 client = Client()
50 resp = client.get('http://localhost:8000/api/1.0/tasks')
51 self.assertEqual(resp.status_code, 200)
52 response = json.loads(resp.content)
53 self.assertTrue(len(json.loads(response['list'])) > 0)
54 recipe_id = self.get_recipes_id("pseudo-native")
55 print recipe_id
56 for item in json.loads(response['list']):
57 fields = item['fields']
58 if fields["build"] == 1 and fields["task_name"] == "do_populate_lic_setscene" and fields["recipe"] == recipe_id and fields["task_executed"] == True:
59 self.assertTrue(fields["message"] == "recipe pseudo-native-1.5.1-r4: task do_populate_lic_setscene: Succeeded")
60 self.assertTrue(fields["cpu_usage"] == "6.3")
61 self.assertTrue(fields["disk_io"] == 124)
62 self.assertTrue(fields["script_type"] == 2)
63 self.assertTrue(fields["path_to_sstate_obj"] == "")
64 self.assertTrue(fields["elapsed_time"] == "0.103494")
65 self.assertTrue("tmp/work/i686-linux/pseudo-native/1.5.1-r4/temp/log.do_populate_lic_setscene.5867" in fields["logfile"])
66 self.assertTrue(fields["sstate_result"] == 0)
67 self.assertTrue(fields["outcome"] == 0)
68 if fields["build"] == 1 and fields["task_name"] == "do_populate_lic" and fields["recipe"] == recipe_id and fields["task_executed"] == True:
69 self.assertTrue(fields["cpu_usage"] == None)
70 self.assertTrue(fields["disk_io"] == None)
71 self.assertTrue(fields["script_type"] == 2)
72 self.assertTrue(fields["path_to_sstate_obj"] == "")
73 self.assertTrue(fields["elapsed_time"] == "0")
74 self.assertTrue(fields["logfile"], None)
75 self.assertTrue(fields["sstate_result"] == 3)
76 self.assertTrue(fields["outcome"] == 2)
77
78 def test_layers(self):
79 client = Client()
80 resp = client.get('http://localhost:8000/api/1.0/layers')
81 self.assertEqual(resp.status_code, 200)
82 response = json.loads(resp.content)
83 self.assertTrue(len(json.loads(response['list'])) > 0)
84 for item in json.loads(response['list']):
85 fields = item['fields']
86 if fields["name"] == "meta-yocto-bsp":
87 self.assertTrue(fields["local_path"].endswith("meta-yocto-bsp"))
88 self.assertTrue(fields["layer_index_url"] == "http://layers.openembedded.org/layerindex/layer/meta-yocto-bsp/")
89 elif fields["name"] == "meta":
90 self.assertTrue(fields["local_path"].endswith("/meta"))
91 self.assertTrue(fields["layer_index_url"] == "http://layers.openembedded.org/layerindex/layer/openembedded-core/")
92 elif fields["name"] == "meta-yocto":
93 self.assertTrue(fields["local_path"].endswith("/meta-yocto"))
94 self.assertTrue(fields["layer_index_url"] == "http://layers.openembedded.org/layerindex/layer/meta-yocto/")
95
96 def test_layerversions(self):
97 client = Client()
98 resp = client.get('http://localhost:8000/api/1.0/layerversions')
99 self.assertEqual(resp.status_code, 200)
100 response = json.loads(resp.content)
101 self.assertTrue(len(json.loads(response['list'])) > 0)
102 layer_id = self.get_layer_id("meta")
103 find = False
104 for item in json.loads(response['list']):
105 fields = item['fields']
106 if fields["layer"] == layer_id:
107 find = True
108 self.assertTrue(fields["build"] == 1)
109 self.assertTrue(fields["priority"] == 5)
110 self.assertTrue(fields["branch"] == "master")
111 self.assertTrue(find == True)
112
113 def test_recipes(self):
114 client = Client()
115 resp = client.get('http://localhost:8000/api/1.0/recipes')
116 self.assertEqual(resp.status_code, 200)
117 response = json.loads(resp.content)
118 self.assertTrue(len(json.loads(response['list'])) > 0)
119 find = False
120 for item in json.loads(response['list']):
121 fields = item['fields']
122 if fields["name"] == "busybox":
123 find = True
124 self.assertTrue(fields["version"] == "1.21.1-r0")
125 self.assertTrue(fields["license"] == "GPLv2 & bzip2")
126 self.assertTrue(fields["file_path"].endswith("/meta/recipes-core/busybox/busybox_1.21.1.bb"))
127 self.assertTrue(fields["summary"] == "Tiny versions of many common UNIX utilities in a single small executable.")
128 self.assertTrue(fields["description"] == "BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides minimalist replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete POSIX environment for any small or embedded system.")
129 self.assertTrue(fields["bugtracker"] == "https://bugs.busybox.net/")
130 self.assertTrue(fields["homepage"] == "http://www.busybox.net")
131 self.assertTrue(fields["section"] == "base")
132 self.assertTrue(find == True)
133
134 def test_task_dependencies(self):
135 client = Client()
136 resp = client.get('http://localhost:8000/api/1.0/task_dependencies')
137 self.assertEqual(resp.status_code, 200)
138 response = json.loads(resp.content)
139 self.assertTrue(len(json.loads(response['list'])) > 0)
140 ids = self.get_task_id()
141 do_install = ids["do_install"]
142 do_compile = ids["do_compile"]
143 entry = False
144 for item in json.loads(response['list']):
145 fields = item['fields']
146 if fields["task"] == do_install and fields["depends_on"] == do_compile:
147 entry = True
148 self.assertTrue(entry == True)
149
150 def test_target_installed_package(self):
151 client = Client()
152 resp = client.get('http://localhost:8000/api/1.0/target_installed_packages')
153 self.assertEqual(resp.status_code, 200)
154 response = json.loads(resp.content)
155 self.assertTrue(len(json.loads(response['list'])) > 0)
156 package = self.get_package_id("udev-utils")
157 find = False
158 for item in json.loads(response['list']):
159 fields = item['fields']
160 if fields["package"] == package:
161 self.assertTrue(fields["target"], 1)
162 find = True
163 self.assertTrue(find, True)
164
165 def test_packages(self):
166 client = Client()
167 resp = client.get('http://localhost:8000/api/1.0/packages')
168 self.assertEqual(resp.status_code, 200)
169 response = json.loads(resp.content)
170 self.assertTrue(response['count'] > 0)
171 for item in json.loads(response['list']):
172 fields = item['fields']
173 if fields["name"] == "base-files-dev":
174 self.assertTrue(fields["license"] == "GPLv2")
175 self.assertTrue(fields["description"] == "The base-files package creates the basic system directory structure and provides a small set of key configuration files for the system. This package contains symbolic links, header files, and related items necessary for software development.")
176 self.assertTrue(fields["summary"] == "Miscellaneous files for the base system. - Development files")
177 self.assertTrue(fields["version"] == "3.0.14")
178 self.assertTrue(fields["build"] == 1)
179 self.assertTrue(fields["section"] == "devel")
180 self.assertTrue(fields["revision"] == "r73")
181 self.assertTrue(fields["size"] == 0)
182 self.assertTrue(fields["installed_size"] == 0)
183 self.assertTrue(self.get_recipe_name(fields["recipe"]) == "base-files")
184
185 def test_package_dependencies(self):
186 client = Client()
187 resp = client.get('http://localhost:8000/api/1.0/package_dependencies')
188 self.assertEqual(resp.status_code, 200)
189 response = json.loads(resp.content)
190 self.assertTrue(len(json.loads(response['list'])) > 0)
191 build_package = self.get_package_id("busybox")
192 build_package_id = self.get_package_id("busybox-syslog")
193 entry = False
194 for item in json.loads(response['list']):
195 fields = item['fields']
196 self.assertTrue(fields["target"] == 1)
197 if fields["package"] == build_package and fields["dep_type"] == 7 and fields["depends_on"] == build_package_id:
198 entry = True
199 self.assertTrue(entry == True)
200
201 def test_recipe_dependencies(self):
202 client = Client()
203 resp = client.get('http://localhost:8000/api/1.0/recipe_dependencies')
204 self.assertEqual(resp.status_code, 200)
205 response = json.loads(resp.content)
206 self.assertTrue(len(json.loads(response['list'])) > 0)
207 depends_on = self.get_recipes_id("autoconf-native")
208 recipe = self.get_recipes_id("ncurses")
209 entry = False
210 for item in json.loads(response['list']):
211 fields = item['fields']
212 if fields["recipe"] == recipe and fields["depends_on"] == depends_on and fields["dep_type"] == 0:
213 entry = True
214 self.assertTrue(entry == True)
215
216 def test_package_files(self):
217 client = Client()
218 resp = client.get('http://localhost:8000/api/1.0/package_files')
219 self.assertEqual(resp.status_code, 200)
220 response = json.loads(resp.content)
221 self.assertTrue(len(json.loads(response['list'])) > 0)
222 build_package = self.get_package_id("base-files")
223 entry = False
224 for item in json.loads(response['list']):
225 fields = item['fields']
226 if fields["path"] == "/etc/motd" and fields["package"] == build_package and fields["size"] == 0:
227 entry = True
228 self.assertTrue(entry == True)
229
230 def test_Variable(self):
231 client = Client()
232 resp = client.get('http://localhost:8000/api/1.0/variables')
233 self.assertEqual(resp.status_code, 200)
234 response = json.loads(resp.content)
235 self.assertTrue(len(json.loads(response['list'])) > 0)
236 for item in json.loads(response['list']):
237 fields = item['fields']
238 self.assertTrue(fields["build"] == 1)
239 if fields["variable_name"] == "USRBINPATH":
240 self.assertTrue(fields["variable_value"] == "/usr/bin")
241 self.assertTrue(fields["changed"] == False)
242 self.assertTrue(fields["description"] == "")
243 if fields["variable_name"] == "PREFERRED_PROVIDER_virtual/libx11":
244 self.assertTrue(fields["variable_value"] == "libx11")
245 self.assertTrue(fields["changed"] == False)
246 self.assertTrue(fields["description"] == "If multiple recipes provide an item, this variable determines which recipe should be given preference.")
247 if fields["variable_name"] == "base_libdir_nativesdk":
248 self.assertTrue(fields["variable_value"] == "/lib")
249
250 def test_VariableHistory(self):
251 client = Client()
252 resp = client.get('http://localhost:8000/api/1.0/variableshistory')
253 self.assertEqual(resp.status_code, 200)
254 response = json.loads(resp.content)
255 self.assertTrue(len(json.loads(response['list'])) > 0)
256 variable_id = self.get_variable_id("STAGING_INCDIR_NATIVE")
257 find = False
258 for item in json.loads(response['list']):
259 fields = item['fields']
260 if fields["variable"] == variable_id:
261 find = True
262 self.assertTrue(fields["file_name"] == "conf/bitbake.conf")
263 self.assertTrue(fields["operation"] == "set")
264 self.assertTrue(fields["line_number"] == 358)
265 self.assertTrue(find == True)
266
267 def get_task_id(self):
268 client = Client()
269 resp = client.get('http://localhost:8000/api/1.0/tasks')
270 self.assertEqual(resp.status_code, 200)
271 response = json.loads(resp.content)
272 self.assertTrue(len(json.loads(response['list'])) > 0)
273 for item in json.loads(response['list']):
274 fields = item['fields']
275 if fields["recipe"] == 7 and fields["task_name"] == "do_install":
276 do_install = item["pk"]
277 if fields["recipe"] == 7 and fields["task_name"] == "do_compile":
278 do_compile = item["pk"]
279 result = {}
280 result["do_install"] = do_install
281 result["do_compile"] = do_compile
282 return result
283
284 def get_recipes_id(self, value):
285 client = Client()
286 resp = client.get('http://localhost:8000/api/1.0/recipes')
287 self.assertEqual(resp.status_code, 200)
288 response = json.loads(resp.content)
289 self.assertTrue(len(json.loads(response['list'])) > 0)
290 for item in json.loads(response['list']):
291 fields = item['fields']
292 if fields["name"] == value:
293 return item["pk"]
294 return None
295
296 def get_recipe_name(self, value):
297 client = Client()
298 resp = client.get('http://localhost:8000/api/1.0/recipes')
299 self.assertEqual(resp.status_code, 200)
300 response = json.loads(resp.content)
301 self.assertTrue(len(json.loads(response['list'])) > 0)
302 for item in json.loads(response['list']):
303 fields = item['fields']
304 if item["pk"] == value:
305 return fields["name"]
306 return None
307
308 def get_layer_id(self, value):
309 client = Client()
310 resp = client.get('http://localhost:8000/api/1.0/layers')
311 self.assertEqual(resp.status_code, 200)
312 response = json.loads(resp.content)
313 self.assertTrue(len(json.loads(response['list'])) > 0)
314 for item in json.loads(response['list']):
315 fields = item['fields']
316 if fields["name"] == value:
317 return item["pk"]
318 return None
319
320 def get_package_id(self, field):
321 client = Client()
322 resp = client.get('http://localhost:8000/api/1.0/packages')
323 self.assertEqual(resp.status_code, 200)
324 response = json.loads(resp.content)
325 self.assertTrue(response['count'] > 0)
326 for item in json.loads(response['list']):
327 fields = item['fields']
328 if fields["name"] == field:
329 return item["pk"]
330 return None
331
332 def get_variable_id(self, field):
333 client = Client()
334 resp = client.get('http://localhost:8000/api/1.0/variables')
335 self.assertEqual(resp.status_code, 200)
336 response = json.loads(resp.content)
337 self.assertTrue(len(json.loads(response['list'])) > 0)
338 for item in json.loads(response['list']):
339 fields = item['fields']
340 if fields["variable_name"] == field:
341 return item["pk"]
342 return None
diff --git a/bitbake/lib/toaster/bldviewer/views.py b/bitbake/lib/toaster/bldviewer/views.py
index e8f6b96df7..435bc8e6bd 100644
--- a/bitbake/lib/toaster/bldviewer/views.py
+++ b/bitbake/lib/toaster/bldviewer/views.py
@@ -23,9 +23,9 @@ import operator
23 23
24from django.db.models import Q 24from django.db.models import Q
25from django.shortcuts import render 25from django.shortcuts import render
26from orm.models import Build, Target, Task, Layer, Layer_Version, Recipe, LogMessage, Variable 26from orm.models import Build, Target, Task, Layer, Layer_Version, Recipe, LogMessage, Variable, Target_Installed_Package
27from orm.models import Task_Dependency, Recipe_Dependency, Package, Package_File, Package_Dependency 27from orm.models import Task_Dependency, Recipe_Dependency, Package, Package_File, Package_Dependency
28from orm.models import Target_Installed_Package 28from orm.models import Target_Installed_Package, VariableHistory
29from django.views.decorators.cache import cache_control 29from django.views.decorators.cache import cache_control
30from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger 30from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
31 31
@@ -168,8 +168,10 @@ def model_explorer(request, model_name):
168 'recipe_dependency': Recipe_Dependency, 168 'recipe_dependency': Recipe_Dependency,
169 'package': Package, 169 'package': Package,
170 'package_dependency': Package_Dependency, 170 'package_dependency': Package_Dependency,
171 'target_installed_package': Target_Installed_Package,
171 'build_file': Package_File, 172 'build_file': Package_File,
172 'variable': Variable, 173 'variable': Variable,
174 'variablehistory': VariableHistory,
173 'logmessage': LogMessage, 175 'logmessage': LogMessage,
174 } 176 }
175 177