blob: 6761c05a3746bda31ca9daf0bc51ebfab08062ec [file] [log] [blame]
jadmanskia543fb02008-09-15 14:30:25 +00001#!/usr/bin/python
2
showard4cfdce12009-06-15 20:23:29 +00003import unittest, os, time, re, glob, logging
jadmanskia543fb02008-09-15 14:30:25 +00004import common
5from autotest_lib.client.common_lib.test_utils import mock
mbligh53da18e2009-01-05 21:13:26 +00006from autotest_lib.client.bin import kernel, job, utils, kernelexpand
jadmanskia543fb02008-09-15 14:30:25 +00007from autotest_lib.client.bin import kernel_config, boottool, os_dep
8
Eric Li6f27d4f2010-09-29 10:55:17 -07009
10class TestAddKernelToBootLoader(unittest.TestCase):
11
12 def add_to_bootloader(self, base_args, args, bootloader_args,
13 bootloader_root, tag='image', image='image',
14 initrd='initrd'):
15 god = mock.mock_god()
16 bootloader = god.create_mock_class(boottool.boottool, "boottool")
17
18 # record
19 bootloader.remove_kernel.expect_call(tag)
20 bootloader.add_kernel.expect_call(image, tag, initrd=initrd,
Eric Lie0493a42010-11-15 13:05:43 -080021 args='_dummy_', root=bootloader_root)
22
23 for a in bootloader_args.split():
24 bootloader.add_args.expect_call(kernel=tag, args=a)
25 bootloader.remove_args.expect_call(kernel=tag, args='_dummy_')
Eric Li6f27d4f2010-09-29 10:55:17 -070026
27 # run and check
28 kernel._add_kernel_to_bootloader(bootloader, base_args, tag, args,
29 image, initrd)
30 god.check_playback()
31
32
33 def test_add_kernel_to_bootloader(self):
34 self.add_to_bootloader(base_args='baseargs', args='',
35 bootloader_args='baseargs', bootloader_root=None)
36 self.add_to_bootloader(base_args='arg1 root=/dev/oldroot arg2',
37 args='root=/dev/newroot arg3',
38 bootloader_args='arg1 arg2 arg3',
39 bootloader_root='/dev/newroot')
40
41
42class TestBootableKernel(unittest.TestCase):
43
44 def setUp(self):
45 self.god = mock.mock_god()
46 self.god.stub_function(time, "time")
47 self.god.stub_function(utils, "system")
48 self.god.stub_function(kernel, "_add_kernel_to_bootloader")
49 job_ = self.god.create_mock_class(job.job, "job")
50 self.kernel = kernel.BootableKernel(job_)
51 self.kernel.job.bootloader = self.god.create_mock_class(
52 boottool.boottool, "boottool")
53
54
55 def tearDown(self):
56 # note: time.time() can only be unstubbed via tearDown()
57 self.god.unstub_all()
58
59
60 def boot_kernel(self, ident_check):
61 notes = "applied_patches"
62 when = 1
63 args = ''
64 base_args = 'base_args'
65 tag = 'ident'
66 subdir = 'subdir'
67 self.kernel.image = 'image'
68 self.kernel.initrd = 'initrd'
69 self.kernel.installed_as = tag
70
71 # record
72 args_ = args
73 if ident_check:
74 time.time.expect_call().and_return(when)
75 args_ += " IDENT=%d" % when
76 status = ["job.end_reboot_and_verify", when, tag, subdir, notes]
77 else:
78 status = ["job.end_reboot", subdir, tag, notes]
79 self.kernel.job.next_step_prepend.expect_call(status)
80 self.kernel.job.config_get.expect_call(
81 'boot.default_args').and_return(base_args)
82 kernel._add_kernel_to_bootloader.expect_call(
83 self.kernel.job.bootloader, base_args, tag,
84 args_, self.kernel.image, self.kernel.initrd)
85 utils.system.expect_call('touch /fastboot')
86 self.kernel.job.start_reboot.expect_call()
87 self.kernel.job.reboot.expect_call(tag=tag)
88
89 # run and check
90 self.kernel._boot_kernel(args=args, ident_check=ident_check,
91 expected_ident=tag, subdir=subdir, notes=notes)
92 self.god.check_playback()
93
94
95 def test_boot_kernel(self):
96 self.boot_kernel(ident_check=False)
97 self.boot_kernel(ident_check=True)
98
99
jadmanskia543fb02008-09-15 14:30:25 +0000100class TestKernel(unittest.TestCase):
101 def setUp(self):
102 self.god = mock.mock_god()
103
showard4cfdce12009-06-15 20:23:29 +0000104 logging.disable(logging.CRITICAL)
105
jadmanskia543fb02008-09-15 14:30:25 +0000106 self.god.stub_function(time, "time")
107 self.god.stub_function(os, "mkdir")
108 self.god.stub_function(os, "chdir")
109 self.god.stub_function(os, "symlink")
110 self.god.stub_function(os, "remove")
111 self.god.stub_function(os.path, "isdir")
112 self.god.stub_function(os.path, "exists")
113 self.god.stub_function(os.path, "isfile")
114 self.god.stub_function(os_dep, "commands")
115 self.god.stub_function(kernel, "open")
116 self.god.stub_function(utils, "system")
117 self.god.stub_function(utils, "system_output")
118 self.god.stub_function(utils, "get_file")
mbligh53da18e2009-01-05 21:13:26 +0000119 self.god.stub_function(utils, "get_current_kernel_arch")
120 self.god.stub_function(utils, "cat_file_to_cmd")
121 self.god.stub_function(utils, "force_copy")
122 self.god.stub_function(utils, "extract_tarball_to_dir")
123 self.god.stub_function(utils, "count_cpus")
124 self.god.stub_function(utils, "get_os_vendor")
jadmanskia543fb02008-09-15 14:30:25 +0000125 self.god.stub_function(kernelexpand, "expand_classic")
126 self.god.stub_function(kernel_config, "modules_needed")
127 self.god.stub_function(glob, "glob")
showard75cdfee2009-06-10 17:40:41 +0000128 def dummy_mark(filename, msg):
129 pass
130 self.god.stub_with(kernel, '_mark', dummy_mark)
jadmanskia543fb02008-09-15 14:30:25 +0000131
132 self.job = self.god.create_mock_class(job.job, "job")
133 self.job.bootloader = self.god.create_mock_class(boottool.boottool,
134 "boottool")
135
showard75cdfee2009-06-10 17:40:41 +0000136 class DummyLoggingManager(object):
137 def tee_redirect_debug_dir(self, *args, **kwargs):
138 pass
139
140
141 def restore(self, *args, **kwargs):
142 pass
143
144 self.job.logging = DummyLoggingManager()
145
jadmanskia543fb02008-09-15 14:30:25 +0000146 self.job.autodir = "autodir"
147 self.base_tree = "2.6.24"
148 self.tmp_dir = "tmpdir"
149 self.subdir = "subdir"
150
151
152 def tearDown(self):
153 self.god.unstub_all()
154
155
156 def construct_kernel(self):
157 self.kernel = kernel.kernel.__new__(kernel.kernel)
158 self.god.stub_function(self.kernel, "extract")
159
160 # setup
161 self.src_dir = os.path.join(self.tmp_dir, 'src')
162 self.build_dir = os.path.join(self.tmp_dir, "build_dir")
163 self.config_dir = os.path.join(self.subdir, 'config')
164 self.log_dir = os.path.join(self.subdir, 'debug')
165 self.results_dir = os.path.join(self.subdir, 'results')
166
167 # record
168 os.path.isdir.expect_call(self.src_dir).and_return(True)
169 utils.system.expect_call('rm -rf ' + self.src_dir)
170 os.path.isdir.expect_call(self.build_dir).and_return(True)
171 utils.system.expect_call('rm -rf ' + self.build_dir)
172 os.path.exists.expect_call(self.src_dir).and_return(False)
173 os.mkdir.expect_call(self.src_dir)
174 for path in [self.config_dir, self.log_dir, self.results_dir]:
175 os.path.exists.expect_call(path).and_return(True)
176 utils.system.expect_call('rm -rf ' + path)
177 os.mkdir.expect_call(path)
178
179 logpath = os.path.join(self.log_dir, 'build_log')
180 self.logfile = self.god.create_mock_class(file, "file")
181 kernel.open.expect_call(logpath, 'w+').and_return(self.logfile)
mbligh53da18e2009-01-05 21:13:26 +0000182 utils.get_current_kernel_arch.expect_call().and_return('ia64')
jadmanskia543fb02008-09-15 14:30:25 +0000183 self.logfile.write.expect_call('BASE: %s\n' % self.base_tree)
184 self.kernel.extract.expect_call(self.base_tree)
185
186 # finish creation of kernel object and test (and unstub extract)
187 self.kernel.__init__(self.job, self.base_tree, self.subdir,
188 self.tmp_dir, "build_dir")
189 self.god.check_playback()
190 self.god.unstub(self.kernel, "extract")
191
192
193 def test_constructor(self):
194 self.construct_kernel()
195
196
197 def test_kernelexpand1(self):
198 self.construct_kernel()
199
200 ret_val = self.kernel.kernelexpand("/path/to/kernel")
201 self.assertEquals(ret_val, ["/path/to/kernel"])
202 self.god.check_playback()
203
204
205 def test_kernel_expand2(self):
206 self.construct_kernel()
207 kernel = "kernel.tar.gz"
208
209 # record
210 self.job.config_get.expect_call('mirror.mirrors').and_return('mirror')
211 kernelexpand.expand_classic.expect_call(kernel,
212 'mirror').and_return('patches')
213
214 # run
215 self.assertEquals(self.kernel.kernelexpand(kernel), 'patches')
216 self.god.check_playback()
217
218
219 def test_kernel_expand3(self):
220 self.construct_kernel()
221 kernel = "kernel.tar.gz"
222
223 # record
224 self.job.config_get.expect_call('mirror.mirrors')
225 self.job.config_get.expect_call(
226 'mirror.ftp_kernel_org').and_return('mirror')
227 korg = 'http://www.kernel.org/pub/linux/kernel'
228 mirrors = [
229 [ korg + '/v2.6', 'mirror' + '/v2.6' ],
230 [ korg + '/people/akpm/patches/2.6', 'mirror' + '/akpm' ],
231 [ korg + '/people/mbligh', 'mirror' + '/mbligh' ],
232 ]
233 kernelexpand.expand_classic.expect_call(kernel,
234 mirrors).and_return('patches')
235
236 # run
237 self.assertEquals(self.kernel.kernelexpand(kernel), 'patches')
238 self.god.check_playback()
239
240
241 def test_extract1(self):
242 self.construct_kernel()
243
244 # setup
245 self.god.stub_function(self.kernel, "get_kernel_tree")
246
247 # record
248 os.path.exists.expect_call(self.base_tree).and_return(True)
249 self.kernel.get_kernel_tree.expect_call(self.base_tree)
250 self.job.record.expect_call('GOOD', self.subdir, 'kernel.extract')
251
252 # run
253 self.kernel.extract(self.base_tree)
254 self.god.check_playback()
255 self.god.unstub(self.kernel, "get_kernel_tree")
256
257
258 def test_extract2(self):
259 self.construct_kernel()
260
261 # setup
262 self.god.stub_function(self.kernel, "kernelexpand")
263 self.god.stub_function(self.kernel, "get_kernel_tree")
264 self.god.stub_function(self.kernel, "patch")
265
266 # record
267 os.path.exists.expect_call(self.base_tree).and_return(False)
268 components = ["component0", "component1"]
269 self.kernel.kernelexpand.expect_call(self.base_tree).and_return(
270 components)
271 self.kernel.get_kernel_tree.expect_call(components[0])
272 self.kernel.patch.expect_call(components[1])
273 self.job.record.expect_call('GOOD', self.subdir, 'kernel.extract')
274
275 # run
276 self.kernel.extract(self.base_tree)
277 self.god.check_playback()
278 self.god.unstub(self.kernel, "kernelexpand")
279 self.god.unstub(self.kernel, "get_kernel_tree")
280 self.god.unstub(self.kernel, "patch")
281
282
283 def test_patch1(self):
284 self.construct_kernel()
285 patches = ('patch1', 'patch2')
286 self.god.stub_function(self.kernel, "apply_patches")
287 self.god.stub_function(self.kernel, "get_patches")
288
289 #record
290 self.kernel.get_patches.expect_call(patches).and_return(patches)
291 self.kernel.apply_patches.expect_call(patches)
292 self.job.record.expect_call('GOOD', self.subdir, 'kernel.patch')
293
294 #run
295 self.kernel.patch(*patches)
296 self.god.check_playback()
297 self.god.unstub(self.kernel, "apply_patches")
298 self.god.unstub(self.kernel, "get_patches")
299
300
301 def test_patch2(self):
302 self.construct_kernel()
303 patches = []
304
305 # record
306 self.job.record.expect_call('GOOD', self.subdir, 'kernel.patch')
307
308 # run
309 self.kernel.patch(*patches)
310 self.god.check_playback()
311
312
313 def test_config(self):
314 self.construct_kernel()
315
316 # setup
317 self.god.stub_function(self.kernel, "set_cross_cc")
318 self.god.stub_class(kernel_config, "kernel_config")
319
320 # record
321 self.kernel.set_cross_cc.expect_call()
322 kernel_config.kernel_config.expect_new(self.job, self.build_dir,
323 self.config_dir, '', None,
jadmanski8b71d012008-11-06 16:46:41 +0000324 False, self.base_tree, None)
jadmanskia543fb02008-09-15 14:30:25 +0000325 self.job.record.expect_call('GOOD', self.subdir, 'kernel.config')
326
327 # run
328 self.kernel.config()
329 self.god.check_playback()
330 self.god.unstub(self.kernel, "set_cross_cc")
331
332
333 def test_get_patches(self):
334 self.construct_kernel()
335
336 # setup
337 patches = ['patch1', 'patch2', 'patch3']
338 local_patches = []
339
340 # record
341 for patch in patches:
342 dest = os.path.join(self.src_dir, os.path.basename(patch))
343 utils.get_file.expect_call(patch, dest)
344 utils.system_output.expect_call(
345 'md5sum ' + dest).and_return('md5sum')
346 local_patches.append((patch, dest, 'md5sum'))
347
348 # run and check
349 self.assertEquals(self.kernel.get_patches(patches), local_patches)
350 self.god.check_playback()
351
352
353 def test_apply_patches(self):
354 self.construct_kernel()
355
356 # setup
357 patches = []
358 patches.append(('patch1', 'patch1.gz', 'md5sum1'))
359 patches.append(('patch2', 'patch2.bz2', 'md5sum2'))
360 patches.append(('patch3', 'patch3', 'md5sum3'))
361 applied_patches = []
362
363 # record
364 os.chdir.expect_call(self.build_dir)
365
366 patch_id = "%s %s %s" % ('patch1', 'patch1', 'md5sum1')
367 log = "PATCH: " + patch_id + "\n"
mbligh53da18e2009-01-05 21:13:26 +0000368 utils.cat_file_to_cmd.expect_call('patch1.gz',
jadmanskia543fb02008-09-15 14:30:25 +0000369 'patch -p1 > /dev/null')
370 self.logfile.write.expect_call(log)
371 applied_patches.append(patch_id)
372
373 patch_id = "%s %s %s" % ('patch2', 'patch2', 'md5sum2')
374 log = "PATCH: " + patch_id + "\n"
mbligh53da18e2009-01-05 21:13:26 +0000375 utils.cat_file_to_cmd.expect_call('patch2.bz2',
jadmanskia543fb02008-09-15 14:30:25 +0000376 'patch -p1 > /dev/null')
377 self.logfile.write.expect_call(log)
378 applied_patches.append(patch_id)
379
mbligh53da18e2009-01-05 21:13:26 +0000380 utils.force_copy.expect_call('patch3',
jadmanskia543fb02008-09-15 14:30:25 +0000381 self.results_dir).and_return('local_patch3')
382 self.job.relative_path.expect_call('local_patch3').and_return(
383 'rel_local_patch3')
384 patch_id = "%s %s %s" % ('patch3', 'rel_local_patch3', 'md5sum3')
385 log = "PATCH: " + patch_id + "\n"
mbligh53da18e2009-01-05 21:13:26 +0000386 utils.cat_file_to_cmd.expect_call('patch3',
jadmanskia543fb02008-09-15 14:30:25 +0000387 'patch -p1 > /dev/null')
388 self.logfile.write.expect_call(log)
389 applied_patches.append(patch_id)
390
391 # run and test
392 self.kernel.apply_patches(patches)
393 self.assertEquals(self.kernel.applied_patches, applied_patches)
394 self.god.check_playback()
395
396
397 def test_get_kernel_tree1(self):
398 self.construct_kernel()
399
400 # record
401 os.path.isdir.expect_call(self.base_tree).and_return(True)
402 os.symlink.expect_call(self.base_tree, self.build_dir)
403
404 # run and check
405 self.kernel.get_kernel_tree(self.base_tree)
406 self.god.check_playback()
407
408
409 def test_get_kernel_tree2(self):
410 self.construct_kernel()
411
412 # record
413 os.path.isdir.expect_call(self.base_tree).and_return(False)
414 os.chdir.expect_call(os.path.dirname(self.src_dir))
415 tarball = os.path.join(self.src_dir, os.path.basename(self.base_tree))
416 utils.get_file.expect_call(self.base_tree, tarball)
mbligh53da18e2009-01-05 21:13:26 +0000417 utils.extract_tarball_to_dir.expect_call(tarball,
jadmanskia543fb02008-09-15 14:30:25 +0000418 self.build_dir)
419
420 # run and check
421 self.kernel.get_kernel_tree(self.base_tree)
422 self.god.check_playback()
423
424
425 def test_extraversion(self):
426 self.construct_kernel()
427 tag = "tag"
428
429 # record
430 os.chdir.expect_call(self.build_dir)
431 extraversion_sub = r's/^EXTRAVERSION =\s*\(.*\)/EXTRAVERSION = '
432 p = extraversion_sub + '\\1-%s/' % tag
433 utils.system.expect_call('mv Makefile Makefile.old')
434 utils.system.expect_call('sed "%s" < Makefile.old > Makefile' % p)
435
436 # run and check
437 self.kernel.extraversion(tag)
438 self.god.check_playback()
439
440
441 def test_build(self):
442 self.construct_kernel()
443 self.god.stub_function(self.kernel, "extraversion")
444 self.god.stub_function(self.kernel, "set_cross_cc")
445 self.god.stub_function(self.kernel, "get_kernel_build_ver")
446 self.kernel.build_target = 'build_target'
447
448 # record
449 os_dep.commands.expect_call('gcc', 'make')
450 logfile = os.path.join(self.log_dir, 'kernel_build')
451 os.chdir.expect_call(self.build_dir)
452 self.kernel.extraversion.expect_call('autotest')
453 self.kernel.set_cross_cc.expect_call()
454 utils.system.expect_call('make dep', ignore_status=True)
mbligh53da18e2009-01-05 21:13:26 +0000455 utils.count_cpus.expect_call().and_return(4)
jadmanskia543fb02008-09-15 14:30:25 +0000456 threads = 2 * 4
457 build_string = 'make -j %d %s %s' % (threads, '', 'build_target')
458 utils.system.expect_call(build_string)
459 kernel_config.modules_needed.expect_call('.config').and_return(True)
460 utils.system.expect_call('make -j %d modules' % (threads))
461 self.kernel.get_kernel_build_ver.expect_call().and_return('2.6.24')
462 kernel_version = re.sub('-autotest', '', '2.6.24')
463 self.logfile.write.expect_call('BUILD VERSION: %s\n' % kernel_version)
mbligh53da18e2009-01-05 21:13:26 +0000464 utils.force_copy.expect_call(self.build_dir+'/System.map',
jadmanskia543fb02008-09-15 14:30:25 +0000465 self.results_dir)
466 self.job.record.expect_call('GOOD', self.subdir, 'kernel.build')
467
468 # run and check
469 self.kernel.build()
470 self.god.check_playback()
471
472
473 def test_build_timed(self):
474 self.construct_kernel()
475 self.god.stub_function(self.kernel, "set_cross_cc")
476 self.god.stub_function(self.kernel, "clean")
477
478 # record
479 os.chdir.expect_call(self.build_dir)
480 self.kernel.set_cross_cc.expect_call()
Eric Lie0493a42010-11-15 13:05:43 -0800481 self.kernel.clean.expect_call()
jadmanskia543fb02008-09-15 14:30:25 +0000482 build_string = "/usr/bin/time -o /dev/null make -j 8 vmlinux"
483 build_string += ' > /dev/null 2>&1'
484 utils.system.expect_call(build_string)
485 os.path.isfile.expect_call('vmlinux').and_return(True)
486
487 # run and check
488 self.kernel.build_timed(threads=8)
489 self.god.check_playback()
490
491
492 def test_clean(self):
493 self.construct_kernel()
494
495 # record
496 os.chdir.expect_call(self.build_dir)
497 utils.system.expect_call('make clean > /dev/null 2> /dev/null')
498 self.job.record.expect_call('GOOD', self.subdir, 'kernel.clean')
499
500 # run and check
501 self.kernel.clean()
502 self.god.check_playback()
503
504
505 def test_mkinitrd(self):
506 self.construct_kernel()
507
508 # record
mbligh53da18e2009-01-05 21:13:26 +0000509 utils.get_os_vendor.expect_call().and_return('Ubuntu')
jadmanskia543fb02008-09-15 14:30:25 +0000510 os.path.isfile.expect_call('initrd').and_return(True)
511 os.remove.expect_call('initrd')
512 self.job.config_get.expect_call(
513 'kernel.mkinitrd_extra_args').and_return(None)
514 args = ''
Eric Lie0493a42010-11-15 13:05:43 -0800515 glob.glob.expect_call('/lib/modules/2.6.24*').and_return(['2.6.24'])
jadmanskia543fb02008-09-15 14:30:25 +0000516 os.path.isfile.expect_call('/usr/sbin/mkinitrd').and_return(True)
517 cmd = '/usr/sbin/mkinitrd'
518 utils.system.expect_call('%s %s -o initrd 2.6.24' % (cmd, args))
519 self.job.record.expect_call('GOOD', self.subdir, 'kernel.mkinitrd')
520
521 # run and check
522 self.kernel.mkinitrd(version="2.6.24", image="image",
523 system_map="system_map", initrd="initrd")
524 self.god.check_playback()
525
526
527 def test_install(self):
528 self.construct_kernel()
529 tag = 'autotest'
530 prefix = '/'
531 self.kernel.build_image = None
532 self.kernel.build_target = 'build_target'
533 self.god.stub_function(self.kernel, "get_kernel_build_ver")
534 self.god.stub_function(self.kernel, "mkinitrd")
535
536 # record
537 os.chdir.expect_call(self.build_dir)
538 os.path.isdir.expect_call(prefix).and_return(False)
539 os.mkdir.expect_call(prefix)
540 boot_dir = os.path.join(prefix, 'boot')
541 os.path.isdir.expect_call(boot_dir).and_return(False)
542 os.mkdir.expect_call(boot_dir)
543 glob.glob.expect_call(
544 'arch/*/boot/' + 'build_target').and_return('')
545 build_image = self.kernel.build_target
mbligh53da18e2009-01-05 21:13:26 +0000546 utils.force_copy.expect_call('vmlinux',
jadmanskia543fb02008-09-15 14:30:25 +0000547 '/boot/vmlinux-autotest')
mbligh53da18e2009-01-05 21:13:26 +0000548 utils.force_copy.expect_call('build_target',
jadmanskia543fb02008-09-15 14:30:25 +0000549 '/boot/vmlinuz-autotest')
mbligh53da18e2009-01-05 21:13:26 +0000550 utils.force_copy.expect_call('System.map',
jadmanskia543fb02008-09-15 14:30:25 +0000551 '/boot/System.map-autotest')
mbligh53da18e2009-01-05 21:13:26 +0000552 utils.force_copy.expect_call('.config',
jadmanskia543fb02008-09-15 14:30:25 +0000553 '/boot/config-autotest')
554 kernel_config.modules_needed.expect_call('.config').and_return(True)
555 utils.system.expect_call('make modules_install INSTALL_MOD_PATH=%s'
556 % prefix)
557 initrd = boot_dir + '/initrd-' + tag
558 self.kernel.get_kernel_build_ver.expect_call().and_return('2.6.24')
559 self.kernel.mkinitrd.expect_call('2.6.24', '/boot/vmlinuz-autotest',
560 '/boot/System.map-autotest', '/boot/initrd-autotest')
561 self.job.record.expect_call('GOOD', self.subdir, 'kernel.install')
562
563 # run and check
564 self.kernel.install()
565 self.god.check_playback()
566
567
jadmanskia543fb02008-09-15 14:30:25 +0000568 def test_get_kernel_build_arch1(self):
569 self.construct_kernel()
570
571 # record
mbligh53da18e2009-01-05 21:13:26 +0000572 utils.get_current_kernel_arch.expect_call().and_return("i386")
jadmanskia543fb02008-09-15 14:30:25 +0000573
574 # run and check
575 self.assertEquals(self.kernel.get_kernel_build_arch(), "i386")
576 self.god.check_playback()
577
578
579 def test_get_kernel_build_arch2(self):
580 self.construct_kernel()
581
582 # run and check
583 self.assertEquals(self.kernel.get_kernel_build_arch('i586'), "i386")
584 self.god.check_playback()
585
586
587 def test_get_kernel_build_release(self):
588 self.construct_kernel()
589 mock_file = self.god.create_mock_class(file, "file")
590
591 # record
592 for f in [self.build_dir + "/include/linux/version.h",
593 self.build_dir + "/include/linux/utsrelease.h"]:
594 os.path.exists.expect_call(f).and_return(True)
595 kernel.open.expect_call(f, 'r').and_return(mock_file)
596 mock_file.readlines.expect_call().and_return("Some lines")
597 mock_file.close.expect_call()
598
showard1104cd12009-11-13 20:45:10 +0000599 for f in [self.build_dir + "/include/linux/compile.h",
600 self.build_dir + "/include/generated/utsrelease.h",
601 self.build_dir + "/include/generated/compile.h"]:
602 os.path.exists.expect_call(f).and_return(False)
jadmanskia543fb02008-09-15 14:30:25 +0000603
604 # run and test
605 self.kernel.get_kernel_build_release()
606 self.god.check_playback()
607
608
609 def test_get_kernel_build_ident(self):
610 self.construct_kernel()
611 self.god.stub_function(self.kernel, "get_kernel_build_release")
612
613 # record
614 self.kernel.get_kernel_build_release.expect_call().and_return(
615 ("AwesomeRelease", "1.0"))
616
617 # run and check
618 self.assertEquals(self.kernel.get_kernel_build_ident(),
619 "AwesomeRelease::1.0")
620 self.god.check_playback()
621
622
623 def test_boot(self):
624 self.construct_kernel()
625 self.god.stub_function(self.kernel, "get_kernel_build_ident")
626 self.god.stub_function(self.kernel, "install")
Eric Li6f27d4f2010-09-29 10:55:17 -0700627 self.god.stub_function(self.kernel, "_boot_kernel")
jadmanskia543fb02008-09-15 14:30:25 +0000628 self.kernel.applied_patches = "applied_patches"
Eric Li6f27d4f2010-09-29 10:55:17 -0700629 self.kernel.installed_as = None
jadmanskia543fb02008-09-15 14:30:25 +0000630 args = ''
Eric Li6f27d4f2010-09-29 10:55:17 -0700631 expected_ident = 'ident'
632 ident = True
jadmanskia543fb02008-09-15 14:30:25 +0000633
634 # record
jadmanskia543fb02008-09-15 14:30:25 +0000635 self.kernel.install.expect_call()
Eric Li6f27d4f2010-09-29 10:55:17 -0700636 self.kernel.get_kernel_build_ident.expect_call(
637 ).and_return(expected_ident)
638 self.kernel._boot_kernel.expect_call(
639 args, ident, expected_ident,
640 self.subdir, self.kernel.applied_patches)
jadmanskia543fb02008-09-15 14:30:25 +0000641
642 # run and check
Eric Li6f27d4f2010-09-29 10:55:17 -0700643 self.kernel.boot(args=args, ident=ident)
jadmanski067b26c2008-09-25 19:46:56 +0000644 self.god.check_playback()
645
646
jadmanskia543fb02008-09-15 14:30:25 +0000647if __name__ == "__main__":
648 unittest.main()