1#!/bin/bash 2 3set -e 4 5usage() { 6 echo " 7Usage: $0 [OPTION] 8 9Generates control files for Tast categories. 10 11For each Tast category, e.g. 'example', a file 12'server/site_tests/tast/control.category-<category>' and 13'test_suites/control.bvt-tast-cq-<category>' is generated, and attributes to add 14to attribute_allowlist.txt are printed. 15 16The control files follow templates that use test expressions based on test name, 17e.g. name:example.*. 18 19-f Overwrite existing control files. 20-h Print this help message. 21" 22 exit 1 23} 24 25overwrite=false 26 27while getopts "fh" o; do 28 case "${o}" in 29 f) 30 overwrite=true ;; 31 *) 32 usage ;; 33 esac 34done 35 36readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")" 37readonly repo_root=$(realpath "${script_dir}"/..) 38readonly src_root="$(realpath "${script_dir}"/../../../..)" 39 40categories=() 41types=( "remote" "local" ) 42for type in "${types[@]}"; do 43 mapfile -t categories < <(find \ 44 "${src_root}/platform/tast-tests/src/chromiumos/tast/${type}/bundles/cros" \ 45 -maxdepth 1 -mindepth 1 -type d -printf "%f\n") 46done 47 48mapfile -t categories < <(printf '%s\n' "${categories[@]}" | sort -u) 49 50attributes=() 51 52for c in "${categories[@]}"; do 53 test_suites_file="${repo_root}/test_suites/control.bvt-tast-cq-${c}" 54 if [[ -e ${test_suites_file} && ${overwrite} == "false" ]]; then 55 echo "File ${test_suites_file} already exists. Use -f to overwrite." 56 exit 1 57 fi 58 cat << EOF > "${test_suites_file}" 59# Copyright 2021 The Chromium OS Authors. All rights reserved. 60# Use of this source code is governed by a BSD-style license that can be 61# found in the LICENSE file. 62 63AUTHOR = "ChromeOS Team" 64NAME = "bvt-tast-cq-${c}" 65PURPOSE = 'Tests the critical Tast tests in the "${c}" category.' 66 67TIME = "SHORT" 68TEST_CATEGORY = "General" 69TEST_CLASS = "suite" 70TEST_TYPE = "Server" 71 72DOC = """ 73This suite verifies ChromeOS's basic functionality for the ChromeOS Commit 74Queue by running all Tast integration tests in the "${c}" category that must 75always pass against a DUT. See http://go/tast for more information about Tast. 76 77The only Autotest test executed by this suite is tast.category-${c}, which 78is a server test that executes the tast executable. The tast executable runs 79individual Tast tests. If any of these Tast tests fail, then the 80test.category-${c} test (and this suite) fail. 81""" 82 83import common 84from autotest_lib.server.cros.dynamic_suite import dynamic_suite 85 86args_dict['name'] = NAME 87args_dict['max_runtime_mins'] = 30 88args_dict['timeout_mins'] = 60 89args_dict['job'] = job 90 91dynamic_suite.reimage_and_run(**args_dict) 92EOF 93 94 tast_file="${repo_root}/server/site_tests/tast/control.category-${c}" 95 if [[ -e ${tast_file} && ${overwrite} == "false" ]]; then 96 echo "File ${tast_file} already exists. Use -f to overwrite." 97 exit 1 98 fi 99 cat << EOF > "${tast_file}" 100# Copyright 2021 The Chromium OS Authors. All rights reserved. 101# Use of this source code is governed by a BSD-style license that can be 102# found in the LICENSE file. 103 104from autotest_lib.client.common_lib import utils 105 106AUTHOR = 'Chromium OS team' 107NAME = 'tast.category-${c}' 108TIME = 'MEDIUM' 109TEST_TYPE = 'Server' 110DEPENDENCIES = 'servo_state:WORKING' 111ATTRIBUTES = 'suite:bvt-tast-cq-${c}' 112MAX_RESULT_SIZE_KB = 256 * 1024 113 114# tast.py uses binaries installed from autotest_server_package.tar.bz2. 115REQUIRE_SSP = True 116 117DOC = ''' 118Run the critical Tast tests in the "${c}" category. 119 120Tast is an integration-testing framework analagous to the test-running portion 121of Autotest. See https://chromium.googlesource.com/chromiumos/platform/tast/ for 122more information. 123 124This test runs Tast tests in the "${c}" category that are required to pass 125against a remote DUT. It fails if any individual Tast tests fail. 126 127See http://go/tast-failures for information about investigating failures. 128''' 129 130args_dict = utils.args_to_dict(args) 131assert 'servo_state:WORKING' in DEPENDENCIES 132servo_args = hosts.CrosHost.get_servo_arguments(args_dict) 133 134def run(machine): 135 job.run_test('tast', 136 host=hosts.create_host(machine, servo_args=servo_args), 137 test_exprs=['(' 138 '"group:mainline" && ' 139 '!informational && ' 140 '"name:${c}.*"' 141 ')'], 142 ignore_test_failures=False, max_run_sec=1800, 143 command_args=args, 144 clear_tpm=True) 145 146parallel_simple(run, machines) 147EOF 148 149 attributes+=( "suite:bvt-tast-cq-${c}" ) 150 151done 152 153echo "Add the following attributes to attribute_allowlist.txt:" 154printf "%s\n" "${attributes[@]}"