blob: 726daff7c6ee1a90e652557f644b6f84dfdda58e [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
11from oeqa.utils.commands import Command, runCmd, bitbake, get_bb_var, get_test_layer
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 = [
24 "xcursor-transparent-theme-dev: RDEPENDS: removed \"xcursor-transparent-theme (['= %s-r1'])\", added \"xcursor-transparent-theme (['= %s-r0'])\"" % (pkgv, pkgv),
25 "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
Andrew Geissler82c905d2020-04-13 13:39:40 -050037@unittest.skipUnless(importlib.util.find_spec("cairo"), "Python cairo module is not present")
Brad Bishopc342db32019-05-15 21:57:59 -040038class OEScriptTests(OESelftestTestCase):
39
40 @classmethod
41 def setUpClass(cls):
42 super(OEScriptTests, cls).setUpClass()
Andrew Geissler82c905d2020-04-13 13:39:40 -050043 import cairo
Brad Bishopc342db32019-05-15 21:57:59 -040044 bitbake("core-image-minimal -c rootfs -f")
45 cls.tmpdir = get_bb_var('TMPDIR')
46 cls.buildstats = cls.tmpdir + "/buildstats/" + sorted(os.listdir(cls.tmpdir + "/buildstats"))[-1]
47
48 scripts_dir = os.path.join(get_bb_var('COREBASE'), 'scripts')
49
50class OEPybootchartguyTests(OEScriptTests):
51
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 Bishop1d80a2e2019-11-15 16:35:03 -050067
Brad Bishopa34c0302019-09-23 22:34:48 -040068class OEGitproxyTests(OESelftestTestCase):
69
70 scripts_dir = os.path.join(get_bb_var('COREBASE'), 'scripts')
71
72 def test_oegitproxy_help(self):
73 try:
74 res = runCmd('%s/oe-git-proxy --help' % self.scripts_dir, assert_error=False)
75 self.assertTrue(False)
76 except CommandError as e:
77 self.assertEqual(2, e.retcode)
78
79 def run_oegitproxy(self, custom_shell=None):
80 os.environ['SOCAT'] = shutil.which("echo")
81 os.environ['ALL_PROXY'] = "https://proxy.example.com:3128"
82 os.environ['NO_PROXY'] = "*.example.com,.no-proxy.org,192.168.42.0/24,127.*.*.*"
83
84 if custom_shell is None:
85 prefix = ''
86 else:
87 prefix = custom_shell + ' '
88
89 # outside, use the proxy
90 res = runCmd('%s%s/oe-git-proxy host.outside-example.com 9418' %
91 (prefix,self.scripts_dir))
92 self.assertIn('PROXY:', res.output)
93 # match with wildcard suffix
94 res = runCmd('%s%s/oe-git-proxy host.example.com 9418' %
95 (prefix, self.scripts_dir))
96 self.assertIn('TCP:', res.output)
97 # match just suffix
98 res = runCmd('%s%s/oe-git-proxy host.no-proxy.org 9418' %
99 (prefix, self.scripts_dir))
100 self.assertIn('TCP:', res.output)
101 # match IP subnet
102 res = runCmd('%s%s/oe-git-proxy 192.168.42.42 9418' %
103 (prefix, self.scripts_dir))
104 self.assertIn('TCP:', res.output)
105 # match IP wildcard
106 res = runCmd('%s%s/oe-git-proxy 127.1.2.3 9418' %
107 (prefix, self.scripts_dir))
108 self.assertIn('TCP:', res.output)
109
110 # test that * globbering is off
111 os.environ['NO_PROXY'] = "*"
112 res = runCmd('%s%s/oe-git-proxy host.example.com 9418' %
113 (prefix, self.scripts_dir))
114 self.assertIn('TCP:', res.output)
115
116 def test_oegitproxy_proxy(self):
117 self.run_oegitproxy()
118
119 def test_oegitproxy_proxy_dash(self):
120 dash = shutil.which("dash")
121 if dash is None:
122 self.skipTest("No \"dash\" found on test system.")
123 self.run_oegitproxy(custom_shell=dash)
Brad Bishop64c979e2019-11-04 13:55:29 -0500124
125class OeRunNativeTest(OESelftestTestCase):
126 def test_oe_run_native(self):
127 bitbake("qemu-helper-native -c addto_recipe_sysroot")
128 result = runCmd("oe-run-native qemu-helper-native tunctl -h")
129 self.assertIn("Delete: tunctl -d device-name [-f tun-clone-device]", result.output)
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500130
131class OEListPackageconfigTests(OEScriptTests):
132 #oe-core.scripts.List_all_the_PACKAGECONFIG's_flags
133 def check_endlines(self, results, expected_endlines):
134 for line in results.output.splitlines():
135 for el in expected_endlines:
Andrew Geissler475cb722020-07-10 16:00:51 -0500136 if line.split() == el.split():
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500137 expected_endlines.remove(el)
138 break
139
140 if expected_endlines:
141 self.fail('Missing expected listings:\n %s' % '\n '.join(expected_endlines))
142
143
144 #oe-core.scripts.List_all_the_PACKAGECONFIG's_flags
145 def test_packageconfig_flags_help(self):
146 runCmd('%s/contrib/list-packageconfig-flags.py -h' % self.scripts_dir)
147
148 def test_packageconfig_flags_default(self):
149 results = runCmd('%s/contrib/list-packageconfig-flags.py' % self.scripts_dir)
150 expected_endlines = []
151 expected_endlines.append("RECIPE NAME PACKAGECONFIG FLAGS")
152 expected_endlines.append("pinentry gtk2 libcap ncurses qt secret")
153 expected_endlines.append("tar acl")
154
155 self.check_endlines(results, expected_endlines)
156
157
158 def test_packageconfig_flags_option_flags(self):
159 results = runCmd('%s/contrib/list-packageconfig-flags.py -f' % self.scripts_dir)
160 expected_endlines = []
161 expected_endlines.append("PACKAGECONFIG FLAG RECIPE NAMES")
162 expected_endlines.append("qt nativesdk-pinentry pinentry pinentry-native")
163 expected_endlines.append("secret nativesdk-pinentry pinentry pinentry-native")
164
165 self.check_endlines(results, expected_endlines)
166
167 def test_packageconfig_flags_option_all(self):
168 results = runCmd('%s/contrib/list-packageconfig-flags.py -a' % self.scripts_dir)
169 expected_endlines = []
170 expected_endlines.append("pinentry-1.1.0")
171 expected_endlines.append("PACKAGECONFIG ncurses libcap")
172 expected_endlines.append("PACKAGECONFIG[qt] --enable-pinentry-qt, --disable-pinentry-qt, qtbase-native qtbase")
173 expected_endlines.append("PACKAGECONFIG[gtk2] --enable-pinentry-gtk2, --disable-pinentry-gtk2, gtk+ glib-2.0")
174 expected_endlines.append("PACKAGECONFIG[libcap] --with-libcap, --without-libcap, libcap")
175 expected_endlines.append("PACKAGECONFIG[ncurses] --enable-ncurses --with-ncurses-include-dir=${STAGING_INCDIR}, --disable-ncurses, ncurses")
176 expected_endlines.append("PACKAGECONFIG[secret] --enable-libsecret, --disable-libsecret, libsecret")
177
178 self.check_endlines(results, expected_endlines)
179
Andrew Geissler475cb722020-07-10 16:00:51 -0500180 def test_packageconfig_flags_options_preferred_only(self):
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500181 results = runCmd('%s/contrib/list-packageconfig-flags.py -p' % self.scripts_dir)
182 expected_endlines = []
183 expected_endlines.append("RECIPE NAME PACKAGECONFIG FLAGS")
184 expected_endlines.append("pinentry gtk2 libcap ncurses qt secret")
185
186 self.check_endlines(results, expected_endlines)
187