• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# coding=utf-8
3
4#
5# Copyright (c) 2020 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19import os
20import platform
21import subprocess
22
23from xdevice import platform_logger
24
25
26class BuildLiteManager(object):
27    """
28    build lite system version or test cases
29    build param:
30    device type:for examples, watch or camera
31    board platform:for examples, HI3518ev300 or HI3516DV300
32    kernel type:for examples, liteos_m, liteos_a, linux
33    """
34    log = platform_logger("BuildLiteManager")
35
36    def __init__(self, project_root_path):
37        self.project_rootpath = project_root_path
38
39    def build_testcases(self, param):
40        if platform.system() != "Linux":
41            self.log.info("Windows environment, only use .bin test cases")
42            return True
43
44        current_path = os.getcwd()
45        os.chdir(self.project_rootpath)
46
47        command = []
48        if param.productform.find("wifiiot") == -1:
49            command.append("hb")
50            command.append("build")
51            command.append("-p")
52            command.append("%s@hisilicon" % param.productform)
53            command.append("-b")
54            command.append("debug")
55            if param.testsuit != "":
56                command.append("target=%s" % param.testsuit)
57        else:
58            build_script = os.path.abspath(os.path.join(
59                os.path.dirname(__file__),
60                "build_lite_testcases.sh"))
61            print("build_script=%s" % build_script)
62            command.append(build_script)
63            command.append("product=%s" % param.productform)
64            command.append("kernel=liteos_m")
65            if param.testsuit != "":
66                command.append("target=%s" % param.testsuit)
67        self.log.info("build_command: %s" % str(command))
68
69        build_result = False
70        try:
71            build_result = subprocess.call(command) == 0
72        except IOError as exception:
73            self.log.error("build test case failed, exception=%s" % exception)
74
75        if build_result:
76            self.log.info("build test case successed.")
77        else:
78            self.log.info("build test case failed.")
79
80        os.chdir(os.path.realpath(current_path))
81        return build_result
82
83    def build_version(self, productform):
84        current_path = os.getcwd()
85        os.chdir(self.project_rootpath)
86
87        command = []
88        command.append("hb")
89        command.append("build")
90        command.append("-p")
91        command.append("%s@hisilicon" % productform)
92        command.append("-f")
93        self.log.info("build_command: %s" % str(command))
94
95        build_result = False
96        try:
97            build_result = subprocess.call(command) == 0
98        except IOError as exception:
99            self.log.error("build version failed, exception=%s" % exception)
100
101        if build_result:
102            self.log.info("build version successed.")
103        else:
104            self.log.info("build version failed.")
105
106        os.chdir(os.path.realpath(current_path))
107        return build_result
108