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