1#
2# Copyright (C) 2016 Intel Corporation
3#
4# SPDX-License-Identifier: MIT
5#
6
7import os
8import shutil
9import subprocess
10
11from oeqa.sdkext.case import OESDKExtTestCase
12from oeqa.utils.httpserver import HTTPService
13
14from oeqa.utils.subprocesstweak import errors_have_output
15errors_have_output()
16
17class DevtoolTest(OESDKExtTestCase):
18    @classmethod
19    def setUpClass(cls):
20        myapp_src = os.path.join(cls.tc.esdk_files_dir, "myapp")
21        cls.myapp_dst = os.path.join(cls.tc.sdk_dir, "myapp")
22        shutil.copytree(myapp_src, cls.myapp_dst)
23        subprocess.check_output(['git', 'init', '.'], cwd=cls.myapp_dst)
24        subprocess.check_output(['git', 'add', '.'], cwd=cls.myapp_dst)
25        subprocess.check_output(['git', 'commit', '-m', "'test commit'"], cwd=cls.myapp_dst)
26
27        myapp_cmake_src = os.path.join(cls.tc.esdk_files_dir, "myapp_cmake")
28        cls.myapp_cmake_dst = os.path.join(cls.tc.sdk_dir, "myapp_cmake")
29        shutil.copytree(myapp_cmake_src, cls.myapp_cmake_dst)
30        subprocess.check_output(['git', 'init', '.'], cwd=cls.myapp_cmake_dst)
31        subprocess.check_output(['git', 'add', '.'], cwd=cls.myapp_cmake_dst)
32        subprocess.check_output(['git', 'commit', '-m', "'test commit'"], cwd=cls.myapp_cmake_dst)
33
34    @classmethod
35    def tearDownClass(cls):
36        shutil.rmtree(cls.myapp_dst)
37        shutil.rmtree(cls.myapp_cmake_dst)
38
39    def _test_devtool_build(self, directory):
40        self._run('devtool add myapp %s' % directory)
41        try:
42            self._run('devtool build myapp')
43        finally:
44            self._run('devtool reset myapp')
45
46    def _test_devtool_build_package(self, directory):
47        self._run('devtool add myapp %s' % directory)
48        try:
49            self._run('devtool package myapp')
50        finally:
51            self._run('devtool reset myapp')
52
53    def test_devtool_location(self):
54        output = self._run('which devtool')
55        self.assertEqual(output.startswith(self.tc.sdk_dir), True, \
56            msg="Seems that devtool isn't the eSDK one: %s" % output)
57
58    def test_devtool_add_reset(self):
59        self._run('devtool add myapp %s' % self.myapp_dst)
60        self._run('devtool reset myapp')
61
62    def test_devtool_build_make(self):
63        self._test_devtool_build(self.myapp_dst)
64
65    def test_devtool_build_esdk_package(self):
66        self._test_devtool_build_package(self.myapp_dst)
67
68    def test_devtool_build_cmake(self):
69        self._test_devtool_build(self.myapp_cmake_dst)
70
71    def test_extend_autotools_recipe_creation(self):
72        req = 'https://github.com/rdfa/librdfa'
73        recipe = "librdfa"
74        self._run('devtool sdk-install libxml2')
75        self._run('devtool add %s %s' % (recipe, req) )
76        try:
77            self._run('devtool build %s' % recipe)
78        finally:
79            self._run('devtool reset %s' % recipe)
80
81    def test_devtool_kernelmodule(self):
82        docfile = 'https://git.yoctoproject.org/git/kernel-module-hello-world'
83        recipe = 'kernel-module-hello-world'
84        self._run('devtool add %s %s' % (recipe, docfile) )
85        try:
86            self._run('devtool build %s' % recipe)
87        finally:
88            self._run('devtool reset %s' % recipe)
89
90    def test_recipes_for_nodejs(self):
91        package_nodejs = "npm://registry.npmjs.org;name=winston;version=2.2.0"
92        self._run('devtool add %s ' % package_nodejs)
93        try:
94            self._run('devtool build %s ' % package_nodejs)
95        finally:
96            self._run('devtool reset %s '% package_nodejs)
97
98class SdkUpdateTest(OESDKExtTestCase):
99    @classmethod
100    def setUpClass(self):
101        self.publish_dir = os.path.join(self.tc.sdk_dir, 'esdk_publish')
102        if os.path.exists(self.publish_dir):
103            shutil.rmtree(self.publish_dir)
104        os.mkdir(self.publish_dir)
105
106        base_tcname = "%s/%s" % (self.td.get("SDK_DEPLOY", ''),
107            self.td.get("TOOLCHAINEXT_OUTPUTNAME", ''))
108        tcname_new = "%s-new.sh" % base_tcname
109        if not os.path.exists(tcname_new):
110            tcname_new = "%s.sh" % base_tcname
111
112        cmd = 'oe-publish-sdk %s %s' % (tcname_new, self.publish_dir)
113        subprocess.check_output(cmd, shell=True)
114
115        self.http_service = HTTPService(self.publish_dir, logger=self.logger)
116        self.http_service.start()
117
118        self.http_url = "http://127.0.0.1:%d" % self.http_service.port
119
120    def test_sdk_update_http(self):
121        output = self._run("devtool sdk-update \"%s\"" % self.http_url)
122
123    @classmethod
124    def tearDownClass(self):
125        self.http_service.stop()
126        shutil.rmtree(self.publish_dir)
127