runtime_test.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. from oeqa.selftest.case import OESelftestTestCase
  2. from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu
  3. from oeqa.utils.sshcontrol import SSHControl
  4. import os
  5. import re
  6. import tempfile
  7. import shutil
  8. import oe.lsb
  9. class TestExport(OESelftestTestCase):
  10. @classmethod
  11. def tearDownClass(cls):
  12. runCmd("rm -rf /tmp/sdk")
  13. super(TestExport, cls).tearDownClass()
  14. def test_testexport_basic(self):
  15. """
  16. Summary: Check basic testexport functionality with only ping test enabled.
  17. Expected: 1. testexport directory must be created.
  18. 2. runexported.py must run without any error/exception.
  19. 3. ping test must succeed.
  20. Product: oe-core
  21. Author: Mariano Lopez <mariano.lopez@intel.com>
  22. """
  23. features = 'INHERIT += "testexport"\n'
  24. # These aren't the actual IP addresses but testexport class needs something defined
  25. features += 'TEST_SERVER_IP = "192.168.7.1"\n'
  26. features += 'TEST_TARGET_IP = "192.168.7.1"\n'
  27. features += 'TEST_SUITES = "ping"\n'
  28. self.write_config(features)
  29. # Build tesexport for core-image-minimal
  30. bitbake('core-image-minimal')
  31. bitbake('-c testexport core-image-minimal')
  32. testexport_dir = get_bb_var('TEST_EXPORT_DIR', 'core-image-minimal')
  33. # Verify if TEST_EXPORT_DIR was created
  34. isdir = os.path.isdir(testexport_dir)
  35. self.assertEqual(True, isdir, 'Failed to create testexport dir: %s' % testexport_dir)
  36. with runqemu('core-image-minimal') as qemu:
  37. # Attempt to run runexported.py to perform ping test
  38. test_path = os.path.join(testexport_dir, "oe-test")
  39. data_file = os.path.join(testexport_dir, 'data', 'testdata.json')
  40. manifest = os.path.join(testexport_dir, 'data', 'manifest')
  41. cmd = ("%s runtime --test-data-file %s --packages-manifest %s "
  42. "--target-ip %s --server-ip %s --quiet"
  43. % (test_path, data_file, manifest, qemu.ip, qemu.server_ip))
  44. result = runCmd(cmd)
  45. # Verify ping test was succesful
  46. self.assertEqual(0, result.status, 'oe-test runtime returned a non 0 status')
  47. def test_testexport_sdk(self):
  48. """
  49. Summary: Check sdk functionality for testexport.
  50. Expected: 1. testexport directory must be created.
  51. 2. SDK tarball must exists.
  52. 3. Uncompressing of tarball must succeed.
  53. 4. Check if the SDK directory is added to PATH.
  54. 5. Run tar from the SDK directory.
  55. Product: oe-core
  56. Author: Mariano Lopez <mariano.lopez@intel.com>
  57. """
  58. features = 'INHERIT += "testexport"\n'
  59. # These aren't the actual IP addresses but testexport class needs something defined
  60. features += 'TEST_SERVER_IP = "192.168.7.1"\n'
  61. features += 'TEST_TARGET_IP = "192.168.7.1"\n'
  62. features += 'TEST_SUITES = "ping"\n'
  63. features += 'TEST_EXPORT_SDK_ENABLED = "1"\n'
  64. features += 'TEST_EXPORT_SDK_PACKAGES = "nativesdk-tar"\n'
  65. self.write_config(features)
  66. # Build tesexport for core-image-minimal
  67. bitbake('core-image-minimal')
  68. bitbake('-c testexport core-image-minimal')
  69. needed_vars = ['TEST_EXPORT_DIR', 'TEST_EXPORT_SDK_DIR', 'TEST_EXPORT_SDK_NAME']
  70. bb_vars = get_bb_vars(needed_vars, 'core-image-minimal')
  71. testexport_dir = bb_vars['TEST_EXPORT_DIR']
  72. sdk_dir = bb_vars['TEST_EXPORT_SDK_DIR']
  73. sdk_name = bb_vars['TEST_EXPORT_SDK_NAME']
  74. # Check for SDK
  75. tarball_name = "%s.sh" % sdk_name
  76. tarball_path = os.path.join(testexport_dir, sdk_dir, tarball_name)
  77. msg = "Couldn't find SDK tarball: %s" % tarball_path
  78. self.assertEqual(os.path.isfile(tarball_path), True, msg)
  79. # Extract SDK and run tar from SDK
  80. result = runCmd("%s -y -d /tmp/sdk" % tarball_path)
  81. self.assertEqual(0, result.status, "Couldn't extract SDK")
  82. env_script = result.output.split()[-1]
  83. result = runCmd(". %s; which tar" % env_script, shell=True)
  84. self.assertEqual(0, result.status, "Couldn't setup SDK environment")
  85. is_sdk_tar = True if "/tmp/sdk" in result.output else False
  86. self.assertTrue(is_sdk_tar, "Couldn't setup SDK environment")
  87. tar_sdk = result.output
  88. result = runCmd("%s --version" % tar_sdk)
  89. self.assertEqual(0, result.status, "Couldn't run tar from SDK")
  90. class TestImage(OESelftestTestCase):
  91. def test_testimage_install(self):
  92. """
  93. Summary: Check install packages functionality for testimage/testexport.
  94. Expected: 1. Import tests from a directory other than meta.
  95. 2. Check install/uninstall of socat.
  96. Product: oe-core
  97. Author: Mariano Lopez <mariano.lopez@intel.com>
  98. """
  99. if get_bb_var('DISTRO') == 'poky-tiny':
  100. self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
  101. features = 'INHERIT += "testimage"\n'
  102. features += 'IMAGE_INSTALL_append = " libssl"\n'
  103. features += 'TEST_SUITES = "ping ssh selftest"\n'
  104. self.write_config(features)
  105. # Build core-image-sato and testimage
  106. bitbake('core-image-full-cmdline socat')
  107. bitbake('-c testimage core-image-full-cmdline')
  108. def test_testimage_dnf(self):
  109. """
  110. Summary: Check package feeds functionality for dnf
  111. Expected: 1. Check that remote package feeds can be accessed
  112. Product: oe-core
  113. Author: Alexander Kanavin <alex.kanavin@gmail.com>
  114. """
  115. if get_bb_var('DISTRO') == 'poky-tiny':
  116. self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
  117. features = 'INHERIT += "testimage"\n'
  118. features += 'TEST_SUITES = "ping ssh dnf_runtime dnf.DnfBasicTest.test_dnf_help"\n'
  119. # We don't yet know what the server ip and port will be - they will be patched
  120. # in at the start of the on-image test
  121. features += 'PACKAGE_FEED_URIS = "http://bogus_ip:bogus_port"\n'
  122. features += 'EXTRA_IMAGE_FEATURES += "package-management"\n'
  123. features += 'PACKAGE_CLASSES = "package_rpm"\n'
  124. bitbake('gnupg-native -c addto_recipe_sysroot')
  125. # Enable package feed signing
  126. self.gpg_home = tempfile.mkdtemp(prefix="oeqa-feed-sign-")
  127. signing_key_dir = os.path.join(self.testlayer_path, 'files', 'signing')
  128. runCmd('gpg --batch --homedir %s --import %s' % (self.gpg_home, os.path.join(signing_key_dir, 'key.secret')), native_sysroot=get_bb_var("RECIPE_SYSROOT_NATIVE", "gnupg-native"))
  129. features += 'INHERIT += "sign_package_feed"\n'
  130. features += 'PACKAGE_FEED_GPG_NAME = "testuser"\n'
  131. features += 'PACKAGE_FEED_GPG_PASSPHRASE_FILE = "%s"\n' % os.path.join(signing_key_dir, 'key.passphrase')
  132. features += 'GPG_PATH = "%s"\n' % self.gpg_home
  133. self.write_config(features)
  134. # Build core-image-sato and testimage
  135. bitbake('core-image-full-cmdline socat')
  136. bitbake('-c testimage core-image-full-cmdline')
  137. # remove the oeqa-feed-sign temporal directory
  138. shutil.rmtree(self.gpg_home, ignore_errors=True)
  139. def test_testimage_virgl_gtk(self):
  140. """
  141. Summary: Check host-assisted accelerate OpenGL functionality in qemu with gtk frontend
  142. Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
  143. 2. Check that kmscube demo runs without crashing.
  144. Product: oe-core
  145. Author: Alexander Kanavin <alex.kanavin@gmail.com>
  146. """
  147. if "DISPLAY" not in os.environ:
  148. self.skipTest("virgl gtk test must be run inside a X session")
  149. distro = oe.lsb.distro_identifier()
  150. if distro and distro == 'debian-8':
  151. self.skipTest('virgl isn\'t working with Debian 8')
  152. qemu_packageconfig = get_bb_var('PACKAGECONFIG', 'qemu-system-native')
  153. features = 'INHERIT += "testimage"\n'
  154. if 'gtk+' not in qemu_packageconfig:
  155. features += 'PACKAGECONFIG_append_pn-qemu-system-native = " gtk+"\n'
  156. if 'virglrenderer' not in qemu_packageconfig:
  157. features += 'PACKAGECONFIG_append_pn-qemu-system-native = " virglrenderer"\n'
  158. if 'glx' not in qemu_packageconfig:
  159. features += 'PACKAGECONFIG_append_pn-qemu-system-native = " glx"\n'
  160. features += 'TEST_SUITES = "ping ssh virgl"\n'
  161. features += 'IMAGE_FEATURES_append = " ssh-server-dropbear"\n'
  162. features += 'IMAGE_INSTALL_append = " kmscube"\n'
  163. features += 'TEST_RUNQEMUPARAMS = "gtk-gl"\n'
  164. self.write_config(features)
  165. bitbake('core-image-minimal')
  166. bitbake('-c testimage core-image-minimal')
  167. def test_testimage_virgl_headless(self):
  168. """
  169. Summary: Check host-assisted accelerate OpenGL functionality in qemu with egl-headless frontend
  170. Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
  171. 2. Check that kmscube demo runs without crashing.
  172. Product: oe-core
  173. Author: Alexander Kanavin <alex.kanavin@gmail.com>
  174. """
  175. import subprocess, os
  176. try:
  177. content = os.listdir("/dev/dri")
  178. if len([i for i in content if i.startswith('render')]) == 0:
  179. self.skipTest("No render nodes found in /dev/dri: %s" %(content))
  180. except FileNotFoundError:
  181. self.skipTest("/dev/dri directory does not exist; no render nodes available on this machine.")
  182. try:
  183. dripath = subprocess.check_output("pkg-config --variable=dridriverdir dri", shell=True)
  184. except subprocess.CalledProcessError as e:
  185. self.skipTest("Could not determine the path to dri drivers on the host via pkg-config.\nPlease install Mesa development files (particularly, dri.pc) on the host machine.")
  186. qemu_packageconfig = get_bb_var('PACKAGECONFIG', 'qemu-system-native')
  187. features = 'INHERIT += "testimage"\n'
  188. if 'virglrenderer' not in qemu_packageconfig:
  189. features += 'PACKAGECONFIG_append_pn-qemu-system-native = " virglrenderer"\n'
  190. if 'glx' not in qemu_packageconfig:
  191. features += 'PACKAGECONFIG_append_pn-qemu-system-native = " glx"\n'
  192. features += 'TEST_SUITES = "ping ssh virgl"\n'
  193. features += 'IMAGE_FEATURES_append = " ssh-server-dropbear"\n'
  194. features += 'IMAGE_INSTALL_append = " kmscube"\n'
  195. features += 'TEST_RUNQEMUPARAMS = "egl-headless"\n'
  196. self.write_config(features)
  197. bitbake('core-image-minimal')
  198. bitbake('-c testimage core-image-minimal')
  199. class Postinst(OESelftestTestCase):
  200. def test_postinst_rootfs_and_boot(self):
  201. """
  202. Summary: The purpose of this test case is to verify Post-installation
  203. scripts are called when rootfs is created and also test
  204. that script can be delayed to run at first boot.
  205. Dependencies: NA
  206. Steps: 1. Add proper configuration to local.conf file
  207. 2. Build a "core-image-minimal" image
  208. 3. Verify that file created by postinst_rootfs recipe is
  209. present on rootfs dir.
  210. 4. Boot the image created on qemu and verify that the file
  211. created by postinst_boot recipe is present on image.
  212. Expected: The files are successfully created during rootfs and boot
  213. time for 3 different package managers: rpm,ipk,deb and
  214. for initialization managers: sysvinit and systemd.
  215. """
  216. import oe.path
  217. vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
  218. rootfs = vars["IMAGE_ROOTFS"]
  219. self.assertIsNotNone(rootfs)
  220. sysconfdir = vars["sysconfdir"]
  221. self.assertIsNotNone(sysconfdir)
  222. # Need to use oe.path here as sysconfdir starts with /
  223. hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
  224. targettestdir = os.path.join(sysconfdir, "postinst-test")
  225. for init_manager in ("sysvinit", "systemd"):
  226. for classes in ("package_rpm", "package_deb", "package_ipk"):
  227. with self.subTest(init_manager=init_manager, package_class=classes):
  228. features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-delayed-b"\n'
  229. features += 'IMAGE_FEATURES += "package-management empty-root-password"\n'
  230. features += 'PACKAGE_CLASSES = "%s"\n' % classes
  231. if init_manager == "systemd":
  232. features += 'DISTRO_FEATURES_append = " systemd"\n'
  233. features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n'
  234. features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n'
  235. features += 'VIRTUAL-RUNTIME_initscripts = ""\n'
  236. self.write_config(features)
  237. bitbake('core-image-minimal')
  238. self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs")),
  239. "rootfs state file was not created")
  240. with runqemu('core-image-minimal') as qemu:
  241. # Make the test echo a string and search for that as
  242. # run_serial()'s status code is useless.'
  243. for filename in ("rootfs", "delayed-a", "delayed-b"):
  244. status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
  245. self.assertEqual(output, "found", "%s was not present on boot" % filename)
  246. def test_failing_postinst(self):
  247. """
  248. Summary: The purpose of this test case is to verify that post-installation
  249. scripts that contain errors are properly reported.
  250. Expected: The scriptlet failure is properly reported.
  251. The file that is created after the error in the scriptlet is not present.
  252. Product: oe-core
  253. Author: Alexander Kanavin <alex.kanavin@gmail.com>
  254. """
  255. import oe.path
  256. vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
  257. rootfs = vars["IMAGE_ROOTFS"]
  258. self.assertIsNotNone(rootfs)
  259. sysconfdir = vars["sysconfdir"]
  260. self.assertIsNotNone(sysconfdir)
  261. # Need to use oe.path here as sysconfdir starts with /
  262. hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
  263. for classes in ("package_rpm", "package_deb", "package_ipk"):
  264. with self.subTest(package_class=classes):
  265. features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
  266. features += 'PACKAGE_CLASSES = "%s"\n' % classes
  267. self.write_config(features)
  268. bb_result = bitbake('core-image-minimal', ignore_status=True)
  269. self.assertGreaterEqual(bb_result.output.find("Postinstall scriptlets of ['postinst-rootfs-failing'] have failed."), 0,
  270. "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
  271. self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
  272. "rootfs-before-failure file was not created")
  273. self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
  274. "rootfs-after-failure file was created")