blob: c1a21c456d47049726abf440155a730b2df99982 [file] [log] [blame]
# Copyright 2018 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from recipe_engine import recipe_api
CATAPULT_URL = "https://chromeperf.appspot.com"
class CatapultApi(recipe_api.RecipeApi):
"""CatapultApi provides support for the Catapult infra tool."""
@property
def _catapult(self):
return self.m.ensure_tool("catapult", self.resource("tool_manifest.json"))
def upload_test_outputs(self, output_dir):
"""Uploads test outputs to Catapult from a specified directory.
Uploads only Catapult HistogramSet JSON files with the expected catapult
extension (.catapult_json)
Args:
output_dir (Path): A directory containing catapult files produced by
the tests.
"""
for filepath in self.m.file.glob_paths(
"locate catapult files",
output_dir,
pattern=self.m.path.join("**", "*.catapult_json"),
test_data=["benchmark.catapult_json"],
):
basename = self.m.path.basename(filepath)
with self.m.step.nest(f"upload {basename}"):
self._run("upload", "-url", CATAPULT_URL, "-timeout", "60s", filepath)
def _run(self, subcommand, *flags, **kwargs):
"""Return a catapult command step.
Args:
subcommand (str): The Catapult CLI command to run; e.g.
'make_histogram' or 'update'.
flags (seq(str)): Flags to pass to the subcommand.
kwargs (dict): Passed through to api.step().
"""
cmd = [self._catapult, subcommand]
cmd.extend(flags)
with self.m.context(infra_steps=True):
return self.m.step("catapult " + subcommand, cmd, **kwargs)