1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use {
    serde::{Deserialize, Serialize},
    std::cmp::{Eq, PartialEq},
    std::fmt::Debug,
};

#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(tag = "schema_id")]
pub enum TestList {
    #[serde(rename = "experimental")]
    Experimental { data: Vec<TestListEntry> },
}

#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct TestListEntry {
    /// The name of the test.
    ///
    /// MUST BE unique within the test list file.
    pub name: String,

    /// Arbitrary labels for this test list.
    ///
    /// No format requirements are imposed on these labels,
    /// but for GN this is typically a build label.
    pub labels: Vec<String>,

    // Arbitrary tags for this test suite.
    pub tags: Vec<TestTag>,

    // Instructions for how to execute this test.
    // If missing, this test cannot be executed by ffx test.
    pub execution: Option<ExecutionEntry>,
}

#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, PartialOrd, Ord, Clone)]
pub struct TestTag {
    pub key: String,
    pub value: String,
}

impl TestTag {
    pub fn new(key: impl Into<String>, value: impl Into<String>) -> Self {
        Self { key: key.into(), value: value.into() }
    }
}

#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
#[serde(tag = "type")]
pub enum ExecutionEntry {
    #[serde(rename = "fuchsia_component")]
    /// The test is executed as a Fuchsia component on a target device.
    FuchsiaComponent(FuchsiaComponentExecutionEntry),
}

#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct FuchsiaComponentExecutionEntry {
    /// The URL of the component to execute.
    pub component_url: String,

    /// Command line arguments passed to the test for execution.
    #[serde(default = "Vec::new")]
    pub test_args: Vec<String>,

    /// The number of seconds to wait before the test is killed and marked "timed out".
    pub timeout_seconds: Option<std::num::NonZeroU32>,

    /// Filters for which test cases in the suite to execute.
    pub test_filters: Option<Vec<String>>,

    /// If true, test cases in the suite marked "disabled" will be run anyway.
    #[serde(default)]
    pub also_run_disabled_tests: bool,

    /// The number of test cases to run in parallel.
    ///
    /// This value is a hint to the test runner, which is free to
    /// override the preference. If unset, a value is chosen by the
    /// test runner.
    pub parallel: Option<u16>,

    /// The maximum severity of logs the test is allowed to write.
    ///
    /// This may be used to catch log spam from components by ensuring
    /// that all logging during test execution is equal to or below
    /// this level.
    pub max_severity_logs: Option<diagnostics_data::Severity>,

    /// The minimum severity of logs the test will be asked to produce.
    ///
    /// This may be used to request DEBUG or TRACE level logs from tests
    /// which only produce INFO and above by default.
    pub min_severity_logs: Option<diagnostics_data::Severity>,

    /// The moniker of the realm to to run this test in.
    pub realm: Option<String>,
}