blob: 0587f62117d32dd961cfa5584dbe30dae2dde17f [file] [log] [blame]
mblighdcd57a82007-07-11 23:06:47 +00001#!/usr/bin/python
2#
3# Copyright 2007 Google Inc. Released under the GPL v2
4
mblighdc735a22007-08-02 16:54:37 +00005"""
6This module defines the SourceKernel class
mblighdcd57a82007-07-11 23:06:47 +00007
8 SourceKernel: an linux kernel built from source
9"""
10
mblighdc735a22007-08-02 16:54:37 +000011__author__ = """
12mbligh@google.com (Martin J. Bligh),
mblighdcd57a82007-07-11 23:06:47 +000013poirier@google.com (Benjamin Poirier),
mblighdc735a22007-08-02 16:54:37 +000014stutsman@google.com (Ryan Stutsman)
15"""
mblighdcd57a82007-07-11 23:06:47 +000016
17
18import kernel
19
20
21
22class SourceKernel(kernel.Kernel):
mblighdc735a22007-08-02 16:54:37 +000023 """
24 This class represents a linux kernel built from source.
mblighdcd57a82007-07-11 23:06:47 +000025
26 It is used to obtain a built kernel or create one from source and
27 install it on a Host.
28
29 Implementation details:
30 This is a leaf class in an abstract class hierarchy, it must
31 implement the unimplemented methods in parent classes.
32 """
33 def __init__(self):
34 super(kernel.Kernel, self).__init__()
35 self.__patch_list = []
36 self.__config_file = None
mblighdc735a22007-08-02 16:54:37 +000037
38
mblighdcd57a82007-07-11 23:06:47 +000039 def configure(self, configFile):
40 self.__config_file = configFile
mblighdc735a22007-08-02 16:54:37 +000041
42
mblighdcd57a82007-07-11 23:06:47 +000043 def patch(self, patchFile):
44 self.__patch_list.append(patchFile)
mblighdc735a22007-08-02 16:54:37 +000045
46
mblighdcd57a82007-07-11 23:06:47 +000047 def build(self, host):
48 at = autotest.Autotest()
49 at.install(host)
50 ctlfile = self.control_file(self.__kernel, self.__patch_list,
51 self.__config_file)
52 at.run(ctlfile, host.get_tmp_dir(), host)
53
mblighdc735a22007-08-02 16:54:37 +000054
mblighdcd57a82007-07-11 23:06:47 +000055 def __control_file(self, kernel, patch_list, config):
56 ctl = ("def step_init():\n"
57 "\tjob.next_step([step_test])\n"
58 "\ttestkernel = job.kernel('%s')\n" % kernel)
59
60 if len(patch_list):
61 patches = ', '.join(["'%s'" % x for x in patch_list])
62 ctl += "\ttestkernel.patch(%s)" % patches
63
64 if config:
65 ctl += "\ttestkernel.config('%s')" % config
66 else:
67 ctl += "\ttestkernel.config('', None, True)"
68
69 ctl += "\ttestkernel.build()"
70
71 # copy back to server
72
73 return ctl