Skip to main content

device_tests/
failure.rs

1use core::fmt;
2use std::io;
3use std::net::Ipv4Addr;
4use std::process::ExitStatus;
5use std::time::Duration;
6
7use ql_qmi::codec::DecodeError;
8use ql_qmi::status::QmiError;
9
10use crate::digits::DigitsError;
11use crate::display::Chain;
12use crate::model::Model;
13use crate::system::CommandError;
14
15/// Why a test failed.
16///
17/// The debug output is the error chain, which libtest prints for a failed
18/// test.
19#[derive(thiserror::Error)]
20pub enum Failure {
21    /// A QMI request failed.
22    #[error(transparent)]
23    Qmi(#[from] ql_qmi::Error),
24    /// A UIM request failed.
25    #[error(transparent)]
26    Uim(#[from] ql_uim::Error),
27    /// A WDS request failed.
28    #[error(transparent)]
29    Wds(#[from] ql_wds::Error),
30    /// A WMS request failed.
31    #[error(transparent)]
32    Wms(#[from] ql_wms::Error),
33    /// A NAS request failed.
34    #[error(transparent)]
35    Nas(#[from] ql_nas::Error),
36    /// A wake lock or autosleep operation failed.
37    #[error(transparent)]
38    Sleep(#[from] ql_sleep::Error),
39    /// A command failed to run.
40    #[error(transparent)]
41    Command(#[from] CommandError),
42    /// The runtime for a restore failed to start.
43    #[error("failed to start a runtime")]
44    Runtime(#[source] io::Error),
45    /// QMI services that the crates use are missing.
46    #[error("required services are missing: {}", names.join(", "))]
47    MissingServices {
48        /// Names of the missing services.
49        names: Vec<&'static str>,
50    },
51    /// A response failed to decode.
52    #[error("failed to decode the response to message {msg_id:#06x}")]
53    Decode {
54        /// ID of the message.
55        msg_id: u16,
56        /// Underlying error.
57        #[source]
58        source: DecodeError,
59    },
60    /// `ql_manager` answered the model probe with an unexpected error.
61    #[error("ql_manager answered the probe with {error}, expected success or ENCODING")]
62    UnexpectedProbe {
63        /// The error in the response.
64        error: QmiError,
65    },
66    /// The probe found another model than the one in the project version file.
67    #[error("the probe says {probed}, the project version file says {expected}")]
68    ModelMismatch {
69        /// Model from the probe.
70        probed: Model,
71        /// Model from the project version file.
72        expected: Model,
73    },
74    /// A response lacks a value.
75    #[error("the {field} is missing")]
76    Missing {
77        /// Name of the value.
78        field: &'static str,
79    },
80    /// An IMEI, ICCID or IMSI is invalid.
81    #[error("{field} {value} is invalid")]
82    InvalidId {
83        /// Name of the value.
84        field: &'static str,
85        /// The value.
86        value: String,
87        /// What is wrong with it.
88        #[source]
89        source: DigitsError,
90    },
91    /// No SIM card is present.
92    #[error("no card is present")]
93    NoCard,
94    /// No SMS arrived in time.
95    #[error("no SMS arrived within {} s", timeout.as_secs())]
96    NoSms {
97        /// How long the test waited.
98        timeout: Duration,
99    },
100    /// A file failed to read.
101    #[error("failed to read {path}")]
102    Read {
103        /// Path of the file.
104        path: &'static str,
105        /// Underlying error.
106        #[source]
107        source: io::Error,
108    },
109    /// The kernel's wakeup source is in the wrong state after a step.
110    #[error("the wakeup source is {state} after the step {step}, expected {expected}")]
111    WakeupSource {
112        /// The step of the test.
113        step: &'static str,
114        /// State of the wakeup source.
115        state: &'static str,
116        /// Expected state.
117        expected: &'static str,
118    },
119    /// Autosleep is still on after the wake lock was dropped.
120    #[error("autosleep is still on after the wake lock was dropped")]
121    AutosleepStillOn,
122    /// The interface addresses failed to read.
123    #[error("failed to read the interface addresses")]
124    Interfaces(#[source] nix::Error),
125    /// An interface didn't get its address in time.
126    #[error("{interface} did not get {expected} within {} s", timeout.as_secs())]
127    AddressMissing {
128        /// Name of the interface.
129        interface: &'static str,
130        /// Expected address.
131        expected: Ipv4Addr,
132        /// How long the test waited.
133        timeout: Duration,
134    },
135    /// An interface kept an IPv4 address.
136    #[error("{interface} still has an IPv4 address after {} s", timeout.as_secs())]
137    AddressStays {
138        /// Name of the interface.
139        interface: &'static str,
140        /// How long the test waited.
141        timeout: Duration,
142    },
143    /// Ping failed.
144    #[error("ping failed with {status}")]
145    Ping {
146        /// Exit status of ping.
147        status: ExitStatus,
148    },
149    /// A command exited with an error.
150    #[error("{command} failed with {status}")]
151    Exit {
152        /// The program.
153        command: &'static str,
154        /// Exit status of the program.
155        status: ExitStatus,
156    },
157    /// A signal failed to send.
158    #[error("failed to send a signal to {program}")]
159    Signal {
160        /// Name of the program.
161        program: &'static str,
162        /// Underlying error.
163        #[source]
164        source: nix::Error,
165    },
166    /// A process didn't start or stop in time.
167    #[error("{program} is not {expected} after {} s", timeout.as_secs())]
168    Process {
169        /// Name of the program.
170        program: &'static str,
171        /// The state that the test waited for.
172        expected: &'static str,
173        /// How long the test waited.
174        timeout: Duration,
175    },
176    /// SMS arrived wrong or not at all.
177    #[error("wrong or missing messages: {}", cases.join(", "))]
178    Sms {
179        /// Keys of the failed cases.
180        cases: Vec<&'static str>,
181    },
182}
183
184impl fmt::Debug for Failure {
185    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
186        Chain(self).fmt(f)
187    }
188}