mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 1 | __author__ = """Copyright Martin J. Bligh, 2006, |
| 2 | Copyright IBM Corp. 2006, Ryan Harper <ryanh@us.ibm.com>""" |
| 3 | |
mbligh | 02ff2d5 | 2008-06-03 15:00:21 +0000 | [diff] [blame] | 4 | import os, shutil, copy, pickle, re, glob |
mbligh | c61fb36 | 2008-06-05 16:22:15 +0000 | [diff] [blame] | 5 | from autotest_lib.client.bin import kernel, kernel_config, os_dep, test |
mbligh | 53da18e | 2009-01-05 21:13:26 +0000 | [diff] [blame^] | 6 | from autotest_lib.client.bin import utils |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 7 | |
| 8 | |
| 9 | class xen(kernel.kernel): |
| 10 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 11 | def log(self, msg): |
| 12 | print msg |
| 13 | self.logfile.write('%s\n' % msg) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 14 | |
| 15 | |
mbligh | 8b35285 | 2008-06-07 01:07:08 +0000 | [diff] [blame] | 16 | def __init__(self, job, base_tree, results_dir, tmp_dir, build_dir, |
| 17 | leave = False, kjob = None): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 18 | # call base-class |
mbligh | 8b35285 | 2008-06-07 01:07:08 +0000 | [diff] [blame] | 19 | kernel.kernel.__init__(self, job, base_tree, results_dir, |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 20 | tmp_dir, build_dir, leave) |
| 21 | self.kjob = kjob |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 22 | |
| 23 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 24 | def config(self, config_file, config_list = None): |
| 25 | raise NotImplementedError('config() not implemented for xen') |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 26 | |
| 27 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 28 | def build(self, make_opts = '', logfile = '', extraversion='autotest'): |
| 29 | """build xen |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 30 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 31 | make_opts |
| 32 | additional options to make, if any |
| 33 | """ |
| 34 | self.log('running build') |
| 35 | os_dep.commands('gcc', 'make') |
| 36 | # build xen with extraversion flag |
| 37 | os.environ['XEN_EXTRAVERSION'] = '-unstable-%s'% extraversion |
| 38 | if logfile == '': |
| 39 | logfile = os.path.join(self.log_dir, 'xen_build') |
| 40 | os.chdir(self.build_dir) |
| 41 | self.log('log_dir: %s ' % os.path.join(self.log_dir, 'stdout')) |
| 42 | self.job.stdout.tee_redirect(logfile + '.stdout') |
| 43 | self.job.stderr.tee_redirect(logfile + '.stderr') |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 44 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 45 | # build xen hypervisor and user-space tools |
| 46 | targets = ['xen', 'tools'] |
mbligh | 53da18e | 2009-01-05 21:13:26 +0000 | [diff] [blame^] | 47 | threads = 2 * utils.count_cpus() |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 48 | for t in targets: |
| 49 | build_string = 'make -j %d %s %s' % (threads, make_opts, t) |
| 50 | self.log('build_string: %s' % build_string) |
mbligh | 23955fc | 2008-06-12 17:41:18 +0000 | [diff] [blame] | 51 | utils.system(build_string) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 52 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 53 | # make a kernel job out of the kernel from the xen src if one isn't provided |
mbligh | d876f45 | 2008-12-03 15:09:17 +0000 | [diff] [blame] | 54 | if self.kjob is None: |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 55 | # get xen kernel tree ready |
| 56 | self.log("prep-ing xen'ified kernel source tree") |
mbligh | 23955fc | 2008-06-12 17:41:18 +0000 | [diff] [blame] | 57 | utils.system('make prep-kernels') |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 58 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 59 | v = self.get_xen_kernel_build_ver() |
| 60 | self.log('building xen kernel version: %s' % v) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 61 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 62 | # build xen-ified kernel in xen tree |
| 63 | kernel_base_tree = os.path.join(self.build_dir, \ |
| 64 | 'linux-%s' % self.get_xen_kernel_build_ver()) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 65 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 66 | self.log('kernel_base_tree = %s' % kernel_base_tree) |
| 67 | # fix up XENGUEST value in EXTRAVERSION; we can't have |
| 68 | # files with '$(XENGEUST)' in the name, =( |
| 69 | self.fix_up_xen_kernel_makefile(kernel_base_tree) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 70 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 71 | # make the kernel job |
| 72 | self.kjob = self.job.kernel(kernel_base_tree) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 73 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 74 | # hardcoding dom0 config (no modules for testing, yay!) |
| 75 | # FIXME: probe host to determine which config to pick |
| 76 | c = self.build_dir + '/buildconfigs/linux-defconfig_xen0_x86_32' |
| 77 | self.log('using kernel config: %s ' % c) |
| 78 | self.kjob.config(c) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 79 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 80 | # Xen's kernel tree sucks; doesn't use bzImage, but vmlinux |
| 81 | self.kjob.set_build_target('vmlinuz') |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 82 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 83 | # also, the vmlinuz is not out in arch/*/boot, ARGH! more hackery |
| 84 | self.kjob.set_build_image(self.job.tmpdir + '/build/linux/vmlinuz') |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 85 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 86 | self.kjob.build() |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 87 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 88 | self.job.stdout.restore() |
| 89 | self.job.stderr.restore() |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 90 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 91 | xen_version = self.get_xen_build_ver() |
| 92 | self.log('BUILD VERSION: Xen: %s Kernel:%s' % \ |
| 93 | (xen_version, self.kjob.get_kernel_build_ver())) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 94 | |
| 95 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 96 | def build_timed(self, *args, **kwds): |
| 97 | raise NotImplementedError('build_timed() not implemented') |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 98 | |
| 99 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 100 | def install(self, tag='', prefix = '/', extraversion='autotest'): |
| 101 | """make install in the kernel tree""" |
| 102 | self.log('Installing ...') |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 103 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 104 | os.chdir(self.build_dir) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 105 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 106 | if not os.path.isdir(prefix): |
| 107 | os.mkdir(prefix) |
| 108 | self.boot_dir = os.path.join(prefix, 'boot') |
| 109 | if not os.path.isdir(self.boot_dir): |
| 110 | os.mkdir(self.boot_dir) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 111 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 112 | # remember what we are going to install |
| 113 | xen_version = '%s-%s' % (self.get_xen_build_ver(), extraversion) |
| 114 | self.xen_image = self.boot_dir + '/xen-' + xen_version + '.gz' |
| 115 | self.xen_syms = self.boot_dir + '/xen-syms-' + xen_version |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 116 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 117 | self.log('Installing Xen ...') |
| 118 | os.environ['XEN_EXTRAVERSION'] = '-unstable-%s'% extraversion |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 119 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 120 | # install xen |
mbligh | 23955fc | 2008-06-12 17:41:18 +0000 | [diff] [blame] | 121 | utils.system('make DESTDIR=%s -C xen install' % prefix) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 122 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 123 | # install tools |
mbligh | 23955fc | 2008-06-12 17:41:18 +0000 | [diff] [blame] | 124 | utils.system('make DESTDIR=%s -C tools install' % prefix) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 125 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 126 | # install kernel |
| 127 | ktag = self.kjob.get_kernel_build_ver() |
| 128 | kprefix = prefix |
| 129 | self.kjob.install(tag=ktag, prefix=kprefix) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 130 | |
| 131 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 132 | def add_to_bootloader(self, tag='autotest', args=''): |
| 133 | """ add this kernel to bootloader, taking an |
| 134 | optional parameter of space separated parameters |
| 135 | e.g.: kernel.add_to_bootloader('mykernel', 'ro acpi=off') |
| 136 | """ |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 137 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 138 | # turn on xen mode |
| 139 | self.job.bootloader.enable_xen_mode() |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 140 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 141 | # remove existing entry if present |
| 142 | self.job.bootloader.remove_kernel(tag) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 143 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 144 | # add xen and xen kernel |
mbligh | 8b35285 | 2008-06-07 01:07:08 +0000 | [diff] [blame] | 145 | self.job.bootloader.add_kernel(self.kjob.image, tag, |
| 146 | self.kjob.initrd, self.xen_image) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 147 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 148 | # if no args passed, populate from /proc/cmdline |
| 149 | if not args: |
| 150 | args = open('/proc/cmdline', 'r').readline().strip() |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 151 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 152 | # add args to entry one at a time |
| 153 | for a in args.split(' '): |
| 154 | self.job.bootloader.add_args(tag, a) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 155 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 156 | # turn off xen mode |
| 157 | self.job.bootloader.disable_xen_mode() |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 158 | |
| 159 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 160 | def get_xen_kernel_build_ver(self): |
| 161 | """Check xen buildconfig for current kernel version""" |
| 162 | version = patchlevel = sublevel = '' |
| 163 | extraversion = localversion = '' |
mbligh | f25cde1 | 2006-12-17 23:13:48 +0000 | [diff] [blame] | 164 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 165 | version_file = self.build_dir + '/buildconfigs/mk.linux-2.6-xen' |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 166 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 167 | for line in open(version_file, 'r').readlines(): |
| 168 | if line.startswith('LINUX_VER'): |
| 169 | start = line.index('=') + 1 |
| 170 | version = line[start:].strip() + "-xen" |
| 171 | break |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 172 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 173 | return version |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 174 | |
| 175 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 176 | def fix_up_xen_kernel_makefile(self, kernel_dir): |
| 177 | """Fix up broken EXTRAVERSION in xen-ified Linux kernel Makefile""" |
| 178 | xenguest = '' |
| 179 | makefile = kernel_dir + '/Makefile' |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 180 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 181 | for line in open(makefile, 'r').readlines(): |
| 182 | if line.startswith('XENGUEST'): |
| 183 | start = line.index('=') + 1 |
| 184 | xenguest = line[start:].strip() |
| 185 | break; |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 186 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 187 | # change out $XENGUEST in EXTRAVERSION line |
mbligh | 23955fc | 2008-06-12 17:41:18 +0000 | [diff] [blame] | 188 | utils.system('sed -i.old "s,\$(XENGUEST),%s," %s' % (xenguest, |
| 189 | makefile)) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 190 | |
| 191 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 192 | def get_xen_build_ver(self): |
| 193 | """Check Makefile and .config to return kernel version""" |
| 194 | version = patchlevel = sublevel = '' |
| 195 | extraversion = localversion = '' |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 196 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 197 | for line in open(self.build_dir + '/xen/Makefile', 'r').readlines(): |
| 198 | if line.startswith('export XEN_VERSION'): |
| 199 | start = line.index('=') + 1 |
| 200 | version = line[start:].strip() |
| 201 | if line.startswith('export XEN_SUBVERSION'): |
| 202 | start = line.index('=') + 1 |
| 203 | sublevel = line[start:].strip() |
| 204 | if line.startswith('export XEN_EXTRAVERSION'): |
| 205 | start = line.index('=') + 1 |
| 206 | extraversion = line[start:].strip() |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 207 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 208 | return "%s.%s%s" % (version, sublevel, extraversion) |