1*9c5db199SXin Li# Copyright 2018 The Chromium OS Authors. All rights reserved. 2*9c5db199SXin Li# Use of this source code is governed by a BSD-style license that can be 3*9c5db199SXin Li# found in the LICENSE file. 4*9c5db199SXin Li 5*9c5db199SXin Li"""Tast-specific logics of TKO parser.""" 6*9c5db199SXin Li 7*9c5db199SXin Liimport json 8*9c5db199SXin Liimport os 9*9c5db199SXin Li 10*9c5db199SXin Liimport common 11*9c5db199SXin Li 12*9c5db199SXin Lifrom autotest_lib.client.common_lib import utils 13*9c5db199SXin Li 14*9c5db199SXin Li# Name of the Autotest test case that runs Tast tests. 15*9c5db199SXin Li_TAST_AUTOTEST_NAME = 'tast' 16*9c5db199SXin Li 17*9c5db199SXin Li# Prefix added to Tast test names when writing their results to TKO. 18*9c5db199SXin Li# This should match with _TEST_NAME_PREFIX in server/site_tests/tast/tast.py. 19*9c5db199SXin Li_TAST_TEST_NAME_PREFIX = 'tast.' 20*9c5db199SXin Li 21*9c5db199SXin Li 22*9c5db199SXin Lidef is_tast_test(test_name): 23*9c5db199SXin Li """Checks if a test is a Tast test.""" 24*9c5db199SXin Li return test_name.startswith(_TAST_TEST_NAME_PREFIX) 25*9c5db199SXin Li 26*9c5db199SXin Li 27*9c5db199SXin Lidef load_tast_test_aux_results(job, test_name): 28*9c5db199SXin Li """Loads auxiliary results of a Tast test. 29*9c5db199SXin Li 30*9c5db199SXin Li @param job: A job object. 31*9c5db199SXin Li @param test_name: The name of the test. 32*9c5db199SXin Li @return (attributes, perf_values) where 33*9c5db199SXin Li attributes: A str-to-str dict of attribute keyvals 34*9c5db199SXin Li perf_values: A dict loaded from a chromeperf JSON 35*9c5db199SXin Li """ 36*9c5db199SXin Li assert is_tast_test(test_name) 37*9c5db199SXin Li 38*9c5db199SXin Li test_dir = os.path.join(job.dir, _TAST_AUTOTEST_NAME) 39*9c5db199SXin Li 40*9c5db199SXin Li case_name = test_name[len(_TAST_TEST_NAME_PREFIX):] 41*9c5db199SXin Li case_dir = os.path.join(test_dir, 'results', 'tests', case_name) 42*9c5db199SXin Li 43*9c5db199SXin Li # Load attribute keyvals. 44*9c5db199SXin Li attributes_path = os.path.join(test_dir, 'keyval') 45*9c5db199SXin Li if os.path.exists(attributes_path): 46*9c5db199SXin Li attributes = utils.read_keyval(attributes_path) 47*9c5db199SXin Li else: 48*9c5db199SXin Li attributes = {} 49*9c5db199SXin Li 50*9c5db199SXin Li # Load a chromeperf JSON. 51*9c5db199SXin Li perf_values_path = os.path.join(case_dir, 'results-chart.json') 52*9c5db199SXin Li if os.path.exists(perf_values_path): 53*9c5db199SXin Li with open(perf_values_path) as fp: 54*9c5db199SXin Li perf_values = json.load(fp) 55*9c5db199SXin Li else: 56*9c5db199SXin Li perf_values = {} 57*9c5db199SXin Li 58*9c5db199SXin Li return attributes, perf_values 59