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