1# 2# Copyright (C) 2024 The Android Open Source Project 3# 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# 16 17import unittest 18import subprocess 19import os 20from unittest import mock 21from src.device import AdbDevice 22from src.utils import convert_simpleperf_to_gecko 23 24 25class UtilsUnitTest(unittest.TestCase): 26 27 @mock.patch.object(subprocess, "run", autospec=True) 28 @mock.patch.object(os.path, "exists", autospec=True) 29 def test_convert_simpleperf_to_gecko_success(self, mock_exists, 30 mock_subprocess_run): 31 mock_exists.return_value = True 32 mock_subprocess_run.return_value = None 33 34 # No exception is expected to be thrown 35 convert_simpleperf_to_gecko("/scripts", "/path/file.data", 36 "/path/file.json", "/symbols") 37 38 @mock.patch.object(subprocess, "run", autospec=True) 39 @mock.patch.object(os.path, "exists", autospec=True) 40 def test_convert_simpleperf_to_gecko_failure(self, mock_exists, 41 mock_subprocess_run): 42 mock_exists.return_value = False 43 mock_subprocess_run.return_value = None 44 45 with self.assertRaises(Exception) as e: 46 convert_simpleperf_to_gecko("/scripts", "/path/file.data", 47 "/path/file.json", "/symbols") 48 49 self.assertEqual(str(e.exception), "Gecko file was not created.") 50 51 52if __name__ == '__main__': 53 unittest.main() 54