mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 1 | __author__ = """Copyright Martin J. Bligh, 2006""" |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 2 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 3 | import os,os.path,shutil,urllib,copy,pickle,re,glob,time |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 4 | from autotest_utils import * |
mbligh | 119c12a | 2007-11-12 22:13:44 +0000 | [diff] [blame] | 5 | from common import logging |
apw | 001e40a | 2007-11-21 19:24:37 +0000 | [diff] [blame] | 6 | from fd_stack import tee_output_logdir_mark |
mbligh | 1003801 | 2006-10-19 03:32:45 +0000 | [diff] [blame] | 7 | import kernel_config, test, os_dep |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 8 | |
mbligh | b8e0a11 | 2007-11-05 20:27:36 +0000 | [diff] [blame] | 9 | |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 10 | class kernel: |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 11 | """ Class for compiling kernels. |
| 12 | |
| 13 | Data for the object includes the src files |
| 14 | used to create the kernel, patches applied, config (base + changes), |
| 15 | the build directory itself, and logged output |
| 16 | |
| 17 | Properties: |
| 18 | job |
| 19 | Backpointer to the job object we're part of |
| 20 | autodir |
| 21 | Path to the top level autotest dir (/usr/local/autotest) |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 22 | src_dir |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 23 | <tmp_dir>/src/ |
mbligh | c49af7b | 2006-11-24 04:02:21 +0000 | [diff] [blame] | 24 | build_dir |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 25 | <tmp_dir>/linux/ |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 26 | config_dir |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 27 | <results_dir>/config/ |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 28 | log_dir |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 29 | <results_dir>/debug/ |
| 30 | results_dir |
| 31 | <results_dir>/results/ |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 32 | """ |
| 33 | |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 34 | autodir = '' |
| 35 | |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 36 | def __init__(self, job, base_tree, subdir, tmp_dir, build_dir, leave = False): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 37 | """Initialize the kernel build environment |
| 38 | |
| 39 | job |
| 40 | which job this build is part of |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 41 | base_tree |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 42 | base kernel tree. Can be one of the following: |
| 43 | 1. A local tarball |
| 44 | 2. A URL to a tarball |
| 45 | 3. A local directory (will symlink it) |
| 46 | 4. A shorthand expandable (eg '2.6.11-git3') |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 47 | subdir |
| 48 | subdir in the results directory (eg "build") |
| 49 | (holds config/, debug/, results/) |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 50 | tmp_dir |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 51 | |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 52 | leave |
| 53 | Boolean, whether to leave existing tmpdir or not |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 54 | """ |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 55 | self.job = job |
mbligh | 678823f | 2006-12-07 18:49:00 +0000 | [diff] [blame] | 56 | self.autodir = job.autodir |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 57 | |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 58 | self.src_dir = os.path.join(tmp_dir, 'src') |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 59 | self.build_dir = os.path.join(tmp_dir, build_dir) |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 60 | # created by get_kernel_tree |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 61 | self.config_dir = os.path.join(subdir, 'config') |
| 62 | self.log_dir = os.path.join(subdir, 'debug') |
| 63 | self.results_dir = os.path.join(subdir, 'results') |
| 64 | self.subdir = os.path.basename(subdir) |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 65 | |
apw | 87c65c1 | 2007-09-27 17:19:37 +0000 | [diff] [blame] | 66 | self.installed_as = None |
| 67 | |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 68 | if not leave: |
| 69 | if os.path.isdir(self.src_dir): |
| 70 | system('rm -rf ' + self.src_dir) |
| 71 | if os.path.isdir(self.build_dir): |
| 72 | system('rm -rf ' + self.build_dir) |
| 73 | |
mbligh | 30f28c5 | 2007-10-11 18:35:35 +0000 | [diff] [blame] | 74 | if not os.path.exists(self.src_dir): |
| 75 | os.mkdir(self.src_dir) |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 76 | for path in [self.config_dir, self.log_dir, self.results_dir]: |
| 77 | if os.path.exists(path): |
| 78 | system('rm -rf ' + path) |
| 79 | os.mkdir(path) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 80 | |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 81 | logpath = os.path.join(self.log_dir, 'build_log') |
| 82 | self.logfile = open(logpath, 'w+') |
| 83 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 84 | self.target_arch = None |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 85 | self.build_target = 'bzImage' |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 86 | self.build_image = None |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 87 | |
apw | e895612 | 2007-12-13 19:00:15 +0000 | [diff] [blame] | 88 | arch = get_current_kernel_arch() |
| 89 | if arch == 's390' or arch == 's390x': |
| 90 | self.build_target = 'image' |
| 91 | elif arch == 'ia64': |
mbligh | cac347a | 2007-06-02 17:21:48 +0000 | [diff] [blame] | 92 | self.build_target = 'all' |
| 93 | self.build_image = 'vmlinux.gz' |
| 94 | |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 95 | if leave: |
| 96 | return |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 97 | |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 98 | self.logfile.write('BASE: %s\n' % base_tree) |
apw | 2366d99 | 2007-03-12 20:35:57 +0000 | [diff] [blame] | 99 | |
| 100 | # Where we have direct version hint record that |
| 101 | # for later configuration selection. |
| 102 | shorthand = re.compile(r'^\d+\.\d+\.\d+') |
| 103 | if shorthand.match(base_tree): |
| 104 | self.base_tree_version = base_tree |
| 105 | else: |
| 106 | self.base_tree_version = None |
| 107 | |
apw | 040dcaa | 2007-11-21 19:36:55 +0000 | [diff] [blame] | 108 | # Actually extract the tree. Make sure we know it occured |
| 109 | self.extract(base_tree) |
| 110 | |
| 111 | |
| 112 | @logging.record |
| 113 | @tee_output_logdir_mark |
| 114 | def extract(self, base_tree): |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 115 | if os.path.exists(base_tree): |
| 116 | self.get_kernel_tree(base_tree) |
| 117 | else: |
apw | 8ad56be | 2006-11-06 17:49:54 +0000 | [diff] [blame] | 118 | args = self.job.config_get('mirror.ftp_kernel_org') |
mbligh | 548f29a | 2006-10-17 04:55:12 +0000 | [diff] [blame] | 119 | if args: |
| 120 | args = '-l ' + args |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 121 | base_components = kernelexpand(base_tree, args) |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 122 | print 'kernelexpand: ' |
| 123 | print base_components |
| 124 | self.get_kernel_tree(base_components.pop(0)) |
| 125 | if base_components: # apply remaining patches |
| 126 | self.patch(*base_components) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 127 | |
| 128 | |
mbligh | 119c12a | 2007-11-12 22:13:44 +0000 | [diff] [blame] | 129 | @logging.record |
apw | 001e40a | 2007-11-21 19:24:37 +0000 | [diff] [blame] | 130 | @tee_output_logdir_mark |
mbligh | b8e0a11 | 2007-11-05 20:27:36 +0000 | [diff] [blame] | 131 | def patch(self, *patches): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 132 | """Apply a list of patches (in order)""" |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 133 | if not patches: |
| 134 | return |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 135 | print 'Applying patches: ', patches |
mbligh | 0763e73 | 2007-08-30 16:35:06 +0000 | [diff] [blame] | 136 | self.apply_patches(self.get_patches(patches)) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 137 | |
| 138 | |
mbligh | 119c12a | 2007-11-12 22:13:44 +0000 | [diff] [blame] | 139 | @logging.record |
apw | 001e40a | 2007-11-21 19:24:37 +0000 | [diff] [blame] | 140 | @tee_output_logdir_mark |
mbligh | b8e0a11 | 2007-11-05 20:27:36 +0000 | [diff] [blame] | 141 | def config(self, config_file = '', config_list = None, defconfig = False): |
mbligh | 678823f | 2006-12-07 18:49:00 +0000 | [diff] [blame] | 142 | self.set_cross_cc() |
apw | b449c7d | 2006-12-05 12:21:44 +0000 | [diff] [blame] | 143 | config = kernel_config.kernel_config(self.job, self.build_dir, |
apw | 2366d99 | 2007-03-12 20:35:57 +0000 | [diff] [blame] | 144 | self.config_dir, config_file, config_list, |
| 145 | defconfig, self.base_tree_version) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 146 | |
| 147 | |
| 148 | def get_patches(self, patches): |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 149 | """fetch the patches to the local src_dir""" |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 150 | local_patches = [] |
| 151 | for patch in patches: |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 152 | dest = os.path.join(self.src_dir, basename(patch)) |
mbligh | 0763e73 | 2007-08-30 16:35:06 +0000 | [diff] [blame] | 153 | # FIXME: this isn't unique. Append something to it |
| 154 | # like wget does if it's not there? |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 155 | print "get_file %s %s %s %s" % (patch, dest, self.src_dir, basename(patch)) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 156 | get_file(patch, dest) |
mbligh | 0763e73 | 2007-08-30 16:35:06 +0000 | [diff] [blame] | 157 | # probably safer to use the command, not python library |
| 158 | md5sum = system_output('md5sum ' + dest).split()[0] |
| 159 | local_patches.append((patch, dest, md5sum)) |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 160 | return local_patches |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 161 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 162 | |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 163 | def apply_patches(self, local_patches): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 164 | """apply the list of patches, in order""" |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 165 | builddir = self.build_dir |
| 166 | os.chdir(builddir) |
| 167 | |
mbligh | 534015f | 2006-09-15 03:28:56 +0000 | [diff] [blame] | 168 | if not local_patches: |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 169 | return None |
mbligh | 0763e73 | 2007-08-30 16:35:06 +0000 | [diff] [blame] | 170 | for (spec, local, md5sum) in local_patches: |
| 171 | if local.endswith('.bz2') or local.endswith('.gz'): |
| 172 | ref = spec |
| 173 | else: |
| 174 | ref = force_copy(local, self.results_dir) |
| 175 | ref = self.job.relative_path(ref) |
| 176 | log = 'PATCH: %s %s %s\n' % (spec, ref, md5sum) |
| 177 | print log |
| 178 | cat_file_to_cmd(local, 'patch -p1 > /dev/null') |
| 179 | self.logfile.write(log) |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 180 | |
| 181 | |
| 182 | def get_kernel_tree(self, base_tree): |
mbligh | c49af7b | 2006-11-24 04:02:21 +0000 | [diff] [blame] | 183 | """Extract/link base_tree to self.build_dir""" |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 184 | |
| 185 | # if base_tree is a dir, assume uncompressed kernel |
| 186 | if os.path.isdir(base_tree): |
| 187 | print 'Symlinking existing kernel source' |
mbligh | c49af7b | 2006-11-24 04:02:21 +0000 | [diff] [blame] | 188 | os.symlink(base_tree, self.build_dir) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 189 | |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 190 | # otherwise, extract tarball |
| 191 | else: |
mbligh | c49af7b | 2006-11-24 04:02:21 +0000 | [diff] [blame] | 192 | os.chdir(os.path.dirname(self.src_dir)) |
| 193 | # Figure out local destination for tarball |
| 194 | tarball = os.path.join(self.src_dir, os.path.basename(base_tree)) |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 195 | get_file(base_tree, tarball) |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 196 | print 'Extracting kernel tarball:', tarball, '...' |
mbligh | c49af7b | 2006-11-24 04:02:21 +0000 | [diff] [blame] | 197 | extract_tarball_to_dir(tarball, self.build_dir) |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 198 | |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 199 | |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 200 | def extraversion(self, tag, append=1): |
| 201 | os.chdir(self.build_dir) |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 202 | extraversion_sub = r's/^EXTRAVERSION =\s*\(.*\)/EXTRAVERSION = ' |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 203 | if append: |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 204 | p = extraversion_sub + '\\1-%s/' % tag |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 205 | else: |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 206 | p = extraversion_sub + '-%s/' % tag |
mbligh | 4c3fe4a | 2007-07-31 17:59:21 +0000 | [diff] [blame] | 207 | system('mv Makefile Makefile.old') |
| 208 | system('sed "%s" < Makefile.old > Makefile' % p) |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 209 | |
| 210 | |
mbligh | 119c12a | 2007-11-12 22:13:44 +0000 | [diff] [blame] | 211 | @logging.record |
apw | 001e40a | 2007-11-21 19:24:37 +0000 | [diff] [blame] | 212 | @tee_output_logdir_mark |
mbligh | b8e0a11 | 2007-11-05 20:27:36 +0000 | [diff] [blame] | 213 | def build(self, make_opts = '', logfile = '', extraversion='autotest'): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 214 | """build the kernel |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 215 | |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 216 | make_opts |
| 217 | additional options to make, if any |
| 218 | """ |
mbligh | 1003801 | 2006-10-19 03:32:45 +0000 | [diff] [blame] | 219 | os_dep.commands('gcc', 'make') |
mbligh | 6d4c941 | 2006-09-13 23:08:44 +0000 | [diff] [blame] | 220 | if logfile == '': |
| 221 | logfile = os.path.join(self.log_dir, 'kernel_build') |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 222 | os.chdir(self.build_dir) |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 223 | if extraversion: |
| 224 | self.extraversion(extraversion) |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 225 | self.set_cross_cc() |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 226 | # setup_config_file(config_file, config_overrides) |
apw | c784610 | 2006-04-06 18:22:13 +0000 | [diff] [blame] | 227 | |
| 228 | # Not needed on 2.6, but hard to tell -- handle failure |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 229 | system('make dep', ignorestatus=1) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 230 | threads = 2 * count_cpus() |
mbligh | 6d4c941 | 2006-09-13 23:08:44 +0000 | [diff] [blame] | 231 | build_string = 'make -j %d %s %s' % (threads, make_opts, |
| 232 | self.build_target) |
| 233 | # eg make bzImage, or make zImage |
| 234 | print build_string |
| 235 | system(build_string) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 236 | if kernel_config.modules_needed('.config'): |
apw | d470197 | 2006-10-16 09:24:56 +0000 | [diff] [blame] | 237 | system('make -j %d modules' % (threads)) |
apw | c784610 | 2006-04-06 18:22:13 +0000 | [diff] [blame] | 238 | |
mbligh | 4426de0 | 2006-10-10 07:18:28 +0000 | [diff] [blame] | 239 | kernel_version = self.get_kernel_build_ver() |
| 240 | kernel_version = re.sub('-autotest', '', kernel_version) |
| 241 | self.logfile.write('BUILD VERSION: %s\n' % kernel_version) |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 242 | |
| 243 | force_copy(self.build_dir+'/System.map', self.results_dir) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 244 | |
| 245 | |
mbligh | 30f28c5 | 2007-10-11 18:35:35 +0000 | [diff] [blame] | 246 | def build_timed(self, threads, timefile = '/dev/null', make_opts = '', |
mbligh | 2e793a4 | 2007-10-12 23:58:35 +0000 | [diff] [blame] | 247 | output = '/dev/null'): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 248 | """time the bulding of the kernel""" |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 249 | os.chdir(self.build_dir) |
mbligh | 678823f | 2006-12-07 18:49:00 +0000 | [diff] [blame] | 250 | self.set_cross_cc() |
mbligh | 30f28c5 | 2007-10-11 18:35:35 +0000 | [diff] [blame] | 251 | |
mbligh | d79b2b4 | 2007-11-05 20:38:15 +0000 | [diff] [blame] | 252 | self.clean(logged=False) |
mbligh | 30f28c5 | 2007-10-11 18:35:35 +0000 | [diff] [blame] | 253 | build_string = "/usr/bin/time -o %s make %s -j %s vmlinux" \ |
| 254 | % (timefile, make_opts, threads) |
mbligh | 2e793a4 | 2007-10-12 23:58:35 +0000 | [diff] [blame] | 255 | build_string += ' > %s 2>&1' % output |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 256 | print build_string |
apw | c784610 | 2006-04-06 18:22:13 +0000 | [diff] [blame] | 257 | system(build_string) |
mbligh | 30f28c5 | 2007-10-11 18:35:35 +0000 | [diff] [blame] | 258 | |
apw | c784610 | 2006-04-06 18:22:13 +0000 | [diff] [blame] | 259 | if (not os.path.isfile('vmlinux')): |
| 260 | raise TestError("no vmlinux found, kernel build failed") |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 261 | |
| 262 | |
mbligh | 119c12a | 2007-11-12 22:13:44 +0000 | [diff] [blame] | 263 | @logging.record |
apw | 001e40a | 2007-11-21 19:24:37 +0000 | [diff] [blame] | 264 | @tee_output_logdir_mark |
mbligh | b8e0a11 | 2007-11-05 20:27:36 +0000 | [diff] [blame] | 265 | def clean(self): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 266 | """make clean in the kernel tree""" |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 267 | os.chdir(self.build_dir) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 268 | print "make clean" |
mbligh | 30f28c5 | 2007-10-11 18:35:35 +0000 | [diff] [blame] | 269 | system('make clean > /dev/null 2> /dev/null') |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 270 | |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 271 | |
mbligh | 119c12a | 2007-11-12 22:13:44 +0000 | [diff] [blame] | 272 | @logging.record |
apw | 001e40a | 2007-11-21 19:24:37 +0000 | [diff] [blame] | 273 | @tee_output_logdir_mark |
mbligh | b8e0a11 | 2007-11-05 20:27:36 +0000 | [diff] [blame] | 274 | def mkinitrd(self, version, image, system_map, initrd): |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 275 | """Build kernel initrd image. |
| 276 | Try to use distro specific way to build initrd image. |
| 277 | Parameters: |
| 278 | version |
| 279 | new kernel version |
| 280 | image |
| 281 | new kernel image file |
| 282 | system_map |
| 283 | System.map file |
| 284 | initrd |
| 285 | initrd image file to build |
| 286 | """ |
| 287 | vendor = get_os_vendor() |
| 288 | |
| 289 | if os.path.isfile(initrd): |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 290 | print "Existing %s file, will remove it." % initrd |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 291 | os.remove(initrd) |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 292 | |
apw | e43a30b | 2007-09-25 16:51:30 +0000 | [diff] [blame] | 293 | args = self.job.config_get('kernel.mkinitrd_extra_args') |
| 294 | |
mbligh | 3d515d4 | 2007-11-09 17:00:36 +0000 | [diff] [blame] | 295 | # don't leak 'None' into mkinitrd command |
| 296 | if not args: |
| 297 | args = '' |
| 298 | |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 299 | if vendor in ['Red Hat', 'Fedora Core']: |
apw | e43a30b | 2007-09-25 16:51:30 +0000 | [diff] [blame] | 300 | system('mkinitrd %s %s %s' % (args, initrd, version)) |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 301 | elif vendor in ['SUSE']: |
apw | e43a30b | 2007-09-25 16:51:30 +0000 | [diff] [blame] | 302 | system('mkinitrd %s -k %s -i %s -M %s' % (args, image, initrd, system_map)) |
apw | c898a1f | 2007-02-28 15:27:22 +0000 | [diff] [blame] | 303 | elif vendor in ['Debian', 'Ubuntu']: |
| 304 | if os.path.isfile('/usr/sbin/mkinitrd'): |
| 305 | cmd = '/usr/sbin/mkinitrd' |
| 306 | elif os.path.isfile('/usr/sbin/mkinitramfs'): |
| 307 | cmd = '/usr/sbin/mkinitramfs' |
| 308 | else: |
| 309 | raise TestError('No Debian initrd builder') |
apw | e43a30b | 2007-09-25 16:51:30 +0000 | [diff] [blame] | 310 | system('%s %s -o %s %s' % (cmd, args, initrd, version)) |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 311 | else: |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 312 | raise TestError('Unsupported vendor %s' % vendor) |
mbligh | 50f42ea | 2006-09-30 22:22:21 +0000 | [diff] [blame] | 313 | |
| 314 | |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 315 | def set_build_image(self, image): |
| 316 | self.build_image = image |
| 317 | |
| 318 | |
mbligh | 119c12a | 2007-11-12 22:13:44 +0000 | [diff] [blame] | 319 | @logging.record |
apw | 001e40a | 2007-11-21 19:24:37 +0000 | [diff] [blame] | 320 | @tee_output_logdir_mark |
mbligh | b8e0a11 | 2007-11-05 20:27:36 +0000 | [diff] [blame] | 321 | def install(self, tag='autotest', prefix = '/'): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 322 | """make install in the kernel tree""" |
apw | 87c65c1 | 2007-09-27 17:19:37 +0000 | [diff] [blame] | 323 | |
| 324 | # Record that we have installed the kernel, and |
| 325 | # the tag under which we installed it. |
| 326 | self.installed_as = tag |
| 327 | |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 328 | os.chdir(self.build_dir) |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 329 | |
mbligh | 6a1d4db | 2006-10-06 04:30:16 +0000 | [diff] [blame] | 330 | if not os.path.isdir(prefix): |
| 331 | os.mkdir(prefix) |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 332 | self.boot_dir = os.path.join(prefix, 'boot') |
| 333 | if not os.path.isdir(self.boot_dir): |
| 334 | os.mkdir(self.boot_dir) |
mbligh | 0ad6558 | 2006-10-06 04:16:36 +0000 | [diff] [blame] | 335 | |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 336 | if not self.build_image: |
| 337 | images = glob.glob('arch/*/boot/' + self.build_target) |
| 338 | if len(images): |
| 339 | self.build_image = images[0] |
| 340 | else: |
| 341 | self.build_image = self.build_target |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 342 | |
| 343 | # remember installed files |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 344 | self.vmlinux = self.boot_dir + '/vmlinux-' + tag |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 345 | if (self.build_image != 'vmlinux'): |
apw | 9a61c5b | 2006-11-28 10:03:15 +0000 | [diff] [blame] | 346 | self.image = self.boot_dir + '/vmlinuz-' + tag |
| 347 | else: |
| 348 | self.image = self.vmlinux |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 349 | self.system_map = self.boot_dir + '/System.map-' + tag |
| 350 | self.config = self.boot_dir + '/config-' + tag |
| 351 | self.initrd = '' |
| 352 | |
| 353 | # copy to boot dir |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 354 | force_copy('vmlinux', self.vmlinux) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 355 | if (self.build_image != 'vmlinux'): |
| 356 | force_copy(self.build_image, self.image) |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 357 | force_copy('System.map', self.system_map) |
| 358 | force_copy('.config', self.config) |
| 359 | |
mbligh | 6a1d4db | 2006-10-06 04:30:16 +0000 | [diff] [blame] | 360 | if not kernel_config.modules_needed('.config'): |
| 361 | return |
| 362 | |
| 363 | system('make modules_install INSTALL_MOD_PATH=%s' % prefix) |
| 364 | if prefix == '/': |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 365 | self.initrd = self.boot_dir + '/initrd-' + tag |
mbligh | b8e0a11 | 2007-11-05 20:27:36 +0000 | [diff] [blame] | 366 | self.mkinitrd(self.get_kernel_build_ver(), self.image, |
| 367 | self.system_map, self.initrd) |
mbligh | 5925e96 | 2007-08-30 17:05:22 +0000 | [diff] [blame] | 368 | |
| 369 | |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 370 | def add_to_bootloader(self, tag='autotest', args=''): |
| 371 | """ add this kernel to bootloader, taking an |
| 372 | optional parameter of space separated parameters |
| 373 | e.g.: kernel.add_to_bootloader('mykernel', 'ro acpi=off') |
| 374 | """ |
| 375 | |
| 376 | # remove existing entry if present |
| 377 | self.job.bootloader.remove_kernel(tag) |
| 378 | |
apw | cbe3257 | 2006-11-28 10:00:23 +0000 | [diff] [blame] | 379 | # pull the base argument set from the job config, |
apw | cbe3257 | 2006-11-28 10:00:23 +0000 | [diff] [blame] | 380 | baseargs = self.job.config_get('boot.default_args') |
mbligh | 78bc05e | 2006-12-25 02:29:59 +0000 | [diff] [blame] | 381 | if baseargs: |
| 382 | args = baseargs + " " + args |
| 383 | |
| 384 | # otherwise populate from /proc/cmdline |
| 385 | # if not baseargs: |
| 386 | # baseargs = open('/proc/cmdline', 'r').readline().strip() |
| 387 | # NOTE: This is unnecessary, because boottool does it. |
apw | cbe3257 | 2006-11-28 10:00:23 +0000 | [diff] [blame] | 388 | |
mbligh | 78bc05e | 2006-12-25 02:29:59 +0000 | [diff] [blame] | 389 | root = None |
| 390 | roots = [x for x in args.split() if x.startswith('root=')] |
| 391 | if roots: |
| 392 | root = re.sub('^root=', '', roots[0]) |
| 393 | arglist = [x for x in args.split() if not x.startswith('root=')] |
| 394 | args = ' '.join(arglist) |
mbligh | a87116f | 2006-10-10 02:47:08 +0000 | [diff] [blame] | 395 | |
mbligh | 78bc05e | 2006-12-25 02:29:59 +0000 | [diff] [blame] | 396 | # add the kernel entry |
| 397 | # add_kernel(image, title='autotest', initrd='') |
| 398 | self.job.bootloader.add_kernel(self.image, tag, self.initrd, \ |
| 399 | args = args, root = root) |
mbligh | 6a1d4db | 2006-10-06 04:30:16 +0000 | [diff] [blame] | 400 | |
mbligh | 201aa89 | 2006-10-29 04:02:05 +0000 | [diff] [blame] | 401 | |
mbligh | 548f29a | 2006-10-17 04:55:12 +0000 | [diff] [blame] | 402 | def get_kernel_build_arch(self, arch=None): |
mbligh | 201aa89 | 2006-10-29 04:02:05 +0000 | [diff] [blame] | 403 | """ |
| 404 | Work out the current kernel architecture (as a kernel arch) |
| 405 | """ |
mbligh | 548f29a | 2006-10-17 04:55:12 +0000 | [diff] [blame] | 406 | if not arch: |
| 407 | arch = get_current_kernel_arch() |
| 408 | if re.match('i.86', arch): |
| 409 | return 'i386' |
| 410 | elif re.match('sun4u', arch): |
| 411 | return 'sparc64' |
| 412 | elif re.match('arm.*', arch): |
| 413 | return 'arm' |
| 414 | elif re.match('sa110', arch): |
| 415 | return 'arm' |
| 416 | elif re.match('s390x', arch): |
| 417 | return 's390' |
| 418 | elif re.match('parisc64', arch): |
| 419 | return 'parisc' |
| 420 | elif re.match('ppc.*', arch): |
| 421 | return 'powerpc' |
| 422 | elif re.match('mips.*', arch): |
| 423 | return 'mips' |
| 424 | else: |
| 425 | return arch |
| 426 | |
mbligh | 6a1d4db | 2006-10-06 04:30:16 +0000 | [diff] [blame] | 427 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 428 | def get_kernel_build_release(self): |
| 429 | releasem = re.compile(r'.*UTS_RELEASE\s+"([^"]+)".*'); |
| 430 | versionm = re.compile(r'.*UTS_VERSION\s+"([^"]+)".*'); |
| 431 | |
| 432 | release = None |
| 433 | version = None |
| 434 | |
| 435 | for file in [ self.build_dir + "/include/linux/version.h", |
| 436 | self.build_dir + "/include/linux/utsrelease.h", |
| 437 | self.build_dir + "/include/linux/compile.h" ]: |
| 438 | if os.path.exists(file): |
| 439 | fd = open(file, 'r') |
| 440 | for line in fd.readlines(): |
| 441 | m = releasem.match(line) |
| 442 | if m: |
| 443 | release = m.groups()[0] |
| 444 | m = versionm.match(line) |
| 445 | if m: |
| 446 | version = m.groups()[0] |
| 447 | fd.close() |
| 448 | |
| 449 | return (release, version) |
| 450 | |
| 451 | |
| 452 | def get_kernel_build_ident(self): |
| 453 | (release, version) = self.get_kernel_build_release() |
| 454 | |
| 455 | if not release or not version: |
| 456 | raise JobError('kernel has no identity') |
| 457 | |
| 458 | return release + '::' + version |
| 459 | |
| 460 | |
apw | 11985b7 | 2007-10-04 15:44:47 +0000 | [diff] [blame] | 461 | def boot(self, args='', ident=1): |
apw | 1b5dc36 | 2006-10-31 11:24:26 +0000 | [diff] [blame] | 462 | """ install and boot this kernel, do not care how |
| 463 | just make it happen. |
| 464 | """ |
| 465 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 466 | # If we can check the kernel identity do so. |
| 467 | if ident: |
| 468 | when = int(time.time()) |
| 469 | ident = self.get_kernel_build_ident() |
| 470 | args += " IDENT=%d" % (when) |
| 471 | |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 472 | # TODO: how do we get the changelist number here? |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 473 | self.job.next_step_prepend(["job.kernel_check_ident", |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 474 | when, ident, None, self.subdir]) |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 475 | |
apw | 87c65c1 | 2007-09-27 17:19:37 +0000 | [diff] [blame] | 476 | # Check if the kernel has been installed, if not install |
| 477 | # as the default tag and boot that. |
| 478 | if not self.installed_as: |
| 479 | self.install() |
| 480 | |
| 481 | # Boot the selected tag. |
| 482 | self.add_to_bootloader(args=args, tag=self.installed_as) |
apw | 1b5dc36 | 2006-10-31 11:24:26 +0000 | [diff] [blame] | 483 | |
| 484 | # Boot it. |
apw | 11985b7 | 2007-10-04 15:44:47 +0000 | [diff] [blame] | 485 | self.job.reboot(tag=self.installed_as) |
apw | 1b5dc36 | 2006-10-31 11:24:26 +0000 | [diff] [blame] | 486 | |
| 487 | |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 488 | def get_kernel_build_ver(self): |
mbligh | e11f5fc | 2006-10-04 04:42:22 +0000 | [diff] [blame] | 489 | """Check Makefile and .config to return kernel version""" |
| 490 | version = patchlevel = sublevel = extraversion = localversion = '' |
| 491 | |
| 492 | for line in open(self.build_dir + '/Makefile', 'r').readlines(): |
| 493 | if line.startswith('VERSION'): |
| 494 | version = line[line.index('=') + 1:].strip() |
| 495 | if line.startswith('PATCHLEVEL'): |
| 496 | patchlevel = line[line.index('=') + 1:].strip() |
| 497 | if line.startswith('SUBLEVEL'): |
| 498 | sublevel = line[line.index('=') + 1:].strip() |
| 499 | if line.startswith('EXTRAVERSION'): |
| 500 | extraversion = line[line.index('=') + 1:].strip() |
| 501 | |
| 502 | for line in open(self.build_dir + '/.config', 'r').readlines(): |
| 503 | if line.startswith('CONFIG_LOCALVERSION='): |
| 504 | localversion = line.rstrip().split('"')[1] |
| 505 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 506 | return "%s.%s.%s%s%s" %(version, patchlevel, sublevel, extraversion, localversion) |
mbligh | fdbcaec | 2006-10-01 23:28:57 +0000 | [diff] [blame] | 507 | |
| 508 | |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 509 | def set_build_target(self, build_target): |
| 510 | if build_target: |
| 511 | self.build_target = build_target |
| 512 | print 'BUILD TARGET: %s' % self.build_target |
| 513 | |
| 514 | |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 515 | def set_cross_cc(self, target_arch=None, cross_compile=None, |
| 516 | build_target='bzImage'): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 517 | """Set up to cross-compile. |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 518 | This is broken. We need to work out what the default |
| 519 | compile produces, and if not, THEN set the cross |
| 520 | compiler. |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 521 | """ |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 522 | |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 523 | if self.target_arch: |
| 524 | return |
mbligh | 678823f | 2006-12-07 18:49:00 +0000 | [diff] [blame] | 525 | |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 526 | # if someone has set build_target, don't clobber in set_cross_cc |
| 527 | # run set_build_target before calling set_cross_cc |
| 528 | if not self.build_target: |
| 529 | self.set_build_target(build_target) |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 530 | |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 531 | # If no 'target_arch' given assume native compilation |
| 532 | if target_arch == None: |
mbligh | 548f29a | 2006-10-17 04:55:12 +0000 | [diff] [blame] | 533 | target_arch = get_current_kernel_arch() |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 534 | if target_arch == 'ppc64': |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 535 | if self.build_target == 'bzImage': |
apw | 9a61c5b | 2006-11-28 10:03:15 +0000 | [diff] [blame] | 536 | self.build_target = 'vmlinux' |
mbligh | 678823f | 2006-12-07 18:49:00 +0000 | [diff] [blame] | 537 | |
| 538 | if not cross_compile: |
| 539 | cross_compile = self.job.config_get('kernel.cross_cc') |
| 540 | |
| 541 | if cross_compile: |
| 542 | os.environ['CROSS_COMPILE'] = cross_compile |
| 543 | else: |
| 544 | if os.environ.has_key('CROSS_COMPILE'): |
| 545 | del os.environ['CROSS_COMPILE'] |
| 546 | |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 547 | return # HACK. Crap out for now. |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 548 | |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 549 | # At this point I know what arch I *want* to build for |
| 550 | # but have no way of working out what arch the default |
| 551 | # compiler DOES build for. |
| 552 | |
| 553 | # Oh, and BTW, install_package() doesn't exist yet. |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 554 | |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 555 | if target_arch == 'ppc64': |
| 556 | install_package('ppc64-cross') |
mbligh | 678823f | 2006-12-07 18:49:00 +0000 | [diff] [blame] | 557 | cross_compile = os.path.join(self.autodir, 'sources/ppc64-cross/bin') |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 558 | |
| 559 | elif target_arch == 'x86_64': |
| 560 | install_package('x86_64-cross') |
mbligh | 678823f | 2006-12-07 18:49:00 +0000 | [diff] [blame] | 561 | cross_compile = os.path.join(self.autodir, 'sources/x86_64-cross/bin') |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 562 | |
mbligh | 5970cf0 | 2006-08-06 15:39:22 +0000 | [diff] [blame] | 563 | os.environ['ARCH'] = self.target_arch = target_arch |
| 564 | |
| 565 | self.cross_compile = cross_compile |
| 566 | if self.cross_compile: |
| 567 | os.environ['CROSS_COMPILE'] = self.cross_compile |
mbligh | cc2e666 | 2006-09-14 01:24:07 +0000 | [diff] [blame] | 568 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 569 | |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 570 | def pickle_dump(self, filename): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 571 | """dump a pickle of ourself out to the specified filename |
| 572 | |
| 573 | we can't pickle the backreference to job (it contains fd's), |
mbligh | 709bb9b | 2006-10-12 04:32:16 +0000 | [diff] [blame] | 574 | nor would we want to. Same for logfile (fd's). |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 575 | """ |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 576 | temp = copy.copy(self) |
| 577 | temp.job = None |
mbligh | 709bb9b | 2006-10-12 04:32:16 +0000 | [diff] [blame] | 578 | temp.logfile = None |
mbligh | b8a14e3 | 2006-05-06 00:17:35 +0000 | [diff] [blame] | 579 | pickle.dump(temp, open(filename, 'w')) |
mbligh | 736adc9 | 2007-10-18 03:23:22 +0000 | [diff] [blame] | 580 | |
| 581 | |
| 582 | class rpm_kernel: |
| 583 | """ Class for installing rpm kernel package |
| 584 | """ |
| 585 | |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 586 | def __init__(self, job, rpm_package, subdir): |
mbligh | 736adc9 | 2007-10-18 03:23:22 +0000 | [diff] [blame] | 587 | self.job = job |
mbligh | 6ee7ee0 | 2007-11-13 23:49:05 +0000 | [diff] [blame] | 588 | self.rpm_package = rpm_package |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 589 | self.log_dir = os.path.join(subdir, 'debug') |
| 590 | self.subdir = os.path.basename(subdir) |
mbligh | 736adc9 | 2007-10-18 03:23:22 +0000 | [diff] [blame] | 591 | if os.path.exists(self.log_dir): |
| 592 | system('rm -rf ' + self.log_dir) |
| 593 | os.mkdir(self.log_dir) |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 594 | self.installed_as = None |
| 595 | cl_re = re.compile(r'[-.](\d{7,})\.rpm$') |
| 596 | match = cl_re.findall(rpm_package) |
| 597 | if match: |
| 598 | self.changelist = match[0] |
| 599 | else: |
| 600 | self.changelist = None |
mbligh | 736adc9 | 2007-10-18 03:23:22 +0000 | [diff] [blame] | 601 | |
| 602 | |
mbligh | 119c12a | 2007-11-12 22:13:44 +0000 | [diff] [blame] | 603 | @logging.record |
apw | 001e40a | 2007-11-21 19:24:37 +0000 | [diff] [blame] | 604 | @tee_output_logdir_mark |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 605 | def install(self, tag='autotest'): |
| 606 | self.installed_as = tag |
| 607 | |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 608 | self.rpm_name = system_output('rpm -qp ' + self.rpm_package) |
mbligh | 736adc9 | 2007-10-18 03:23:22 +0000 | [diff] [blame] | 609 | |
| 610 | # install |
| 611 | system('rpm -i --force ' + self.rpm_package) |
| 612 | |
| 613 | # get file list |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 614 | files = system_output('rpm -ql ' + self.rpm_name).splitlines() |
mbligh | 736adc9 | 2007-10-18 03:23:22 +0000 | [diff] [blame] | 615 | |
mbligh | 736adc9 | 2007-10-18 03:23:22 +0000 | [diff] [blame] | 616 | # search for vmlinuz |
| 617 | for file in files: |
| 618 | if file.startswith('/boot/vmlinuz'): |
| 619 | self.image = file |
| 620 | break |
| 621 | else: |
| 622 | raise TestError(self.rpm_package + " doesn't contain /boot/vmlinuz") |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 623 | |
mbligh | 736adc9 | 2007-10-18 03:23:22 +0000 | [diff] [blame] | 624 | # search for initrd |
| 625 | self.initrd = '' |
| 626 | for file in files: |
| 627 | if file.startswith('/boot/initrd'): |
| 628 | self.initrd = file |
| 629 | break |
| 630 | |
| 631 | # get version and release number |
| 632 | self.version, self.release = system_output( |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 633 | 'rpm --queryformat="%{VERSION}\\n%{RELEASE}\\n" -q ' + self.rpm_name).splitlines()[0:2] |
mbligh | 736adc9 | 2007-10-18 03:23:22 +0000 | [diff] [blame] | 634 | |
| 635 | |
| 636 | def add_to_bootloader(self, tag='autotest', args=''): |
| 637 | """ Add this kernel to bootloader |
| 638 | """ |
| 639 | |
| 640 | # remove existing entry if present |
| 641 | self.job.bootloader.remove_kernel(tag) |
| 642 | |
| 643 | # pull the base argument set from the job config |
| 644 | baseargs = self.job.config_get('boot.default_args') |
| 645 | if baseargs: |
| 646 | args = baseargs + ' ' + args |
| 647 | |
| 648 | # otherwise populate from /proc/cmdline |
| 649 | # if not baseargs: |
| 650 | # baseargs = open('/proc/cmdline', 'r').readline().strip() |
| 651 | # NOTE: This is unnecessary, because boottool does it. |
| 652 | |
| 653 | root = None |
| 654 | roots = [x for x in args.split() if x.startswith('root=')] |
| 655 | if roots: |
| 656 | root = re.sub('^root=', '', roots[0]) |
| 657 | arglist = [x for x in args.split() if not x.startswith('root=')] |
| 658 | args = ' '.join(arglist) |
| 659 | |
| 660 | # add the kernel entry |
| 661 | self.job.bootloader.add_kernel(self.image, tag, self.initrd, args = args, root = root) |
mbligh | 10a24a7 | 2007-10-24 21:02:53 +0000 | [diff] [blame] | 662 | |
| 663 | |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 664 | def boot(self, args='', ident=1): |
| 665 | """ install and boot this kernel |
| 666 | """ |
mbligh | 73e82a3 | 2007-11-08 21:35:29 +0000 | [diff] [blame] | 667 | |
mbligh | 10a24a7 | 2007-10-24 21:02:53 +0000 | [diff] [blame] | 668 | # Check if the kernel has been installed, if not install |
| 669 | # as the default tag and boot that. |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 670 | if not self.installed_as: |
mbligh | 73e82a3 | 2007-11-08 21:35:29 +0000 | [diff] [blame] | 671 | self.install() |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 672 | |
| 673 | # If we can check the kernel identity do so. |
| 674 | if ident: |
| 675 | when = int(time.time()) |
| 676 | ident = '-'.join([self.version, self.rpm_name.split('-')[1], self.release]) |
| 677 | args += " IDENT=%d" % (when) |
| 678 | |
| 679 | self.job.next_step_prepend(["job.kernel_check_ident", |
| 680 | when, ident, self.changelist, self.subdir, 'rpm']) |
mbligh | 10a24a7 | 2007-10-24 21:02:53 +0000 | [diff] [blame] | 681 | |
| 682 | # Boot the selected tag. |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 683 | self.add_to_bootloader(args=args, tag=self.installed_as) |
mbligh | 10a24a7 | 2007-10-24 21:02:53 +0000 | [diff] [blame] | 684 | |
| 685 | # Boot it. |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 686 | self.job.reboot(tag=self.installed_as) |
mbligh | 6ee7ee0 | 2007-11-13 23:49:05 +0000 | [diff] [blame] | 687 | |
| 688 | |
| 689 | # pull in some optional site-specific path pre-processing |
| 690 | try: |
| 691 | import site_kernel |
| 692 | preprocess_path = site_kernel.preprocess_path |
| 693 | del site_kernel |
| 694 | except ImportError: |
| 695 | # just make the preprocessor a nop |
| 696 | def preprocess_path(path): |
| 697 | return path |
| 698 | |
| 699 | def auto_kernel(job, path, subdir, tmp_dir, build_dir, leave=False): |
| 700 | """\ |
| 701 | Create a kernel object, dynamically selecting the appropriate class to use |
| 702 | based on the path provided. |
| 703 | """ |
| 704 | path = preprocess_path(path) |
| 705 | if path.endswith('.rpm'): |
| 706 | return rpm_kernel(job, path, subdir) |
| 707 | else: |
| 708 | return kernel(job, path, subdir, tmp_dir, build_dir, leave) |