blob: 41cbe048080cc3a61a6396aa02ea9ce0d626c578 [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
Brad Bishop15ae2502019-06-18 21:44:24 -04007import unittest
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008from oeqa.selftest.case import OESelftestTestCase
9from oeqa.selftest.cases.buildhistory import BuildhistoryBase
10from oeqa.utils.commands import Command, runCmd, bitbake, get_bb_var, get_test_layer
Brad Bishopa34c0302019-09-23 22:34:48 -040011from oeqa.utils import CommandError
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012
13class BuildhistoryDiffTests(BuildhistoryBase):
14
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015 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)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080019 result = runCmd("oe-pkgdata-util read-value PKGV %s" % target)
20 pkgv = result.output.rstrip()
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021 result = runCmd("buildhistory-diff -p %s" % get_bb_var('BUILDHISTORY_DIR'))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080022 expected_endlines = [
23 "xcursor-transparent-theme-dev: RDEPENDS: 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))
Brad Bishopc342db32019-05-15 21:57:59 -040035
36class OEScriptTests(OESelftestTestCase):
37
38 @classmethod
39 def setUpClass(cls):
40 super(OEScriptTests, cls).setUpClass()
41 try:
42 import cairo
43 except ImportError:
Brad Bishop15ae2502019-06-18 21:44:24 -040044 raise unittest.SkipTest('Python module cairo is not present')
Brad Bishopc342db32019-05-15 21:57:59 -040045 bitbake("core-image-minimal -c rootfs -f")
46 cls.tmpdir = get_bb_var('TMPDIR')
47 cls.buildstats = cls.tmpdir + "/buildstats/" + sorted(os.listdir(cls.tmpdir + "/buildstats"))[-1]
48
49 scripts_dir = os.path.join(get_bb_var('COREBASE'), 'scripts')
50
51class OEPybootchartguyTests(OEScriptTests):
52
53 def test_pybootchartguy_help(self):
54 runCmd('%s/pybootchartgui/pybootchartgui.py --help' % self.scripts_dir)
55
56 def test_pybootchartguy_to_generate_build_png_output(self):
57 runCmd('%s/pybootchartgui/pybootchartgui.py %s -o %s/charts -f png' % (self.scripts_dir, self.buildstats, self.tmpdir))
58 self.assertTrue(os.path.exists(self.tmpdir + "/charts.png"))
59
60 def test_pybootchartguy_to_generate_build_svg_output(self):
61 runCmd('%s/pybootchartgui/pybootchartgui.py %s -o %s/charts -f svg' % (self.scripts_dir, self.buildstats, self.tmpdir))
62 self.assertTrue(os.path.exists(self.tmpdir + "/charts.svg"))
63
64 def test_pybootchartguy_to_generate_build_pdf_output(self):
65 runCmd('%s/pybootchartgui/pybootchartgui.py %s -o %s/charts -f pdf' % (self.scripts_dir, self.buildstats, self.tmpdir))
66 self.assertTrue(os.path.exists(self.tmpdir + "/charts.pdf"))
67
Brad Bishop1d80a2e2019-11-15 16:35:03 -050068
Brad Bishopa34c0302019-09-23 22:34:48 -040069class OEGitproxyTests(OESelftestTestCase):
70
71 scripts_dir = os.path.join(get_bb_var('COREBASE'), 'scripts')
72
73 def test_oegitproxy_help(self):
74 try:
75 res = runCmd('%s/oe-git-proxy --help' % self.scripts_dir, assert_error=False)
76 self.assertTrue(False)
77 except CommandError as e:
78 self.assertEqual(2, e.retcode)
79
80 def run_oegitproxy(self, custom_shell=None):
81 os.environ['SOCAT'] = shutil.which("echo")
82 os.environ['ALL_PROXY'] = "https://proxy.example.com:3128"
83 os.environ['NO_PROXY'] = "*.example.com,.no-proxy.org,192.168.42.0/24,127.*.*.*"
84
85 if custom_shell is None:
86 prefix = ''
87 else:
88 prefix = custom_shell + ' '
89
90 # outside, use the proxy
91 res = runCmd('%s%s/oe-git-proxy host.outside-example.com 9418' %
92 (prefix,self.scripts_dir))
93 self.assertIn('PROXY:', res.output)
94 # match with wildcard suffix
95 res = runCmd('%s%s/oe-git-proxy host.example.com 9418' %
96 (prefix, self.scripts_dir))
97 self.assertIn('TCP:', res.output)
98 # match just suffix
99 res = runCmd('%s%s/oe-git-proxy host.no-proxy.org 9418' %
100 (prefix, self.scripts_dir))
101 self.assertIn('TCP:', res.output)
102 # match IP subnet
103 res = runCmd('%s%s/oe-git-proxy 192.168.42.42 9418' %
104 (prefix, self.scripts_dir))
105 self.assertIn('TCP:', res.output)
106 # match IP wildcard
107 res = runCmd('%s%s/oe-git-proxy 127.1.2.3 9418' %
108 (prefix, self.scripts_dir))
109 self.assertIn('TCP:', res.output)
110
111 # test that * globbering is off
112 os.environ['NO_PROXY'] = "*"
113 res = runCmd('%s%s/oe-git-proxy host.example.com 9418' %
114 (prefix, self.scripts_dir))
115 self.assertIn('TCP:', res.output)
116
117 def test_oegitproxy_proxy(self):
118 self.run_oegitproxy()
119
120 def test_oegitproxy_proxy_dash(self):
121 dash = shutil.which("dash")
122 if dash is None:
123 self.skipTest("No \"dash\" found on test system.")
124 self.run_oegitproxy(custom_shell=dash)
Brad Bishop64c979e2019-11-04 13:55:29 -0500125
126class OeRunNativeTest(OESelftestTestCase):
127 def test_oe_run_native(self):
128 bitbake("qemu-helper-native -c addto_recipe_sysroot")
129 result = runCmd("oe-run-native qemu-helper-native tunctl -h")
130 self.assertIn("Delete: tunctl -d device-name [-f tun-clone-device]", result.output)
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500131
132class OEListPackageconfigTests(OEScriptTests):
133 #oe-core.scripts.List_all_the_PACKAGECONFIG's_flags
134 def check_endlines(self, results, expected_endlines):
135 for line in results.output.splitlines():
136 for el in expected_endlines:
137 if line == el:
138 expected_endlines.remove(el)
139 break
140
141 if expected_endlines:
142 self.fail('Missing expected listings:\n %s' % '\n '.join(expected_endlines))
143
144
145 #oe-core.scripts.List_all_the_PACKAGECONFIG's_flags
146 def test_packageconfig_flags_help(self):
147 runCmd('%s/contrib/list-packageconfig-flags.py -h' % self.scripts_dir)
148
149 def test_packageconfig_flags_default(self):
150 results = runCmd('%s/contrib/list-packageconfig-flags.py' % self.scripts_dir)
151 expected_endlines = []
152 expected_endlines.append("RECIPE NAME PACKAGECONFIG FLAGS")
153 expected_endlines.append("pinentry gtk2 libcap ncurses qt secret")
154 expected_endlines.append("tar acl")
155
156 self.check_endlines(results, expected_endlines)
157
158
159 def test_packageconfig_flags_option_flags(self):
160 results = runCmd('%s/contrib/list-packageconfig-flags.py -f' % self.scripts_dir)
161 expected_endlines = []
162 expected_endlines.append("PACKAGECONFIG FLAG RECIPE NAMES")
163 expected_endlines.append("qt nativesdk-pinentry pinentry pinentry-native")
164 expected_endlines.append("secret nativesdk-pinentry pinentry pinentry-native")
165
166 self.check_endlines(results, expected_endlines)
167
168 def test_packageconfig_flags_option_all(self):
169 results = runCmd('%s/contrib/list-packageconfig-flags.py -a' % self.scripts_dir)
170 expected_endlines = []
171 expected_endlines.append("pinentry-1.1.0")
172 expected_endlines.append("PACKAGECONFIG ncurses libcap")
173 expected_endlines.append("PACKAGECONFIG[qt] --enable-pinentry-qt, --disable-pinentry-qt, qtbase-native qtbase")
174 expected_endlines.append("PACKAGECONFIG[gtk2] --enable-pinentry-gtk2, --disable-pinentry-gtk2, gtk+ glib-2.0")
175 expected_endlines.append("PACKAGECONFIG[libcap] --with-libcap, --without-libcap, libcap")
176 expected_endlines.append("PACKAGECONFIG[ncurses] --enable-ncurses --with-ncurses-include-dir=${STAGING_INCDIR}, --disable-ncurses, ncurses")
177 expected_endlines.append("PACKAGECONFIG[secret] --enable-libsecret, --disable-libsecret, libsecret")
178
179 self.check_endlines(results, expected_endlines)
180
181 def test_packageconfig_flags_optiins_preferred_only(self):
182 results = runCmd('%s/contrib/list-packageconfig-flags.py -p' % self.scripts_dir)
183 expected_endlines = []
184 expected_endlines.append("RECIPE NAME PACKAGECONFIG FLAGS")
185 expected_endlines.append("pinentry gtk2 libcap ncurses qt secret")
186
187 self.check_endlines(results, expected_endlines)
188