oescripts.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. import os
  7. import shutil
  8. import importlib
  9. import unittest
  10. from oeqa.selftest.case import OESelftestTestCase
  11. from oeqa.selftest.cases.buildhistory import BuildhistoryBase
  12. from oeqa.utils.commands import runCmd, bitbake, get_bb_var
  13. from oeqa.utils import CommandError
  14. class BuildhistoryDiffTests(BuildhistoryBase):
  15. def test_buildhistory_diff(self):
  16. target = 'xcursor-transparent-theme'
  17. self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True)
  18. self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True)
  19. result = runCmd("oe-pkgdata-util read-value PKGV %s" % target)
  20. pkgv = result.output.rstrip()
  21. result = runCmd("buildhistory-diff -p %s" % get_bb_var('BUILDHISTORY_DIR'))
  22. expected_endlines = [
  23. "xcursor-transparent-theme-dev: RRECOMMENDS: removed \"xcursor-transparent-theme (['= %s-r1'])\", added \"xcursor-transparent-theme (['= %s-r0'])\"" % (pkgv, pkgv),
  24. "xcursor-transparent-theme-staticdev: RDEPENDS: removed \"xcursor-transparent-theme-dev (['= %s-r1'])\", added \"xcursor-transparent-theme-dev (['= %s-r0'])\"" % (pkgv, pkgv)
  25. ]
  26. for line in result.output.splitlines():
  27. for el in expected_endlines:
  28. if line.endswith(el):
  29. expected_endlines.remove(el)
  30. break
  31. else:
  32. self.fail('Unexpected line:\n%s\nExpected line endings:\n %s' % (line, '\n '.join(expected_endlines)))
  33. if expected_endlines:
  34. self.fail('Missing expected line endings:\n %s' % '\n '.join(expected_endlines))
  35. @unittest.skipUnless(importlib.util.find_spec("cairo"), "Python cairo module is not present")
  36. class OEPybootchartguyTests(OESelftestTestCase):
  37. @classmethod
  38. def setUpClass(cls):
  39. super().setUpClass()
  40. bitbake("core-image-minimal -c rootfs -f")
  41. cls.tmpdir = get_bb_var('TMPDIR')
  42. cls.buildstats = cls.tmpdir + "/buildstats/" + sorted(os.listdir(cls.tmpdir + "/buildstats"))[-1]
  43. cls.scripts_dir = os.path.join(get_bb_var('COREBASE'), 'scripts')
  44. def test_pybootchartguy_help(self):
  45. runCmd('%s/pybootchartgui/pybootchartgui.py --help' % self.scripts_dir)
  46. def test_pybootchartguy_to_generate_build_png_output(self):
  47. runCmd('%s/pybootchartgui/pybootchartgui.py %s -o %s/charts -f png' % (self.scripts_dir, self.buildstats, self.tmpdir))
  48. self.assertTrue(os.path.exists(self.tmpdir + "/charts.png"))
  49. def test_pybootchartguy_to_generate_build_svg_output(self):
  50. runCmd('%s/pybootchartgui/pybootchartgui.py %s -o %s/charts -f svg' % (self.scripts_dir, self.buildstats, self.tmpdir))
  51. self.assertTrue(os.path.exists(self.tmpdir + "/charts.svg"))
  52. def test_pybootchartguy_to_generate_build_pdf_output(self):
  53. runCmd('%s/pybootchartgui/pybootchartgui.py %s -o %s/charts -f pdf' % (self.scripts_dir, self.buildstats, self.tmpdir))
  54. self.assertTrue(os.path.exists(self.tmpdir + "/charts.pdf"))
  55. class OEGitproxyTests(OESelftestTestCase):
  56. @classmethod
  57. def setUpClass(cls):
  58. super().setUpClass()
  59. cls.scripts_dir = os.path.join(get_bb_var('COREBASE'), 'scripts')
  60. def test_oegitproxy_help(self):
  61. try:
  62. res = runCmd('%s/oe-git-proxy --help' % self.scripts_dir, assert_error=False)
  63. self.assertTrue(False)
  64. except CommandError as e:
  65. self.assertEqual(2, e.retcode)
  66. def run_oegitproxy(self, custom_shell=None):
  67. os.environ['SOCAT'] = shutil.which("echo")
  68. os.environ['ALL_PROXY'] = "https://proxy.example.com:3128"
  69. os.environ['NO_PROXY'] = "*.example.com,.no-proxy.org,192.168.42.0/24,127.*.*.*"
  70. if custom_shell is None:
  71. prefix = ''
  72. else:
  73. prefix = custom_shell + ' '
  74. # outside, use the proxy
  75. res = runCmd('%s%s/oe-git-proxy host.outside-example.com 9418' %
  76. (prefix,self.scripts_dir))
  77. self.assertIn('PROXY:', res.output)
  78. # match with wildcard suffix
  79. res = runCmd('%s%s/oe-git-proxy host.example.com 9418' %
  80. (prefix, self.scripts_dir))
  81. self.assertIn('TCP:', res.output)
  82. # match just suffix
  83. res = runCmd('%s%s/oe-git-proxy host.no-proxy.org 9418' %
  84. (prefix, self.scripts_dir))
  85. self.assertIn('TCP:', res.output)
  86. # match IP subnet
  87. res = runCmd('%s%s/oe-git-proxy 192.168.42.42 9418' %
  88. (prefix, self.scripts_dir))
  89. self.assertIn('TCP:', res.output)
  90. # match IP wildcard
  91. res = runCmd('%s%s/oe-git-proxy 127.1.2.3 9418' %
  92. (prefix, self.scripts_dir))
  93. self.assertIn('TCP:', res.output)
  94. # test that * globbering is off
  95. os.environ['NO_PROXY'] = "*"
  96. res = runCmd('%s%s/oe-git-proxy host.example.com 9418' %
  97. (prefix, self.scripts_dir))
  98. self.assertIn('TCP:', res.output)
  99. def test_oegitproxy_proxy(self):
  100. self.run_oegitproxy()
  101. def test_oegitproxy_proxy_dash(self):
  102. dash = shutil.which("dash")
  103. if dash is None:
  104. self.skipTest("No \"dash\" found on test system.")
  105. self.run_oegitproxy(custom_shell=dash)
  106. class OeRunNativeTest(OESelftestTestCase):
  107. def test_oe_run_native(self):
  108. bitbake("qemu-helper-native -c addto_recipe_sysroot")
  109. result = runCmd("oe-run-native qemu-helper-native qemu-oe-bridge-helper --help")
  110. self.assertIn("Helper function to find and exec qemu-bridge-helper", result.output)
  111. class OEListPackageconfigTests(OESelftestTestCase):
  112. @classmethod
  113. def setUpClass(cls):
  114. super().setUpClass()
  115. cls.scripts_dir = os.path.join(get_bb_var('COREBASE'), 'scripts')
  116. #oe-core.scripts.List_all_the_PACKAGECONFIG's_flags
  117. def check_endlines(self, results, expected_endlines):
  118. for line in results.output.splitlines():
  119. for el in expected_endlines:
  120. if line and line.split()[0] == el.split()[0] and \
  121. ' '.join(sorted(el.split())) in ' '.join(sorted(line.split())):
  122. expected_endlines.remove(el)
  123. break
  124. if expected_endlines:
  125. self.fail('Missing expected listings:\n %s' % '\n '.join(expected_endlines))
  126. #oe-core.scripts.List_all_the_PACKAGECONFIG's_flags
  127. def test_packageconfig_flags_help(self):
  128. runCmd('%s/contrib/list-packageconfig-flags.py -h' % self.scripts_dir)
  129. def test_packageconfig_flags_default(self):
  130. results = runCmd('%s/contrib/list-packageconfig-flags.py' % self.scripts_dir)
  131. expected_endlines = []
  132. expected_endlines.append("RECIPE NAME PACKAGECONFIG FLAGS")
  133. expected_endlines.append("pinentry gtk2 ncurses qt secret")
  134. expected_endlines.append("tar acl selinux")
  135. self.check_endlines(results, expected_endlines)
  136. def test_packageconfig_flags_option_flags(self):
  137. results = runCmd('%s/contrib/list-packageconfig-flags.py -f' % self.scripts_dir)
  138. expected_endlines = []
  139. expected_endlines.append("PACKAGECONFIG FLAG RECIPE NAMES")
  140. expected_endlines.append("qt nativesdk-pinentry pinentry pinentry-native")
  141. expected_endlines.append("secret nativesdk-pinentry pinentry pinentry-native")
  142. self.check_endlines(results, expected_endlines)
  143. def test_packageconfig_flags_option_all(self):
  144. results = runCmd('%s/contrib/list-packageconfig-flags.py -a' % self.scripts_dir)
  145. expected_endlines = []
  146. expected_endlines.append("pinentry-1.3.1")
  147. expected_endlines.append("PACKAGECONFIG ncurses")
  148. expected_endlines.append("PACKAGECONFIG[qt] --enable-pinentry-qt, --disable-pinentry-qt, qtbase-native qtbase")
  149. expected_endlines.append("PACKAGECONFIG[gtk2] --enable-pinentry-gtk2, --disable-pinentry-gtk2, gtk+ glib-2.0")
  150. expected_endlines.append("PACKAGECONFIG[ncurses] --enable-ncurses --with-ncurses-include-dir=${STAGING_INCDIR}, --disable-ncurses, ncurses")
  151. expected_endlines.append("PACKAGECONFIG[secret] --enable-libsecret, --disable-libsecret, libsecret")
  152. self.check_endlines(results, expected_endlines)
  153. def test_packageconfig_flags_options_preferred_only(self):
  154. results = runCmd('%s/contrib/list-packageconfig-flags.py -p' % self.scripts_dir)
  155. expected_endlines = []
  156. expected_endlines.append("RECIPE NAME PACKAGECONFIG FLAGS")
  157. expected_endlines.append("pinentry gtk2 ncurses qt secret")
  158. self.check_endlines(results, expected_endlines)