blob: 6d5850ff8e94a9a4c40b35dcacaab5e30d8f3b43 [file] [log] [blame]
mblighdcd57a82007-07-11 23:06:47 +00001# Copyright 2007 Google Inc. Released under the GPL v2
2
mblighdc735a22007-08-02 16:54:37 +00003"""
4This module defines the SourceKernel class
mblighdcd57a82007-07-11 23:06:47 +00005
jadmanski0afbb632008-06-06 21:10:57 +00006 SourceKernel: an linux kernel built from source
mblighdcd57a82007-07-11 23:06:47 +00007"""
8
mblighdcd57a82007-07-11 23:06:47 +00009
mbligh421a4f02008-07-16 20:38:22 +000010from autotest_lib.server import kernel, autotest
mblighdcd57a82007-07-11 23:06:47 +000011
12
13class SourceKernel(kernel.Kernel):
jadmanski0afbb632008-06-06 21:10:57 +000014 """
15 This class represents a linux kernel built from source.
16
17 It is used to obtain a built kernel or create one from source and
18 install it on a Host.
19
20 Implementation details:
21 This is a leaf class in an abstract class hierarchy, it must
22 implement the unimplemented methods in parent classes.
23 """
24 def __init__(self, k):
Dale Curtis8adf7892011-09-08 16:13:36 -070025 super(SourceKernel, self).__init__()
jadmanski0afbb632008-06-06 21:10:57 +000026 self.__kernel = k
27 self.__patch_list = []
28 self.__config_file = None
29 self.__autotest = autotest.Autotest()
mblighdc735a22007-08-02 16:54:37 +000030
31
jadmanski0afbb632008-06-06 21:10:57 +000032 def configure(self, configFile):
33 self.__config_file = configFile
mblighdc735a22007-08-02 16:54:37 +000034
35
jadmanski0afbb632008-06-06 21:10:57 +000036 def patch(self, patchFile):
37 self.__patch_list.append(patchFile)
mblighdc735a22007-08-02 16:54:37 +000038
39
jadmanski0afbb632008-06-06 21:10:57 +000040 def build(self, host):
41 ctlfile = self.__control_file(self.__kernel, self.__patch_list,
42 self.__config_file)
43 self.__autotest.run(ctlfile, host.get_tmp_dir(), host)
mblighdcd57a82007-07-11 23:06:47 +000044
mblighdc735a22007-08-02 16:54:37 +000045
jadmanski0afbb632008-06-06 21:10:57 +000046 def install(self, host):
47 self.__autotest.install(host)
48 ctlfile = ("testkernel = job.kernel('%s')\n"
49 "testkernel.install()\n"
50 "testkernel.add_to_bootloader()\n" %(self.__kernel))
51 self.__autotest.run(ctlfile, host.get_tmp_dir(), host)
mblighe761b052007-12-04 22:44:08 +000052
mblighdcd57a82007-07-11 23:06:47 +000053
jadmanski0afbb632008-06-06 21:10:57 +000054 def __control_file(self, kernel, patch_list, config):
55 ctl = ("testkernel = job.kernel('%s')\n" % kernel)
mblighdcd57a82007-07-11 23:06:47 +000056
jadmanski0afbb632008-06-06 21:10:57 +000057 if len(patch_list):
58 patches = ', '.join(["'%s'" % x for x in patch_list])
59 ctl += "testkernel.patch(%s)\n" % patches
mblighdcd57a82007-07-11 23:06:47 +000060
jadmanski0afbb632008-06-06 21:10:57 +000061 if config:
62 ctl += "testkernel.config('%s')\n" % config
63 else:
64 ctl += "testkernel.config('', None, True)\n"
mblighdcd57a82007-07-11 23:06:47 +000065
jadmanski0afbb632008-06-06 21:10:57 +000066 ctl += "testkernel.build()\n"
mblighdcd57a82007-07-11 23:06:47 +000067
jadmanski0afbb632008-06-06 21:10:57 +000068 # copy back to server
69
70 return ctl