• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 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
5load("@proto//chromiumos/config/api/test/metadata/v1/metadata.proto",
6    metadata_pb = "chromiumos.config.api.test.metadata.v1"
7)
8load("@proto//google/protobuf/struct.proto", google_pb = "google.protobuf")
9
10
11
12_TEST_NAME_PREFIX = "remoteTestDrivers/tauto/tests/"
13
14_COMMON_DEPS = {
15    "bluetooth": "scope.hardware_topology.bluetooth == scope.hardware_features.PRESENT",
16}
17
18
19
20def _define_test(
21    name,
22    *,
23    suites = [],
24    main_package = 'NOT SET',
25    main_args = [],
26):
27    """Define a single Tauto test.
28
29    Args:
30        name: The globally unique name of the test, as known to the scheduling
31                infrastructure.
32        suites: A list of test suites this test belongs to, without the 'suite:'
33                prefix.
34        main_package: Python package that contains the entry function.
35                e.g. autotest_lib.client.site_tests.dummy_Pass.dummy_Pass
36        main_args: A list of arguments to the entry function.
37    """
38    test_args = google_pb.ListValue(values = [
39        google_pb.Value(string_value = a) for a in main_args
40    ])
41    informational = metadata_pb.Informational(
42        details = google_pb.Struct(fields = {
43            "main": google_pb.Value(struct_value = google_pb.Struct(fields = {
44                "python_package": google_pb.Value(string_value = main_package),
45                "test_args": google_pb.Value(list_value = test_args),
46            })),
47        }),
48    )
49    return metadata_pb.Test(
50        name = _TEST_NAME_PREFIX + name,
51        attributes = [metadata_pb.Attribute(name = "suite:" + s)
52                      for s in suites],
53        informational = informational,
54    )
55
56
57def _define_client_test(
58    test_name,
59    purpose,
60    doc,
61    owner_emails = [],
62    owner_groups = [],
63    suites = [],
64    common_deps = [],
65    dep_expressions = [],
66    named_args = {},
67):
68
69    attrs = [metadata_pb.Attribute(name = "suite:" + s) for s in suites]
70
71    contacts = ([metadata_pb.Contact(email = e) for e in owner_emails]
72                + [metadata_pb.Contact(mdb_group = g) for g in owner_groups])
73
74    details = google_pb.Struct(fields = {
75        "purpose": google_pb.Value(string_value = purpose),
76        "doc": google_pb.Value(string_value = doc),
77        "named_args": google_pb.Value(string_value = to_json(named_args))
78    })
79
80    info = metadata_pb.Informational(
81        authors = contacts,
82        details = details,
83    )
84
85    missing = [dep for dep in common_deps if dep not in _COMMON_DEPS]
86    if missing:
87        fail(str(missing) + " are not known common dependencies! " +
88             "Please add to test_common.star or check spelling.")
89
90    dep_strs = dep_expressions + [_COMMON_DEPS[dep] for dep in common_deps]
91    expression = " && ".join(dep_strs)
92    deps = [metadata_pb.DUTCondition(expression = expression)]
93
94    return metadata_pb.Test(
95                name = _TEST_NAME_PREFIX + test_name,
96                attributes = attrs,
97                informational = info,
98                dut_constraint = metadata_pb.DUTConstraint(
99                    config = metadata_pb.DUTConfigConstraint(
100                        expression = expression,
101                    )
102                ),
103    )
104
105
106test_common = struct(
107    define_client_test = _define_client_test,
108    define_test = _define_test,
109)
110