runtime_test.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. @classmethod
  15. def tearDownClass(cls):
  16. runCmd("rm -rf /tmp/sdk")
  17. super(TestExport, cls).tearDownClass()
  18. def test_testexport_basic(self):
  19. """
  20. Summary: Check basic testexport functionality with only ping test enabled.
  21. Expected: 1. testexport directory must be created.
  22. 2. runexported.py must run without any error/exception.
  23. 3. ping test must succeed.
  24. Product: oe-core
  25. Author: Mariano Lopez <mariano.lopez@intel.com>
  26. """
  27. features = 'INHERIT += "testexport"\n'
  28. # These aren't the actual IP addresses but testexport class needs something defined
  29. features += 'TEST_SERVER_IP = "192.168.7.1"\n'
  30. features += 'TEST_TARGET_IP = "192.168.7.1"\n'
  31. features += 'TEST_SUITES = "ping"\n'
  32. self.write_config(features)
  33. # Build tesexport for core-image-minimal
  34. bitbake('core-image-minimal')
  35. bitbake('-c testexport core-image-minimal')
  36. testexport_dir = get_bb_var('TEST_EXPORT_DIR', 'core-image-minimal')
  37. # Verify if TEST_EXPORT_DIR was created
  38. isdir = os.path.isdir(testexport_dir)
  39. self.assertEqual(True, isdir, 'Failed to create testexport dir: %s' % testexport_dir)
  40. with runqemu('core-image-minimal') as qemu:
  41. # Attempt to run runexported.py to perform ping test
  42. test_path = os.path.join(testexport_dir, "oe-test")
  43. data_file = os.path.join(testexport_dir, 'data', 'testdata.json')
  44. manifest = os.path.join(testexport_dir, 'data', 'manifest')
  45. cmd = ("%s runtime --test-data-file %s --packages-manifest %s "
  46. "--target-ip %s --server-ip %s --quiet"
  47. % (test_path, data_file, manifest, qemu.ip, qemu.server_ip))
  48. result = runCmd(cmd)
  49. # Verify ping test was succesful
  50. self.assertEqual(0, result.status, 'oe-test runtime returned a non 0 status')
  51. def test_testexport_sdk(self):
  52. """
  53. Summary: Check sdk functionality for testexport.
  54. Expected: 1. testexport directory must be created.
  55. 2. SDK tarball must exists.
  56. 3. Uncompressing of tarball must succeed.
  57. 4. Check if the SDK directory is added to PATH.
  58. 5. Run tar from the SDK directory.
  59. Product: oe-core
  60. Author: Mariano Lopez <mariano.lopez@intel.com>
  61. """
  62. features = 'INHERIT += "testexport"\n'
  63. # These aren't the actual IP addresses but testexport class needs something defined
  64. features += 'TEST_SERVER_IP = "192.168.7.1"\n'
  65. features += 'TEST_TARGET_IP = "192.168.7.1"\n'
  66. features += 'TEST_SUITES = "ping"\n'
  67. features += 'TEST_EXPORT_SDK_ENABLED = "1"\n'
  68. features += 'TEST_EXPORT_SDK_PACKAGES = "nativesdk-tar"\n'
  69. self.write_config(features)
  70. # Build tesexport for core-image-minimal
  71. bitbake('core-image-minimal')
  72. bitbake('-c testexport core-image-minimal')
  73. needed_vars = ['TEST_EXPORT_DIR', 'TEST_EXPORT_SDK_DIR', 'TEST_EXPORT_SDK_NAME']
  74. bb_vars = get_bb_vars(needed_vars, 'core-image-minimal')
  75. testexport_dir = bb_vars['TEST_EXPORT_DIR']
  76. sdk_dir = bb_vars['TEST_EXPORT_SDK_DIR']
  77. sdk_name = bb_vars['TEST_EXPORT_SDK_NAME']
  78. # Check for SDK
  79. tarball_name = "%s.sh" % sdk_name
  80. tarball_path = os.path.join(testexport_dir, sdk_dir, tarball_name)
  81. msg = "Couldn't find SDK tarball: %s" % tarball_path
  82. self.assertEqual(os.path.isfile(tarball_path), True, msg)
  83. # Extract SDK and run tar from SDK
  84. result = runCmd("%s -y -d /tmp/sdk" % tarball_path)
  85. self.assertEqual(0, result.status, "Couldn't extract SDK")
  86. env_script = result.output.split()[-1]
  87. result = runCmd(". %s; which tar" % env_script, shell=True)
  88. self.assertEqual(0, result.status, "Couldn't setup SDK environment")
  89. is_sdk_tar = True if "/tmp/sdk" in result.output else False
  90. self.assertTrue(is_sdk_tar, "Couldn't setup SDK environment")
  91. tar_sdk = result.output
  92. result = runCmd("%s --version" % tar_sdk)
  93. self.assertEqual(0, result.status, "Couldn't run tar from SDK")
  94. class TestImage(OESelftestTestCase):
  95. def test_testimage_install(self):
  96. """
  97. Summary: Check install packages functionality for testimage/testexport.
  98. Expected: 1. Import tests from a directory other than meta.
  99. 2. Check install/uninstall of socat.
  100. Product: oe-core
  101. Author: Mariano Lopez <mariano.lopez@intel.com>
  102. """
  103. if get_bb_var('DISTRO') == 'poky-tiny':
  104. self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
  105. features = 'INHERIT += "testimage"\n'
  106. features += 'IMAGE_INSTALL_append = " libssl"\n'
  107. features += 'TEST_SUITES = "ping ssh selftest"\n'
  108. self.write_config(features)
  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. self.track_for_cleanup(self.gpg_home)
  131. signing_key_dir = os.path.join(self.testlayer_path, 'files', 'signing')
  132. 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)
  133. features += 'INHERIT += "sign_package_feed"\n'
  134. features += 'PACKAGE_FEED_GPG_NAME = "testuser"\n'
  135. features += 'PACKAGE_FEED_GPG_PASSPHRASE_FILE = "%s"\n' % os.path.join(signing_key_dir, 'key.passphrase')
  136. features += 'GPG_PATH = "%s"\n' % self.gpg_home
  137. features += 'PSEUDO_IGNORE_PATHS .= ",%s"\n' % self.gpg_home
  138. self.write_config(features)
  139. bitbake('core-image-full-cmdline socat')
  140. bitbake('-c testimage core-image-full-cmdline')
  141. def test_testimage_virgl_gtk_sdl(self):
  142. """
  143. Summary: Check host-assisted accelerate OpenGL functionality in qemu with gtk and SDL frontends
  144. Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
  145. 2. Check that kmscube demo runs without crashing.
  146. Product: oe-core
  147. Author: Alexander Kanavin <alex.kanavin@gmail.com>
  148. """
  149. if "DISPLAY" not in os.environ:
  150. self.skipTest("virgl gtk test must be run inside a X session")
  151. distro = oe.lsb.distro_identifier()
  152. if distro and distro == 'debian-8':
  153. self.skipTest('virgl isn\'t working with Debian 8')
  154. if distro and distro == 'debian-9':
  155. self.skipTest('virgl isn\'t working with Debian 9')
  156. if distro and distro == 'centos-7':
  157. self.skipTest('virgl isn\'t working with Centos 7')
  158. if distro and distro == 'opensuseleap-15.0':
  159. self.skipTest('virgl isn\'t working with Opensuse 15.0')
  160. qemu_packageconfig = get_bb_var('PACKAGECONFIG', 'qemu-system-native')
  161. qemu_distrofeatures = get_bb_var('DISTRO_FEATURES', 'qemu-system-native')
  162. features = 'INHERIT += "testimage"\n'
  163. if 'gtk+' not in qemu_packageconfig:
  164. features += 'PACKAGECONFIG_append_pn-qemu-system-native = " gtk+"\n'
  165. if 'sdl' not in qemu_packageconfig:
  166. features += 'PACKAGECONFIG_append_pn-qemu-system-native = " sdl"\n'
  167. if 'opengl' not in qemu_distrofeatures:
  168. features += 'DISTRO_FEATURES_append = " opengl"\n'
  169. features += 'TEST_SUITES = "ping ssh virgl"\n'
  170. features += 'IMAGE_FEATURES_append = " ssh-server-dropbear"\n'
  171. features += 'IMAGE_INSTALL_append = " kmscube"\n'
  172. features_gtk = features + 'TEST_RUNQEMUPARAMS = "gtk gl"\n'
  173. self.write_config(features_gtk)
  174. bitbake('core-image-minimal')
  175. bitbake('-c testimage core-image-minimal')
  176. features_sdl = features + 'TEST_RUNQEMUPARAMS = "sdl gl"\n'
  177. self.write_config(features_sdl)
  178. bitbake('core-image-minimal')
  179. bitbake('-c testimage core-image-minimal')
  180. def test_testimage_virgl_headless(self):
  181. """
  182. Summary: Check host-assisted accelerate OpenGL functionality in qemu with egl-headless frontend
  183. Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
  184. 2. Check that kmscube demo runs without crashing.
  185. Product: oe-core
  186. Author: Alexander Kanavin <alex.kanavin@gmail.com>
  187. """
  188. import subprocess, os
  189. try:
  190. content = os.listdir("/dev/dri")
  191. if len([i for i in content if i.startswith('render')]) == 0:
  192. self.skipTest("No render nodes found in /dev/dri: %s" %(content))
  193. except FileNotFoundError:
  194. self.skipTest("/dev/dri directory does not exist; no render nodes available on this machine.")
  195. try:
  196. dripath = subprocess.check_output("pkg-config --variable=dridriverdir dri", shell=True)
  197. except subprocess.CalledProcessError as e:
  198. 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.")
  199. qemu_distrofeatures = get_bb_var('DISTRO_FEATURES', 'qemu-system-native')
  200. features = 'INHERIT += "testimage"\n'
  201. if 'opengl' not in qemu_distrofeatures:
  202. features += 'DISTRO_FEATURES_append = " opengl"\n'
  203. features += 'TEST_SUITES = "ping ssh virgl"\n'
  204. features += 'IMAGE_FEATURES_append = " ssh-server-dropbear"\n'
  205. features += 'IMAGE_INSTALL_append = " kmscube"\n'
  206. features += 'TEST_RUNQEMUPARAMS = "egl-headless"\n'
  207. self.write_config(features)
  208. bitbake('core-image-minimal')
  209. bitbake('-c testimage core-image-minimal')
  210. class Postinst(OESelftestTestCase):
  211. def init_manager_loop(self, init_manager):
  212. import oe.path
  213. vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
  214. rootfs = vars["IMAGE_ROOTFS"]
  215. self.assertIsNotNone(rootfs)
  216. sysconfdir = vars["sysconfdir"]
  217. self.assertIsNotNone(sysconfdir)
  218. # Need to use oe.path here as sysconfdir starts with /
  219. hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
  220. targettestdir = os.path.join(sysconfdir, "postinst-test")
  221. for classes in ("package_rpm", "package_deb", "package_ipk"):
  222. with self.subTest(init_manager=init_manager, package_class=classes):
  223. features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-delayed-b"\n'
  224. features += 'IMAGE_FEATURES += "package-management empty-root-password"\n'
  225. features += 'PACKAGE_CLASSES = "%s"\n' % classes
  226. if init_manager == "systemd":
  227. features += 'DISTRO_FEATURES_append = " systemd"\n'
  228. features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n'
  229. features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n'
  230. features += 'VIRTUAL-RUNTIME_initscripts = ""\n'
  231. self.write_config(features)
  232. bitbake('core-image-minimal')
  233. self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs")),
  234. "rootfs state file was not created")
  235. with runqemu('core-image-minimal') as qemu:
  236. # Make the test echo a string and search for that as
  237. # run_serial()'s status code is useless.'
  238. for filename in ("rootfs", "delayed-a", "delayed-b"):
  239. status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
  240. self.assertIn("found", output, "%s was not present on boot" % filename)
  241. @skipIfNotQemu('qemuall', 'Test only runs in qemu')
  242. def test_postinst_rootfs_and_boot_sysvinit(self):
  243. """
  244. Summary: The purpose of this test case is to verify Post-installation
  245. scripts are called when rootfs is created and also test
  246. that script can be delayed to run at first boot.
  247. Dependencies: NA
  248. Steps: 1. Add proper configuration to local.conf file
  249. 2. Build a "core-image-minimal" image
  250. 3. Verify that file created by postinst_rootfs recipe is
  251. present on rootfs dir.
  252. 4. Boot the image created on qemu and verify that the file
  253. created by postinst_boot recipe is present on image.
  254. Expected: The files are successfully created during rootfs and boot
  255. time for 3 different package managers: rpm,ipk,deb and
  256. for initialization managers: sysvinit.
  257. """
  258. self.init_manager_loop("sysvinit")
  259. @skipIfNotQemu('qemuall', 'Test only runs in qemu')
  260. def test_postinst_rootfs_and_boot_systemd(self):
  261. """
  262. Summary: The purpose of this test case is to verify Post-installation
  263. scripts are called when rootfs is created and also test
  264. that script can be delayed to run at first boot.
  265. Dependencies: NA
  266. Steps: 1. Add proper configuration to local.conf file
  267. 2. Build a "core-image-minimal" image
  268. 3. Verify that file created by postinst_rootfs recipe is
  269. present on rootfs dir.
  270. 4. Boot the image created on qemu and verify that the file
  271. created by postinst_boot recipe is present on image.
  272. Expected: The files are successfully created during rootfs and boot
  273. time for 3 different package managers: rpm,ipk,deb and
  274. for initialization managers: systemd.
  275. """
  276. self.init_manager_loop("systemd")
  277. def test_failing_postinst(self):
  278. """
  279. Summary: The purpose of this test case is to verify that post-installation
  280. scripts that contain errors are properly reported.
  281. Expected: The scriptlet failure is properly reported.
  282. The file that is created after the error in the scriptlet is not present.
  283. Product: oe-core
  284. Author: Alexander Kanavin <alex.kanavin@gmail.com>
  285. """
  286. import oe.path
  287. vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
  288. rootfs = vars["IMAGE_ROOTFS"]
  289. self.assertIsNotNone(rootfs)
  290. sysconfdir = vars["sysconfdir"]
  291. self.assertIsNotNone(sysconfdir)
  292. # Need to use oe.path here as sysconfdir starts with /
  293. hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
  294. for classes in ("package_rpm", "package_deb", "package_ipk"):
  295. with self.subTest(package_class=classes):
  296. features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
  297. features += 'PACKAGE_CLASSES = "%s"\n' % classes
  298. self.write_config(features)
  299. bb_result = bitbake('core-image-minimal', ignore_status=True)
  300. self.assertGreaterEqual(bb_result.output.find("Postinstall scriptlets of ['postinst-rootfs-failing'] have failed."), 0,
  301. "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
  302. self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
  303. "rootfs-before-failure file was not created")
  304. self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
  305. "rootfs-after-failure file was created")
  306. class SystemTap(OESelftestTestCase):
  307. """
  308. Summary: The purpose of this test case is to verify native crosstap
  309. works while talking to a target.
  310. Expected: The script should successfully connect to the qemu machine
  311. and run some systemtap examples on a qemu machine.
  312. """
  313. @classmethod
  314. def setUpClass(cls):
  315. super(SystemTap, cls).setUpClass()
  316. cls.image = "core-image-minimal"
  317. def default_config(self):
  318. return """
  319. # These aren't the actual IP addresses but testexport class needs something defined
  320. TEST_SERVER_IP = "192.168.7.1"
  321. TEST_TARGET_IP = "192.168.7.2"
  322. EXTRA_IMAGE_FEATURES += "tools-profile dbg-pkgs"
  323. IMAGE_FEATURES_append = " ssh-server-dropbear"
  324. # enables kernel debug symbols
  325. KERNEL_EXTRA_FEATURES_append = " features/debug/debug-kernel.scc"
  326. KERNEL_EXTRA_FEATURES_append = " features/systemtap/systemtap.scc"
  327. # add systemtap run-time into target image if it is not there yet
  328. IMAGE_INSTALL_append = " systemtap-runtime"
  329. """
  330. def test_crosstap_helloworld(self):
  331. self.write_config(self.default_config())
  332. bitbake('systemtap-native')
  333. systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
  334. bitbake(self.image)
  335. with runqemu(self.image) as qemu:
  336. cmd = "crosstap -r root@192.168.7.2 -s %s/general/helloworld.stp " % systemtap_examples
  337. result = runCmd(cmd)
  338. self.assertEqual(0, result.status, 'crosstap helloworld returned a non 0 status:%s' % result.output)
  339. def test_crosstap_pstree(self):
  340. self.write_config(self.default_config())
  341. bitbake('systemtap-native')
  342. systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
  343. bitbake(self.image)
  344. with runqemu(self.image) as qemu:
  345. cmd = "crosstap -r root@192.168.7.2 -s %s/process/pstree.stp" % systemtap_examples
  346. result = runCmd(cmd)
  347. self.assertEqual(0, result.status, 'crosstap pstree returned a non 0 status:%s' % result.output)
  348. def test_crosstap_syscalls_by_proc(self):
  349. self.write_config(self.default_config())
  350. bitbake('systemtap-native')
  351. systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
  352. bitbake(self.image)
  353. with runqemu(self.image) as qemu:
  354. cmd = "crosstap -r root@192.168.7.2 -s %s/process/ syscalls_by_proc.stp" % systemtap_examples
  355. result = runCmd(cmd)
  356. self.assertEqual(0, result.status, 'crosstap syscalls_by_proc returned a non 0 status:%s' % result.output)
  357. def test_crosstap_syscalls_by_pid(self):
  358. self.write_config(self.default_config())
  359. bitbake('systemtap-native')
  360. systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
  361. bitbake(self.image)
  362. with runqemu(self.image) as qemu:
  363. cmd = "crosstap -r root@192.168.7.2 -s %s/process/ syscalls_by_pid.stp" % systemtap_examples
  364. result = runCmd(cmd)
  365. self.assertEqual(0, result.status, 'crosstap syscalls_by_pid returned a non 0 status:%s' % result.output)