wic.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. """Test cases for wic."""
  24. import os
  25. import sys
  26. from glob import glob
  27. from shutil import rmtree
  28. from oeqa.selftest.base import oeSelfTest
  29. from oeqa.utils.commands import runCmd, bitbake, get_bb_var
  30. from oeqa.utils.decorators import testcase
  31. class Wic(oeSelfTest):
  32. """Wic test class."""
  33. resultdir = "/var/tmp/wic/build/"
  34. @classmethod
  35. def setUpClass(cls):
  36. """Build wic runtime dependencies."""
  37. bitbake('syslinux syslinux-native parted-native gptfdisk-native '
  38. 'dosfstools-native mtools-native')
  39. Wic.image_is_ready = False
  40. def setUpLocal(self):
  41. """This code is executed before each test method."""
  42. if not Wic.image_is_ready:
  43. # build core-image-minimal with required features
  44. features = 'IMAGE_FSTYPES += " hddimg"\nMACHINE_FEATURES_append = " efi"\n'
  45. self.append_config(features)
  46. bitbake('core-image-minimal')
  47. # set this class variable to avoid buiding image many times
  48. Wic.image_is_ready = True
  49. rmtree(self.resultdir, ignore_errors=True)
  50. @testcase(1208)
  51. def test01_help(self):
  52. """Test wic --help"""
  53. self.assertEqual(0, runCmd('wic --help').status)
  54. @testcase(1209)
  55. def test02_createhelp(self):
  56. """Test wic create --help"""
  57. self.assertEqual(0, runCmd('wic create --help').status)
  58. @testcase(1210)
  59. def test03_listhelp(self):
  60. """Test wic list --help"""
  61. self.assertEqual(0, runCmd('wic list --help').status)
  62. @testcase(1211)
  63. def test04_build_image_name(self):
  64. """Test wic create directdisk --image-name core-image-minimal"""
  65. self.assertEqual(0, runCmd("wic create directdisk "
  66. "--image-name core-image-minimal").status)
  67. self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
  68. @testcase(1212)
  69. def test05_build_artifacts(self):
  70. """Test wic create directdisk providing all artifacts."""
  71. vars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \
  72. for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE',
  73. 'STAGING_DIR_NATIVE', 'IMAGE_ROOTFS'))
  74. status = runCmd("wic create directdisk "
  75. "-b %(staging_datadir)s "
  76. "-k %(deploy_dir_image)s "
  77. "-n %(staging_dir_native)s "
  78. "-r %(image_rootfs)s" % vars).status
  79. self.assertEqual(0, status)
  80. self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
  81. @testcase(1157)
  82. def test06_gpt_image(self):
  83. """Test creation of core-image-minimal with gpt table and UUID boot"""
  84. self.assertEqual(0, runCmd("wic create directdisk-gpt "
  85. "--image-name core-image-minimal").status)
  86. self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
  87. @testcase(1213)
  88. def test07_unsupported_subcommand(self):
  89. """Test unsupported subcommand"""
  90. self.assertEqual(1, runCmd('wic unsupported',
  91. ignore_status=True).status)
  92. @testcase(1214)
  93. def test08_no_command(self):
  94. """Test wic without command"""
  95. self.assertEqual(1, runCmd('wic', ignore_status=True).status)
  96. @testcase(1215)
  97. def test09_help_overview(self):
  98. """Test wic help overview"""
  99. self.assertEqual(0, runCmd('wic help overview').status)
  100. @testcase(1216)
  101. def test10_help_plugins(self):
  102. """Test wic help plugins"""
  103. self.assertEqual(0, runCmd('wic help plugins').status)
  104. @testcase(1217)
  105. def test11_help_kickstart(self):
  106. """Test wic help kickstart"""
  107. self.assertEqual(0, runCmd('wic help kickstart').status)
  108. @testcase(1264)
  109. def test12_compress_gzip(self):
  110. """Test compressing an image with gzip"""
  111. self.assertEqual(0, runCmd("wic create directdisk "
  112. "--image-name core-image-minimal "
  113. "-c gzip").status)
  114. self.assertEqual(1, len(glob(self.resultdir + \
  115. "directdisk-*.direct.gz")))
  116. @testcase(1265)
  117. def test13_compress_bzip2(self):
  118. """Test compressing an image with bzip2"""
  119. self.assertEqual(0, runCmd("wic create directdisk "
  120. "--image-name core-image-minimal "
  121. "-c bzip2").status)
  122. self.assertEqual(1, len(glob(self.resultdir + \
  123. "directdisk-*.direct.bz2")))
  124. @testcase(1266)
  125. def test14_compress_xz(self):
  126. """Test compressing an image with xz"""
  127. self.assertEqual(0, runCmd("wic create directdisk "
  128. "--image-name core-image-minimal "
  129. "-c xz").status)
  130. self.assertEqual(1, len(glob(self.resultdir + \
  131. "directdisk-*.direct.xz")))
  132. @testcase(1267)
  133. def test15_wrong_compressor(self):
  134. """Test how wic breaks if wrong compressor is provided"""
  135. self.assertEqual(2, runCmd("wic create directdisk "
  136. "--image-name core-image-minimal "
  137. "-c wrong", ignore_status=True).status)
  138. @testcase(1268)
  139. def test16_rootfs_indirect_recipes(self):
  140. """Test usage of rootfs plugin with rootfs recipes"""
  141. wks = "directdisk-multi-rootfs"
  142. self.assertEqual(0, runCmd("wic create %s "
  143. "--image-name core-image-minimal "
  144. "--rootfs rootfs1=core-image-minimal "
  145. "--rootfs rootfs2=core-image-minimal" \
  146. % wks).status)
  147. self.assertEqual(1, len(glob(self.resultdir + "%s*.direct" % wks)))
  148. @testcase(1269)
  149. def test17_rootfs_artifacts(self):
  150. """Test usage of rootfs plugin with rootfs paths"""
  151. vars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \
  152. for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE',
  153. 'STAGING_DIR_NATIVE', 'IMAGE_ROOTFS'))
  154. vars['wks'] = "directdisk-multi-rootfs"
  155. status = runCmd("wic create %(wks)s "
  156. "-b %(staging_datadir)s "
  157. "-k %(deploy_dir_image)s "
  158. "-n %(staging_dir_native)s "
  159. "--rootfs-dir rootfs1=%(image_rootfs)s "
  160. "--rootfs-dir rootfs2=%(image_rootfs)s" \
  161. % vars).status
  162. self.assertEqual(0, status)
  163. self.assertEqual(1, len(glob(self.resultdir + \
  164. "%(wks)s-*.direct" % vars)))
  165. @testcase(1264)
  166. def test18_iso_image(self):
  167. """Test creation of hybrid iso image with legacy and EFI boot"""
  168. self.assertEqual(0, runCmd("wic create mkhybridiso "
  169. "--image-name core-image-minimal").status)
  170. self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.direct")))
  171. self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.iso")))
  172. @testcase(1347)
  173. def test19_image_env(self):
  174. """Test generation of <image>.env files."""
  175. image = 'core-image-minimal'
  176. stdir = get_bb_var('STAGING_DIR_TARGET', image)
  177. imgdatadir = os.path.join(stdir, 'imgdata')
  178. basename = get_bb_var('IMAGE_BASENAME', image)
  179. self.assertEqual(basename, image)
  180. path = os.path.join(imgdatadir, basename) + '.env'
  181. self.assertTrue(os.path.isfile(path))
  182. wicvars = set(get_bb_var('WICVARS', image).split())
  183. # filter out optional variables
  184. wicvars = wicvars.difference(('HDDDIR', 'IMAGE_BOOT_FILES',
  185. 'INITRD', 'ISODIR'))
  186. with open(path) as envfile:
  187. content = dict(line.split("=", 1) for line in envfile)
  188. # test if variables used by wic present in the .env file
  189. for var in wicvars:
  190. self.assertTrue(var in content, "%s is not in .env file" % var)
  191. self.assertTrue(content[var])
  192. @testcase(1351)
  193. def test20_wic_image_type(self):
  194. """Test building wic images by bitbake"""
  195. self.assertEqual(0, bitbake('wic-image-minimal').status)
  196. deploy_dir = get_bb_var('DEPLOY_DIR_IMAGE')
  197. machine = get_bb_var('MACHINE')
  198. prefix = os.path.join(deploy_dir, 'wic-image-minimal-%s.' % machine)
  199. # check if we have result image and manifests symlinks
  200. # pointing to existing files
  201. for suffix in ('wic.bz2', 'manifest'):
  202. path = prefix + suffix
  203. self.assertTrue(os.path.islink(path))
  204. self.assertTrue(os.path.isfile(os.path.realpath(path)))
  205. @testcase(1348)
  206. def test21_qemux86_directdisk(self):
  207. """Test creation of qemux-86-directdisk image"""
  208. image = "qemux86-directdisk"
  209. self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \
  210. % image).status)
  211. self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image)))
  212. @testcase(1349)
  213. def test22_mkgummidisk(self):
  214. """Test creation of mkgummidisk image"""
  215. image = "mkgummidisk"
  216. self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \
  217. % image).status)
  218. self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image)))
  219. @testcase(1350)
  220. def test23_mkefidisk(self):
  221. """Test creation of mkefidisk image"""
  222. image = "mkefidisk"
  223. self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \
  224. % image).status)
  225. self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image)))