forked from jkcoxson/minimuxer
-
Notifications
You must be signed in to change notification settings - Fork 13
/
tests.rs
112 lines (93 loc) · 2.54 KB
/
tests.rs
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
102
103
104
105
106
107
108
109
110
111
112
use log::info;
use std::io::{self, Write};
use std::process::Command;
use std::sync::Once;
use crate::afc_file_manager::AfcFileManager;
use crate::device::fetch_udid;
use crate::heartbeat::start_beat;
use crate::jit::attach_debugger;
use crate::mounter::start_auto_mounter;
use crate::provision::dump_profiles;
use crate::{ready, set_debug};
/* Utils */
fn init() {
static INIT: Once = Once::new();
INIT.call_once(|| {
set_debug(true);
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "trace")
}
env_logger::init();
info!("Successfully initialized tests");
println!();
});
}
/// Wrapper for a test function to ensure init() gets called
macro_rules! make_test {
($name: ident, $code: expr) => {
#[test]
fn $name() {
init();
$code
}
};
}
fn list_profiles() -> String {
let output = Command::new("ideviceprovision")
.arg("list")
.output()
.expect("failed to execute process");
info!("{}", output.status);
io::stdout().write_all(&output.stdout).unwrap();
io::stderr().write_all(&output.stderr).unwrap();
String::from_utf8(output.stdout).unwrap()
}
/* Tests */
make_test!(is_ready, {
info!("Starting heartbeat");
println!();
start_beat();
println!();
info!("Starting auto mounter");
println!();
let input = "./target/dmg".to_string();
start_auto_mounter(input);
println!();
info!("Sleeping for 10 seconds to allow for image to be mounted and heartbeat to start");
println!();
std::thread::sleep(std::time::Duration::from_secs(10));
println!();
assert!(ready());
});
make_test!(udid, {
let udid = fetch_udid().unwrap();
println!();
info!("UDID: {}", udid);
});
make_test!(jit_pid, {
let pid = 0; // Put the PID to attach to here
println!();
info!("Attaching to {pid}");
println!();
let output = attach_debugger(pid);
println!();
info!("Got output: {:?}", output);
assert!(matches!(output, Ok(())));
});
make_test!(afc_file_manager, {
// warning: may take a while
dbg!(AfcFileManager::contents());
dbg!(AfcFileManager::write_file(
"/hello_apple".to_string(),
std::fs::read("./README.md").unwrap().as_slice(),
)
.unwrap());
dbg!(AfcFileManager::copy_file_outside_afc(
"/hello_apple".to_string(),
"./target/hello".to_string()
)
.unwrap());
});
make_test!(dump_profiles_, {
dump_profiles("./target".to_string()).unwrap();
});