• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright 2019 The Chromium OS Authors. All rights reserved.
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
9from __future__ import print_function
10
11import io
12import unittest
13
14from afdo_redaction import remove_indirect_calls
15
16
17def _run_test(input_lines):
18  input_buf = io.StringIO('\n'.join(input_lines))
19  output_buf = io.StringIO()
20  remove_indirect_calls.run(input_buf, output_buf)
21  return output_buf.getvalue().splitlines()
22
23
24class Test(unittest.TestCase):
25  """Tests"""
26
27  def test_empty_profile(self):
28    self.assertEqual(_run_test([]), [])
29
30  def test_removal_on_real_world_code(self):
31    # These are copied from an actual textual AFDO profile, but the names made
32    # lints unhappy due to their length, so I had to be creative.
33    profile_lines = """_ZLongSymbolName:52862:1766
34 14: 2483
35 8.1: _SomeInlinedSym:45413
36  11: _AndAnother:35481
37   2: 2483
38   2.1: _YetAnother:25549
39    3: 2483
40    3.1: 351
41    3.3: 2526 IndirectTarg1:675 Targ2:397 Targ3:77
42  13.2: Whee:9932
43   1.1: Whoo:9932
44    0: BleepBloop:9932
45     0: 2483
46  """.strip().splitlines()
47
48    expected_lines = """_ZLongSymbolName:52862:1766
49 14: 2483
50 8.1: _SomeInlinedSym:45413
51  11: _AndAnother:35481
52   2: 2483
53   2.1: _YetAnother:25549
54    3: 2483
55    3.1: 351
56    3.3: 2526
57  13.2: Whee:9932
58   1.1: Whoo:9932
59    0: BleepBloop:9932
60     0: 2483
61  """.strip().splitlines()
62
63    self.assertEqual(_run_test(profile_lines), expected_lines)
64
65
66if __name__ == '__main__':
67  unittest.main()
68