13298bea7Sopenharmony_ci#!/usr/bin/env python
23298bea7Sopenharmony_ci# -*- coding: utf-8 -*-
33298bea7Sopenharmony_ci"""
43298bea7Sopenharmony_ciCopyright (C) 2022 Huawei Device Co., Ltd.
53298bea7Sopenharmony_ciSPDX-License-Identifier: GPL-2.0
63298bea7Sopenharmony_ci
73298bea7Sopenharmony_ciUnless required by applicable law or agreed to in writing, software
83298bea7Sopenharmony_cidistributed under the License is distributed on an "AS IS" BASIS,
93298bea7Sopenharmony_ciWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
103298bea7Sopenharmony_ciSee the License for the specific language governing permissions and
113298bea7Sopenharmony_cilimitations under the License.
123298bea7Sopenharmony_ci"""
133298bea7Sopenharmony_ci
143298bea7Sopenharmony_ciimport logging
153298bea7Sopenharmony_ciimport os
163298bea7Sopenharmony_ciimport re
173298bea7Sopenharmony_ciimport select
183298bea7Sopenharmony_ciimport sys
193298bea7Sopenharmony_ciimport subprocess
203298bea7Sopenharmony_ciimport shlex
213298bea7Sopenharmony_ciimport time
223298bea7Sopenharmony_ci
233298bea7Sopenharmony_ci
243298bea7Sopenharmony_ciignores = [
253298bea7Sopenharmony_ci    "include/trace/events/eas_sched.h: warning: format '%d' expects argument of type 'int', but argument 9 has type 'long unsigned int' [-Wformat=]",
263298bea7Sopenharmony_ci    "drivers/block/zram/zram_drv.c: warning: left shift count >= width of type",
273298bea7Sopenharmony_ci    "include/trace/events/eas_sched.h: note: in expansion of macro",
283298bea7Sopenharmony_ci    "include/trace/events/eas_sched.h: note: format string is defined here",
293298bea7Sopenharmony_ci    "include/trace/trace_events.h: note: in expansion of macro",
303298bea7Sopenharmony_ci    "mm/vmscan.c: warning: suggest parentheses around assignment used as truth value [-Wparentheses]",
313298bea7Sopenharmony_ci    "lib/bitfield_kunit.c: warning: the frame size of \d+ bytes is larger than \d+ bytes",
323298bea7Sopenharmony_ci    "drivers/mmc/host/sdhci-esdhc-imx.c: warning: 'sdhci_esdhc_imx_probe_nondt' defined but not used",
333298bea7Sopenharmony_ci]
343298bea7Sopenharmony_ci
353298bea7Sopenharmony_ci
363298bea7Sopenharmony_ciclass Reporter:
373298bea7Sopenharmony_ci    def __init__(self, arch, path):
383298bea7Sopenharmony_ci        self.arch = arch
393298bea7Sopenharmony_ci        self.path = path
403298bea7Sopenharmony_ci
413298bea7Sopenharmony_ci
423298bea7Sopenharmony_ci    def normpath(self, filename):
433298bea7Sopenharmony_ci        if re.search("^[\.]+[^/]", filename):
443298bea7Sopenharmony_ci            filename = re.sub("^[\.]+", "", filename)
453298bea7Sopenharmony_ci        return os.path.normpath(filename)
463298bea7Sopenharmony_ci
473298bea7Sopenharmony_ci
483298bea7Sopenharmony_ci    def format_title(self, title):
493298bea7Sopenharmony_ci        title = re.sub("\u2018", "'", title)
503298bea7Sopenharmony_ci        title = re.sub("\u2019", "'", title)
513298bea7Sopenharmony_ci
523298bea7Sopenharmony_ci        return title.strip()
533298bea7Sopenharmony_ci
543298bea7Sopenharmony_ci
553298bea7Sopenharmony_ci    def report_build_warning(self, filename, regex, details):
563298bea7Sopenharmony_ci        report = {}
573298bea7Sopenharmony_ci
583298bea7Sopenharmony_ci        if len(details) == 0 or filename is None:
593298bea7Sopenharmony_ci            return report
603298bea7Sopenharmony_ci
613298bea7Sopenharmony_ci        if not os.path.exists(os.path.join(self.path, filename)):
623298bea7Sopenharmony_ci            return report
633298bea7Sopenharmony_ci
643298bea7Sopenharmony_ci        line = details[0]
653298bea7Sopenharmony_ci        try:
663298bea7Sopenharmony_ci            warning = re.search(regex, line).group(0)
673298bea7Sopenharmony_ci        except GetBuildWaringErr as e:
683298bea7Sopenharmony_ci            print('Except>>>', details)
693298bea7Sopenharmony_ci            return report
703298bea7Sopenharmony_ci
713298bea7Sopenharmony_ci        report = {
723298bea7Sopenharmony_ci            'title': self.format_title("%s: %s" % (filename, warning)),
733298bea7Sopenharmony_ci            'filename': filename,
743298bea7Sopenharmony_ci            'report': '\n'.join(details),
753298bea7Sopenharmony_ci            'nr': line.split(':')[1],
763298bea7Sopenharmony_ci        }
773298bea7Sopenharmony_ci
783298bea7Sopenharmony_ci        return report
793298bea7Sopenharmony_ci
803298bea7Sopenharmony_ci
813298bea7Sopenharmony_ci    def parse_build_warning(self, blocks, regex, title_regex):
823298bea7Sopenharmony_ci        issues = {}
833298bea7Sopenharmony_ci        reports = []
843298bea7Sopenharmony_ci        details = []
853298bea7Sopenharmony_ci        filename = None
863298bea7Sopenharmony_ci        unused = False
873298bea7Sopenharmony_ci
883298bea7Sopenharmony_ci        for line in blocks:
893298bea7Sopenharmony_ci            attrs = line.split(':')
903298bea7Sopenharmony_ci            if len(attrs) < 5 and filename is None:
913298bea7Sopenharmony_ci                continue
923298bea7Sopenharmony_ci            if line.startswith(' ') or len(attrs) < 2:
933298bea7Sopenharmony_ci                if unused is True:
943298bea7Sopenharmony_ci                    details.append(line)
953298bea7Sopenharmony_ci                continue
963298bea7Sopenharmony_ci            if not regex in line:
973298bea7Sopenharmony_ci                unused = False
983298bea7Sopenharmony_ci                continue
993298bea7Sopenharmony_ci            unused = True
1003298bea7Sopenharmony_ci            newfile = self.normpath(attrs[0])
1013298bea7Sopenharmony_ci            if newfile != filename:
1023298bea7Sopenharmony_ci                if len(details) and filename:
1033298bea7Sopenharmony_ci                    if filename in issues:
1043298bea7Sopenharmony_ci                        issues[filename].extend(details)
1053298bea7Sopenharmony_ci                    else:
1063298bea7Sopenharmony_ci                        issues[filename] = details
1073298bea7Sopenharmony_ci                filename = newfile
1083298bea7Sopenharmony_ci                details = []
1093298bea7Sopenharmony_ci
1103298bea7Sopenharmony_ci            details.append(line)
1113298bea7Sopenharmony_ci
1123298bea7Sopenharmony_ci        if len(details) and filename:
1133298bea7Sopenharmony_ci            if filename in issues:
1143298bea7Sopenharmony_ci                issues[filename].extend(details)
1153298bea7Sopenharmony_ci            else:
1163298bea7Sopenharmony_ci                issues[filename] = details
1173298bea7Sopenharmony_ci
1183298bea7Sopenharmony_ci        for filename, details in issues.items():
1193298bea7Sopenharmony_ci            report = self.report_build_warning(filename, title_regex, details)
1203298bea7Sopenharmony_ci            if not report is None:
1213298bea7Sopenharmony_ci                reports.append(report)
1223298bea7Sopenharmony_ci
1233298bea7Sopenharmony_ci        return reports
1243298bea7Sopenharmony_ci
1253298bea7Sopenharmony_ci
1263298bea7Sopenharmony_ci    def parse(self, content):
1273298bea7Sopenharmony_ci        blocks = content.split('\n')
1283298bea7Sopenharmony_ci        reports = []
1293298bea7Sopenharmony_ci
1303298bea7Sopenharmony_ci        patterns = (
1313298bea7Sopenharmony_ci            ('[-Wunused-but-set-variable]', 'warning: .* set but not used'),
1323298bea7Sopenharmony_ci            ('[-Wunused-but-set-parameter]', 'warning: .* set but not used'),
1333298bea7Sopenharmony_ci            ('[-Wunused-const-variable=]', 'warning: .* defined but not used'),
1343298bea7Sopenharmony_ci            ('[-Wold-style-definition]', 'warning: .* definition'),
1353298bea7Sopenharmony_ci            ('[-Wold-style-declaration]', 'warning: .* declaration'),
1363298bea7Sopenharmony_ci            ('[-Wmaybe-uninitialized]', 'warning: .* uninitialized'),
1373298bea7Sopenharmony_ci            ('[-Wtype-limits]', 'warning: .* always (false|true)'),
1383298bea7Sopenharmony_ci            ('[-Wunused-function]', 'warning: .* defined but not used'),
1393298bea7Sopenharmony_ci            ('[-Wsequence-point]', 'warning: .* may be undefined'),
1403298bea7Sopenharmony_ci            ('[-Wformat=]', 'warning: format.*'),
1413298bea7Sopenharmony_ci            ('[-Wunused-variable]', 'warning: [^\[]*'),
1423298bea7Sopenharmony_ci            ('[-Wframe-larger-than=]', 'warning: the frame size [^\[]*'),
1433298bea7Sopenharmony_ci            ('[-Wshift-count-overflow]', 'warning: left shift count >= width of type'),
1443298bea7Sopenharmony_ci            ('definition or declaration', 'warning: .* declared inside parameter list will not be visible outside of this definition or declaration'),
1453298bea7Sopenharmony_ci            ('character', 'warning: missing terminating .* character'),
1463298bea7Sopenharmony_ci            ('in expansion of macro', 'note: in expansion of macro'),
1473298bea7Sopenharmony_ci            ('note: format string is defined here', 'note: format string is defined here'),
1483298bea7Sopenharmony_ci            ('[-Wparentheses]', 'suggest parentheses around assignment used as truth value'),
1493298bea7Sopenharmony_ci        )
1503298bea7Sopenharmony_ci
1513298bea7Sopenharmony_ci        for regex, title_regex in patterns:
1523298bea7Sopenharmony_ci            items = self.parse_build_warning(blocks, regex, title_regex)
1533298bea7Sopenharmony_ci            if items is None:
1543298bea7Sopenharmony_ci                continue
1553298bea7Sopenharmony_ci
1563298bea7Sopenharmony_ci            reports.extend(items)
1573298bea7Sopenharmony_ci
1583298bea7Sopenharmony_ci        return reports
1593298bea7Sopenharmony_ci
1603298bea7Sopenharmony_ci
1613298bea7Sopenharmony_cidef exec_cmd(command_list, shell=False, show_output=False, cwd=None):
1623298bea7Sopenharmony_ci    if isinstance(command_list, str):
1633298bea7Sopenharmony_ci        command_list = shlex.split(command_list)
1643298bea7Sopenharmony_ci    elif not isinstance(command_list, list):
1653298bea7Sopenharmony_ci        raise f"command_list to exec_cmd need to be a list or string"
1663298bea7Sopenharmony_ci    command_list = ['nice'] + [str(s) for s in command_list]
1673298bea7Sopenharmony_ci
1683298bea7Sopenharmony_ci    print(f"cwd: '{cwd}'")
1693298bea7Sopenharmony_ci    print(f"cmd: '{command_list}'")
1703298bea7Sopenharmony_ci    start = time.time()
1713298bea7Sopenharmony_ci    proc = subprocess.Popen(
1723298bea7Sopenharmony_ci        command_list if not shell else ' '.join(command_list),
1733298bea7Sopenharmony_ci        cwd=cwd,
1743298bea7Sopenharmony_ci        shell=shell,
1753298bea7Sopenharmony_ci        stdout=subprocess.PIPE,
1763298bea7Sopenharmony_ci        stderr=subprocess.PIPE,
1773298bea7Sopenharmony_ci        bufsize=1,
1783298bea7Sopenharmony_ci        universal_newlines=True,
1793298bea7Sopenharmony_ci    )
1803298bea7Sopenharmony_ci
1813298bea7Sopenharmony_ci    outmsg = ""
1823298bea7Sopenharmony_ci    errmsg = ""
1833298bea7Sopenharmony_ci    poller = select.epoll()
1843298bea7Sopenharmony_ci    poller.register(proc.stdout, select.EPOLLIN)
1853298bea7Sopenharmony_ci    poller.register(proc.stderr, select.EPOLLIN)
1863298bea7Sopenharmony_ci    while proc.poll() is None:
1873298bea7Sopenharmony_ci        for fd, event in poller.poll():
1883298bea7Sopenharmony_ci            if event is not select.EPOLLIN:
1893298bea7Sopenharmony_ci                continue
1903298bea7Sopenharmony_ci            if fd == proc.stdout.fileno():
1913298bea7Sopenharmony_ci                line = proc.stdout.readline()
1923298bea7Sopenharmony_ci                if show_output is True:
1933298bea7Sopenharmony_ci                    print(">> [stdout] %s", line.strip('\n'))
1943298bea7Sopenharmony_ci                outmsg += line
1953298bea7Sopenharmony_ci            elif fd == proc.stderr.fileno():
1963298bea7Sopenharmony_ci                line = proc.stderr.readline()
1973298bea7Sopenharmony_ci                if show_output is True:
1983298bea7Sopenharmony_ci                    print(">> [stderr] %s", line.strip('\n'))
1993298bea7Sopenharmony_ci                errmsg += line
2003298bea7Sopenharmony_ci
2013298bea7Sopenharmony_ci    for line in proc.stdout.readlines():
2023298bea7Sopenharmony_ci        if show_output is True:
2033298bea7Sopenharmony_ci            print(">> [stdout] %s", line.strip('\n'))
2043298bea7Sopenharmony_ci        outmsg += line
2053298bea7Sopenharmony_ci    for line in proc.stderr.readlines():
2063298bea7Sopenharmony_ci        if show_output is True:
2073298bea7Sopenharmony_ci            print(">> [stderr] %s", line.strip('\n'))
2083298bea7Sopenharmony_ci        errmsg += line
2093298bea7Sopenharmony_ci
2103298bea7Sopenharmony_ci    ret = proc.wait()
2113298bea7Sopenharmony_ci    print(f"Returned {ret} in {int(time.time() - start)} seconds")
2123298bea7Sopenharmony_ci
2133298bea7Sopenharmony_ci    return outmsg, errmsg, ret
2143298bea7Sopenharmony_ci
2153298bea7Sopenharmony_ci
2163298bea7Sopenharmony_cidef make_cmd(cmd, arch, cross_compile, knl_path):
2173298bea7Sopenharmony_ci    make = f"{cmd} ARCH={arch} CROSS_COMPILE={cross_compile}"
2183298bea7Sopenharmony_ci    outmsg, errmsg, ret = exec_cmd(make, cwd=knl_path)
2193298bea7Sopenharmony_ci    if ret:
2203298bea7Sopenharmony_ci        print(f'"{make}" errors --> \n {errmsg}')
2213298bea7Sopenharmony_ci        return ret, f'"{make}" errors --> \n {errmsg}'
2223298bea7Sopenharmony_ci
2233298bea7Sopenharmony_ci    return ret, f'"{make}" success!'
2243298bea7Sopenharmony_ci
2253298bea7Sopenharmony_ci
2263298bea7Sopenharmony_cidef make_config(arch, config, corss_compile, knl_path):
2273298bea7Sopenharmony_ci    make = f"make {config} ARCH={arch} CROSS_COMPILE={corss_compile}"
2283298bea7Sopenharmony_ci    outmsg, errmsg, ret = exec_cmd(make, cwd=knl_path)
2293298bea7Sopenharmony_ci    if ret:
2303298bea7Sopenharmony_ci        print(f'"{make}" errors --> \n {errmsg}')
2313298bea7Sopenharmony_ci        return ret, f'"{make}" errors --> \n {errmsg}'
2323298bea7Sopenharmony_ci
2333298bea7Sopenharmony_ci    return ret, f'"{make}" success!'
2343298bea7Sopenharmony_ci
2353298bea7Sopenharmony_ci
2363298bea7Sopenharmony_cidef make_j(arch, cross_compile, knl_path):
2373298bea7Sopenharmony_ci    make = f'make -j{os.cpu_count()} ARCH={arch} CROSS_COMPILE={cross_compile}'
2383298bea7Sopenharmony_ci    outmsg, errmsg, ret = exec_cmd(make, cwd=knl_path)
2393298bea7Sopenharmony_ci    if ret:
2403298bea7Sopenharmony_ci        print(f'"{make}" errors --> \n {errmsg}')
2413298bea7Sopenharmony_ci        return ret, f'"{make}" errors --> \n {errmsg}'
2423298bea7Sopenharmony_ci    elif len(errmsg) > 0:
2433298bea7Sopenharmony_ci        print(f'"{make}" warnings --> \n {errmsg}')
2443298bea7Sopenharmony_ci        result = "success"
2453298bea7Sopenharmony_ci        reporter = Reporter(arch, knl_path)
2463298bea7Sopenharmony_ci        known_issue = "\nKnown issue:\n"
2473298bea7Sopenharmony_ci        for report in reporter.parse(errmsg):
2483298bea7Sopenharmony_ci            if ignores and [i for i in ignores if re.match(i, report['title'])]:
2493298bea7Sopenharmony_ci                known_issue = known_issue + report['title'] + "\n"
2503298bea7Sopenharmony_ci                known_issue = known_issue + report['report'] + "\n"
2513298bea7Sopenharmony_ci                continue
2523298bea7Sopenharmony_ci            result = 'failed'
2533298bea7Sopenharmony_ci
2543298bea7Sopenharmony_ci        print(known_issue)
2553298bea7Sopenharmony_ci        new_issue = "\nNew Issue:\n"
2563298bea7Sopenharmony_ci        if result == "failed":
2573298bea7Sopenharmony_ci            for report in reporter.parse(errmsg):
2583298bea7Sopenharmony_ci                if ignores and [i for i in ignores if re.match(i, report['title'])]:
2593298bea7Sopenharmony_ci                    continue
2603298bea7Sopenharmony_ci                new_issue = new_issue + report['title'] + "\n"
2613298bea7Sopenharmony_ci                new_issue = new_issue + report['report'] + "\n"
2623298bea7Sopenharmony_ci            print(new_issue)
2633298bea7Sopenharmony_ci            return 2, f'"{make}" warning --> \n {new_issue}'
2643298bea7Sopenharmony_ci
2653298bea7Sopenharmony_ci        return ret, f'"{make}" warnings in ignores --> \n {known_issue}'
2663298bea7Sopenharmony_ci
2673298bea7Sopenharmony_ci    return ret, f'"{make}" success!'
2683298bea7Sopenharmony_ci
2693298bea7Sopenharmony_ci
2703298bea7Sopenharmony_cidef cp_config(arch, config, config_path, knl_path):
2713298bea7Sopenharmony_ci    if os.path.exists(config_path.format(arch, config)):
2723298bea7Sopenharmony_ci        cp = f'cp ' + config_path.format(arch, config) + ' ' + os.path.join(knl_path, 'arch', arch, 'configs', config)
2733298bea7Sopenharmony_ci        outmsg, errmsg, ret = exec_cmd(cp)
2743298bea7Sopenharmony_ci        if ret:
2753298bea7Sopenharmony_ci            print(f'"{cp}" errors --> \n {errmsg}')
2763298bea7Sopenharmony_ci            return ret, f'"{cp}" errors --> \n {errmsg}'
2773298bea7Sopenharmony_ci    else:
2783298bea7Sopenharmony_ci        print(f'"{config_path.format(arch, config)}" not exists!')
2793298bea7Sopenharmony_ci        return ret, f'"{config_path.format(arch, config)}" not exists!'
2803298bea7Sopenharmony_ci
2813298bea7Sopenharmony_ci    return ret, f'"{cp}" success!'
2823298bea7Sopenharmony_ci
2833298bea7Sopenharmony_ci
2843298bea7Sopenharmony_cidef get_logger(filename):
2853298bea7Sopenharmony_ci    log_format = '%(asctime)s %(name)s %(levelname)s %(message)s'
2863298bea7Sopenharmony_ci    log_date_format = '%Y-%m-%d %H:%M:%S'
2873298bea7Sopenharmony_ci    logging.basicConfig(
2883298bea7Sopenharmony_ci        level=logging.INFO,
2893298bea7Sopenharmony_ci        filename=filename,
2903298bea7Sopenharmony_ci        format=log_format,
2913298bea7Sopenharmony_ci        datefmt=log_date_format
2923298bea7Sopenharmony_ci    )
2933298bea7Sopenharmony_ci    logger = logging.getLogger(__name__)
2943298bea7Sopenharmony_ci    return logger
2953298bea7Sopenharmony_ci
2963298bea7Sopenharmony_ci
2973298bea7Sopenharmony_cidef build(arch, config, config_path, cross_compile, knl_path, logger):
2983298bea7Sopenharmony_ci    ret, msg = make_cmd('make defconfig', arch, cross_compile, knl_path)
2993298bea7Sopenharmony_ci    if ret:
3003298bea7Sopenharmony_ci        logger.error(msg)
3013298bea7Sopenharmony_ci        return ret, msg
3023298bea7Sopenharmony_ci
3033298bea7Sopenharmony_ci    ret, msg = make_cmd('make oldconfig', arch, cross_compile, knl_path)
3043298bea7Sopenharmony_ci    if ret:
3053298bea7Sopenharmony_ci        logger.error(msg)
3063298bea7Sopenharmony_ci        return ret, msg
3073298bea7Sopenharmony_ci
3083298bea7Sopenharmony_ci    ret, msg = make_cmd('make clean', arch, cross_compile, knl_path)
3093298bea7Sopenharmony_ci    if ret:
3103298bea7Sopenharmony_ci        logger.error(msg)
3113298bea7Sopenharmony_ci        return ret, msg
3123298bea7Sopenharmony_ci
3133298bea7Sopenharmony_ci    ret, msg = make_j(arch, cross_compile, knl_path)
3143298bea7Sopenharmony_ci    if ret:
3153298bea7Sopenharmony_ci        logger.error(msg)
3163298bea7Sopenharmony_ci        return ret, msg
3173298bea7Sopenharmony_ci
3183298bea7Sopenharmony_ci    ret, msg = cp_config(arch, config, config_path, knl_path)
3193298bea7Sopenharmony_ci    if ret:
3203298bea7Sopenharmony_ci        logger.error(msg)
3213298bea7Sopenharmony_ci        return ret, msg
3223298bea7Sopenharmony_ci    else:
3233298bea7Sopenharmony_ci        ret, msg = make_config(arch, config, cross_compile, knl_path)
3243298bea7Sopenharmony_ci        if ret:
3253298bea7Sopenharmony_ci            logger.error(msg)
3263298bea7Sopenharmony_ci            return ret, msg
3273298bea7Sopenharmony_ci
3283298bea7Sopenharmony_ci        ret, msg = make_cmd('make clean', arch, cross_compile, knl_path)
3293298bea7Sopenharmony_ci        if ret:
3303298bea7Sopenharmony_ci            logger.error(msg)
3313298bea7Sopenharmony_ci            return ret, msg
3323298bea7Sopenharmony_ci
3333298bea7Sopenharmony_ci        ret, msg = make_j(arch, cross_compile, knl_path)
3343298bea7Sopenharmony_ci        if ret:
3353298bea7Sopenharmony_ci            logger.error(msg)
3363298bea7Sopenharmony_ci            return ret, msg
3373298bea7Sopenharmony_ci
3383298bea7Sopenharmony_ci    ret, msg = make_cmd('make allmodconfig', arch, cross_compile, knl_path)
3393298bea7Sopenharmony_ci    if ret:
3403298bea7Sopenharmony_ci        logger.error(msg)
3413298bea7Sopenharmony_ci        return ret, msg
3423298bea7Sopenharmony_ci
3433298bea7Sopenharmony_ci    sed = f'sed -i s/^.*CONFIG_FRAME_WARN.*$/CONFIG_FRAME_WARN=2048/ .config'
3443298bea7Sopenharmony_ci    outmsg, errmsg, ret = exec_cmd(sed, cwd=knl_path)
3453298bea7Sopenharmony_ci
3463298bea7Sopenharmony_ci    ret, msg = make_cmd('make clean', arch, cross_compile, knl_path)
3473298bea7Sopenharmony_ci    if ret:
3483298bea7Sopenharmony_ci        logger.error(msg)
3493298bea7Sopenharmony_ci        return ret, msg
3503298bea7Sopenharmony_ci
3513298bea7Sopenharmony_ci    ret, msg = make_j(arch, cross_compile, knl_path)
3523298bea7Sopenharmony_ci    if ret:
3533298bea7Sopenharmony_ci        logger.error(msg)
3543298bea7Sopenharmony_ci        return ret, msg
3553298bea7Sopenharmony_ci
3563298bea7Sopenharmony_ci    return 0, f'build success!'
3573298bea7Sopenharmony_ci
3583298bea7Sopenharmony_ci
3593298bea7Sopenharmony_cidef main():
3603298bea7Sopenharmony_ci    config_path = './kernel/linux/config/linux-5.10/arch/{0}/configs/{1}'
3613298bea7Sopenharmony_ci    knl_path = './kernel/linux/linux-5.10'
3623298bea7Sopenharmony_ci    log_path = os.getcwd()
3633298bea7Sopenharmony_ci    now_date = time.strftime("%Y%m%d%H%M%S", time.localtime())
3643298bea7Sopenharmony_ci    log_file = os.path.join(log_path, 'kernel_build_test.log')
3653298bea7Sopenharmony_ci    logger = get_logger(log_file)
3663298bea7Sopenharmony_ci
3673298bea7Sopenharmony_ci    arch = 'arm'
3683298bea7Sopenharmony_ci    config = 'hispark_taurus_standard_defconfig'
3693298bea7Sopenharmony_ci    cross_compile = '../../../prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/bin/arm-linux-gnueabi-'
3703298bea7Sopenharmony_ci    arm_ret, arm_msg = build(arch, config, config_path, cross_compile, knl_path, logger)
3713298bea7Sopenharmony_ci
3723298bea7Sopenharmony_ci    arch = 'arm64'
3733298bea7Sopenharmony_ci    config = 'rk3568_standard_defconfig'
3743298bea7Sopenharmony_ci    cross_compile = '../../../prebuilts/gcc/linux-x86/aarch64/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-'
3753298bea7Sopenharmony_ci    arm64_ret, arm64_msg = build(arch, config, config_path, cross_compile, knl_path, logger)
3763298bea7Sopenharmony_ci
3773298bea7Sopenharmony_ci    print(f'arm_ret: {arm_ret}, arm64_ret: {arm64_ret}')
3783298bea7Sopenharmony_ci    if any([arm_ret, arm64_ret]):
3793298bea7Sopenharmony_ci        print('kernel build test failed!')
3803298bea7Sopenharmony_ci        exit(arm_ret or arm64_ret)
3813298bea7Sopenharmony_ci
3823298bea7Sopenharmony_ci    print('kernel build test success.')
3833298bea7Sopenharmony_ci    exit(0)
3843298bea7Sopenharmony_ci
3853298bea7Sopenharmony_ci
3863298bea7Sopenharmony_ciif __name__ == "__main__":
3873298bea7Sopenharmony_ci    main()
388