Skip to content

Commit

Permalink
Reland "Add presubmit to add PERFETTO_TESTS to cl description"
Browse files Browse the repository at this point in the history
This is a reland of commit 73fabae

The change was originally reverted due to 1473397. The fix is to replace PresubmitError with PresubmitNotifyResult.

Original change's description:
> Add presubmit to add PERFETTO_TESTS to cl description
>
> When making changes to the trace processor chrome standard library, developers should run the Perfetto Diff Tests and ensure they pass before submitting.
>
> PERFETTO_TESTS=`autoninja -C out/Default perfetto_diff_tests && out/Default/bin/run_perfetto_diff_tests`
>
> Change-Id: Ief2d38f05a204c5b64055cbf53f9084ce6b4476e
> Bug: b/287233796
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4774631
> Commit-Queue: Rasika Navarange <rasikan@google.com>
> Reviewed-by: Stephen Nusko <nuskos@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1184099}

Bug: b/287233796
Change-Id: Iac87ec5bdb2bd3adb125fd7e2fbe686c14d745d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4788748
Reviewed-by: Alexander Timin <altimin@chromium.org>
Commit-Queue: Rasika Navarange <rasikan@google.com>
Cr-Commit-Position: refs/heads/main@{#1184745}
  • Loading branch information
Rasika Navarange authored and Chromium LUCI CQ committed Aug 17, 2023
1 parent 7016984 commit 22504bc
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
9 changes: 9 additions & 0 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4999,3 +4999,12 @@ source_set("partition_alloc_test_support") {
configs += [ "//build/config/compiler:optimize_speed" ]
}
}

if (enable_base_tracing) {
# This group makes visible those targets in subdirectories that are not
# explicitly depended on.
group("gn_all") {
testonly = true
deps = [ "//base/tracing:perfetto_diff_tests" ]
}
}
81 changes: 81 additions & 0 deletions base/tracing/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/util/generate_wrapper.gni")
import("//build_overrides/build.gni")

if (enable_base_tracing) {
generate_wrapper("perfetto_diff_tests") {
testonly = true

_protos_path = "$root_gen_dir/third_party/perfetto/protos"
_trace_descriptor = "$_protos_path/perfetto/trace/trace.descriptor"
_rebased_trace_descriptor = rebase_path(_trace_descriptor, root_build_dir)
_test_extensions_descriptor =
"$_protos_path/perfetto/trace/test_extensions.descriptor"
_rebased_test_extensions_descriptor =
rebase_path(_test_extensions_descriptor, root_build_dir)
_metrics_descriptor = "$_protos_path/perfetto/metrics/metrics.descriptor"
_rebased_metrics_descriptor =
rebase_path(_metrics_descriptor, root_build_dir)
_all_chrome_metrics_descriptor =
"$_protos_path/perfetto/metrics/chrome/all_chrome_metrics.descriptor"
_rebased_all_chrome_metrics_descriptor =
rebase_path(_all_chrome_metrics_descriptor, root_build_dir)
_chrome_track_event_descriptor =
"$_protos_path/third_party/chromium/chrome_track_event.descriptor"
_rebased_chrome_track_event_descriptor =
rebase_path(_chrome_track_event_descriptor, root_build_dir)

_perfetto_script =
rebase_path("//third_party/perfetto/tools/diff_test_trace_processor.py",
root_build_dir)
_chrome_stdlib = rebase_path("//base/tracing/stdlib/chrome", root_build_dir)
_test_dir = rebase_path("//base/tracing", root_build_dir)

executable = "//base/tracing/test/run_perfetto_diff_tests.py"
wrapper_script = "$root_build_dir/bin/run_perfetto_diff_tests"

executable_args = [
"--trace-processor-shell",
"@WrappedPath(./trace_processor_shell)",
"--chrome-stdlib",
"@WrappedPath($_chrome_stdlib)",
"--test-dir",
"@WrappedPath($_test_dir)",
"--trace-descriptor",
"@WrappedPath($_rebased_trace_descriptor)",
"--test-extensions-descriptor",
"@WrappedPath($_rebased_test_extensions_descriptor)",
"--metrics-descriptor",
"@WrappedPath($_rebased_metrics_descriptor)",
"--all-chrome-metrics-descriptor",
"@WrappedPath($_rebased_all_chrome_metrics_descriptor)",
"--chrome-track-event-descriptor",
"@WrappedPath($_rebased_chrome_track_event_descriptor)",
"--script",
"@WrappedPath($_perfetto_script)",
]

data_deps = [
"//third_party/perfetto/protos/perfetto/metrics:descriptor",
"//third_party/perfetto/protos/perfetto/metrics/chrome:descriptor",
"//third_party/perfetto/protos/perfetto/trace:descriptor",
"//third_party/perfetto/protos/perfetto/trace:test_extensions_descriptor",
"//third_party/perfetto/protos/third_party/chromium:descriptor",
"//third_party/perfetto/src/trace_processor:trace_processor_shell",
]

data = [
"//third_party/perfetto/tools/diff_test_trace_processor.py",
"//third_party/perfetto/python/generators/diff_tests/",
"//base/tracing/",
_trace_descriptor,
_test_extensions_descriptor,
_metrics_descriptor,
_all_chrome_metrics_descriptor,
_chrome_track_event_descriptor,
]
}
}
28 changes: 28 additions & 0 deletions base/tracing/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,31 @@ def CheckSqlModules(input_api, output_api):
# is complete.
return []
return []

