Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
| 5 | import os |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 6 | import shutil |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 7 | import unittest |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8 | from oeqa.selftest.case import OESelftestTestCase |
| 9 | from oeqa.selftest.cases.buildhistory import BuildhistoryBase |
| 10 | from oeqa.utils.commands import Command, runCmd, bitbake, get_bb_var, get_test_layer |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 11 | from oeqa.utils import CommandError |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | |
| 13 | class BuildhistoryDiffTests(BuildhistoryBase): |
| 14 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 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) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 19 | result = runCmd("oe-pkgdata-util read-value PKGV %s" % target) |
| 20 | pkgv = result.output.rstrip() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 21 | result = runCmd("buildhistory-diff -p %s" % get_bb_var('BUILDHISTORY_DIR')) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 22 | 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 Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 35 | |
| 36 | class OEScriptTests(OESelftestTestCase): |
| 37 | |
| 38 | @classmethod |
| 39 | def setUpClass(cls): |
| 40 | super(OEScriptTests, cls).setUpClass() |
| 41 | try: |
| 42 | import cairo |
| 43 | except ImportError: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 44 | raise unittest.SkipTest('Python module cairo is not present') |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 45 | 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 | |
| 51 | class 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 Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 68 | class 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 Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 124 | |
| 125 | class 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) |