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