summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/eSDK.py
blob: a66ff92140c4bcacc8c50ee2b1d04255c38947ba (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
130
131
132
133
134
135
136
137
138
import unittest
import tempfile
import shutil
import os
import glob
import logging
import subprocess
import oeqa.utils.ftools as ftools
from oeqa.utils.decorators import testcase
from oeqa.selftest.base import oeSelfTest
from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars
from oeqa.utils.httpserver import HTTPService

class oeSDKExtSelfTest(oeSelfTest):
    """
    # Bugzilla Test Plan: 6033
    # This code is planned to be part of the automation for eSDK containig
    # Install libraries and headers, image generation binary feeds, sdk-update.
    """

    @staticmethod
    def get_esdk_environment(env_eSDK, tmpdir_eSDKQA):
        # XXX: at this time use the first env need to investigate
        # what environment load oe-selftest, i586, x86_64
        pattern = os.path.join(tmpdir_eSDKQA, 'environment-setup-*')
        return glob.glob(pattern)[0]

    @staticmethod
    def run_esdk_cmd(env_eSDK, tmpdir_eSDKQA, cmd, postconfig=None, **options):
        if postconfig:
            esdk_conf_file = os.path.join(tmpdir_eSDKQA, 'conf', 'local.conf')
            with open(esdk_conf_file, 'a+') as f:
                f.write(postconfig)
        if not options:
            options = {}
        if not 'shell' in options:
            options['shell'] = True

        runCmd("cd %s; . %s; %s" % (tmpdir_eSDKQA, env_eSDK, cmd), **options)

    @staticmethod
    def generate_eSDK(image):
        pn_task = '%s -c populate_sdk_ext' % image
        bitbake(pn_task)

    @staticmethod
    def get_eSDK_toolchain(image):
        pn_task = '%s -c populate_sdk_ext' % image

        bb_vars = get_bb_vars(['SDK_DEPLOY', 'TOOLCHAINEXT_OUTPUTNAME'], pn_task)
        sdk_deploy = bb_vars['SDK_DEPLOY']
        toolchain_name = bb_vars['TOOLCHAINEXT_OUTPUTNAME']
        return os.path.join(sdk_deploy, toolchain_name + '.sh')

    @staticmethod
    def update_configuration(cls, image, tmpdir_eSDKQA, env_eSDK, ext_sdk_path):
        sstate_dir = os.path.join(os.environ['BUILDDIR'], 'sstate-cache')
        cls.http_service = HTTPService(sstate_dir)
        cls.http_service.start()
        cls.http_url = "http://127.0.0.1:%d" % cls.http_service.port

        oeSDKExtSelfTest.generate_eSDK(cls.image)

        cls.ext_sdk_path = oeSDKExtSelfTest.get_eSDK_toolchain(cls.image)
        runCmd("%s -y -d \"%s\"" % (cls.ext_sdk_path, cls.tmpdir_eSDKQA))

        cls.env_eSDK = oeSDKExtSelfTest.get_esdk_environment('', cls.tmpdir_eSDKQA)

        sstate_config="""
SDK_LOCAL_CONF_WHITELIST = "SSTATE_MIRRORS"
SSTATE_MIRRORS =  "file://.* http://%s/PATH"
CORE_IMAGE_EXTRA_INSTALL = "perl"
        """ % cls.http_url

        with open(os.path.join(cls.tmpdir_eSDKQA, 'conf', 'local.conf'), 'a+') as f:
            f.write(sstate_config)

    @classmethod
    def setUpClass(cls):
        # If there is an exception in setUpClass it will not run tearDownClass
        # method and it leaves HTTP server running forever, so we need to be
        # sure tearDownClass is run.
        try:
            cls.tmpdir_eSDKQA = tempfile.mkdtemp(prefix='eSDKQA')

            # Start to serve sstate dir
            sstate_dir = get_bb_var('SSTATE_DIR')
            cls.http_service = HTTPService(sstate_dir)
            cls.http_url = "http://127.0.0.1:%d" % cls.http_service.port
            cls.http_service.start()

            cls.image = 'core-image-minimal'
            oeSDKExtSelfTest.generate_eSDK(cls.image)

            # Install eSDK
            cls.ext_sdk_path = oeSDKExtSelfTest.get_eSDK_toolchain(cls.image)
            runCmd("%s -y -d \"%s\"" % (cls.ext_sdk_path, cls.tmpdir_eSDKQA))

            cls.env_eSDK = oeSDKExtSelfTest.get_esdk_environment('', cls.tmpdir_eSDKQA)

            # Configure eSDK to use sstate mirror from poky
            sstate_config="""
SDK_LOCAL_CONF_WHITELIST = "SSTATE_MIRRORS"
SSTATE_MIRRORS =  "file://.* http://%s/PATH"
            """ % cls.http_url
            with open(os.path.join(cls.tmpdir_eSDKQA, 'conf', 'local.conf'), 'a+') as f:
                f.write(sstate_config)
        except:
            cls.tearDownClass()
            raise

    @classmethod
    def tearDownClass(cls):
        shutil.rmtree(cls.tmpdir_eSDKQA)
        cls.http_service.stop()

    @testcase (1602)
    def test_install_libraries_headers(self):
        pn_sstate = 'bc'
        bitbake(pn_sstate)
        cmd = "devtool sdk-install %s " % pn_sstate
        oeSDKExtSelfTest.run_esdk_cmd(self.env_eSDK, self.tmpdir_eSDKQA, cmd)

    @testcase(1603)
    def test_image_generation_binary_feeds(self):
        image = 'core-image-minimal'
        cmd = "devtool build-image %s" % image
        oeSDKExtSelfTest.run_esdk_cmd(self.env_eSDK, self.tmpdir_eSDKQA, cmd)

    @testcase(1567)
    def test_sdk_update_http(self):
        cmd = "devtool sdk-update %s" % self.http_url
        oeSDKExtSelfTest.update_configuration(self, self.image, self.tmpdir_eSDKQA, self.env_eSDK, self.ext_sdk_path)
        oeSDKExtSelfTest.run_esdk_cmd(self.env_eSDK, self.tmpdir_eSDKQA, cmd)
        self.http_service.stop()

if __name__ == '__main__':
    unittest.main()