_STDLIB_PATHS = (
r"^base/tracing/stdlib/",
r"^base/tracing/test/",
)

def CheckPerfettoTestsTag(input_api, output_api):
"""Checks that commits to the trace processor chrome stdlib or the
Perfetto diff tests contain a PERFETTO_TESTS tag in their commit
message."""
def FileFilter(affected_file):
return input_api.FilterSourceFile(affected_file,
files_to_check=_STDLIB_PATHS)

# Only consider changes to chrome stdlib or tests paths
if not any (input_api.AffectedFiles(file_filter=FileFilter)):
return []

if input_api.change.PERFETTO_TESTS:
return []

message = (
'Must provide PERFETTO_TESTS='
'`autoninja -C out/Default perfetto_diff_tests && '
'out/Default/bin/run_perfetto_diff_tests` line in CL description.'
'\nPlease ensure the Perfetto diff tests pass before submitting.'
)
return [output_api.PresubmitNotifyResult(message)]
51 changes: 51 additions & 0 deletions base/tracing/test/run_perfetto_diff_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env vpython3
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# A wrapper script for //third_party/perfetto/diff_test_trace_processor.py.

import argparse
import subprocess
import sys
import os
import time
import json

def main():
parser = argparse.ArgumentParser()
parser.add_argument('--trace-descriptor', type=str, required=True)
parser.add_argument('--test-extensions-descriptor', type=str, required=True)
parser.add_argument('--metrics-descriptor', type=str, required=True)
parser.add_argument(
'--all-chrome-metrics-descriptor', type=str, required=True)
parser.add_argument(
'--chrome-track-event-descriptor', type=str, required=True)
parser.add_argument(
'--chrome-stdlib', type=str, required=True)
parser.add_argument('--test-dir', type=str, required=True)
parser.add_argument(
'--trace-processor-shell', type=str, required=True)
parser.add_argument("--script", type=str, required=True)
args, _ = parser.parse_known_args()

cmd = [
"vpython3", args.script,
"--trace-descriptor", args.trace_descriptor,
"--test-extensions", args.test_extensions_descriptor,
"--metrics-descriptor", args.metrics_descriptor,
args.all_chrome_metrics_descriptor,
"--chrome-track-event-descriptor", args.chrome_track_event_descriptor,
"--override-sql-module", os.path.abspath(args.chrome_stdlib),
"--test-dir", args.test_dir,
args.trace_processor_shell,
]

test_start_time = time.time()
completed_process = subprocess.run(cmd, capture_output=True)

sys.stderr.buffer.write(completed_process.stderr)
return completed_process.returncode

if __name__ == '__main__':
sys.exit(main())

0 comments on commit 22504bc

Please sign in to comment.