1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# 5# Copyright (c) 2024 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 importlib 21 22from util import file_exists, make_binary_file, print_failure, print_success, get_subclasses, get_idl 23from test_base import Test 24 25exclude_file = ["test_base.py", "unit_test.py", "util.py"] 26for file_name in os.listdir(os.path.dirname(os.path.abspath(__file__))): 27 if file_name.endswith('.py'): 28 if file_name in exclude_file: 29 continue 30 module_name = file_name[:-3] 31 importlib.import_module(module_name) 32 33 34class Suite: 35 test_cases = get_subclasses(Test) 36 test_objs = list() 37 38 @staticmethod 39 def set_up_test_case(): 40 hdi_gen_file = get_idl() 41 ret = file_exists(hdi_gen_file) 42 if not ret: 43 hdi_gen_path = "../../" 44 if make_binary_file(hdi_gen_path)[0] == 0: 45 ret = True 46 if not ret: 47 print_failure("[===========] failed to make idl-gen") 48 return ret 49 50 @staticmethod 51 def run_suite(): 52 test_case_num = len(Suite.test_cases) 53 success_case_num = 0 54 print_success("[===========] start {} test".format(test_case_num)) 55 for test_case in Suite.test_cases: 56 obj = test_case() 57 Suite.test_objs.append(obj) 58 if obj.test(): 59 success_case_num += 1 60 print_success("[ PASSED ] {} test".format(success_case_num)) 61 failure_case_num = test_case_num - success_case_num 62 if failure_case_num > 0: 63 print_failure("[ FAILED ] {} test".format(failure_case_num)) 64 65 66if __name__ == "__main__": 67 if not Suite.set_up_test_case(): 68 print_failure("test case set up failed!") 69 exit(-1) 70 Suite.run_suite() 71