• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.error_message import ErrorMessage
22from devicetest.core.exception import TestPrepareError
23from devicetest.core.result_upload import UploadResultHandler
24from devicetest.runner.test_runner import TestRunner
25from devicetest.runner.test_runner import TestSuiteRunner
26
27
28class DeviceTest:
29
30    def __init__(self, test_list, configs, devices, log, result_file):
31
32        self.test_list = test_list or []
33        self.configs = configs or {}
34        self.devices = devices or []
35        self.log = log
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(self.test_list, self.configs,
43                                             self.devices, self.log,
44                                             self.upload_result_handler)
45            self.upload_result_handler.set_test_runner(self.log, test_runner)
46            test_runner.run()
47
48        except TestPrepareError as err:
49            self.log.error(err)
50
51        except Exception as err:
52            self.log.debug(traceback.format_exc())
53            self.log.error(ErrorMessage.Error_01434.Message.en)
54            self.log.error(err)
55        finally:
56            self.upload_result_handler.upload_suitereporter()
57
58
59class DeviceTestSuite:
60    def __init__(self, test_list=None, configs=None, devices=None, log=None):
61
62        self.test_list = test_list or []
63        self.configs = configs or {}
64        self.devices = devices or []
65        self.log = log
66
67    def run(self):
68        try:
69            test_runner = TestSuiteRunner(self.test_list, self.configs,
70                                          self.devices, self.log)
71            test_runner.run()
72
73        except Exception as err:
74            self.log.debug(traceback.format_exc())
75            self.log.error("Failed to instantiate the test runner.")
76            self.log.error(err)
77