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