mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 1 | # Copyright 2007 Google Inc. Released under the GPL v2 |
| 2 | |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 3 | """ |
| 4 | This module defines the SourceKernel class |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 5 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 6 | SourceKernel: an linux kernel built from source |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 7 | """ |
| 8 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 9 | |
mbligh | 421a4f0 | 2008-07-16 20:38:22 +0000 | [diff] [blame] | 10 | from autotest_lib.server import kernel, autotest |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 11 | |
| 12 | |
| 13 | class SourceKernel(kernel.Kernel): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 14 | """ |
| 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 Curtis | 8adf789 | 2011-09-08 16:13:36 -0700 | [diff] [blame] | 25 | super(SourceKernel, self).__init__() |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 26 | self.__kernel = k |
| 27 | self.__patch_list = [] |
| 28 | self.__config_file = None |
| 29 | self.__autotest = autotest.Autotest() |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 30 | |
| 31 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 32 | def configure(self, configFile): |
| 33 | self.__config_file = configFile |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 34 | |
| 35 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 36 | def patch(self, patchFile): |
| 37 | self.__patch_list.append(patchFile) |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 38 | |
| 39 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 40 | 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) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 44 | |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 45 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 46 | 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) |
mbligh | e761b05 | 2007-12-04 22:44:08 +0000 | [diff] [blame] | 52 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 53 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 54 | def __control_file(self, kernel, patch_list, config): |
| 55 | ctl = ("testkernel = job.kernel('%s')\n" % kernel) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 56 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 57 | if len(patch_list): |
| 58 | patches = ', '.join(["'%s'" % x for x in patch_list]) |
| 59 | ctl += "testkernel.patch(%s)\n" % patches |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 60 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 61 | if config: |
| 62 | ctl += "testkernel.config('%s')\n" % config |
| 63 | else: |
| 64 | ctl += "testkernel.config('', None, True)\n" |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 65 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 66 | ctl += "testkernel.build()\n" |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 67 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 68 | # copy back to server |
| 69 | |
| 70 | return ctl |