1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2021 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import os 17import unittest 18from hiperf_utils import get_lib 19from hiperf_utils import remove 20from hiperf_utils import is_elf_file 21from hiperf_utils import get_hiperf_binary_path 22from hiperf_utils import str_to_bytes 23from hiperf_utils import bytes_to_str 24from hiperf_utils import executable_file_available 25from hiperf_utils import find_tool_path 26 27 28class TestUtils(unittest.TestCase): 29 30 def setUp(self): 31 print("set up") 32 33 def tearDown(self): 34 print("tear down") 35 36 def test_get_lib(self): 37 lib = get_lib() 38 result = True if lib else False 39 self.assertEqual(result, True) 40 41 def test_is_elf_file(self): 42 result = is_elf_file('libhiperf_report.z.so') 43 self.assertEqual(result, True) 44 45 def test_remove(self): 46 os.mkdir('remove_test') 47 remove('remove_test') 48 result = True if not os.path.exists('remove_test') else False 49 self.assertEqual(result, True) 50 51 def test_get_hiperf_binary_path(self): 52 result = get_hiperf_binary_path('arm', 'hiperf') 53 print(result) 54 self.assertEqual(result, 'D:\\tool_third\perf_data\\' 55 'new_report\OHOS\\arm\hiperf') 56 57 def test_str_to_bytes(self): 58 result = str_to_bytes('test') 59 self.assertEqual(result, b'test') 60 61 def test_bytes_to_str(self): 62 result = bytes_to_str(b'test') 63 self.assertEqual(result, 'test') 64 65 def test_executable_file_available(self): 66 result = executable_file_available('hdc') 67 self.assertEqual(result, True) 68 69 def test_find_tool_path(self): 70 result = find_tool_path('hdc') 71 self.assertEqual(result, 'hdc') 72