Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # ex:ts=4:sw=4:sts=4:et |
| 3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- |
| 4 | # |
| 5 | # Copyright (c) 2015, Intel Corporation. |
| 6 | # All rights reserved. |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License version 2 as |
| 10 | # published by the Free Software Foundation. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License along |
| 18 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | # |
| 21 | # AUTHORS |
| 22 | # Ed Bartosh <ed.bartosh@linux.intel.com> |
| 23 | |
| 24 | """Test cases for wic.""" |
| 25 | |
| 26 | import os |
| 27 | import sys |
| 28 | |
| 29 | from glob import glob |
| 30 | from shutil import rmtree |
| 31 | |
| 32 | from oeqa.selftest.base import oeSelfTest |
| 33 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var |
| 34 | |
| 35 | class Wic(oeSelfTest): |
| 36 | """Wic test class.""" |
| 37 | |
| 38 | resultdir = "/var/tmp/wic/build/" |
| 39 | |
| 40 | @classmethod |
| 41 | def setUpClass(cls): |
| 42 | """Build wic runtime dependencies.""" |
| 43 | bitbake('syslinux syslinux-native parted-native gptfdisk-native ' |
| 44 | 'dosfstools-native mtools-native') |
| 45 | Wic.image_is_ready = False |
| 46 | |
| 47 | def setUp(self): |
| 48 | """This code is executed before each test method.""" |
| 49 | if not Wic.image_is_ready: |
| 50 | # build core-image-minimal with required features |
| 51 | features = 'IMAGE_FSTYPES += " hddimg"\nMACHINE_FEATURES_append = " efi"\n' |
| 52 | self.append_config(features) |
| 53 | bitbake('core-image-minimal') |
| 54 | # set this class variable to avoid buiding image many times |
| 55 | Wic.image_is_ready = True |
| 56 | |
| 57 | rmtree(self.resultdir, ignore_errors=True) |
| 58 | |
| 59 | def test01_help(self): |
| 60 | """Test wic --help""" |
| 61 | self.assertEqual(0, runCmd('wic --help').status) |
| 62 | |
| 63 | def test02_createhelp(self): |
| 64 | """Test wic create --help""" |
| 65 | self.assertEqual(0, runCmd('wic create --help').status) |
| 66 | |
| 67 | def test03_listhelp(self): |
| 68 | """Test wic list --help""" |
| 69 | self.assertEqual(0, runCmd('wic list --help').status) |
| 70 | |
| 71 | def test04_build_image_name(self): |
| 72 | """Test wic create directdisk --image-name core-image-minimal""" |
| 73 | self.assertEqual(0, runCmd("wic create directdisk " |
| 74 | "--image-name core-image-minimal").status) |
| 75 | self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) |
| 76 | |
| 77 | def test05_build_artifacts(self): |
| 78 | """Test wic create directdisk providing all artifacts.""" |
| 79 | vars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \ |
| 80 | for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE', |
| 81 | 'STAGING_DIR_NATIVE', 'IMAGE_ROOTFS')) |
| 82 | status = runCmd("wic create directdisk " |
| 83 | "-b %(staging_datadir)s " |
| 84 | "-k %(deploy_dir_image)s " |
| 85 | "-n %(staging_dir_native)s " |
| 86 | "-r %(image_rootfs)s" % vars).status |
| 87 | self.assertEqual(0, status) |
| 88 | self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) |
| 89 | |
| 90 | def test06_gpt_image(self): |
| 91 | """Test creation of core-image-minimal with gpt table and UUID boot""" |
| 92 | self.assertEqual(0, runCmd("wic create directdisk-gpt " |
| 93 | "--image-name core-image-minimal").status) |
| 94 | self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) |
| 95 | |
| 96 | def test07_unsupported_subcommand(self): |
| 97 | """Test unsupported subcommand""" |
| 98 | self.assertEqual(1, runCmd('wic unsupported', |
| 99 | ignore_status=True).status) |
| 100 | |
| 101 | def test08_no_command(self): |
| 102 | """Test wic without command""" |
| 103 | self.assertEqual(1, runCmd('wic', ignore_status=True).status) |
| 104 | |
| 105 | def test09_help_kickstart(self): |
| 106 | """Test wic help overview""" |
| 107 | self.assertEqual(0, runCmd('wic help overview').status) |
| 108 | |
| 109 | def test10_help_plugins(self): |
| 110 | """Test wic help plugins""" |
| 111 | self.assertEqual(0, runCmd('wic help plugins').status) |
| 112 | |
| 113 | def test11_help_kickstart(self): |
| 114 | """Test wic help kickstart""" |
| 115 | self.assertEqual(0, runCmd('wic help kickstart').status) |
| 116 | |
| 117 | def test12_compress_gzip(self): |
| 118 | """Test compressing an image with gzip""" |
| 119 | self.assertEqual(0, runCmd("wic create directdisk " |
| 120 | "--image-name core-image-minimal " |
| 121 | "-c gzip").status) |
| 122 | self.assertEqual(1, len(glob(self.resultdir + \ |
| 123 | "directdisk-*.direct.gz"))) |
| 124 | |
| 125 | def test13_compress_gzip(self): |
| 126 | """Test compressing an image with bzip2""" |
| 127 | self.assertEqual(0, runCmd("wic create directdisk " |
| 128 | "--image-name core-image-minimal " |
| 129 | "-c bzip2").status) |
| 130 | self.assertEqual(1, len(glob(self.resultdir + \ |
| 131 | "directdisk-*.direct.bz2"))) |
| 132 | |
| 133 | def test14_compress_gzip(self): |
| 134 | """Test compressing an image with xz""" |
| 135 | self.assertEqual(0, runCmd("wic create directdisk " |
| 136 | "--image-name core-image-minimal " |
| 137 | "-c xz").status) |
| 138 | self.assertEqual(1, len(glob(self.resultdir + \ |
| 139 | "directdisk-*.direct.xz"))) |
| 140 | |
| 141 | def test15_wrong_compressor(self): |
| 142 | """Test how wic breaks if wrong compressor is provided""" |
| 143 | self.assertEqual(2, runCmd("wic create directdisk " |
| 144 | "--image-name core-image-minimal " |
| 145 | "-c wrong", ignore_status=True).status) |
| 146 | |
| 147 | def test16_rootfs_indirect_recipes(self): |
| 148 | """Test usage of rootfs plugin with rootfs recipes""" |
| 149 | wks = "directdisk-multi-rootfs" |
| 150 | self.assertEqual(0, runCmd("wic create %s " |
| 151 | "--image-name core-image-minimal " |
| 152 | "--rootfs rootfs1=core-image-minimal " |
| 153 | "--rootfs rootfs2=core-image-minimal" \ |
| 154 | % wks).status) |
| 155 | self.assertEqual(1, len(glob(self.resultdir + "%s*.direct" % wks))) |
| 156 | |
| 157 | def test17_rootfs_artifacts(self): |
| 158 | """Test usage of rootfs plugin with rootfs paths""" |
| 159 | vars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \ |
| 160 | for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE', |
| 161 | 'STAGING_DIR_NATIVE', 'IMAGE_ROOTFS')) |
| 162 | vars['wks'] = "directdisk-multi-rootfs" |
| 163 | status = runCmd("wic create %(wks)s " |
| 164 | "-b %(staging_datadir)s " |
| 165 | "-k %(deploy_dir_image)s " |
| 166 | "-n %(staging_dir_native)s " |
| 167 | "--rootfs-dir rootfs1=%(image_rootfs)s " |
| 168 | "--rootfs-dir rootfs2=%(image_rootfs)s" \ |
| 169 | % vars).status |
| 170 | self.assertEqual(0, status) |
| 171 | self.assertEqual(1, len(glob(self.resultdir + \ |
| 172 | "%(wks)s-*.direct" % vars))) |
| 173 | |
| 174 | def test18_iso_image(self): |
| 175 | """Test creation of hybrid iso imagewith legacy and EFI boot""" |
| 176 | self.assertEqual(0, runCmd("wic create mkhybridiso " |
| 177 | "--image-name core-image-minimal").status) |
| 178 | self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.direct"))) |
| 179 | self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.iso"))) |
| 180 | |
| 181 | def test19_image_env(self): |
| 182 | """Test generation of <image>.env files.""" |
| 183 | image = 'core-image-minimal' |
| 184 | stdir = get_bb_var('STAGING_DIR_TARGET', image) |
| 185 | imgdatadir = os.path.join(stdir, 'imgdata') |
| 186 | |
| 187 | basename = get_bb_var('IMAGE_BASENAME', image) |
| 188 | self.assertEqual(basename, image) |
| 189 | path = os.path.join(imgdatadir, basename) + '.env' |
| 190 | self.assertTrue(os.path.isfile(path)) |
| 191 | |
| 192 | wicvars = set(get_bb_var('WICVARS', image).split()) |
| 193 | # filter out optional variables |
| 194 | wicvars = wicvars.difference(('HDDDIR', 'IMAGE_BOOT_FILES', |
| 195 | 'INITRD', 'ISODIR')) |
| 196 | with open(path) as envfile: |
| 197 | content = dict(line.split("=", 1) for line in envfile) |
| 198 | # test if variables used by wic present in the .env file |
| 199 | for var in wicvars: |
| 200 | self.assertTrue(var in content, "%s is not in .env file" % var) |
| 201 | self.assertTrue(content[var]) |
| 202 | |
| 203 | def test20_wic_image_type(self): |
| 204 | """Test building wic images by bitbake""" |
| 205 | self.assertEqual(0, bitbake('wic-image-minimal').status) |
| 206 | |
| 207 | deploy_dir = get_bb_var('DEPLOY_DIR_IMAGE') |
| 208 | machine = get_bb_var('MACHINE') |
| 209 | prefix = os.path.join(deploy_dir, 'wic-image-minimal-%s.' % machine) |
| 210 | # check if we have result image and manifests symlinks |
| 211 | # pointing to existing files |
| 212 | for suffix in ('wic.bz2', 'manifest'): |
| 213 | path = prefix + suffix |
| 214 | self.assertTrue(os.path.islink(path)) |
| 215 | self.assertTrue(os.path.isfile(os.path.realpath(path))) |
| 216 | |
| 217 | def test21_qemux86_directdisk(self): |
| 218 | """Test creation of qemux-86-directdisk image""" |
| 219 | image = "qemux86-directdisk" |
| 220 | self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ |
| 221 | % image).status) |
| 222 | self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) |
| 223 | |
| 224 | def test22_mkgummidisk(self): |
| 225 | """Test creation of mkgummidisk image""" |
| 226 | image = "mkgummidisk" |
| 227 | self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ |
| 228 | % image).status) |
| 229 | self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) |
| 230 | |
| 231 | def test23_mkefidisk(self): |
| 232 | """Test creation of mkefidisk image""" |
| 233 | image = "mkefidisk" |
| 234 | self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ |
| 235 | % image).status) |
| 236 | self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) |