1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright 2019 The ChromiumOS Authors 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7"""Tests for remove_indirect_calls""" 8 9 10import io 11import unittest 12 13from afdo_redaction import remove_indirect_calls 14 15 16def _run_test(input_lines): 17 input_buf = io.StringIO("\n".join(input_lines)) 18 output_buf = io.StringIO() 19 remove_indirect_calls.run(input_buf, output_buf) 20 return output_buf.getvalue().splitlines() 21 22 23class Test(unittest.TestCase): 24 """Tests""" 25 26 def test_empty_profile(self): 27 self.assertEqual(_run_test([]), []) 28 29 def test_removal_on_real_world_code(self): 30 # These are copied from an actual textual AFDO profile, but the names made 31 # lints unhappy due to their length, so I had to be creative. 32 profile_lines = """_ZLongSymbolName:52862:1766 33 14: 2483 34 8.1: _SomeInlinedSym:45413 35 11: _AndAnother:35481 36 2: 2483 37 2.1: _YetAnother:25549 38 3: 2483 39 3.1: 351 40 3.3: 2526 IndirectTarg1:675 Targ2:397 Targ3:77 41 13.2: Whee:9932 42 1.1: Whoo:9932 43 0: BleepBloop:9932 44 0: 2483 45 """.strip().splitlines() 46 47 expected_lines = """_ZLongSymbolName:52862:1766 48 14: 2483 49 8.1: _SomeInlinedSym:45413 50 11: _AndAnother:35481 51 2: 2483 52 2.1: _YetAnother:25549 53 3: 2483 54 3.1: 351 55 3.3: 2526 56 13.2: Whee:9932 57 1.1: Whoo:9932 58 0: BleepBloop:9932 59 0: 2483 60 """.strip().splitlines() 61 62 self.assertEqual(_run_test(profile_lines), expected_lines) 63 64 65if __name__ == "__main__": 66 unittest.main() 67