Commit c401a7d6 authored by Deepanjan Roy's avatar Deepanjan Roy Committed by Commit Bot

[tbmv3] Add an integration test for run_tbmv3_metric

Adding a simple smoke test to make sure run_tbmv3_metric does not break
silently.

Change-Id: I54f4d525e221eef403678034efde505ee19cbc1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2078736Reviewed-by: default avatarCaleb Rouleau <crouleau@chromium.org>
Reviewed-by: default avatarDeep Roy <dproy@chromium.org>
Reviewed-by: default avatarMikhail Khokhlov <khokhlov@google.com>
Commit-Queue: Deep Roy <dproy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747385}
parent b65bd7c4
...@@ -17,9 +17,11 @@ class BinaryDepsManagerTests(unittest.TestCase): ...@@ -17,9 +17,11 @@ class BinaryDepsManagerTests(unittest.TestCase):
def setUp(self): def setUp(self):
self.temp_dir = tempfile.mkdtemp() self.temp_dir = tempfile.mkdtemp()
self.config_path = os.path.join(self.temp_dir, 'config.json') self.config_path = os.path.join(self.temp_dir, 'config.json')
self.original_config_path = binary_deps_manager.CONFIG_PATH
binary_deps_manager.CONFIG_PATH = self.config_path binary_deps_manager.CONFIG_PATH = self.config_path
def tearDown(self): def tearDown(self):
binary_deps_manager.CONFIG_PATH = self.original_config_path
shutil.rmtree(self.temp_dir) shutil.rmtree(self.temp_dir)
def writeConfig(self, config): def writeConfig(self, config):
......
...@@ -24,17 +24,15 @@ from core.tbmv3 import trace_processor ...@@ -24,17 +24,15 @@ from core.tbmv3 import trace_processor
_CHROMIUM_SRC_PATH = os.path.join( _CHROMIUM_SRC_PATH = os.path.join(
os.path.dirname(__file__), '..', '..', '..', '..') os.path.dirname(__file__), '..', '..', '..', '..')
_DEFAULT_TP_PATH = os.path.realpath(os.path.join(
_CHROMIUM_SRC_PATH, 'out', 'Debug', 'trace_processor_shell'))
def _WriteHistogramSetToFile(histograms, outfile): def _WriteHistogramSetToFile(histograms, outfile):
with open(outfile, 'w') as f: with open(outfile, 'w') as f:
json.dump(histograms.AsDicts(), f, indent=2, sort_keys=True, json.dump(histograms.AsDicts(), f, indent=2, sort_keys=True,
separators=(',', ': ')) separators=(',', ': '))
f.write("\n")
def Main(): def Main(cli_args):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='[Experimental] Runs TBMv3 metrics on local traces and ' description='[Experimental] Runs TBMv3 metrics on local traces and '
'produces histogram json.') 'produces histogram json.')
...@@ -42,12 +40,13 @@ def Main(): ...@@ -42,12 +40,13 @@ def Main():
help='Trace file you want to compute metric on') help='Trace file you want to compute metric on')
parser.add_argument('--metric', required=True, parser.add_argument('--metric', required=True,
help=('Name of the metric you want to run')) help=('Name of the metric you want to run'))
parser.add_argument('--trace-processor-path', default=_DEFAULT_TP_PATH, parser.add_argument(
help='Path to trace processor shell. ' '--trace-processor-path',
'Default: %(default)s') help='Path to trace processor shell. '
'Default: Binary downloaded from cloud storage.')
parser.add_argument('--outfile', default='results.json', parser.add_argument('--outfile', default='results.json',
help='Path to output file. Default: %(default)s') help='Path to output file. Default: %(default)s')
args = parser.parse_args() args = parser.parse_args(cli_args)
histograms = trace_processor.RunMetric(args.trace_processor_path, histograms = trace_processor.RunMetric(args.trace_processor_path,
args.trace, args.metric) args.trace, args.metric)
...@@ -56,4 +55,4 @@ def Main(): ...@@ -56,4 +55,4 @@ def Main():
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(Main()) sys.exit(Main(sys.argv[1:]))
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Integration tests for run_tbmv3_metric.py.
These test check run_tbmv3_metric works end to end, using the real trace
processor shell.
"""
import json
import os
import shutil
import tempfile
import unittest
from core.tbmv3 import run_tbmv3_metric
from tracing.value import histogram_set
# For testing the TBMv3 workflow we use dummy_metric defined in
# tools/perf/core/tbmv3/metrics/dummy_metric_*.
# This metric ignores the trace data and outputs a histogram with
# the following name and unit:
DUMMY_HISTOGRAM_NAME = 'dummy::foo'
DUMMY_HISTOGRAM_UNIT = 'count_biggerIsBetter'
class RunTbmv3MetricIntegrationTests(unittest.TestCase):
def setUp(self):
self.output_dir = tempfile.mkdtemp()
self.trace_path = self.CreateEmptyProtoTrace()
self.outfile_path = os.path.join(self.output_dir, 'out.json')
def tearDown(self):
shutil.rmtree(self.output_dir)
def CreateEmptyProtoTrace(self):
"""Create an empty file as a proto trace."""
with tempfile.NamedTemporaryFile(
dir=self.output_dir, delete=False) as trace_file:
# Open temp file and close it so it's written to disk.
pass
return trace_file.name
def testRunTbmv3MetricOnDummyMetric(self):
run_tbmv3_metric.Main([
'--trace', self.trace_path,
'--metric', 'dummy_metric',
'--outfile', self.outfile_path,
])
with open(self.outfile_path) as f:
results = json.load(f)
out_histograms = histogram_set.HistogramSet()
out_histograms.ImportDicts(results)
hist = out_histograms.GetHistogramNamed(DUMMY_HISTOGRAM_NAME)
self.assertEqual(hist.unit, DUMMY_HISTOGRAM_UNIT)
self.assertEqual(hist.num_values, 1)
self.assertEqual(hist.average, 42)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment