xref: /aosp_15_r20/external/autotest/server/site_tests/tast/control.cross-device-chrome-from-tls (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Copyright 2022 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
5import logging
6
7from autotest_lib.client.common_lib.error import TestFail
8from autotest_lib.server.cros import chrome_sideloader
9from autotest_lib.server import utils
10
11AUTHOR = 'ChromeOS SW Engprod Team ([email protected])'
12NAME = 'tast.cross-device-chrome-from-tls'
13TIME = 'MEDIUM'
14TEST_TYPE = 'Server'
15MAX_RESULT_SIZE_KB = 1024 * 1024
16PY_VERSION = 3
17
18# tast.py uses binaries installed from autotest_server_package.tar.bz2.
19REQUIRE_SSP = True
20
21# This mount point controls the version of chrome to use
22CHROME_MOUNT_POINT = '/opt/google/chrome'
23# Location to put the sideloaded chrome artifacts
24CHROME_DIR = '/usr/local/chrome'
25
26DOC = '''
27Runs Cross Device scenarios with a custom chrome binary.
28
29Cross Device scenarios require two chromebooks.
30This control file is a generic wrapper for running cross device tests
31from Chromium builders and Chromium Skylab recipe.
32Chromium builders create chrome binaries and artifacts and upload to GCS.
33The chrome binaries are in turn provisioned to both DUTs through TLS and
34are used in tests.
35
36This control file expects tast_expr or tast_expr_b64 argument to determine
37the set of tast tests to be executed.
38
39Example for tast_expr: test_that --args="tast_expr=nearbyshare.SmokeMultiDUTUI"
40
41Example for tast_expr_b64:
42  In Python:
43    tast_expr = '("group:nearby-share-cq")'
44    # Yields 'KCJ1aS5DaHJvbWVTZXJ2aWNlR1JQQy5kZWZhdWx0X2Zha2VfbG9naW4iKQ=='
45    tast_expr_b64 = base64.b64encode(s.encode('utf-8')).decode('ascii')
46  Then in Autotest CLI:'
47    test_that --args="tast_expr_b64=KCJ1aS5DaHJvbWVTZXJ2aWNlR1JQQy5kZWZhdWx0X2Zha2VfbG9naW4iKQ=="
48
49More details at go/lacros-on-skylab.
50
51'''
52
53
54def run(machine):
55    tast_expr = chrome_sideloader.get_tast_expr(utils.args_to_dict(args))
56
57    primary_dut = hosts.create_host(machine)
58    companions = hosts.create_companion_hosts(companion_hosts)
59
60    if not companions:
61        raise TestFail('Missing companion hosts')
62
63    secondary_dut = companions[0]
64
65    logging.info("Running %s on primary_dut: %s and companion_host:%s with Tast expression:%s",
66                 NAME, primary_dut, secondary_dut, tast_expr)
67
68    # Setup both DUTs to use the chrome binary from TLS
69    for host in [primary_dut, secondary_dut]:
70        chrome_sideloader.setup_host(
71            host, CHROME_DIR, CHROME_MOUNT_POINT)
72
73    # Register a clean up callback to reset the chrome mount.
74    def cleanup():
75        for host in [primary_dut, secondary_dut]:
76            chrome_sideloader.cleanup_host(
77                host, CHROME_DIR, CHROME_MOUNT_POINT)
78    job.add_post_run_hook(cleanup)
79
80    job.run_test('tast',
81                 host=primary_dut,
82                 test_exprs=[tast_expr],
83                 download_data_lazily=False,
84                 ignore_test_failures=False,
85                 max_run_sec=3600,
86                 companion_duts={'cd1': secondary_dut},
87                 command_args=args
88                 )
89
90parallel_simple(run, machines)
91