• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env generate
2
3"""Defines DutAttributes that can be used for test scheduling.
4
5Generates a file containing a DutAttributeList of valid DutAttributes.
6
7Add DutAttributes by appending to _dut_attribute_list.
8
9Note that a DutAttribute used on any branch cannot be deleted or modified,
10because this may break the test plan on the branch.
11"""
12
13# Needed to load from @proto.
14exec("//config/util/bindings/proto.star")
15
16load("@proto//chromiumos/test/api/dut_attribute.proto", dut_attribute_pb = "chromiumos.test.api")
17load("//config/util/generate.star", "generate")
18
19def _dut_attribute_id(value):
20    """Create a DutAttribute.Id instance."""
21    if not value:
22        fail("Empty DutAttribute id")
23    return dut_attribute_pb.DutAttribute.Id(value = value)
24
25def _field_spec_list(field_specs):
26    """Create a DutAttribute.FieldList instance."""
27    return [
28        dut_attribute_pb.DutAttribute.FieldSpec(
29            path = path,
30        )
31        for path in field_specs
32    ]
33
34def _config_attribute(
35        name,
36        field_specs = [],
37        aliases = [],
38        allowed_values = [],
39        exclude_values = []):
40    """Build a DutAttribute with a FlatConfigSource.
41
42    These are attributes that directly reference a config value from the
43    associated FlatConfig payload.
44    """
45
46    return dut_attribute_pb.DutAttribute(
47        id = _dut_attribute_id(name),
48        aliases = aliases,
49        allowed_values = allowed_values,
50        exclude_values = exclude_values,
51        flat_config_source = dut_attribute_pb.DutAttribute.FlatConfigSource(
52            fields = _field_spec_list(field_specs),
53        ),
54    )
55
56def _hwid_attribute(
57        name,
58        component_type,
59        field_specs = [],
60        aliases = [],
61        allowed_values = [],
62        exclude_values = []):
63    """Build a DutAttribute with a HwidSource.
64
65    These are attributes whose value's are mediate by HwidServer at runtime.
66    """
67
68    return dut_attribute_pb.DutAttribute(
69        id = _dut_attribute_id(name),
70        aliases = aliases,
71        allowed_values = allowed_values,
72        exclude_values = exclude_values,
73        hwid_source = dut_attribute_pb.DutAttribute.HwidSource(
74            component_type = component_type,
75            fields = _field_spec_list(field_specs),
76        ),
77    )
78
79def _tle_attribute(
80        name,
81        aliases = [],
82        allowed_values = [],
83        exclude_values = []):
84    """Build a DutAttribute with a TleSource.
85
86    These are attributes whose values are determined by the caller TLE at
87    runtime. Field specs are not maintained here as each TLE should have its own
88    implementation on how to match the label to the desired value.
89    """
90
91    return dut_attribute_pb.DutAttribute(
92        id = _dut_attribute_id(name),
93        aliases = aliases,
94        allowed_values = allowed_values,
95        exclude_values = exclude_values,
96        tle_source = dut_attribute_pb.DutAttribute.TleSource(),
97    )
98
99def _device_attributes():
100    """Return list of generic device attribute definitions."""
101    return [
102        _config_attribute(
103            "attr-cts-abi",
104            ["program.platform.soc_arch"],
105            aliases = [
106                "label-cts_abi",
107                "label-cts_cpu",
108            ],
109        ),
110        _config_attribute(
111            "attr-design",
112            ["hw_design.id.value"],
113            aliases = [
114                "attr-model",
115                "label-model",
116            ],
117        ),
118        _config_attribute(
119            "attr-ec-type",
120            ["hw_design_config.hardware_features.embedded_controller.ec_type"],
121            aliases = [
122                "label-ec_type",
123            ],
124        ),
125        _config_attribute(
126            "attr-fingerprint-location",
127            # Note: need to reference REQUIRED design config constraints too
128            ["hw_design_config.hardware_features.fingerprint.location"],
129        ),
130        _config_attribute(
131            "attr-program",
132            ["program.id.value"],
133            aliases = [
134                "attr-board",
135                "label-platform",
136                "label-board",
137            ],
138        ),
139    ]
140
141def _device_features():
142    """Return list of device features."""
143    return [
144        _config_attribute(
145            "feature-bluetooth",
146            ["hw_design_config.hardware_features.bluetooth.present"],
147            aliases = [
148                "label-bluetooth",
149            ],
150        ),
151        _config_attribute(
152            "feature-fingerprint",
153            ["hw_design_config.hardware_features.fingerprint.location"],
154            exclude_values = ["LOCATION_UNKNOWN", "NOT_PRESENT"],
155            aliases = [
156                "label-fingerprint",
157            ],
158        ),
159        _config_attribute(
160            "feature-hotwording",
161            ["hw_design_config.hardware_features.hotwording.present"],
162            aliases = [
163                "label-hotwording",
164            ],
165        ),
166        _config_attribute(
167            "feature-internal-display",
168            ["hw_design_config.hardware_features.display.type"],
169            allowed_values = ["TYPE_INTERNAL", "TYPE_INTERNAL_EXTERNAL"],
170            aliases = [
171                "label-internal_display",
172            ],
173        ),
174        _config_attribute(
175            "feature-stylus",
176            ["hw_design_config.hardware_features.stylus.stylus"],
177            allowed_values = ["INTERNAL", "EXTERNAL"],
178            aliases = [
179                "label-stylus",
180            ],
181        ),
182        _config_attribute(
183            "feature-touchpad",
184            ["hw_design_config.hardware_features.touchpad.present"],
185            aliases = [
186                "label-touchpad",
187            ],
188        ),
189        _config_attribute(
190            "feature-touchscreen",
191            ["hw_design_config.hardware_features.screen.touch_support"],
192            allowed_values = ["PRESENT"],
193            aliases = [
194                "label-touchscreen",
195            ],
196        ),
197    ]
198
199def _hwid_attributes():
200    """Return list of device attributes looked up through hwid."""
201    return [
202        _hwid_attribute(
203            "hw-wireless",
204            component_type = "wifi",
205            field_specs = ["hwid_label"],
206            aliases = [
207                "label-wifi_chip",
208            ],
209        ),
210    ]
211
212def _tle_attributes():
213    """Return list of device attributes to be looked up by a TLE."""
214    return [
215        _tle_attribute(
216            "attr-cr50-phase",
217            aliases = [
218                "label-cr50_phase",
219            ],
220        ),
221        _tle_attribute(
222            "attr-cr50-key-env",
223            aliases = [
224                "label-cr50_ro_keyid",
225            ],
226        ),
227        _tle_attribute(
228            "attr-dut-id",
229            aliases = [
230                "dut_id",
231            ],
232        ),
233        _tle_attribute(
234            "attr-dut-name",
235            aliases = [
236                "dut_name",
237            ],
238        ),
239        _tle_attribute(
240            "misc-license",
241            aliases = [
242                "label-license",
243            ],
244        ),
245        _tle_attribute(
246            "peripheral-arc",
247            aliases = [
248                "label-arc",
249            ],
250        ),
251        _tle_attribute(
252            "peripheral-atrus",
253            aliases = [
254                "label-atrus",
255            ],
256        ),
257        _tle_attribute(
258            "peripheral-audio-board",
259            aliases = [
260                "label-audio_board",
261            ],
262        ),
263        _tle_attribute(
264            "peripheral-audio-box",
265            aliases = [
266                "label-audio_box",
267            ],
268        ),
269        _tle_attribute(
270            "peripheral-audio-cable",
271            aliases = [
272                "label-audio_cable",
273            ],
274        ),
275        _tle_attribute(
276            "peripheral-audio-loopback",
277            aliases = [
278                "label-audio_loopback_dongle",
279            ],
280        ),
281        _tle_attribute(
282            "peripheral-bluetooth-state",
283            aliases = [
284                "label-bluetooth_state",
285            ],
286        ),
287        _tle_attribute(
288            "peripheral-camerabox-facing",
289            aliases = [
290                "label-camerabox_facing",
291            ],
292        ),
293        _tle_attribute(
294            "peripheral-camerabox-light",
295            aliases = [
296                "label-camerabox_light",
297            ],
298        ),
299        _tle_attribute(
300            "peripheral-carrier",
301            aliases = [
302                "label-carrier",
303            ],
304        ),
305        _tle_attribute(
306            "peripheral-chameleon",
307            aliases = [
308                "label-chameleon",
309            ],
310        ),
311        _tle_attribute(
312            "peripheral-chaos",
313            aliases = [
314                "label-chaos_dut",
315            ],
316        ),
317        _tle_attribute(
318            "peripheral-mimo",
319            aliases = [
320                "label-mimo",
321            ],
322        ),
323        _tle_attribute(
324            "peripheral-num-btpeer",
325            aliases = [
326                "label-working_bluetooth_btpeer",
327            ],
328        ),
329        _tle_attribute(
330            "peripheral-power",
331            aliases = [
332                "label-power",
333            ],
334        ),
335        _tle_attribute(
336            "peripheral-servo",
337            aliases = [
338                "label-servo",
339            ],
340        ),
341        _tle_attribute(
342            "peripheral-servo-component",
343            aliases = [
344                "label-servo_component",
345            ],
346        ),
347        _tle_attribute(
348            "peripheral-servo-state",
349            aliases = [
350                "label-servo_state",
351            ],
352        ),
353        _tle_attribute(
354            "peripheral-servo-usb-state",
355            aliases = [
356                "label-servo_usb_state",
357                "servo_usb_state",
358            ],
359        ),
360        _tle_attribute(
361            "peripheral-wificell",
362            aliases = [
363                "label-wificell",
364            ],
365        ),
366        _tle_attribute(
367            "peripheral-wifi-state",
368            aliases = [
369                "label-wifi_state",
370            ],
371        ),
372        _tle_attribute(
373            "swarming-pool",
374            aliases = [
375                "label-pool",
376            ],
377        ),
378    ]
379
380# List of DutAttributes to generate. Add new DutAttributes here.
381_dut_attribute_list = dut_attribute_pb.DutAttributeList(
382    dut_attributes =
383        _device_attributes() +
384        _device_features() +
385        _hwid_attributes() +
386        _tle_attributes(),
387)
388
389def _validate_dut_attribute_list(dut_attribute_list):
390    """Performs basic validation checks on a DutAttributeList.
391
392    For example, ids must be unique.
393    """
394    ids = set()
395    for attribute in dut_attribute_list.dut_attributes:
396        if attribute.id.value in ids:
397            fail("DutAttribute.Id {} declared multiple times.".format(attribute.id))
398
399        ids = ids.union([attribute.id.value])
400
401# Validate the DutAttributeList and write to a file.
402_validate_dut_attribute_list(_dut_attribute_list)
403
404generate.generate(_dut_attribute_list, "dut_attributes.jsonproto")
405