aboutsummaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/cases/oescripts.py
blob: 80d8b2c4cca9cdd085ea7a86470c742e9fd94084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#
# SPDX-License-Identifier: MIT
#

import os
import shutil
import unittest
from oeqa.selftest.case import OESelftestTestCase
from oeqa.selftest.cases.buildhistory import BuildhistoryBase
from oeqa.utils.commands import Command, runCmd, bitbake, get_bb_var, get_test_layer
from oeqa.utils import CommandError

class BuildhistoryDiffTests(BuildhistoryBase):

    def test_buildhistory_diff(self):
        target = 'xcursor-transparent-theme'
        self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True)
        self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True)
        result = runCmd("oe-pkgdata-util read-value PKGV %s" % target)
        pkgv = result.output.rstrip()
        result = runCmd("buildhistory-diff -p %s" % get_bb_var('BUILDHISTORY_DIR'))
        expected_endlines = [
            "xcursor-transparent-theme-dev: RDEPENDS: removed \"xcursor-transparent-theme (['= %s-r1'])\", added \"xcursor-transparent-theme (['= %s-r0'])\"" % (pkgv, pkgv),
            "xcursor-transparent-theme-staticdev: RDEPENDS: removed \"xcursor-transparent-theme-dev (['= %s-r1'])\", added \"xcursor-transparent-theme-dev (['= %s-r0'])\"" % (pkgv, pkgv)
        ]
        for line in result.output.splitlines():
            for el in expected_endlines:
                if line.endswith(el):
                    expected_endlines.remove(el)
                    break
            else:
                self.fail('Unexpected line:\n%s\nExpected line endings:\n  %s' % (line, '\n  '.join(expected_endlines)))
        if expected_endlines:
            self.fail('Missing expected line endings:\n  %s' % '\n  '.join(expected_endlines))

class OEScriptTests(OESelftestTestCase):

    @classmethod
    def setUpClass(cls):
        super(OEScriptTests, cls).setUpClass()
        try:
            import cairo
        except ImportError:
            raise unittest.SkipTest('Python module cairo is not present')
        bitbake("core-image-minimal -c rootfs -f")
        cls.tmpdir = get_bb_var('TMPDIR')
        cls.buildstats = cls.tmpdir + "/buildstats/" + sorted(os.listdir(cls.tmpdir + "/buildstats"))[-1]

    scripts_dir = os.path.join(get_bb_var('COREBASE'), 'scripts')

class OEPybootchartguyTests(OEScriptTests):

    def test_pybootchartguy_help(self):
        runCmd('%s/pybootchartgui/pybootchartgui.py  --help' % self.scripts_dir)

    def test_pybootchartguy_to_generate_build_png_output(self):
        runCmd('%s/pybootchartgui/pybootchartgui.py  %s -o %s/charts -f png' % (self.scripts_dir, self.buildstats, self.tmpdir))
        self.assertTrue(os.path.exists(self.tmpdir + "/charts.png"))

    def test_pybootchartguy_to_generate_build_svg_output(self):
        runCmd('%s/pybootchartgui/pybootchartgui.py  %s -o %s/charts -f svg' % (self.scripts_dir, self.buildstats, self.tmpdir))
        self.assertTrue(os.path.exists(self.tmpdir + "/charts.svg"))

    def test_pybootchartguy_to_generate_build_pdf_output(self):
        runCmd('%s/pybootchartgui/pybootchartgui.py  %s -o %s/charts -f pdf' % (self.scripts_dir, self.buildstats, self.tmpdir))
        self.assertTrue(os.path.exists(self.tmpdir + "/charts.pdf"))

class OEGitproxyTests(OESelftestTestCase):

    scripts_dir = os.path.join(get_bb_var('COREBASE'), 'scripts')

    def test_oegitproxy_help(self):
        try:
            res = runCmd('%s/oe-git-proxy  --help' % self.scripts_dir, assert_error=False)
            self.assertTrue(False)
        except CommandError as e:
            self.assertEqual(2, e.retcode)

    def run_oegitproxy(self, custom_shell=None):
        os.environ['SOCAT'] = shutil.which("echo")
        os.environ['ALL_PROXY'] = "https://proxy.example.com:3128"
        os.environ['NO_PROXY'] = "*.example.com,.no-proxy.org,192.168.42.0/24,127.*.*.*"

        if custom_shell is None:
            prefix = ''
        else:
            prefix = custom_shell + ' '

        # outside, use the proxy
        res = runCmd('%s%s/oe-git-proxy host.outside-example.com 9418' %
                     (prefix,self.scripts_dir))
        self.assertIn('PROXY:', res.output)
        # match with wildcard suffix
        res = runCmd('%s%s/oe-git-proxy host.example.com 9418' %
                     (prefix, self.scripts_dir))
        self.assertIn('TCP:', res.output)
        # match just suffix
        res = runCmd('%s%s/oe-git-proxy host.no-proxy.org 9418' %
                     (prefix, self.scripts_dir))
        self.assertIn('TCP:', res.output)
        # match IP subnet
        res = runCmd('%s%s/oe-git-proxy 192.168.42.42 9418' %
                     (prefix, self.scripts_dir))
        self.assertIn('TCP:', res.output)
        # match IP wildcard
        res = runCmd('%s%s/oe-git-proxy 127.1.2.3 9418' %
                     (prefix, self.scripts_dir))
        self.assertIn('TCP:', res.output)
        
        # test that * globbering is off
        os.environ['NO_PROXY'] = "*"
        res = runCmd('%s%s/oe-git-proxy host.example.com 9418' %
                     (prefix, self.scripts_dir))
        self.assertIn('TCP:', res.output)

    def test_oegitproxy_proxy(self):
        self.run_oegitproxy()

    def test_oegitproxy_proxy_dash(self):
        dash = shutil.which("dash")
        if dash is None:
            self.skipTest("No \"dash\" found on test system.")
        self.run_oegitproxy(custom_shell=dash)

class OeRunNativeTest(OESelftestTestCase):
    def test_oe_run_native(self):
        bitbake("qemu-helper-native -c addto_recipe_sysroot")
        result = runCmd("oe-run-native qemu-helper-native tunctl -h")
        self.assertIn("Delete: tunctl -d device-name [-f tun-clone-device]", result.output)