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_cifrom hiperf_utils import get_lib 1948f512ceSopenharmony_cifrom hiperf_utils import remove 2048f512ceSopenharmony_cifrom hiperf_utils import is_elf_file 2148f512ceSopenharmony_cifrom hiperf_utils import get_hiperf_binary_path 2248f512ceSopenharmony_cifrom hiperf_utils import str_to_bytes 2348f512ceSopenharmony_cifrom hiperf_utils import bytes_to_str 2448f512ceSopenharmony_cifrom hiperf_utils import executable_file_available 2548f512ceSopenharmony_cifrom hiperf_utils import find_tool_path 2648f512ceSopenharmony_ci 2748f512ceSopenharmony_ci 2848f512ceSopenharmony_ciclass TestUtils(unittest.TestCase): 2948f512ceSopenharmony_ci 3048f512ceSopenharmony_ci def setUp(self): 3148f512ceSopenharmony_ci print("set up") 3248f512ceSopenharmony_ci 3348f512ceSopenharmony_ci def tearDown(self): 3448f512ceSopenharmony_ci print("tear down") 3548f512ceSopenharmony_ci 3648f512ceSopenharmony_ci def test_get_lib(self): 3748f512ceSopenharmony_ci lib = get_lib() 3848f512ceSopenharmony_ci result = True if lib else False 3948f512ceSopenharmony_ci self.assertEqual(result, True) 4048f512ceSopenharmony_ci 4148f512ceSopenharmony_ci def test_is_elf_file(self): 4248f512ceSopenharmony_ci result = is_elf_file('libhiperf_report.z.so') 4348f512ceSopenharmony_ci self.assertEqual(result, True) 4448f512ceSopenharmony_ci 4548f512ceSopenharmony_ci def test_remove(self): 4648f512ceSopenharmony_ci os.mkdir('remove_test') 4748f512ceSopenharmony_ci remove('remove_test') 4848f512ceSopenharmony_ci result = True if not os.path.exists('remove_test') else False 4948f512ceSopenharmony_ci self.assertEqual(result, True) 5048f512ceSopenharmony_ci 5148f512ceSopenharmony_ci def test_get_hiperf_binary_path(self): 5248f512ceSopenharmony_ci result = get_hiperf_binary_path('arm', 'hiperf') 5348f512ceSopenharmony_ci print(result) 5448f512ceSopenharmony_ci self.assertEqual(result, 'D:\\tool_third\perf_data\\' 5548f512ceSopenharmony_ci 'new_report\OHOS\\arm\hiperf') 5648f512ceSopenharmony_ci 5748f512ceSopenharmony_ci def test_str_to_bytes(self): 5848f512ceSopenharmony_ci result = str_to_bytes('test') 5948f512ceSopenharmony_ci self.assertEqual(result, b'test') 6048f512ceSopenharmony_ci 6148f512ceSopenharmony_ci def test_bytes_to_str(self): 6248f512ceSopenharmony_ci result = bytes_to_str(b'test') 6348f512ceSopenharmony_ci self.assertEqual(result, 'test') 6448f512ceSopenharmony_ci 6548f512ceSopenharmony_ci def test_executable_file_available(self): 6648f512ceSopenharmony_ci result = executable_file_available('hdc') 6748f512ceSopenharmony_ci self.assertEqual(result, True) 6848f512ceSopenharmony_ci 6948f512ceSopenharmony_ci def test_find_tool_path(self): 7048f512ceSopenharmony_ci result = find_tool_path('hdc') 7148f512ceSopenharmony_ci self.assertEqual(result, 'hdc') 72