blob: d3a789a6a778db89315af4017bdc03ea819cf6de [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
5import os
Brad Bishopa34c0302019-09-23 22:34:48 -04006import shutil
Andrew Geissler82c905d2020-04-13 13:39:40 -05007import importlib
Brad Bishop15ae2502019-06-18 21:44:24 -04008import unittest
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009from oeqa.selftest.case import OESelftestTestCase
10from oeqa.selftest.cases.buildhistory import BuildhistoryBase
Patrick Williams45852732022-04-02 08:58:32 -050011from oeqa.utils.commands import runCmd, bitbake, get_bb_var
Brad Bishopa34c0302019-09-23 22:34:48 -040012from oeqa.utils import CommandError
Brad Bishopd7bf8c12018-02-25 22:55:05 -050013
14class BuildhistoryDiffTests(BuildhistoryBase):
15
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016 def test_buildhistory_diff(self):
17 target = 'xcursor-transparent-theme'
18 self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True)
19 self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080020 result = runCmd("oe-pkgdata-util read-value PKGV %s" % target)
21 pkgv = result.output.rstrip()
Brad Bishopd7bf8c12018-02-25 22:55:05 -050022 result = runCmd("buildhistory-diff -p %s" % get_bb_var('BUILDHISTORY_DIR'))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080023 expected_endlines = [
Andrew Geissler615f2f12022-07-15 14:00:58 -050024 "xcursor-transparent-theme-dev: RRECOMMENDS: removed \"xcursor-transparent-theme (['= %s-r1'])\", added \"xcursor-transparent-theme (['= %s-r0'])\"" % (pkgv, pkgv),
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080025 "xcursor-transparent-theme-staticdev: RDEPENDS: removed \"xcursor-transparent-theme-dev (['= %s-r1'])\", added \"xcursor-transparent-theme-dev (['= %s-r0'])\"" % (pkgv, pkgv)
26 ]
27 for line in result.output.splitlines():
28 for el in expected_endlines:
29 if line.endswith(el):
30 expected_endlines.remove(el)
31 break
32 else:
33 self.fail('Unexpected line:\n%s\nExpected line endings:\n %s' % (line, '\n '.join(expected_endlines)))
34 if expected_endlines:
35 self.fail('Missing expected line endings:\n %s' % '\n '.join(expected_endlines))
Brad Bishopc342db32019-05-15 21:57:59 -040036
37class OEScriptTests(OESelftestTestCase):
Patrick Williams45852732022-04-02 08:58:32 -050038 scripts_dir = os.path.join(get_bb_var('COREBASE'), 'scripts')
39
40@unittest.skipUnless(importlib.util.find_spec("cairo"), "Python cairo module is not present")
41class OEPybootchartguyTests(OEScriptTests):
Brad Bishopc342db32019-05-15 21:57:59 -040042
43 @classmethod
44 def setUpClass(cls):
45 super(OEScriptTests, cls).setUpClass()
Brad Bishopc342db32019-05-15 21:57:59 -040046 bitbake("core-image-minimal -c rootfs -f")
47 cls.tmpdir = get_bb_var('TMPDIR')
48 cls.buildstats = cls.tmpdir + "/buildstats/" + sorted(os.listdir(cls.tmpdir + "/buildstats"))[-1]
49
Brad Bishopc342db32019-05-15 21:57:59 -040050 def test_pybootchartguy_help(self):
51 runCmd('%s/pybootchartgui/pybootchartgui.py --help' % self.scripts_dir)
52
53 def test_pybootchartguy_to_generate_build_png_output(self):
54 runCmd('%s/pybootchartgui/pybootchartgui.py %s -o %s/charts -f png' % (self.scripts_dir, self.buildstats, self.tmpdir))
55 self.assertTrue(os.path.exists(self.tmpdir + "/charts.png"))
56
57 def test_pybootchartguy_to_generate_build_svg_output(self):
58 runCmd('%s/pybootchartgui/pybootchartgui.py %s -o %s/charts -f svg' % (self.scripts_dir, self.buildstats, self.tmpdir))
59 self.assertTrue(os.path.exists(self.tmpdir + "/charts.svg"))
60
61 def test_pybootchartguy_to_generate_build_pdf_output(self):
62 runCmd('%s/pybootchartgui/pybootchartgui.py %s -o %s/charts -f pdf' % (self.scripts_dir, self.buildstats, self.tmpdir))
63 self.assertTrue(os.path.exists(self.tmpdir + "/charts.pdf"))
64
Brad Bishop1d80a2e2019-11-15 16:35:03 -050065
Patrick Williams45852732022-04-02 08:58:32 -050066class OEGitproxyTests(OEScriptTests):
Brad Bishopa34c0302019-09-23 22:34:48 -040067
68 def test_oegitproxy_help(self):
69 try:
70 res = runCmd('%s/oe-git-proxy --help' % self.scripts_dir, assert_error=False)
71 self.assertTrue(False)
72 except CommandError as e:
73 self.assertEqual(2, e.retcode)
74
75 def run_oegitproxy(self, custom_shell=None):
76 os.environ['SOCAT'] = shutil.which("echo")
77 os.environ['ALL_PROXY'] = "https://proxy.example.com:3128"
78 os.environ['NO_PROXY'] = "*.example.com,.no-proxy.org,192.168.42.0/24,127.*.*.*"
79
80 if custom_shell is None:
81 prefix = ''
82 else:
83 prefix = custom_shell + ' '
84
85 # outside, use the proxy
86 res = runCmd('%s%s/oe-git-proxy host.outside-example.com 9418' %
87 (prefix,self.scripts_dir))
88 self.assertIn('PROXY:', res.output)
89 # match with wildcard suffix
90 res = runCmd('%s%s/oe-git-proxy host.example.com 9418' %
91 (prefix, self.scripts_dir))
92 self.assertIn('TCP:', res.output)
93 # match just suffix
94 res = runCmd('%s%s/oe-git-proxy host.no-proxy.org 9418' %
95 (prefix, self.scripts_dir))
96 self.assertIn('TCP:', res.output)
97 # match IP subnet
98 res = runCmd('%s%s/oe-git-proxy 192.168.42.42 9418' %
99 (prefix, self.scripts_dir))
100 self.assertIn('TCP:', res.output)
101 # match IP wildcard
102 res = runCmd('%s%s/oe-git-proxy 127.1.2.3 9418' %
103 (prefix, self.scripts_dir))
104 self.assertIn('TCP:', res.output)
105
106 # test that * globbering is off
107 os.environ['NO_PROXY'] = "*"
108 res = runCmd('%s%s/oe-git-proxy host.example.com 9418' %
109 (prefix, self.scripts_dir))
110 self.assertIn('TCP:', res.output)
111
112 def test_oegitproxy_proxy(self):
113 self.run_oegitproxy()
114
115 def test_oegitproxy_proxy_dash(self):
116 dash = shutil.which("dash")
117 if dash is None:
118 self.skipTest("No \"dash\" found on test system.")
119 self.run_oegitproxy(custom_shell=dash)
Brad Bishop64c979e2019-11-04 13:55:29 -0500120
121class OeRunNativeTest(OESelftestTestCase):
122 def test_oe_run_native(self):
123 bitbake("qemu-helper-native -c addto_recipe_sysroot")
124 result = runCmd("oe-run-native qemu-helper-native tunctl -h")
125 self.assertIn("Delete: tunctl -d device-name [-f tun-clone-device]", result.output)
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500126
127class OEListPackageconfigTests(OEScriptTests):
128 #oe-core.scripts.List_all_the_PACKAGECONFIG's_flags
129 def check_endlines(self, results, expected_endlines):
130 for line in results.output.splitlines():
131 for el in expected_endlines:
Andrew Geissler78b72792022-06-14 06:47:25 -0500132 if line and line.split()[0] == el.split()[0] and \
133 ' '.join(sorted(el.split())) in ' '.join(sorted(line.split())):
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500134 expected_endlines.remove(el)
135 break
136
137 if expected_endlines:
138 self.fail('Missing expected listings:\n %s' % '\n '.join(expected_endlines))
139
140
141 #oe-core.scripts.List_all_the_PACKAGECONFIG's_flags
142 def test_packageconfig_flags_help(self):
143 runCmd('%s/contrib/list-packageconfig-flags.py -h' % self.scripts_dir)
144
145 def test_packageconfig_flags_default(self):
146 results = runCmd('%s/contrib/list-packageconfig-flags.py' % self.scripts_dir)
147 expected_endlines = []
148 expected_endlines.append("RECIPE NAME PACKAGECONFIG FLAGS")
149 expected_endlines.append("pinentry gtk2 libcap ncurses qt secret")
Andrew Geissler5199d832021-09-24 16:47:35 -0500150 expected_endlines.append("tar acl selinux")
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500151
152 self.check_endlines(results, expected_endlines)
153
154
155 def test_packageconfig_flags_option_flags(self):
156 results = runCmd('%s/contrib/list-packageconfig-flags.py -f' % self.scripts_dir)
157 expected_endlines = []
158 expected_endlines.append("PACKAGECONFIG FLAG RECIPE NAMES")
159 expected_endlines.append("qt nativesdk-pinentry pinentry pinentry-native")
160 expected_endlines.append("secret nativesdk-pinentry pinentry pinentry-native")
161
162 self.check_endlines(results, expected_endlines)
163
164 def test_packageconfig_flags_option_all(self):
165 results = runCmd('%s/contrib/list-packageconfig-flags.py -a' % self.scripts_dir)
166 expected_endlines = []
Andrew Geisslereff27472021-10-29 15:35:00 -0500167 expected_endlines.append("pinentry-1.2.0")
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500168 expected_endlines.append("PACKAGECONFIG ncurses libcap")
169 expected_endlines.append("PACKAGECONFIG[qt] --enable-pinentry-qt, --disable-pinentry-qt, qtbase-native qtbase")
170 expected_endlines.append("PACKAGECONFIG[gtk2] --enable-pinentry-gtk2, --disable-pinentry-gtk2, gtk+ glib-2.0")
171 expected_endlines.append("PACKAGECONFIG[libcap] --with-libcap, --without-libcap, libcap")
172 expected_endlines.append("PACKAGECONFIG[ncurses] --enable-ncurses --with-ncurses-include-dir=${STAGING_INCDIR}, --disable-ncurses, ncurses")
173 expected_endlines.append("PACKAGECONFIG[secret] --enable-libsecret, --disable-libsecret, libsecret")
174
175 self.check_endlines(results, expected_endlines)
176
Andrew Geissler475cb722020-07-10 16:00:51 -0500177 def test_packageconfig_flags_options_preferred_only(self):
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500178 results = runCmd('%s/contrib/list-packageconfig-flags.py -p' % self.scripts_dir)
179 expected_endlines = []
180 expected_endlines.append("RECIPE NAME PACKAGECONFIG FLAGS")
181 expected_endlines.append("pinentry gtk2 libcap ncurses qt secret")
182
183 self.check_endlines(results, expected_endlines)
184