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 19from base import file_exists, make_binary_file, print_failure, print_success, get_subclasses, get_idl 20from base import Test 21from hdi_hash_test import __all__ 22import importlib 23 24for module_name in __all__: 25 module = importlib.import_module(f'hdi_hash_test.{module_name}') 26 27 28class Tests: 29 test_cases = get_subclasses(Test) 30 test_objs = list() 31 32 @staticmethod 33 def set_up_test_case(): 34 hdi_gen_file = get_idl() 35 ret = file_exists(hdi_gen_file) 36 if not ret: 37 hdi_gen_path = "../../" 38 if make_binary_file(hdi_gen_path)[0] == 0: 39 ret = True 40 if not ret: 41 print_failure("[===========] failed to make idl-gen") 42 return ret 43 44 @staticmethod 45 def tear_down_test_case(): 46 for case in Tests.test_objs: 47 case.remove_output() 48 49 @staticmethod 50 def test(): 51 test_case_num = len(Tests.test_cases) 52 success_case_num = 0 53 print_success("[===========] start {} test".format(test_case_num)) 54 for test_case in Tests.test_cases: 55 obj = test_case() 56 Tests.test_objs.append(obj) 57 if obj.test(): 58 success_case_num += 1 59 print_success("[ PASSED ] {} test".format(success_case_num)) 60 failure_case_num = test_case_num - success_case_num 61 if failure_case_num > 0: 62 print_failure("[ FAILED ] {} test".format(failure_case_num)) 63 64 65if __name__ == "__main__": 66 if not Tests.set_up_test_case(): 67 print_failure("test case set up failed!") 68 exit(-1) 69 Tests.test() 70 Tests.tear_down_test_case() 71