blob: fe40e6a1ab7cb452cefc3b4e05f8e68b99a97dc8 [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,
21 args=bootloader_args,
22 root=bootloader_root)
23
24 # run and check
25 kernel._add_kernel_to_bootloader(bootloader, base_args, tag, args,
26 image, initrd)
27 god.check_playback()
28
29
30 def test_add_kernel_to_bootloader(self):
31 self.add_to_bootloader(base_args='baseargs', args='',
32 bootloader_args='baseargs', bootloader_root=None)
33 self.add_to_bootloader(base_args='arg1 root=/dev/oldroot arg2',
34 args='root=/dev/newroot arg3',
35 bootloader_args='arg1 arg2 arg3',
36 bootloader_root='/dev/newroot')
37
38
39class TestBootableKernel(unittest.TestCase):
40
41 def setUp(self):
42 self.god = mock.mock_god()
43 self.god.stub_function(time, "time")
44 self.god.stub_function(utils, "system")
45 self.god.stub_function(kernel, "_add_kernel_to_bootloader")
46 job_ = self.god.create_mock_class(job.job, "job")
47 self.kernel = kernel.BootableKernel(job_)
48 self.kernel.job.bootloader = self.god.create_mock_class(
49 boottool.boottool, "boottool")
50
51
52 def tearDown(self):
53 # note: time.time() can only be unstubbed via tearDown()
54 self.god.unstub_all()
55
56
57 def boot_kernel(self, ident_check):
58 notes = "applied_patches"
59 when = 1
60 args = ''
61 base_args = 'base_args'
62 tag = 'ident'
63 subdir = 'subdir'
64 self.kernel.image = 'image'
65 self.kernel.initrd = 'initrd'
66 self.kernel.installed_as = tag
67
68 # record
69 args_ = args
70 if ident_check:
71 time.time.expect_call().and_return(when)
72 args_ += " IDENT=%d" % when
73 status = ["job.end_reboot_and_verify", when, tag, subdir, notes]
74 else:
75 status = ["job.end_reboot", subdir, tag, notes]
76 self.kernel.job.next_step_prepend.expect_call(status)
77 self.kernel.job.config_get.expect_call(
78 'boot.default_args').and_return(base_args)
79 kernel._add_kernel_to_bootloader.expect_call(
80 self.kernel.job.bootloader, base_args, tag,
81 args_, self.kernel.image, self.kernel.initrd)
82 utils.system.expect_call('touch /fastboot')
83 self.kernel.job.start_reboot.expect_call()
84 self.kernel.job.reboot.expect_call(tag=tag)
85
86 # run and check
87 self.kernel._boot_kernel(args=args, ident_check=ident_check,
88 expected_ident=tag, subdir=subdir, notes=notes)
89 self.god.check_playback()
90
91
92 def test_boot_kernel(self):
93 self.boot_kernel(ident_check=False)
94 self.boot_kernel(ident_check=True)
95
96
jadmanskia543fb02008-09-15 14:30:25 +000097class TestKernel(unittest.TestCase):
98 def setUp(self):
99 self.god = mock.mock_god()
100
showard4cfdce12009-06-15 20:23:29 +0000101 logging.disable(logging.CRITICAL)
102
jadmanskia543fb02008-09-15 14:30:25 +0000103 self.god.stub_function(time, "time")
104 self.god.stub_function(os, "mkdir")
105 self.god.stub_function(os, "chdir")
106 self.god.stub_function(os, "symlink")
107 self.god.stub_function(os, "remove")
108 self.god.stub_function(os.path, "isdir")
109 self.god.stub_function(os.path, "exists")
110 self.god.stub_function(os.path, "isfile")
111 self.god.stub_function(os_dep, "commands")
112 self.god.stub_function(kernel, "open")
113 self.god.stub_function(utils, "system")
114 self.god.stub_function(utils, "system_output")
115 self.god.stub_function(utils, "get_file")
mbligh53da18e2009-01-05 21:13:26 +0000116 self.god.stub_function(utils, "get_current_kernel_arch")
117 self.god.stub_function(utils, "cat_file_to_cmd")
118 self.god.stub_function(utils, "force_copy")
119 self.god.stub_function(utils, "extract_tarball_to_dir")
120 self.god.stub_function(utils, "count_cpus")
121 self.god.stub_function(utils, "get_os_vendor")
jadmanskia543fb02008-09-15 14:30:25 +0000122 self.god.stub_function(kernelexpand, "expand_classic")
123 self.god.stub_function(kernel_config, "modules_needed")
124 self.god.stub_function(glob, "glob")
showard75cdfee2009-06-10 17:40:41 +0000125 def dummy_mark(filename, msg):
126 pass
127 self.god.stub_with(kernel, '_mark', dummy_mark)
jadmanskia543fb02008-09-15 14:30:25 +0000128
129 self.job = self.god.create_mock_class(job.job, "job")
130 self.job.bootloader = self.god.create_mock_class(boottool.boottool,
131 "boottool")
132
showard75cdfee2009-06-10 17:40:41 +0000133 class DummyLoggingManager(object):
134 def tee_redirect_debug_dir(self, *args, **kwargs):
135 pass
136
137
138 def restore(self, *args, **kwargs):
139 pass
140
141 self.job.logging = DummyLoggingManager()
142
jadmanskia543fb02008-09-15 14:30:25 +0000143 self.job.autodir = "autodir"
144 self.base_tree = "2.6.24"
145 self.tmp_dir = "tmpdir"
146 self.subdir = "subdir"
147
148
149 def tearDown(self):
150 self.god.unstub_all()
151
152
153 def construct_kernel(self):
154 self.kernel = kernel.kernel.__new__(kernel.kernel)
155 self.god.stub_function(self.kernel, "extract")
156
157 # setup
158 self.src_dir = os.path.join(self.tmp_dir, 'src')
159 self.build_dir = os.path.join(self.tmp_dir, "build_dir")
160 self.config_dir = os.path.join(self.subdir, 'config')
161 self.log_dir = os.path.join(self.subdir, 'debug')
162 self.results_dir = os.path.join(self.subdir, 'results')
163
164 # record
165 os.path.isdir.expect_call(self.src_dir).and_return(True)
166 utils.system.expect_call('rm -rf ' + self.src_dir)
167 os.path.isdir.expect_call(self.build_dir).and_return(True)
168 utils.system.expect_call('rm -rf ' + self.build_dir)
169 os.path.exists.expect_call(self.src_dir).and_return(False)
170 os.mkdir.expect_call(self.src_dir)
171 for path in [self.config_dir, self.log_dir, self.results_dir]:
172 os.path.exists.expect_call(path).and_return(True)
173 utils.system.expect_call('rm -rf ' + path)
174 os.mkdir.expect_call(path)
175
176 logpath = os.path.join(self.log_dir, 'build_log')
177 self.logfile = self.god.create_mock_class(file, "file")
178 kernel.open.expect_call(logpath, 'w+').and_return(self.logfile)
mbligh53da18e2009-01-05 21:13:26 +0000179 utils.get_current_kernel_arch.expect_call().and_return('ia64')
jadmanskia543fb02008-09-15 14:30:25 +0000180 self.logfile.write.expect_call('BASE: %s\n' % self.base_tree)
181 self.kernel.extract.expect_call(self.base_tree)
182
183 # finish creation of kernel object and test (and unstub extract)
184 self.kernel.__init__(self.job, self.base_tree, self.subdir,
185 self.tmp_dir, "build_dir")
186 self.god.check_playback()
187 self.god.unstub(self.kernel, "extract")
188
189
190 def test_constructor(self):
191 self.construct_kernel()
192
193
194 def test_kernelexpand1(self):
195 self.construct_kernel()
196
197 ret_val = self.kernel.kernelexpand("/path/to/kernel")
198 self.assertEquals(ret_val, ["/path/to/kernel"])
199 self.god.check_playback()
200
201
202 def test_kernel_expand2(self):
203 self.construct_kernel()
204 kernel = "kernel.tar.gz"
205
206 # record
207 self.job.config_get.expect_call('mirror.mirrors').and_return('mirror')
208 kernelexpand.expand_classic.expect_call(kernel,
209 'mirror').and_return('patches')
210
211 # run
212 self.assertEquals(self.kernel.kernelexpand(kernel), 'patches')
213 self.god.check_playback()
214
215
216 def test_kernel_expand3(self):
217 self.construct_kernel()
218 kernel = "kernel.tar.gz"
219
220 # record
221 self.job.config_get.expect_call('mirror.mirrors')
222 self.job.config_get.expect_call(
223 'mirror.ftp_kernel_org').and_return('mirror')
224 korg = 'http://www.kernel.org/pub/linux/kernel'
225 mirrors = [
226 [ korg + '/v2.6', 'mirror' + '/v2.6' ],
227 [ korg + '/people/akpm/patches/2.6', 'mirror' + '/akpm' ],
228 [ korg + '/people/mbligh', 'mirror' + '/mbligh' ],
229 ]
230 kernelexpand.expand_classic.expect_call(kernel,
231 mirrors).and_return('patches')
232
233 # run
234 self.assertEquals(self.kernel.kernelexpand(kernel), 'patches')
235 self.god.check_playback()
236
237
238 def test_extract1(self):
239 self.construct_kernel()
240
241 # setup
242 self.god.stub_function(self.kernel, "get_kernel_tree")
243
244 # record
245 os.path.exists.expect_call(self.base_tree).and_return(True)
246 self.kernel.get_kernel_tree.expect_call(self.base_tree)
247 self.job.record.expect_call('GOOD', self.subdir, 'kernel.extract')
248
249 # run
250 self.kernel.extract(self.base_tree)
251 self.god.check_playback()
252 self.god.unstub(self.kernel, "get_kernel_tree")
253
254
255 def test_extract2(self):
256 self.construct_kernel()
257
258 # setup
259 self.god.stub_function(self.kernel, "kernelexpand")
260 self.god.stub_function(self.kernel, "get_kernel_tree")
261 self.god.stub_function(self.kernel, "patch")
262
263 # record
264 os.path.exists.expect_call(self.base_tree).and_return(False)
265 components = ["component0", "component1"]
266 self.kernel.kernelexpand.expect_call(self.base_tree).and_return(
267 components)
268 self.kernel.get_kernel_tree.expect_call(components[0])
269 self.kernel.patch.expect_call(components[1])
270 self.job.record.expect_call('GOOD', self.subdir, 'kernel.extract')
271
272 # run
273 self.kernel.extract(self.base_tree)
274 self.god.check_playback()
275 self.god.unstub(self.kernel, "kernelexpand")
276 self.god.unstub(self.kernel, "get_kernel_tree")
277 self.god.unstub(self.kernel, "patch")
278
279
280 def test_patch1(self):
281 self.construct_kernel()
282 patches = ('patch1', 'patch2')
283 self.god.stub_function(self.kernel, "apply_patches")
284 self.god.stub_function(self.kernel, "get_patches")
285
286 #record
287 self.kernel.get_patches.expect_call(patches).and_return(patches)
288 self.kernel.apply_patches.expect_call(patches)
289 self.job.record.expect_call('GOOD', self.subdir, 'kernel.patch')
290
291 #run
292 self.kernel.patch(*patches)
293 self.god.check_playback()
294 self.god.unstub(self.kernel, "apply_patches")
295 self.god.unstub(self.kernel, "get_patches")
296
297
298 def test_patch2(self):
299 self.construct_kernel()
300 patches = []
301
302 # record
303 self.job.record.expect_call('GOOD', self.subdir, 'kernel.patch')
304
305 # run
306 self.kernel.patch(*patches)
307 self.god.check_playback()
308
309
310 def test_config(self):
311 self.construct_kernel()
312
313 # setup
314 self.god.stub_function(self.kernel, "set_cross_cc")
315 self.god.stub_class(kernel_config, "kernel_config")
316
317 # record
318 self.kernel.set_cross_cc.expect_call()
319 kernel_config.kernel_config.expect_new(self.job, self.build_dir,
320 self.config_dir, '', None,
jadmanski8b71d012008-11-06 16:46:41 +0000321 False, self.base_tree, None)
jadmanskia543fb02008-09-15 14:30:25 +0000322 self.job.record.expect_call('GOOD', self.subdir, 'kernel.config')
323
324 # run
325 self.kernel.config()
326 self.god.check_playback()
327 self.god.unstub(self.kernel, "set_cross_cc")
328
329
330 def test_get_patches(self):
331 self.construct_kernel()
332
333 # setup
334 patches = ['patch1', 'patch2', 'patch3']
335 local_patches = []
336
337 # record
338 for patch in patches:
339 dest = os.path.join(self.src_dir, os.path.basename(patch))
340 utils.get_file.expect_call(patch, dest)
341 utils.system_output.expect_call(
342 'md5sum ' + dest).and_return('md5sum')
343 local_patches.append((patch, dest, 'md5sum'))
344
345 # run and check
346 self.assertEquals(self.kernel.get_patches(patches), local_patches)
347 self.god.check_playback()
348
349
350 def test_apply_patches(self):
351 self.construct_kernel()
352
353 # setup
354 patches = []
355 patches.append(('patch1', 'patch1.gz', 'md5sum1'))
356 patches.append(('patch2', 'patch2.bz2', 'md5sum2'))
357 patches.append(('patch3', 'patch3', 'md5sum3'))
358 applied_patches = []
359
360 # record
361 os.chdir.expect_call(self.build_dir)
362
363 patch_id = "%s %s %s" % ('patch1', 'patch1', 'md5sum1')
364 log = "PATCH: " + patch_id + "\n"
mbligh53da18e2009-01-05 21:13:26 +0000365 utils.cat_file_to_cmd.expect_call('patch1.gz',
jadmanskia543fb02008-09-15 14:30:25 +0000366 'patch -p1 > /dev/null')
367 self.logfile.write.expect_call(log)
368 applied_patches.append(patch_id)
369
370 patch_id = "%s %s %s" % ('patch2', 'patch2', 'md5sum2')
371 log = "PATCH: " + patch_id + "\n"
mbligh53da18e2009-01-05 21:13:26 +0000372 utils.cat_file_to_cmd.expect_call('patch2.bz2',
jadmanskia543fb02008-09-15 14:30:25 +0000373 'patch -p1 > /dev/null')
374 self.logfile.write.expect_call(log)
375 applied_patches.append(patch_id)
376
mbligh53da18e2009-01-05 21:13:26 +0000377 utils.force_copy.expect_call('patch3',
jadmanskia543fb02008-09-15 14:30:25 +0000378 self.results_dir).and_return('local_patch3')
379 self.job.relative_path.expect_call('local_patch3').and_return(
380 'rel_local_patch3')
381 patch_id = "%s %s %s" % ('patch3', 'rel_local_patch3', 'md5sum3')
382 log = "PATCH: " + patch_id + "\n"
mbligh53da18e2009-01-05 21:13:26 +0000383 utils.cat_file_to_cmd.expect_call('patch3',
jadmanskia543fb02008-09-15 14:30:25 +0000384 'patch -p1 > /dev/null')
385 self.logfile.write.expect_call(log)
386 applied_patches.append(patch_id)
387
388 # run and test
389 self.kernel.apply_patches(patches)
390 self.assertEquals(self.kernel.applied_patches, applied_patches)
391 self.god.check_playback()
392
393
394 def test_get_kernel_tree1(self):
395 self.construct_kernel()
396
397 # record
398 os.path.isdir.expect_call(self.base_tree).and_return(True)
399 os.symlink.expect_call(self.base_tree, self.build_dir)
400
401 # run and check
402 self.kernel.get_kernel_tree(self.base_tree)
403 self.god.check_playback()
404
405
406 def test_get_kernel_tree2(self):
407 self.construct_kernel()
408
409 # record
410 os.path.isdir.expect_call(self.base_tree).and_return(False)
411 os.chdir.expect_call(os.path.dirname(self.src_dir))
412 tarball = os.path.join(self.src_dir, os.path.basename(self.base_tree))
413 utils.get_file.expect_call(self.base_tree, tarball)
mbligh53da18e2009-01-05 21:13:26 +0000414 utils.extract_tarball_to_dir.expect_call(tarball,
jadmanskia543fb02008-09-15 14:30:25 +0000415 self.build_dir)
416
417 # run and check
418 self.kernel.get_kernel_tree(self.base_tree)
419 self.god.check_playback()
420
421
422 def test_extraversion(self):
423 self.construct_kernel()
424 tag = "tag"
425
426 # record
427 os.chdir.expect_call(self.build_dir)
428 extraversion_sub = r's/^EXTRAVERSION =\s*\(.*\)/EXTRAVERSION = '
429 p = extraversion_sub + '\\1-%s/' % tag
430 utils.system.expect_call('mv Makefile Makefile.old')
431 utils.system.expect_call('sed "%s" < Makefile.old > Makefile' % p)
432
433 # run and check
434 self.kernel.extraversion(tag)
435 self.god.check_playback()
436
437
438 def test_build(self):
439 self.construct_kernel()
440 self.god.stub_function(self.kernel, "extraversion")
441 self.god.stub_function(self.kernel, "set_cross_cc")
442 self.god.stub_function(self.kernel, "get_kernel_build_ver")
443 self.kernel.build_target = 'build_target'
444
445 # record
446 os_dep.commands.expect_call('gcc', 'make')
447 logfile = os.path.join(self.log_dir, 'kernel_build')
448 os.chdir.expect_call(self.build_dir)
449 self.kernel.extraversion.expect_call('autotest')
450 self.kernel.set_cross_cc.expect_call()
451 utils.system.expect_call('make dep', ignore_status=True)
mbligh53da18e2009-01-05 21:13:26 +0000452 utils.count_cpus.expect_call().and_return(4)
jadmanskia543fb02008-09-15 14:30:25 +0000453 threads = 2 * 4
454 build_string = 'make -j %d %s %s' % (threads, '', 'build_target')
455 utils.system.expect_call(build_string)
456 kernel_config.modules_needed.expect_call('.config').and_return(True)
457 utils.system.expect_call('make -j %d modules' % (threads))
458 self.kernel.get_kernel_build_ver.expect_call().and_return('2.6.24')
459 kernel_version = re.sub('-autotest', '', '2.6.24')
460 self.logfile.write.expect_call('BUILD VERSION: %s\n' % kernel_version)
mbligh53da18e2009-01-05 21:13:26 +0000461 utils.force_copy.expect_call(self.build_dir+'/System.map',
jadmanskia543fb02008-09-15 14:30:25 +0000462 self.results_dir)
463 self.job.record.expect_call('GOOD', self.subdir, 'kernel.build')
464
465 # run and check
466 self.kernel.build()
467 self.god.check_playback()
468
469
470 def test_build_timed(self):
471 self.construct_kernel()
472 self.god.stub_function(self.kernel, "set_cross_cc")
473 self.god.stub_function(self.kernel, "clean")
474
475 # record
476 os.chdir.expect_call(self.build_dir)
477 self.kernel.set_cross_cc.expect_call()
478 self.kernel.clean.expect_call(logged=False)
479 build_string = "/usr/bin/time -o /dev/null make -j 8 vmlinux"
480 build_string += ' > /dev/null 2>&1'
481 utils.system.expect_call(build_string)
482 os.path.isfile.expect_call('vmlinux').and_return(True)
483
484 # run and check
485 self.kernel.build_timed(threads=8)
486 self.god.check_playback()
487
488
489 def test_clean(self):
490 self.construct_kernel()
491
492 # record
493 os.chdir.expect_call(self.build_dir)
494 utils.system.expect_call('make clean > /dev/null 2> /dev/null')
495 self.job.record.expect_call('GOOD', self.subdir, 'kernel.clean')
496
497 # run and check
498 self.kernel.clean()
499 self.god.check_playback()
500
501
502 def test_mkinitrd(self):
503 self.construct_kernel()
504
505 # record
mbligh53da18e2009-01-05 21:13:26 +0000506 utils.get_os_vendor.expect_call().and_return('Ubuntu')
jadmanskia543fb02008-09-15 14:30:25 +0000507 os.path.isfile.expect_call('initrd').and_return(True)
508 os.remove.expect_call('initrd')
509 self.job.config_get.expect_call(
510 'kernel.mkinitrd_extra_args').and_return(None)
511 args = ''
512 os.path.isfile.expect_call('/usr/sbin/mkinitrd').and_return(True)
513 cmd = '/usr/sbin/mkinitrd'
514 utils.system.expect_call('%s %s -o initrd 2.6.24' % (cmd, args))
515 self.job.record.expect_call('GOOD', self.subdir, 'kernel.mkinitrd')
516
517 # run and check
518 self.kernel.mkinitrd(version="2.6.24", image="image",
519 system_map="system_map", initrd="initrd")
520 self.god.check_playback()
521
522
523 def test_install(self):
524 self.construct_kernel()
525 tag = 'autotest'
526 prefix = '/'
527 self.kernel.build_image = None
528 self.kernel.build_target = 'build_target'
529 self.god.stub_function(self.kernel, "get_kernel_build_ver")
530 self.god.stub_function(self.kernel, "mkinitrd")
531
532 # record
533 os.chdir.expect_call(self.build_dir)
534 os.path.isdir.expect_call(prefix).and_return(False)
535 os.mkdir.expect_call(prefix)
536 boot_dir = os.path.join(prefix, 'boot')
537 os.path.isdir.expect_call(boot_dir).and_return(False)
538 os.mkdir.expect_call(boot_dir)
539 glob.glob.expect_call(
540 'arch/*/boot/' + 'build_target').and_return('')
541 build_image = self.kernel.build_target
mbligh53da18e2009-01-05 21:13:26 +0000542 utils.force_copy.expect_call('vmlinux',
jadmanskia543fb02008-09-15 14:30:25 +0000543 '/boot/vmlinux-autotest')
mbligh53da18e2009-01-05 21:13:26 +0000544 utils.force_copy.expect_call('build_target',
jadmanskia543fb02008-09-15 14:30:25 +0000545 '/boot/vmlinuz-autotest')
mbligh53da18e2009-01-05 21:13:26 +0000546 utils.force_copy.expect_call('System.map',
jadmanskia543fb02008-09-15 14:30:25 +0000547 '/boot/System.map-autotest')
mbligh53da18e2009-01-05 21:13:26 +0000548 utils.force_copy.expect_call('.config',
jadmanskia543fb02008-09-15 14:30:25 +0000549 '/boot/config-autotest')
550 kernel_config.modules_needed.expect_call('.config').and_return(True)
551 utils.system.expect_call('make modules_install INSTALL_MOD_PATH=%s'
552 % prefix)
553 initrd = boot_dir + '/initrd-' + tag
554 self.kernel.get_kernel_build_ver.expect_call().and_return('2.6.24')
555 self.kernel.mkinitrd.expect_call('2.6.24', '/boot/vmlinuz-autotest',
556 '/boot/System.map-autotest', '/boot/initrd-autotest')
557 self.job.record.expect_call('GOOD', self.subdir, 'kernel.install')
558
559 # run and check
560 self.kernel.install()
561 self.god.check_playback()
562
563
jadmanskia543fb02008-09-15 14:30:25 +0000564 def test_get_kernel_build_arch1(self):
565 self.construct_kernel()
566
567 # record
mbligh53da18e2009-01-05 21:13:26 +0000568 utils.get_current_kernel_arch.expect_call().and_return("i386")
jadmanskia543fb02008-09-15 14:30:25 +0000569
570 # run and check
571 self.assertEquals(self.kernel.get_kernel_build_arch(), "i386")
572 self.god.check_playback()
573
574
575 def test_get_kernel_build_arch2(self):
576 self.construct_kernel()
577
578 # run and check
579 self.assertEquals(self.kernel.get_kernel_build_arch('i586'), "i386")
580 self.god.check_playback()
581
582
583 def test_get_kernel_build_release(self):
584 self.construct_kernel()
585 mock_file = self.god.create_mock_class(file, "file")
586
587 # record
588 for f in [self.build_dir + "/include/linux/version.h",
589 self.build_dir + "/include/linux/utsrelease.h"]:
590 os.path.exists.expect_call(f).and_return(True)
591 kernel.open.expect_call(f, 'r').and_return(mock_file)
592 mock_file.readlines.expect_call().and_return("Some lines")
593 mock_file.close.expect_call()
594
showard1104cd12009-11-13 20:45:10 +0000595 for f in [self.build_dir + "/include/linux/compile.h",
596 self.build_dir + "/include/generated/utsrelease.h",
597 self.build_dir + "/include/generated/compile.h"]:
598 os.path.exists.expect_call(f).and_return(False)
jadmanskia543fb02008-09-15 14:30:25 +0000599
600 # run and test
601 self.kernel.get_kernel_build_release()
602 self.god.check_playback()
603
604
605 def test_get_kernel_build_ident(self):
606 self.construct_kernel()
607 self.god.stub_function(self.kernel, "get_kernel_build_release")
608
609 # record
610 self.kernel.get_kernel_build_release.expect_call().and_return(
611 ("AwesomeRelease", "1.0"))
612
613 # run and check
614 self.assertEquals(self.kernel.get_kernel_build_ident(),
615 "AwesomeRelease::1.0")
616 self.god.check_playback()
617
618
619 def test_boot(self):
620 self.construct_kernel()
621 self.god.stub_function(self.kernel, "get_kernel_build_ident")
622 self.god.stub_function(self.kernel, "install")
Eric Li6f27d4f2010-09-29 10:55:17 -0700623 self.god.stub_function(self.kernel, "_boot_kernel")
jadmanskia543fb02008-09-15 14:30:25 +0000624 self.kernel.applied_patches = "applied_patches"
Eric Li6f27d4f2010-09-29 10:55:17 -0700625 self.kernel.installed_as = None
jadmanskia543fb02008-09-15 14:30:25 +0000626 args = ''
Eric Li6f27d4f2010-09-29 10:55:17 -0700627 expected_ident = 'ident'
628 ident = True
jadmanskia543fb02008-09-15 14:30:25 +0000629
630 # record
jadmanskia543fb02008-09-15 14:30:25 +0000631 self.kernel.install.expect_call()
Eric Li6f27d4f2010-09-29 10:55:17 -0700632 self.kernel.get_kernel_build_ident.expect_call(
633 ).and_return(expected_ident)
634 self.kernel._boot_kernel.expect_call(
635 args, ident, expected_ident,
636 self.subdir, self.kernel.applied_patches)
jadmanskia543fb02008-09-15 14:30:25 +0000637
638 # run and check
Eric Li6f27d4f2010-09-29 10:55:17 -0700639 self.kernel.boot(args=args, ident=ident)
jadmanski067b26c2008-09-25 19:46:56 +0000640 self.god.check_playback()
641
642
jadmanskia543fb02008-09-15 14:30:25 +0000643if __name__ == "__main__":
644 unittest.main()