runtime_test.py 15 KB

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