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 /// Whether an empty set of test cases counts as success or failure.
75 pub no_cases_equals_success: Option<bool>,
76
77 /// If true, test cases in the suite marked "disabled" will be run anyway.
78 #[serde(default)]
79 pub also_run_disabled_tests: bool,
80
81 /// The number of test cases to run in parallel.
82 ///
83 /// This value is a hint to the test runner, which is free to
84 /// override the preference. If unset, a value is chosen by the
85 /// test runner.
86 pub parallel: Option<u16>,
87
88 /// The maximum severity of logs the test is allowed to write.
89 ///
90 /// This may be used to catch log spam from components by ensuring
91 /// that all logging during test execution is equal to or below
92 /// this level.
93 #[serde(default, with = "optional_severity")]
94 pub max_severity_logs: Option<Severity>,
95
96 /// The minimum severity of logs the test will be asked to produce.
97 ///
98 /// This may be used to request DEBUG or TRACE level logs from tests
99 /// which only produce INFO and above by default.
100 #[serde(default, with = "optional_severity")]
101 pub min_severity_logs: Option<Severity>,
102
103 /// The moniker of the realm to to run this test in.
104 pub realm: Option<String>,
105
106 /// If true, indicates that test_manager should create no exception channels as it would
107 /// otherwise do to detect panics. Some tests that create exception channels at the job
108 /// level will fail if test_manager creates its customary exception channels.
109 #[serde(default)]
110 pub create_no_exception_channel: bool,
111}