• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 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
5AUTHOR = 'abergman, chromeos-engprod-platform-syd'
6NAME = '{name}'
7ATTRIBUTES = '{attributes}'
8TIME = '{length}'
9TEST_CATEGORY = 'Stress'
10TEST_CLASS = 'Hardware'
11TEST_TYPE = 'Server'
12PRIORITY = {priority}
13MAX_RESULT_SIZE_KB = 1024 * 1024
14JOB_RETRIES = 5
15REQUIRE_SSP = True
16DEPENDENCIES = '{dependencies}'
17PY_VERSION = 3
18
19DOC = '''
20Run the Tast-based MTBF performance CUJ test.
21
22Tast is an integration-testing framework analogous to the test-running portion
23of Autotest. See https://chromium.googlesource.com/chromiumos/platform/tast/ for
24more information.
25
26See http://go/tast-failures for information about investigating failures.
27'''
28
29import common
30import json
31import logging
32import tempfile
33from six.moves import urllib
34import yaml
35
36from autotest_lib.client.common_lib import utils
37from autotest_lib.client.common_lib.cros import dev_server
38from autotest_lib.site_utils.deployment.prepare import dut
39from autotest_lib.utils import labellib
40
41test_args = dict()
42test_args['test_version'] = {version}
43
44def report_host_info(host):
45  labels = labellib.LabelsMapping(host.host_info_store.get().labels)
46  labels['test'] = '{test_exprs}'
47  labels['test_iteration'] = '{iteration}'
48  utils.write_keyval(job.resultdir, labels)
49  # Try to retrieve and report DUT HWID and serial number.
50  try:
51    dut.setup_hwid_and_serialnumber(host)
52    logging.info("Host info store: %s", host.host_info_store.get())
53    utils.write_keyval(job.resultdir, host.host_info_store.get().attributes)
54  except Exception as e:
55    logging.warning("Failed retrieving DUT host info: %s", e)
56
57def parse_config(config_url):
58  response = urllib.request.urlopen(config_url)
59  vars = json.loads(response.read())
60  for key in vars:
61    test_args[key] = vars[key]
62  logging.info('Read %d values from remote configuration.', len(vars))
63
64def stage_config(host):
65  devservers = dev_server.ImageServer.get_available_devservers()
66  devserver_url = devservers[0][0]
67  if devserver_url:
68    logging.info('Using devserver: %s', devserver_url)
69    labels = host.host_info_store.get().labels
70    build = labellib.LabelsMapping(labels).get(labellib.Key.CROS_VERSION)
71    if not build:
72      # Not able to detect build, means not running on Moblab.
73      return
74    ds = dev_server.ImageServer(devserver_url)
75    gs_bucket = dev_server._get_image_storage_server()
76    if gs_bucket:
77      config_path = 'config/perf_cuj/'
78      config_file = 'perf_cuj.config'
79      archive_url = gs_bucket + config_path
80      logging.info('Staging configuration from %s.', gs_bucket)
81      try:
82        ds.stage_artifacts(build,
83                          archive_url = archive_url,
84                          files = [config_file])
85      except Exception as e:
86          logging.error('Staging artifacts failed: %s', str(e))
87      else:
88        logging.info('Parsing configuration from %s.', archive_url)
89        parse_config(devserver_url + '/static/' + config_path + config_file)
90
91def run(machine):
92  with tempfile.NamedTemporaryFile(mode='w+', encoding='utf-8', suffix='.yaml') as temp_file:
93      host=hosts.create_host(machine)
94      report_host_info(host)
95      stage_config(host)
96
97      # Writing all test arguments to yaml file.
98      yaml.safe_dump(test_args,
99                    stream=temp_file,
100                    default_flow_style=False,
101                    allow_unicode=True)
102      job.run_test('tast',
103                  host=host,
104                  test_exprs=['{test_exprs}'],
105                  clear_tpm=False,
106                  ignore_test_failures=False,
107                  max_run_sec={duration},
108                  command_args=args,
109                  varsfiles=[temp_file.name])
110
111parallel_simple(run, machines)
112