148f512ceSopenharmony_ci#!/usr/bin/env python 248f512ceSopenharmony_ci# -*- coding: utf-8 -*- 348f512ceSopenharmony_ci# Copyright (c) 2021 Huawei Device Co., Ltd. 448f512ceSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 548f512ceSopenharmony_ci# you may not use this file except in compliance with the License. 648f512ceSopenharmony_ci# You may obtain a copy of the License at 748f512ceSopenharmony_ci# 848f512ceSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 948f512ceSopenharmony_ci# 1048f512ceSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 1148f512ceSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 1248f512ceSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1348f512ceSopenharmony_ci# See the License for the specific language governing permissions and 1448f512ceSopenharmony_ci# limitations under the License. 1548f512ceSopenharmony_ci 1648f512ceSopenharmony_ciimport os 1748f512ceSopenharmony_ciimport unittest 1848f512ceSopenharmony_ciimport argparse 1948f512ceSopenharmony_cifrom command_script import HostElfEntry 2048f512ceSopenharmony_cifrom command_script import parser_add_argument 2148f512ceSopenharmony_cifrom command_script import check_args 2248f512ceSopenharmony_cifrom command_script import main 2348f512ceSopenharmony_ci 2448f512ceSopenharmony_ci 2548f512ceSopenharmony_cidef fake_parser(): 2648f512ceSopenharmony_ci parser = argparse.ArgumentParser() 2748f512ceSopenharmony_ci parser.add_argument('-p', '--pid') 2848f512ceSopenharmony_ci parser.add_argument('-app', '--package_name') 2948f512ceSopenharmony_ci parser.add_argument('-l', '--local_program') 3048f512ceSopenharmony_ci parser.add_argument('-c', '--cmd') 3148f512ceSopenharmony_ci parser.add_argument('-t', '--tid') 3248f512ceSopenharmony_ci parser.add_argument('-sw', '--system_wide', action='store_true') 3348f512ceSopenharmony_ci parser.add_argument('-a', '--activity') 3448f512ceSopenharmony_ci parser.add_argument('-n', '--not_hdc_root') 3548f512ceSopenharmony_ci parser.add_argument('-lib', '--local_lib_dir') 3648f512ceSopenharmony_ci parser.add_argument('-r', '--record_options', default='-d 1') 3748f512ceSopenharmony_ci parser.add_argument('-o', '--output_perf_data', default='perf.data') 3848f512ceSopenharmony_ci return parser 3948f512ceSopenharmony_ci 4048f512ceSopenharmony_ci 4148f512ceSopenharmony_ciclass TestCommandScript(unittest.TestCase): 4248f512ceSopenharmony_ci 4348f512ceSopenharmony_ci def setUp(self): 4448f512ceSopenharmony_ci print("set up") 4548f512ceSopenharmony_ci 4648f512ceSopenharmony_ci def tearDown(self): 4748f512ceSopenharmony_ci print("tear down") 4848f512ceSopenharmony_ci 4948f512ceSopenharmony_ci def test_host_elf_entry(self): 5048f512ceSopenharmony_ci result = HostElfEntry('test_path', 'test_lib_name').__str__() 5148f512ceSopenharmony_ci self.assertEqual(result, '[path: test_path, name test_lib_name,' 5248f512ceSopenharmony_ci ' score test_lib_score]') 5348f512ceSopenharmony_ci 5448f512ceSopenharmony_ci def test_parser_add_argument(self): 5548f512ceSopenharmony_ci self.parser = fake_parser() 5648f512ceSopenharmony_ci args = self.parser.parse_args(['-p', '14']) 5748f512ceSopenharmony_ci result = args.pid 5848f512ceSopenharmony_ci self.assertEqual(result, '14') 5948f512ceSopenharmony_ci 6048f512ceSopenharmony_ci def test_check_args(self): 6148f512ceSopenharmony_ci self.args = parser_add_argument() 6248f512ceSopenharmony_ci result = check_args(self.args) 6348f512ceSopenharmony_ci self.assertEqual(result, True) 6448f512ceSopenharmony_ci 6548f512ceSopenharmony_ci def test_main(self): 6648f512ceSopenharmony_ci self.parser = fake_parser() 6748f512ceSopenharmony_ci args = self.parser.parse_args(['-sw']) 6848f512ceSopenharmony_ci main(args) 6948f512ceSopenharmony_ci if os.path.exists('perf.data'): 7048f512ceSopenharmony_ci result = True 7148f512ceSopenharmony_ci else: 7248f512ceSopenharmony_ci result = False 7348f512ceSopenharmony_ci self.assertEqual(result, True) 7448f512ceSopenharmony_ci 75