From 2124be5caee6803d5bfe6f7cdc8e3367cb375807 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Thu, 21 Apr 2022 10:27:37 -0700 Subject: toolchain_utils: s/Cr OS/CrOS/g Result of running `sed -ri 's/Chrom(ium|e) OS/Chrom\1OS/g' $(find -type f)`. BUG=None TEST=None Change-Id: I59be92537aa19bc989f52b585e307e76dbde401b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3600147 Reviewed-by: Manoj Gupta Commit-Queue: George Burgess Tested-by: George Burgess --- afdo_redaction/redact_profile_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'afdo_redaction/redact_profile_test.py') diff --git a/afdo_redaction/redact_profile_test.py b/afdo_redaction/redact_profile_test.py index e2438972..26fda3fd 100755 --- a/afdo_redaction/redact_profile_test.py +++ b/afdo_redaction/redact_profile_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2018 The Chromium OS Authors. All rights reserved. +# Copyright 2018 The ChromiumOS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -- cgit v1.2.3 From 74bd380a27f4f0e8e90ff2dc1cef0b502d74961b Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Fri, 2 Sep 2022 16:59:27 -0700 Subject: Autoformat all Python code This autoformats all Python code with our new Python formatter, `black`. BUG=b:244644217 TEST=None Change-Id: I15ee49233d98fb6295c0c53c129bbf8e78e0d9ff Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3877337 Tested-by: George Burgess Reviewed-by: Jordan Abrahams-Whitehead Commit-Queue: George Burgess --- afdo_redaction/redact_profile_test.py | 225 +++++++++++++++++----------------- 1 file changed, 115 insertions(+), 110 deletions(-) (limited to 'afdo_redaction/redact_profile_test.py') diff --git a/afdo_redaction/redact_profile_test.py b/afdo_redaction/redact_profile_test.py index 26fda3fd..154f8f7e 100755 --- a/afdo_redaction/redact_profile_test.py +++ b/afdo_redaction/redact_profile_test.py @@ -6,131 +6,136 @@ """Tests for redact_profile.py.""" -from __future__ import division, print_function +from __future__ import division +from __future__ import print_function import io import unittest from afdo_redaction import redact_profile + _redact_limit = redact_profile.dedup_records.__defaults__[0] def _redact(input_lines, summary_to=None): - if isinstance(input_lines, str): - input_lines = input_lines.splitlines() + if isinstance(input_lines, str): + input_lines = input_lines.splitlines() - if summary_to is None: - summary_to = io.StringIO() + if summary_to is None: + summary_to = io.StringIO() - output_to = io.StringIO() - redact_profile.run( - profile_input_file=input_lines, - summary_output_file=summary_to, - profile_output_file=output_to) - return output_to.getvalue() + output_to = io.StringIO() + redact_profile.run( + profile_input_file=input_lines, + summary_output_file=summary_to, + profile_output_file=output_to, + ) + return output_to.getvalue() def _redact_with_summary(input_lines): - summary = io.StringIO() - result = _redact(input_lines, summary_to=summary) - return result, summary.getvalue() - - -def _generate_repeated_function_body(repeats, fn_name='_some_name'): - # Arbitrary function body ripped from a textual AFDO profile. - function_header = fn_name + ':1234:185' - function_body = [ - ' 6: 83', - ' 15: 126', - ' 62832: 126', - ' 6: _ZNK5blink10PaintLayer14GroupedMappingEv:2349', - ' 1: 206', - ' 1: _ZNK5blink10PaintLayer14GroupedMappersEv:2060', - ' 1: 206', - ' 11: _ZNK5blink10PaintLayer25GetCompositedLayerMappingEv:800', - ' 2.1: 80', - ] - - # Be sure to zfill this, so the functions are output in sorted order. - num_width = len(str(repeats)) - - lines = [] - for i in range(repeats): - num = str(i).zfill(num_width) - lines.append(num + function_header) - lines.extend(function_body) - return lines + summary = io.StringIO() + result = _redact(input_lines, summary_to=summary) + return result, summary.getvalue() + + +def _generate_repeated_function_body(repeats, fn_name="_some_name"): + # Arbitrary function body ripped from a textual AFDO profile. + function_header = fn_name + ":1234:185" + function_body = [ + " 6: 83", + " 15: 126", + " 62832: 126", + " 6: _ZNK5blink10PaintLayer14GroupedMappingEv:2349", + " 1: 206", + " 1: _ZNK5blink10PaintLayer14GroupedMappersEv:2060", + " 1: 206", + " 11: _ZNK5blink10PaintLayer25GetCompositedLayerMappingEv:800", + " 2.1: 80", + ] + + # Be sure to zfill this, so the functions are output in sorted order. + num_width = len(str(repeats)) + + lines = [] + for i in range(repeats): + num = str(i).zfill(num_width) + lines.append(num + function_header) + lines.extend(function_body) + return lines class Tests(unittest.TestCase): - """All of our tests for redact_profile.""" - - def test_no_input_works(self): - self.assertEqual(_redact(''), '') - - def test_single_function_works(self): - lines = _generate_repeated_function_body(1) - result_file = '\n'.join(lines) + '\n' - self.assertEqual(_redact(lines), result_file) - - def test_duplicate_of_single_function_works(self): - lines = _generate_repeated_function_body(2) - result_file = '\n'.join(lines) + '\n' - self.assertEqual(_redact(lines), result_file) - - def test_not_too_many_duplicates_of_single_function_redacts_none(self): - lines = _generate_repeated_function_body(_redact_limit - 1) - result_file = '\n'.join(lines) + '\n' - self.assertEqual(_redact(lines), result_file) - - def test_many_duplicates_of_single_function_redacts_them_all(self): - lines = _generate_repeated_function_body(_redact_limit) - self.assertEqual(_redact(lines), '') - - def test_many_duplicates_of_single_function_leaves_other_functions(self): - kept_lines = _generate_repeated_function_body(1, fn_name='_keep_me') - # Something to distinguish us from the rest. Just bump a random counter. - kept_lines[1] += '1' - - result_file = '\n'.join(kept_lines) + '\n' - - lines = _generate_repeated_function_body( - _redact_limit, fn_name='_discard_me') - self.assertEqual(_redact(kept_lines + lines), result_file) - self.assertEqual(_redact(lines + kept_lines), result_file) - - more_lines = _generate_repeated_function_body( - _redact_limit, fn_name='_and_discard_me') - self.assertEqual(_redact(lines + kept_lines + more_lines), result_file) - self.assertEqual(_redact(lines + more_lines), '') - - def test_correct_summary_is_printed_when_nothing_is_redacted(self): - lines = _generate_repeated_function_body(1) - _, summary = _redact_with_summary(lines) - self.assertIn('Retained 1/1 functions', summary) - self.assertIn('Retained 827/827 samples, total', summary) - # Note that top-level samples == "samples without inlining taken into - # account," not "sum(entry_counts)" - self.assertIn('Retained 335/335 top-level samples', summary) - - def test_correct_summary_is_printed_when_everything_is_redacted(self): - lines = _generate_repeated_function_body(_redact_limit) - _, summary = _redact_with_summary(lines) - self.assertIn('Retained 0/100 functions', summary) - self.assertIn('Retained 0/82,700 samples, total', summary) - self.assertIn('Retained 0/33,500 top-level samples', summary) - - def test_correct_summary_is_printed_when_most_everything_is_redacted(self): - kept_lines = _generate_repeated_function_body(1, fn_name='_keep_me') - kept_lines[1] += '1' - - lines = _generate_repeated_function_body(_redact_limit) - _, summary = _redact_with_summary(kept_lines + lines) - self.assertIn('Retained 1/101 functions', summary) - self.assertIn('Retained 1,575/84,275 samples, total', summary) - self.assertIn('Retained 1,083/34,583 top-level samples', summary) - - -if __name__ == '__main__': - unittest.main() + """All of our tests for redact_profile.""" + + def test_no_input_works(self): + self.assertEqual(_redact(""), "") + + def test_single_function_works(self): + lines = _generate_repeated_function_body(1) + result_file = "\n".join(lines) + "\n" + self.assertEqual(_redact(lines), result_file) + + def test_duplicate_of_single_function_works(self): + lines = _generate_repeated_function_body(2) + result_file = "\n".join(lines) + "\n" + self.assertEqual(_redact(lines), result_file) + + def test_not_too_many_duplicates_of_single_function_redacts_none(self): + lines = _generate_repeated_function_body(_redact_limit - 1) + result_file = "\n".join(lines) + "\n" + self.assertEqual(_redact(lines), result_file) + + def test_many_duplicates_of_single_function_redacts_them_all(self): + lines = _generate_repeated_function_body(_redact_limit) + self.assertEqual(_redact(lines), "") + + def test_many_duplicates_of_single_function_leaves_other_functions(self): + kept_lines = _generate_repeated_function_body(1, fn_name="_keep_me") + # Something to distinguish us from the rest. Just bump a random counter. + kept_lines[1] += "1" + + result_file = "\n".join(kept_lines) + "\n" + + lines = _generate_repeated_function_body( + _redact_limit, fn_name="_discard_me" + ) + self.assertEqual(_redact(kept_lines + lines), result_file) + self.assertEqual(_redact(lines + kept_lines), result_file) + + more_lines = _generate_repeated_function_body( + _redact_limit, fn_name="_and_discard_me" + ) + self.assertEqual(_redact(lines + kept_lines + more_lines), result_file) + self.assertEqual(_redact(lines + more_lines), "") + + def test_correct_summary_is_printed_when_nothing_is_redacted(self): + lines = _generate_repeated_function_body(1) + _, summary = _redact_with_summary(lines) + self.assertIn("Retained 1/1 functions", summary) + self.assertIn("Retained 827/827 samples, total", summary) + # Note that top-level samples == "samples without inlining taken into + # account," not "sum(entry_counts)" + self.assertIn("Retained 335/335 top-level samples", summary) + + def test_correct_summary_is_printed_when_everything_is_redacted(self): + lines = _generate_repeated_function_body(_redact_limit) + _, summary = _redact_with_summary(lines) + self.assertIn("Retained 0/100 functions", summary) + self.assertIn("Retained 0/82,700 samples, total", summary) + self.assertIn("Retained 0/33,500 top-level samples", summary) + + def test_correct_summary_is_printed_when_most_everything_is_redacted(self): + kept_lines = _generate_repeated_function_body(1, fn_name="_keep_me") + kept_lines[1] += "1" + + lines = _generate_repeated_function_body(_redact_limit) + _, summary = _redact_with_summary(kept_lines + lines) + self.assertIn("Retained 1/101 functions", summary) + self.assertIn("Retained 1,575/84,275 samples, total", summary) + self.assertIn("Retained 1,083/34,583 top-level samples", summary) + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3 From c0041a9550814e402f661a560855ff99863cffb2 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Tue, 6 Sep 2022 12:12:02 -0700 Subject: remove `from __future__ import ...` directives These are only useful when we're running code in a Python 2.7 interpreter. Since we no longer support python2, drop these. BUG=b:244644217 TEST=run_tests_for.py shows no new failures Change-Id: Ief9a12b87a560ab38ca71668636874bcb434a0b3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3877339 Reviewed-by: Ryan Beltran Commit-Queue: George Burgess Reviewed-by: Jordan Abrahams-Whitehead Tested-by: George Burgess --- afdo_redaction/redact_profile_test.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'afdo_redaction/redact_profile_test.py') diff --git a/afdo_redaction/redact_profile_test.py b/afdo_redaction/redact_profile_test.py index 154f8f7e..487c5091 100755 --- a/afdo_redaction/redact_profile_test.py +++ b/afdo_redaction/redact_profile_test.py @@ -6,8 +6,6 @@ """Tests for redact_profile.py.""" -from __future__ import division -from __future__ import print_function import io import unittest -- cgit v1.2.3 From fdcd39d5de4bd61cee94cf1e26416838d23092b8 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 13 Sep 2022 14:19:58 -0400 Subject: Update license boilerplate text in source code files Normally we don't do this, but enough changes have accumulated that we're doing a tree-wide one-off update of the name & style. BUG=chromium:1098010 TEST=`repo upload` works Change-Id: Icb42e5012a87920c2cd13b666fb3e55e7e4fb3b8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3891080 Auto-Submit: Mike Frysinger Tested-by: Mike Frysinger Commit-Queue: George Burgess Reviewed-by: George Burgess --- afdo_redaction/redact_profile_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'afdo_redaction/redact_profile_test.py') diff --git a/afdo_redaction/redact_profile_test.py b/afdo_redaction/redact_profile_test.py index 487c5091..93c65510 100755 --- a/afdo_redaction/redact_profile_test.py +++ b/afdo_redaction/redact_profile_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2018 The ChromiumOS Authors. All rights reserved. +# Copyright 2018 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -- cgit v1.2.3