runtime_test.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. from oeqa.core.decorator.data import skipIfNotQemu
  13. class TestExport(OESelftestTestCase):
  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. with tempfile.TemporaryDirectory() as tmpdirname:
  80. # Extract SDK and run tar from SDK
  81. result = runCmd("%s -y -d %s" % (tarball_path, tmpdirname))
  82. self.assertEqual(0, result.status, "Couldn't extract SDK")
  83. env_script = result.output.split()[-1]
  84. result = runCmd(". %s; which tar" % env_script, shell=True)
  85. self.assertEqual(0, result.status, "Couldn't setup SDK environment")
  86. is_sdk_tar = True if tmpdirname in result.output else False
  87. self.assertTrue(is_sdk_tar, "Couldn't setup SDK environment")
  88. tar_sdk = result.output
  89. result = runCmd("%s --version" % tar_sdk)
  90. self.assertEqual(0, result.status, "Couldn't run tar from SDK")
  91. class TestImage(OESelftestTestCase):
  92. def test_testimage_install(self):
  93. """
  94. Summary: Check install packages functionality for testimage/testexport.
  95. Expected: 1. Import tests from a directory other than meta.
  96. 2. Check install/uninstall of socat.
  97. Product: oe-core
  98. Author: Mariano Lopez <mariano.lopez@intel.com>
  99. """
  100. if get_bb_var('DISTRO') == 'poky-tiny':
  101. self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
  102. features = 'INHERIT += "testimage"\n'
  103. features += 'IMAGE_INSTALL:append = " libssl"\n'
  104. features += 'TEST_SUITES = "ping ssh selftest"\n'
  105. self.write_config(features)
  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. self.track_for_cleanup(self.gpg_home)
  128. signing_key_dir = os.path.join(self.testlayer_path, 'files', 'signing')
  129. runCmd('gpgconf --list-dirs --homedir %s; gpg -v --batch --homedir %s --import %s' % (self.gpg_home, self.gpg_home, os.path.join(signing_key_dir, 'key.secret')), native_sysroot=get_bb_var("RECIPE_SYSROOT_NATIVE", "gnupg-native"), shell=True)
  130. features += 'INHERIT += "sign_package_feed"\n'
  131. features += 'PACKAGE_FEED_GPG_NAME = "testuser"\n'
  132. features += 'PACKAGE_FEED_GPG_PASSPHRASE_FILE = "%s"\n' % os.path.join(signing_key_dir, 'key.passphrase')
  133. features += 'GPG_PATH = "%s"\n' % self.gpg_home
  134. features += 'PSEUDO_IGNORE_PATHS .= ",%s"\n' % self.gpg_home
  135. self.write_config(features)
  136. bitbake('core-image-full-cmdline socat')
  137. bitbake('-c testimage core-image-full-cmdline')
  138. def test_testimage_virgl_gtk_sdl(self):
  139. """
  140. Summary: Check host-assisted accelerate OpenGL functionality in qemu with gtk and SDL frontends
  141. Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
  142. 2. Check that kmscube demo runs without crashing.
  143. Product: oe-core
  144. Author: Alexander Kanavin <alex.kanavin@gmail.com>
  145. """
  146. if "DISPLAY" not in os.environ:
  147. self.skipTest("virgl gtk test must be run inside a X session")
  148. distro = oe.lsb.distro_identifier()
  149. if distro and distro == 'debian-8':
  150. self.skipTest('virgl isn\'t working with Debian 8')
  151. if distro and distro == 'debian-9':
  152. self.skipTest('virgl isn\'t working with Debian 9')
  153. if distro and distro == 'centos-7':
  154. self.skipTest('virgl isn\'t working with Centos 7')
  155. if distro and distro == 'opensuseleap-15.0':
  156. self.skipTest('virgl isn\'t working with Opensuse 15.0')
  157. qemu_packageconfig = get_bb_var('PACKAGECONFIG', 'qemu-system-native')
  158. qemu_distrofeatures = get_bb_var('DISTRO_FEATURES', 'qemu-system-native')
  159. features = 'INHERIT += "testimage"\n'
  160. if 'gtk+' not in qemu_packageconfig:
  161. features += 'PACKAGECONFIG:append:pn-qemu-system-native = " gtk+"\n'
  162. if 'sdl' not in qemu_packageconfig:
  163. features += 'PACKAGECONFIG:append:pn-qemu-system-native = " sdl"\n'
  164. if 'opengl' not in qemu_distrofeatures:
  165. features += 'DISTRO_FEATURES:append = " opengl"\n'
  166. features += 'TEST_SUITES = "ping ssh virgl"\n'
  167. features += 'IMAGE_FEATURES:append = " ssh-server-dropbear"\n'
  168. features += 'IMAGE_INSTALL:append = " kmscube"\n'
  169. features_gtk = features + 'TEST_RUNQEMUPARAMS = "gtk gl"\n'
  170. self.write_config(features_gtk)
  171. bitbake('core-image-minimal')
  172. bitbake('-c testimage core-image-minimal')
  173. features_sdl = features + 'TEST_RUNQEMUPARAMS = "sdl gl"\n'
  174. self.write_config(features_sdl)
  175. bitbake('core-image-minimal')
  176. bitbake('-c testimage core-image-minimal')
  177. def test_testimage_virgl_headless(self):
  178. """
  179. Summary: Check host-assisted accelerate OpenGL functionality in qemu with egl-headless frontend
  180. Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
  181. 2. Check that kmscube demo runs without crashing.
  182. Product: oe-core
  183. Author: Alexander Kanavin <alex.kanavin@gmail.com>
  184. """
  185. import subprocess, os
  186. distro = oe.lsb.distro_identifier()
  187. if distro and distro in ['debian-9', 'debian-10', 'centos-7', 'centos-8', 'ubuntu-16.04', 'ubuntu-18.04', 'almalinux-8.5']:
  188. self.skipTest('virgl headless cannot be tested with %s' %(distro))
  189. render_hint = """If /dev/dri/renderD* is absent due to lack of suitable GPU, 'modprobe vgem' will create one suitable for mesa llvmpipe software renderer."""
  190. try:
  191. content = os.listdir("/dev/dri")
  192. if len([i for i in content if i.startswith('render')]) == 0:
  193. self.fail("No render nodes found in /dev/dri: %s. %s" %(content, render_hint))
  194. except FileNotFoundError:
  195. self.fail("/dev/dri directory does not exist; no render nodes available on this machine. %s" %(render_hint))
  196. try:
  197. dripath = subprocess.check_output("pkg-config --variable=dridriverdir dri", shell=True)
  198. except subprocess.CalledProcessError as e:
  199. self.fail("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.")
  200. qemu_distrofeatures = get_bb_var('DISTRO_FEATURES', 'qemu-system-native')
  201. features = 'INHERIT += "testimage"\n'
  202. if 'opengl' not in qemu_distrofeatures:
  203. features += 'DISTRO_FEATURES:append = " opengl"\n'
  204. features += 'TEST_SUITES = "ping ssh virgl"\n'
  205. features += 'IMAGE_FEATURES:append = " ssh-server-dropbear"\n'
  206. features += 'IMAGE_INSTALL:append = " kmscube"\n'
  207. features += 'TEST_RUNQEMUPARAMS = "egl-headless"\n'
  208. self.write_config(features)
  209. bitbake('core-image-minimal')
  210. bitbake('-c testimage core-image-minimal')
  211. class Postinst(OESelftestTestCase):
  212. def init_manager_loop(self, init_manager):
  213. import oe.path
  214. vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
  215. rootfs = vars["IMAGE_ROOTFS"]
  216. self.assertIsNotNone(rootfs)
  217. sysconfdir = vars["sysconfdir"]
  218. self.assertIsNotNone(sysconfdir)
  219. # Need to use oe.path here as sysconfdir starts with /
  220. hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
  221. targettestdir = os.path.join(sysconfdir, "postinst-test")
  222. for classes in ("package_rpm", "package_deb", "package_ipk"):
  223. with self.subTest(init_manager=init_manager, package_class=classes):
  224. features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-delayed-b"\n'
  225. features += 'IMAGE_FEATURES += "package-management empty-root-password"\n'
  226. features += 'PACKAGE_CLASSES = "%s"\n' % classes
  227. if init_manager == "systemd":
  228. features += 'DISTRO_FEATURES:append = " systemd"\n'
  229. features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n'
  230. features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n'
  231. features += 'VIRTUAL-RUNTIME_initscripts = ""\n'
  232. self.write_config(features)
  233. bitbake('core-image-minimal')
  234. self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs")),
  235. "rootfs state file was not created")
  236. with runqemu('core-image-minimal') as qemu:
  237. # Make the test echo a string and search for that as
  238. # run_serial()'s status code is useless.'
  239. for filename in ("rootfs", "delayed-a", "delayed-b"):
  240. status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
  241. self.assertIn("found", output, "%s was not present on boot" % filename)
  242. @skipIfNotQemu('qemuall', 'Test only runs in qemu')
  243. def test_postinst_rootfs_and_boot_sysvinit(self):
  244. """
  245. Summary: The purpose of this test case is to verify Post-installation
  246. scripts are called when rootfs is created and also test
  247. that script can be delayed to run at first boot.
  248. Dependencies: NA
  249. Steps: 1. Add proper configuration to local.conf file
  250. 2. Build a "core-image-minimal" image
  251. 3. Verify that file created by postinst_rootfs recipe is
  252. present on rootfs dir.
  253. 4. Boot the image created on qemu and verify that the file
  254. created by postinst_boot recipe is present on image.
  255. Expected: The files are successfully created during rootfs and boot
  256. time for 3 different package managers: rpm,ipk,deb and
  257. for initialization managers: sysvinit.
  258. """
  259. self.init_manager_loop("sysvinit")
  260. @skipIfNotQemu('qemuall', 'Test only runs in qemu')
  261. def test_postinst_rootfs_and_boot_systemd(self):
  262. """
  263. Summary: The purpose of this test case is to verify Post-installation
  264. scripts are called when rootfs is created and also test
  265. that script can be delayed to run at first boot.
  266. Dependencies: NA
  267. Steps: 1. Add proper configuration to local.conf file
  268. 2. Build a "core-image-minimal" image
  269. 3. Verify that file created by postinst_rootfs recipe is
  270. present on rootfs dir.
  271. 4. Boot the image created on qemu and verify that the file
  272. created by postinst_boot recipe is present on image.
  273. Expected: The files are successfully created during rootfs and boot
  274. time for 3 different package managers: rpm,ipk,deb and
  275. for initialization managers: systemd.
  276. """
  277. self.init_manager_loop("systemd")
  278. def test_failing_postinst(self):
  279. """
  280. Summary: The purpose of this test case is to verify that post-installation
  281. scripts that contain errors are properly reported.
  282. Expected: The scriptlet failure is properly reported.
  283. The file that is created after the error in the scriptlet is not present.
  284. Product: oe-core
  285. Author: Alexander Kanavin <alex.kanavin@gmail.com>
  286. """
  287. import oe.path
  288. vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
  289. rootfs = vars["IMAGE_ROOTFS"]
  290. self.assertIsNotNone(rootfs)
  291. sysconfdir = vars["sysconfdir"]
  292. self.assertIsNotNone(sysconfdir)
  293. # Need to use oe.path here as sysconfdir starts with /
  294. hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
  295. for classes in ("package_rpm", "package_deb", "package_ipk"):
  296. with self.subTest(package_class=classes):
  297. features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
  298. features += 'PACKAGE_CLASSES = "%s"\n' % classes
  299. self.write_config(features)
  300. bb_result = bitbake('core-image-minimal', ignore_status=True)
  301. self.assertGreaterEqual(bb_result.output.find("Postinstall scriptlets of ['postinst-rootfs-failing'] have failed."), 0,
  302. "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
  303. self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
  304. "rootfs-before-failure file was not created")
  305. self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
  306. "rootfs-after-failure file was created")
  307. class SystemTap(OESelftestTestCase):
  308. """
  309. Summary: The purpose of this test case is to verify native crosstap
  310. works while talking to a target.
  311. Expected: The script should successfully connect to the qemu machine
  312. and run some systemtap examples on a qemu machine.
  313. """
  314. @classmethod
  315. def setUpClass(cls):
  316. super(SystemTap, cls).setUpClass()
  317. cls.image = "core-image-minimal"
  318. def default_config(self):
  319. return """
  320. # These aren't the actual IP addresses but testexport class needs something defined
  321. TEST_SERVER_IP = "192.168.7.1"
  322. TEST_TARGET_IP = "192.168.7.2"
  323. EXTRA_IMAGE_FEATURES += "tools-profile dbg-pkgs"
  324. IMAGE_FEATURES:append = " ssh-server-dropbear"
  325. # enables kernel debug symbols
  326. KERNEL_EXTRA_FEATURES:append = " features/debug/debug-kernel.scc"
  327. KERNEL_EXTRA_FEATURES:append = " features/systemtap/systemtap.scc"
  328. # add systemtap run-time into target image if it is not there yet
  329. IMAGE_INSTALL:append = " systemtap-runtime"
  330. """
  331. def test_crosstap_helloworld(self):
  332. self.write_config(self.default_config())
  333. bitbake('systemtap-native')
  334. systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
  335. bitbake(self.image)
  336. with runqemu(self.image) as qemu:
  337. cmd = "crosstap -r root@192.168.7.2 -s %s/general/helloworld.stp " % systemtap_examples
  338. result = runCmd(cmd)
  339. self.assertEqual(0, result.status, 'crosstap helloworld returned a non 0 status:%s' % result.output)
  340. def test_crosstap_pstree(self):
  341. self.write_config(self.default_config())
  342. bitbake('systemtap-native')
  343. systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
  344. bitbake(self.image)
  345. with runqemu(self.image) as qemu:
  346. cmd = "crosstap -r root@192.168.7.2 -s %s/process/pstree.stp" % systemtap_examples
  347. result = runCmd(cmd)
  348. self.assertEqual(0, result.status, 'crosstap pstree returned a non 0 status:%s' % result.output)
  349. def test_crosstap_syscalls_by_proc(self):
  350. self.write_config(self.default_config())
  351. bitbake('systemtap-native')
  352. systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
  353. bitbake(self.image)
  354. with runqemu(self.image) as qemu:
  355. cmd = "crosstap -r root@192.168.7.2 -s %s/process/ syscalls_by_proc.stp" % systemtap_examples
  356. result = runCmd(cmd)
  357. self.assertEqual(0, result.status, 'crosstap syscalls_by_proc returned a non 0 status:%s' % result.output)
  358. def test_crosstap_syscalls_by_pid(self):
  359. self.write_config(self.default_config())
  360. bitbake('systemtap-native')
  361. systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
  362. bitbake(self.image)
  363. with runqemu(self.image) as qemu:
  364. cmd = "crosstap -r root@192.168.7.2 -s %s/process/ syscalls_by_pid.stp" % systemtap_examples
  365. result = runCmd(cmd)
  366. self.assertEqual(0, result.status, 'crosstap syscalls_by_pid returned a non 0 status:%s' % result.output)