1 #!/usr/bin/python 2 3 import unittest 4 import common 5 from autotest_lib.client.common_lib.test_utils import mock 6 from autotest_lib.server import source_kernel, autotest, hosts 7 8 9 class TestSourceKernel(unittest.TestCase): 10 def setUp(self): 11 self.god = mock.mock_god() 12 self.host = self.god.create_mock_class(hosts.RemoteHost, "host") 13 self.god.stub_class(source_kernel.autotest, "Autotest") 14 self.kernel_autotest = source_kernel.autotest.Autotest.expect_new() 15 self.k = "kernel" 16 self.source_kernel = source_kernel.SourceKernel(self.k) 17 18 # call configure to set config_file 19 self.config = "config_file" 20 self.source_kernel.configure(self.config) 21 22 23 def tearDown(self): 24 self.god.unstub_all() 25 26 27 def test_install(self): 28 # setup 29 ctlfile = ("testkernel = job.kernel('%s')\n" 30 "testkernel.install()\n" 31 "testkernel.add_to_bootloader()\n" %(self.k)) 32 33 # record 34 self.kernel_autotest.install.expect_call(self.host) 35 self.host.get_tmp_dir.expect_call().and_return("tmpdir") 36 self.kernel_autotest.run.expect_call(ctlfile, "tmpdir", self.host) 37 38 # run and check 39 self.source_kernel.install(self.host) 40 self.god.check_playback() 41 42 43 def test_build(self): 44 # setup 45 patches = "patches" 46 self.source_kernel.patch(patches) 47 ctlfile = ("testkernel = job.kernel('%s')\n" 48 "testkernel.patch('%s')\n" 49 "testkernel.config('%s')\n" 50 "testkernel.build()\n" % (self.k, patches, self.config)) 51 52 # record 53 self.host.get_tmp_dir.expect_call().and_return("tmpdir") 54 self.kernel_autotest.run.expect_call(ctlfile, "tmpdir", self.host) 55 56 # run and check 57 self.source_kernel.build(self.host) 58 self.god.check_playback() 59 60 61 if __name__ == "__main__": 62 unittest.main() 63