test_list/lib.rs
1// Copyright 2022 The Fuchsia 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
5use diagnostics_log_types_serde::{optional_severity, Severity};
6use serde::{Deserialize, Serialize};
7use std::cmp::{Eq, PartialEq};
8use std::fmt::Debug;
9
10#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
11#[serde(tag = "schema_id")]
12pub enum TestList {
13 #[serde(rename = "experimental")]
14 Experimental { data: Vec<TestListEntry> },
15}
16
17#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
18pub struct TestListEntry {
19 /// The name of the test.
20 ///
21 /// MUST BE unique within the test list file.
22 pub name: String,
23
24 /// Arbitrary labels for this test list.
25 ///
26 /// No format requirements are imposed on these labels,
27 /// but for GN this is typically a build label.
28 pub labels: Vec<String>,
29
30 // Arbitrary tags for this test suite.
31 pub tags: Vec<TestTag>,
32
33 // Instructions for how to execute this test.
34 // If missing, this test cannot be executed by ffx test.
35 pub execution: Option<ExecutionEntry>,
36}
37
38#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, PartialOrd, Ord, Clone)]
39pub struct TestTag {
40 pub key: String,
41 pub value: String,
42}
43
44impl TestTag {
45 pub fn new(key: impl Into<String>, value: impl Into<String>) -> Self {
46 Self { key: key.into(), value: value.into() }
47 }
48}
49
50#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
51#[non_exhaustive]
52#[serde(tag = "type")]
53pub enum ExecutionEntry {
54 #[serde(rename = "fuchsia_component")]
55 /// The test is executed as a Fuchsia component on a target device.
56 FuchsiaComponent(FuchsiaComponentExecutionEntry),
57}
58
59#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
60pub struct FuchsiaComponentExecutionEntry {
61 /// The URL of the component to execute.
62 pub component_url: String,
63
64 /// Command line arguments passed to the test for execution.
65 #[serde(default = "Vec::new")]
66 pub test_args: Vec<String>,
67
68 /// The number of seconds to wait before the test is killed and marked "timed out".
69 pub timeout_seconds: Option<std::num::NonZeroU32>,
70
71 /// Filters for which test cases in the suite to execute.
72 pub test_filters: Option<Vec<String>>,
73
74 /// If true, test cases in the suite marked "disabled" will be run anyway.
75 #[serde(default)]
76 pub also_run_disabled_tests: bool,
77
78 /// The number of test cases to run in parallel.
79 ///
80 /// This value is a hint to the test runner, which is free to
81 /// override the preference. If unset, a value is chosen by the
82 /// test runner.
83 pub parallel: Option<u16>,
84
85 /// The maximum severity of logs the test is allowed to write.
86 ///
87 /// This may be used to catch log spam from components by ensuring
88 /// that all logging during test execution is equal to or below
89 /// this level.
90 #[serde(default, with = "optional_severity")]
91 pub max_severity_logs: Option<Severity>,
92
93 /// The minimum severity of logs the test will be asked to produce.
94 ///
95 /// This may be used to request DEBUG or TRACE level logs from tests
96 /// which only produce INFO and above by default.
97 #[serde(default, with = "optional_severity")]
98 pub min_severity_logs: Option<Severity>,
99
100 /// The moniker of the realm to to run this test in.
101 pub realm: Option<String>,
102
103 /// If true, indicates that test_manager should create no exception channels as it would
104 /// otherwise do to detect panics. Some tests that create exception channels at the job
105 /// level will fail if test_manager creates its customary exception channels.
106 #[serde(default)]
107 pub create_no_exception_channel: bool,
108}