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 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 34 | from oeqa.utils.decorators import testcase |
| 35 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 36 | |
| 37 | class Wic(oeSelfTest): |
| 38 | """Wic test class.""" |
| 39 | |
| 40 | resultdir = "/var/tmp/wic/build/" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 41 | image_is_ready = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 43 | def setUpLocal(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | """This code is executed before each test method.""" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 45 | self.write_config('IMAGE_FSTYPES += " hddimg"\nMACHINE_FEATURES_append = " efi"\n') |
| 46 | |
| 47 | # Do this here instead of in setUpClass as the base setUp does some |
| 48 | # clean up which can result in the native tools built earlier in |
| 49 | # setUpClass being unavailable. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | if not Wic.image_is_ready: |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 51 | bitbake('syslinux syslinux-native parted-native gptfdisk-native ' |
| 52 | 'dosfstools-native mtools-native') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | bitbake('core-image-minimal') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | Wic.image_is_ready = True |
| 55 | |
| 56 | rmtree(self.resultdir, ignore_errors=True) |
| 57 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 58 | @testcase(1208) |
| 59 | def test_help(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | """Test wic --help""" |
| 61 | self.assertEqual(0, runCmd('wic --help').status) |
| 62 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 63 | @testcase(1209) |
| 64 | def test_createhelp(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 65 | """Test wic create --help""" |
| 66 | self.assertEqual(0, runCmd('wic create --help').status) |
| 67 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 68 | @testcase(1210) |
| 69 | def test_listhelp(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | """Test wic list --help""" |
| 71 | self.assertEqual(0, runCmd('wic list --help').status) |
| 72 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 73 | @testcase(1211) |
| 74 | def test_build_image_name(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | """Test wic create directdisk --image-name core-image-minimal""" |
| 76 | self.assertEqual(0, runCmd("wic create directdisk " |
| 77 | "--image-name core-image-minimal").status) |
| 78 | self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) |
| 79 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 80 | @testcase(1212) |
| 81 | def test_build_artifacts(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 82 | """Test wic create directdisk providing all artifacts.""" |
| 83 | vars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \ |
| 84 | for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE', |
| 85 | 'STAGING_DIR_NATIVE', 'IMAGE_ROOTFS')) |
| 86 | status = runCmd("wic create directdisk " |
| 87 | "-b %(staging_datadir)s " |
| 88 | "-k %(deploy_dir_image)s " |
| 89 | "-n %(staging_dir_native)s " |
| 90 | "-r %(image_rootfs)s" % vars).status |
| 91 | self.assertEqual(0, status) |
| 92 | self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) |
| 93 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 94 | @testcase(1157) |
| 95 | def test_gpt_image(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | """Test creation of core-image-minimal with gpt table and UUID boot""" |
| 97 | self.assertEqual(0, runCmd("wic create directdisk-gpt " |
| 98 | "--image-name core-image-minimal").status) |
| 99 | self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) |
| 100 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 101 | @testcase(1213) |
| 102 | def test_unsupported_subcommand(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 | """Test unsupported subcommand""" |
| 104 | self.assertEqual(1, runCmd('wic unsupported', |
| 105 | ignore_status=True).status) |
| 106 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 107 | @testcase(1214) |
| 108 | def test_no_command(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 109 | """Test wic without command""" |
| 110 | self.assertEqual(1, runCmd('wic', ignore_status=True).status) |
| 111 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 112 | @testcase(1215) |
| 113 | def test_help_overview(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | """Test wic help overview""" |
| 115 | self.assertEqual(0, runCmd('wic help overview').status) |
| 116 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 117 | @testcase(1216) |
| 118 | def test_help_plugins(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 119 | """Test wic help plugins""" |
| 120 | self.assertEqual(0, runCmd('wic help plugins').status) |
| 121 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 122 | @testcase(1217) |
| 123 | def test_help_kickstart(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 124 | """Test wic help kickstart""" |
| 125 | self.assertEqual(0, runCmd('wic help kickstart').status) |
| 126 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 127 | @testcase(1264) |
| 128 | def test_compress_gzip(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 129 | """Test compressing an image with gzip""" |
| 130 | self.assertEqual(0, runCmd("wic create directdisk " |
| 131 | "--image-name core-image-minimal " |
| 132 | "-c gzip").status) |
| 133 | self.assertEqual(1, len(glob(self.resultdir + \ |
| 134 | "directdisk-*.direct.gz"))) |
| 135 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 136 | @testcase(1265) |
| 137 | def test_compress_bzip2(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 | """Test compressing an image with bzip2""" |
| 139 | self.assertEqual(0, runCmd("wic create directdisk " |
| 140 | "--image-name core-image-minimal " |
| 141 | "-c bzip2").status) |
| 142 | self.assertEqual(1, len(glob(self.resultdir + \ |
| 143 | "directdisk-*.direct.bz2"))) |
| 144 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 145 | @testcase(1266) |
| 146 | def test_compress_xz(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 147 | """Test compressing an image with xz""" |
| 148 | self.assertEqual(0, runCmd("wic create directdisk " |
| 149 | "--image-name core-image-minimal " |
| 150 | "-c xz").status) |
| 151 | self.assertEqual(1, len(glob(self.resultdir + \ |
| 152 | "directdisk-*.direct.xz"))) |
| 153 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 154 | @testcase(1267) |
| 155 | def test_wrong_compressor(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 156 | """Test how wic breaks if wrong compressor is provided""" |
| 157 | self.assertEqual(2, runCmd("wic create directdisk " |
| 158 | "--image-name core-image-minimal " |
| 159 | "-c wrong", ignore_status=True).status) |
| 160 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 161 | @testcase(1268) |
| 162 | def test_rootfs_indirect_recipes(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 163 | """Test usage of rootfs plugin with rootfs recipes""" |
| 164 | wks = "directdisk-multi-rootfs" |
| 165 | self.assertEqual(0, runCmd("wic create %s " |
| 166 | "--image-name core-image-minimal " |
| 167 | "--rootfs rootfs1=core-image-minimal " |
| 168 | "--rootfs rootfs2=core-image-minimal" \ |
| 169 | % wks).status) |
| 170 | self.assertEqual(1, len(glob(self.resultdir + "%s*.direct" % wks))) |
| 171 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 172 | @testcase(1269) |
| 173 | def test_rootfs_artifacts(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 174 | """Test usage of rootfs plugin with rootfs paths""" |
| 175 | vars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \ |
| 176 | for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE', |
| 177 | 'STAGING_DIR_NATIVE', 'IMAGE_ROOTFS')) |
| 178 | vars['wks'] = "directdisk-multi-rootfs" |
| 179 | status = runCmd("wic create %(wks)s " |
| 180 | "-b %(staging_datadir)s " |
| 181 | "-k %(deploy_dir_image)s " |
| 182 | "-n %(staging_dir_native)s " |
| 183 | "--rootfs-dir rootfs1=%(image_rootfs)s " |
| 184 | "--rootfs-dir rootfs2=%(image_rootfs)s" \ |
| 185 | % vars).status |
| 186 | self.assertEqual(0, status) |
| 187 | self.assertEqual(1, len(glob(self.resultdir + \ |
| 188 | "%(wks)s-*.direct" % vars))) |
| 189 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 190 | @testcase(1346) |
| 191 | def test_iso_image(self): |
| 192 | """Test creation of hybrid iso image with legacy and EFI boot""" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 193 | self.assertEqual(0, runCmd("wic create mkhybridiso " |
| 194 | "--image-name core-image-minimal").status) |
| 195 | self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.direct"))) |
| 196 | self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.iso"))) |
| 197 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 198 | @testcase(1347) |
| 199 | def test_image_env(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 200 | """Test generation of <image>.env files.""" |
| 201 | image = 'core-image-minimal' |
| 202 | stdir = get_bb_var('STAGING_DIR_TARGET', image) |
| 203 | imgdatadir = os.path.join(stdir, 'imgdata') |
| 204 | |
| 205 | basename = get_bb_var('IMAGE_BASENAME', image) |
| 206 | self.assertEqual(basename, image) |
| 207 | path = os.path.join(imgdatadir, basename) + '.env' |
| 208 | self.assertTrue(os.path.isfile(path)) |
| 209 | |
| 210 | wicvars = set(get_bb_var('WICVARS', image).split()) |
| 211 | # filter out optional variables |
| 212 | wicvars = wicvars.difference(('HDDDIR', 'IMAGE_BOOT_FILES', |
| 213 | 'INITRD', 'ISODIR')) |
| 214 | with open(path) as envfile: |
| 215 | content = dict(line.split("=", 1) for line in envfile) |
| 216 | # test if variables used by wic present in the .env file |
| 217 | for var in wicvars: |
| 218 | self.assertTrue(var in content, "%s is not in .env file" % var) |
| 219 | self.assertTrue(content[var]) |
| 220 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 221 | @testcase(1351) |
| 222 | def test_wic_image_type(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 223 | """Test building wic images by bitbake""" |
| 224 | self.assertEqual(0, bitbake('wic-image-minimal').status) |
| 225 | |
| 226 | deploy_dir = get_bb_var('DEPLOY_DIR_IMAGE') |
| 227 | machine = get_bb_var('MACHINE') |
| 228 | prefix = os.path.join(deploy_dir, 'wic-image-minimal-%s.' % machine) |
| 229 | # check if we have result image and manifests symlinks |
| 230 | # pointing to existing files |
| 231 | for suffix in ('wic.bz2', 'manifest'): |
| 232 | path = prefix + suffix |
| 233 | self.assertTrue(os.path.islink(path)) |
| 234 | self.assertTrue(os.path.isfile(os.path.realpath(path))) |
| 235 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 236 | @testcase(1348) |
| 237 | def test_qemux86_directdisk(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 238 | """Test creation of qemux-86-directdisk image""" |
| 239 | image = "qemux86-directdisk" |
| 240 | self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ |
| 241 | % image).status) |
| 242 | self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) |
| 243 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 244 | @testcase(1349) |
| 245 | def test_mkgummidisk(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 246 | """Test creation of mkgummidisk image""" |
| 247 | image = "mkgummidisk" |
| 248 | self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ |
| 249 | % image).status) |
| 250 | self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) |
| 251 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 252 | @testcase(1350) |
| 253 | def test_mkefidisk(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 254 | """Test creation of mkefidisk image""" |
| 255 | image = "mkefidisk" |
| 256 | self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ |
| 257 | % image).status) |
| 258 | self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) |