13af6ab5fSopenharmony_ci#!/usr/bin/env python3
23af6ab5fSopenharmony_ci# coding: utf-8
33af6ab5fSopenharmony_ci
43af6ab5fSopenharmony_ci"""
53af6ab5fSopenharmony_ciCopyright (c) 2023 Huawei Device Co., Ltd.
63af6ab5fSopenharmony_ciLicensed under the Apache License, Version 2.0 (the "License");
73af6ab5fSopenharmony_ciyou may not use this file except in compliance with the License.
83af6ab5fSopenharmony_ciYou may obtain a copy of the License at
93af6ab5fSopenharmony_ci
103af6ab5fSopenharmony_ci    http://www.apache.org/licenses/LICENSE-2.0
113af6ab5fSopenharmony_ci
123af6ab5fSopenharmony_ciUnless required by applicable law or agreed to in writing, software
133af6ab5fSopenharmony_cidistributed under the License is distributed on an "AS IS" BASIS,
143af6ab5fSopenharmony_ciWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
153af6ab5fSopenharmony_ciSee the License for the specific language governing permissions and
163af6ab5fSopenharmony_cilimitations under the License.
173af6ab5fSopenharmony_ci
183af6ab5fSopenharmony_ciDescription: entrance to run sdk test suite
193af6ab5fSopenharmony_ci"""
203af6ab5fSopenharmony_ci
213af6ab5fSopenharmony_ciimport logging
223af6ab5fSopenharmony_ciimport os
233af6ab5fSopenharmony_ciimport sys
243af6ab5fSopenharmony_ciimport time
253af6ab5fSopenharmony_ci
263af6ab5fSopenharmony_cifrom execution import execute
273af6ab5fSopenharmony_cifrom options import process_options
283af6ab5fSopenharmony_cifrom preparation import prepare_test_env
293af6ab5fSopenharmony_cifrom result import process_test_result
303af6ab5fSopenharmony_ci
313af6ab5fSopenharmony_ci
323af6ab5fSopenharmony_cidef run():
333af6ab5fSopenharmony_ci    old_env = os.environ.copy()
343af6ab5fSopenharmony_ci    try:
353af6ab5fSopenharmony_ci        start_time = time.time()
363af6ab5fSopenharmony_ci        test_tasks = process_options()
373af6ab5fSopenharmony_ci        if not test_tasks:
383af6ab5fSopenharmony_ci            logging.error("No test task found, test suite exit!")
393af6ab5fSopenharmony_ci            sys.exit(1)
403af6ab5fSopenharmony_ci
413af6ab5fSopenharmony_ci        if not prepare_test_env():
423af6ab5fSopenharmony_ci            logging.error("Prepare test environment failed, test suite exit!")
433af6ab5fSopenharmony_ci            sys.exit(1)
443af6ab5fSopenharmony_ci
453af6ab5fSopenharmony_ci        execute(test_tasks)
463af6ab5fSopenharmony_ci        process_test_result(test_tasks, start_time)
473af6ab5fSopenharmony_ci    except Exception as e:
483af6ab5fSopenharmony_ci        logging.exception(e)
493af6ab5fSopenharmony_ci    finally:
503af6ab5fSopenharmony_ci        os.environ.clear()
513af6ab5fSopenharmony_ci        os.environ.update(old_env)
523af6ab5fSopenharmony_ci
533af6ab5fSopenharmony_ci
543af6ab5fSopenharmony_ciif __name__ == '__main__':
553af6ab5fSopenharmony_ci    run()