1use std::fs;
2use std::time::Duration;
3
4use nix::unistd;
5use tokio::sync::{Mutex, MutexGuard};
6
7use crate::model::{PROJECT_VERSION, Revision};
8use crate::print::print_skip;
9
10pub const REQUEST_TIMEOUT: Duration = Duration::from_secs(5);
12
13static MODEM: Mutex<()> = Mutex::const_new(());
15
16#[derive(Debug)]
18pub struct Device {
19 revision: Option<Revision>,
20 _modem: MutexGuard<'static, ()>,
21}
22
23impl Device {
24 #[must_use]
26 pub const fn revision(&self) -> Option<&Revision> {
27 self.revision.as_ref()
28 }
29}
30
31pub async fn device() -> Option<Device> {
36 let content = match fs::read_to_string(PROJECT_VERSION) {
37 Ok(content) => content,
38 Err(err) => {
39 print_skip(format_args!(
40 "this is not an AG35, {PROJECT_VERSION} can't be read: {err}"
41 ));
42 return None;
43 }
44 };
45 if !unistd::geteuid().is_root() {
46 print_skip(format_args!("the tests must run as root"));
47 return None;
48 }
49 let modem = MODEM.lock().await;
50 Some(Device {
51 revision: Revision::parse(&content),
52 _modem: modem,
53 })
54}