1#!/usr/bin/env python3 2# coding=utf-8 3 4# 5# Copyright (c) 2022 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 traceback 20 21from devicetest.core.exception import TestPrepareError 22from devicetest.core.result_upload import UploadResultHandler 23from devicetest.error import ErrorMessage 24from devicetest.log.logger import DeviceTestLog as Log 25from devicetest.runner.test_runner import TestRunner 26from devicetest.runner.test_runner import TestSuiteRunner 27 28 29class DeviceTest: 30 31 def __init__(self, test_list, configs, devices, result_file): 32 33 self.test_list = test_list or [] 34 self.configs = configs or {} 35 self.devices = devices or [] 36 self.result_file = result_file 37 self.upload_result_handler = UploadResultHandler(self.result_file) 38 39 def run(self): 40 try: 41 test_runner = TestRunner() 42 test_runner.init_pipeline_runner( 43 self.test_list, self.configs, self.devices, self.upload_result_handler) 44 self.upload_result_handler.set_test_runner(test_runner) 45 test_runner.run() 46 47 except TestPrepareError as err: 48 Log.error(err) 49 50 except Exception as err: 51 Log.error(ErrorMessage.Common.Code_0201017) 52 Log.error(err, exc_info=True) 53 finally: 54 self.upload_result_handler.upload_suitereporter() 55 56 57class DeviceTestSuite: 58 59 def __init__(self, test_list, configs, devices): 60 self.test_list = test_list or [] 61 self.configs = configs or {} 62 self.devices = devices or [] 63 64 def run(self): 65 try: 66 test_runner = TestSuiteRunner(self.test_list, self.configs, self.devices) 67 test_runner.run() 68 69 except Exception as err: 70 Log.debug(traceback.format_exc()) 71 Log.error("Failed to instantiate the test runner.") 72 Log.error(err) 73