runtime_test.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. from oeqa.core.decorator.oeid import OETestID
  5. import os
  6. import re
  7. import tempfile
  8. import shutil
  9. class TestExport(OESelftestTestCase):
  10. @classmethod
  11. def tearDownClass(cls):
  12. runCmd("rm -rf /tmp/sdk")
  13. super(TestExport, cls).tearDownClass()
  14. @OETestID(1499)
  15. def test_testexport_basic(self):
  16. """
  17. Summary: Check basic testexport functionality with only ping test enabled.
  18. Expected: 1. testexport directory must be created.
  19. 2. runexported.py must run without any error/exception.
  20. 3. ping test must succeed.
  21. Product: oe-core
  22. Author: Mariano Lopez <mariano.lopez@intel.com>
  23. """
  24. features = 'INHERIT += "testexport"\n'
  25. # These aren't the actual IP addresses but testexport class needs something defined
  26. features += 'TEST_SERVER_IP = "192.168.7.1"\n'
  27. features += 'TEST_TARGET_IP = "192.168.7.1"\n'
  28. features += 'TEST_SUITES = "ping"\n'
  29. self.write_config(features)
  30. # Build tesexport for core-image-minimal
  31. bitbake('core-image-minimal')
  32. bitbake('-c testexport core-image-minimal')
  33. testexport_dir = get_bb_var('TEST_EXPORT_DIR', 'core-image-minimal')
  34. # Verify if TEST_EXPORT_DIR was created
  35. isdir = os.path.isdir(testexport_dir)
  36. self.assertEqual(True, isdir, 'Failed to create testexport dir: %s' % testexport_dir)
  37. with runqemu('core-image-minimal') as qemu:
  38. # Attempt to run runexported.py to perform ping test
  39. test_path = os.path.join(testexport_dir, "oe-test")
  40. data_file = os.path.join(testexport_dir, 'data', 'testdata.json')
  41. manifest = os.path.join(testexport_dir, 'data', 'manifest')
  42. cmd = ("%s runtime --test-data-file %s --packages-manifest %s "
  43. "--target-ip %s --server-ip %s --quiet"
  44. % (test_path, data_file, manifest, qemu.ip, qemu.server_ip))
  45. result = runCmd(cmd)
  46. # Verify ping test was succesful
  47. self.assertEqual(0, result.status, 'oe-test runtime returned a non 0 status')
  48. @OETestID(1641)
  49. def test_testexport_sdk(self):
  50. """
  51. Summary: Check sdk functionality for testexport.
  52. Expected: 1. testexport directory must be created.
  53. 2. SDK tarball must exists.
  54. 3. Uncompressing of tarball must succeed.
  55. 4. Check if the SDK directory is added to PATH.
  56. 5. Run tar from the SDK directory.
  57. Product: oe-core
  58. Author: Mariano Lopez <mariano.lopez@intel.com>
  59. """
  60. features = 'INHERIT += "testexport"\n'
  61. # These aren't the actual IP addresses but testexport class needs something defined
  62. features += 'TEST_SERVER_IP = "192.168.7.1"\n'
  63. features += 'TEST_TARGET_IP = "192.168.7.1"\n'
  64. features += 'TEST_SUITES = "ping"\n'
  65. features += 'TEST_EXPORT_SDK_ENABLED = "1"\n'
  66. features += 'TEST_EXPORT_SDK_PACKAGES = "nativesdk-tar"\n'
  67. self.write_config(features)
  68. # Build tesexport for core-image-minimal
  69. bitbake('core-image-minimal')
  70. bitbake('-c testexport core-image-minimal')
  71. needed_vars = ['TEST_EXPORT_DIR', 'TEST_EXPORT_SDK_DIR', 'TEST_EXPORT_SDK_NAME']
  72. bb_vars = get_bb_vars(needed_vars, 'core-image-minimal')
  73. testexport_dir = bb_vars['TEST_EXPORT_DIR']
  74. sdk_dir = bb_vars['TEST_EXPORT_SDK_DIR']
  75. sdk_name = bb_vars['TEST_EXPORT_SDK_NAME']
  76. # Check for SDK
  77. tarball_name = "%s.sh" % sdk_name
  78. tarball_path = os.path.join(testexport_dir, sdk_dir, tarball_name)
  79. msg = "Couldn't find SDK tarball: %s" % tarball_path
  80. self.assertEqual(os.path.isfile(tarball_path), True, msg)
  81. # Extract SDK and run tar from SDK
  82. result = runCmd("%s -y -d /tmp/sdk" % tarball_path)
  83. self.assertEqual(0, result.status, "Couldn't extract SDK")
  84. env_script = result.output.split()[-1]
  85. result = runCmd(". %s; which tar" % env_script, shell=True)
  86. self.assertEqual(0, result.status, "Couldn't setup SDK environment")
  87. is_sdk_tar = True if "/tmp/sdk" in result.output else False
  88. self.assertTrue(is_sdk_tar, "Couldn't setup SDK environment")
  89. tar_sdk = result.output
  90. result = runCmd("%s --version" % tar_sdk)
  91. self.assertEqual(0, result.status, "Couldn't run tar from SDK")
  92. class TestImage(OESelftestTestCase):
  93. @OETestID(1644)
  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 += 'TEST_SUITES = "ping ssh selftest"\n'
  106. self.write_config(features)
  107. # Build core-image-sato and testimage
  108. bitbake('core-image-full-cmdline socat')
  109. bitbake('-c testimage core-image-full-cmdline')
  110. @OETestID(1883)
  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 <alexander.kanavin@intel.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. # Enable package feed signing
  128. self.gpg_home = tempfile.mkdtemp(prefix="oeqa-feed-sign-")
  129. signing_key_dir = os.path.join(self.testlayer_path, 'files', 'signing')
  130. runCmd('gpg --batch --homedir %s --import %s' % (self.gpg_home, os.path.join(signing_key_dir, 'key.secret')))
  131. features += 'INHERIT += "sign_package_feed"\n'
  132. features += 'PACKAGE_FEED_GPG_NAME = "testuser"\n'
  133. features += 'PACKAGE_FEED_GPG_PASSPHRASE_FILE = "%s"\n' % os.path.join(signing_key_dir, 'key.passphrase')
  134. features += 'GPG_PATH = "%s"\n' % self.gpg_home
  135. self.write_config(features)
  136. # Build core-image-sato and testimage
  137. bitbake('core-image-full-cmdline socat')
  138. bitbake('-c testimage core-image-full-cmdline')
  139. # remove the oeqa-feed-sign temporal directory
  140. shutil.rmtree(self.gpg_home, ignore_errors=True)
  141. class Postinst(OESelftestTestCase):
  142. @OETestID(1540)
  143. @OETestID(1545)
  144. def test_postinst_rootfs_and_boot(self):
  145. """
  146. Summary: The purpose of this test case is to verify Post-installation
  147. scripts are called when rootfs is created and also test
  148. that script can be delayed to run at first boot.
  149. Dependencies: NA
  150. Steps: 1. Add proper configuration to local.conf file
  151. 2. Build a "core-image-minimal" image
  152. 3. Verify that file created by postinst_rootfs recipe is
  153. present on rootfs dir.
  154. 4. Boot the image created on qemu and verify that the file
  155. created by postinst_boot recipe is present on image.
  156. Expected: The files are successfully created during rootfs and boot
  157. time for 3 different package managers: rpm,ipk,deb and
  158. for initialization managers: sysvinit and systemd.
  159. """
  160. import oe.path
  161. vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
  162. rootfs = vars["IMAGE_ROOTFS"]
  163. self.assertIsNotNone(rootfs)
  164. sysconfdir = vars["sysconfdir"]
  165. self.assertIsNotNone(sysconfdir)
  166. # Need to use oe.path here as sysconfdir starts with /
  167. hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
  168. targettestdir = os.path.join(sysconfdir, "postinst-test")
  169. for init_manager in ("sysvinit", "systemd"):
  170. for classes in ("package_rpm", "package_deb", "package_ipk"):
  171. with self.subTest(init_manager=init_manager, package_class=classes):
  172. features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-delayed-b"\n'
  173. features += 'IMAGE_FEATURES += "package-management empty-root-password"\n'
  174. features += 'PACKAGE_CLASSES = "%s"\n' % classes
  175. if init_manager == "systemd":
  176. features += 'DISTRO_FEATURES_append = " systemd"\n'
  177. features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n'
  178. features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n'
  179. features += 'VIRTUAL-RUNTIME_initscripts = ""\n'
  180. self.write_config(features)
  181. bitbake('core-image-minimal')
  182. self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs")),
  183. "rootfs state file was not created")
  184. with runqemu('core-image-minimal') as qemu:
  185. # Make the test echo a string and search for that as
  186. # run_serial()'s status code is useless.'
  187. for filename in ("rootfs", "delayed-a", "delayed-b"):
  188. status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
  189. self.assertEqual(output, "found", "%s was not present on boot" % filename)
  190. def test_failing_postinst(self):
  191. """
  192. Summary: The purpose of this test case is to verify that post-installation
  193. scripts that contain errors are properly reported.
  194. Expected: The scriptlet failure is properly reported.
  195. The file that is created after the error in the scriptlet is not present.
  196. Product: oe-core
  197. Author: Alexander Kanavin <alexander.kanavin@intel.com>
  198. """
  199. import oe.path
  200. vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
  201. rootfs = vars["IMAGE_ROOTFS"]
  202. self.assertIsNotNone(rootfs)
  203. sysconfdir = vars["sysconfdir"]
  204. self.assertIsNotNone(sysconfdir)
  205. # Need to use oe.path here as sysconfdir starts with /
  206. hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
  207. for classes in ("package_rpm", "package_deb", "package_ipk"):
  208. with self.subTest(package_class=classes):
  209. features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
  210. features += 'PACKAGE_CLASSES = "%s"\n' % classes
  211. self.write_config(features)
  212. bb_result = bitbake('core-image-minimal')
  213. self.assertGreaterEqual(bb_result.output.find("Intentionally failing postinstall scriptlets of ['postinst-rootfs-failing'] to defer them to first boot is deprecated."), 0,
  214. "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
  215. self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
  216. "rootfs-before-failure file was not created")
  217. self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
  218. "rootfs-after-failure file was created")