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 os 20import unittest 21 22from distributed.common.manager import DeviceManager 23from distributed.distribute.distribute import Distribute 24from distributed.common.common import create_empty_result_file 25 26 27class DbinderTest(unittest.TestCase): 28 def __init__(self, result_path, suits_dir): 29 self.result_path = result_path 30 self.suits_dir = suits_dir 31 32 def setUp(self): 33 print('setUp') 34 35 self.manager = DeviceManager(self.result_path) 36 self.major = self.manager.PHONE1 37 self.angent_list = [self.manager.PHONE2] 38 self.hdc = "hdc" 39 40 def test_distribute(self, major_target_name="", agent_target_name="", options=""): 41 42 major_target_name = major_target_name 43 agent_target_name = agent_target_name 44 45 distribute = Distribute(self.suits_dir, self.major, self.angent_list, self.hdc) 46 47 for agent in self.angent_list: 48 if not distribute.exec_agent(agent, agent_target_name, self.result_path, options): 49 print(agent, agent_target_name) 50 create_empty_result_file(self.result_path, major_target_name) 51 return 52 distribute.exec_major(self.major, major_target_name, self.result_path, options) 53 54 result = os.path.join(self.result_path, 'result', 55 self.suits_dir.split("distributedtest")[1].strip(os.sep)) 56 source_path = "%s/%s.xml" % (self.major.test_path, major_target_name) 57 if not os.path.exists(result): 58 os.makedirs(result) 59 distribute.pull_result(self.major, source_path, result) 60 61 def tearDown(self): 62 print('tearDown') 63 64