xref: /aosp_15_r20/tools/asuite/adevice/tests/partial_program_tests.rs (revision c2e18aaa1096c836b086f94603d04f4eb9cf37f5)
1*c2e18aaaSAndroid Build Coastguard Worker mod common;
2*c2e18aaaSAndroid Build Coastguard Worker 
3*c2e18aaaSAndroid Build Coastguard Worker use adevice::adevice::Profiler;
4*c2e18aaaSAndroid Build Coastguard Worker use adevice::cli::RestartChoice;
5*c2e18aaaSAndroid Build Coastguard Worker use adevice::cli::Wait;
6*c2e18aaaSAndroid Build Coastguard Worker use adevice::commands::{AdbAction, AdbCommand};
7*c2e18aaaSAndroid Build Coastguard Worker use adevice::restart_chooser::RestartChooser;
8*c2e18aaaSAndroid Build Coastguard Worker use anyhow::Result;
9*c2e18aaaSAndroid Build Coastguard Worker use common::fakes::FakeDevice;
10*c2e18aaaSAndroid Build Coastguard Worker use std::collections::HashMap;
11*c2e18aaaSAndroid Build Coastguard Worker use std::path::PathBuf;
12*c2e18aaaSAndroid Build Coastguard Worker 
13*c2e18aaaSAndroid Build Coastguard Worker // Just placeholder for now to show we can call adevice.
14*c2e18aaaSAndroid Build Coastguard Worker 
call_update_with_reboot(wait: Wait) -> Result<FakeDevice>15*c2e18aaaSAndroid Build Coastguard Worker fn call_update_with_reboot(wait: Wait) -> Result<FakeDevice> {
16*c2e18aaaSAndroid Build Coastguard Worker     // Use real device for device tests.
17*c2e18aaaSAndroid Build Coastguard Worker     let device = FakeDevice::new(&HashMap::new());
18*c2e18aaaSAndroid Build Coastguard Worker     let mut profiler = Profiler::default();
19*c2e18aaaSAndroid Build Coastguard Worker     // Capture adb command?
20*c2e18aaaSAndroid Build Coastguard Worker     let restart_chooser = RestartChooser::new(&RestartChoice::Reboot);
21*c2e18aaaSAndroid Build Coastguard Worker     let initial_adb_cmds = HashMap::from([(
22*c2e18aaaSAndroid Build Coastguard Worker         PathBuf::from("ignore_me"),
23*c2e18aaaSAndroid Build Coastguard Worker         AdbCommand::from_action(AdbAction::Mkdir, &PathBuf::from("ignore_me")),
24*c2e18aaaSAndroid Build Coastguard Worker     )]);
25*c2e18aaaSAndroid Build Coastguard Worker     adevice::device::update(&restart_chooser, &initial_adb_cmds, &mut profiler, &device, wait)?;
26*c2e18aaaSAndroid Build Coastguard Worker     Ok(device)
27*c2e18aaaSAndroid Build Coastguard Worker }
28*c2e18aaaSAndroid Build Coastguard Worker #[test]
update_has_timeout_commands() -> Result<()>29*c2e18aaaSAndroid Build Coastguard Worker fn update_has_timeout_commands() -> Result<()> {
30*c2e18aaaSAndroid Build Coastguard Worker     // Wait has two parts
31*c2e18aaaSAndroid Build Coastguard Worker     // 1) The prep that clear sys.boot_completed.
32*c2e18aaaSAndroid Build Coastguard Worker     let device = call_update_with_reboot(Wait::Yes)?;
33*c2e18aaaSAndroid Build Coastguard Worker     assert!(
34*c2e18aaaSAndroid Build Coastguard Worker         device.raw_cmds().iter().any(|c| c.contains("setprop sys.boot_completed")),
35*c2e18aaaSAndroid Build Coastguard Worker         "Did not find setprop cmd, did find\n{:?}",
36*c2e18aaaSAndroid Build Coastguard Worker         device.raw_cmds()
37*c2e18aaaSAndroid Build Coastguard Worker     );
38*c2e18aaaSAndroid Build Coastguard Worker     // 2) A call to device.wait() that calls "adb timeout ..."
39*c2e18aaaSAndroid Build Coastguard Worker     // but the FakeDevice mocks this out.
40*c2e18aaaSAndroid Build Coastguard Worker     assert_eq!(1, device.wait_calls());
41*c2e18aaaSAndroid Build Coastguard Worker 
42*c2e18aaaSAndroid Build Coastguard Worker     Ok(())
43*c2e18aaaSAndroid Build Coastguard Worker }
44*c2e18aaaSAndroid Build Coastguard Worker 
45*c2e18aaaSAndroid Build Coastguard Worker #[test]
update_nowait_has_no_timeout_commands() -> Result<()>46*c2e18aaaSAndroid Build Coastguard Worker fn update_nowait_has_no_timeout_commands() -> Result<()> {
47*c2e18aaaSAndroid Build Coastguard Worker     let device = call_update_with_reboot(Wait::No)?;
48*c2e18aaaSAndroid Build Coastguard Worker     // Wait has two parts
49*c2e18aaaSAndroid Build Coastguard Worker     // 1) The prep that clear sys.boot_completed.
50*c2e18aaaSAndroid Build Coastguard Worker     assert_eq!(
51*c2e18aaaSAndroid Build Coastguard Worker         0,
52*c2e18aaaSAndroid Build Coastguard Worker         device.raw_cmds().iter().filter(|c| c.contains("setprop sys.boot_completed")).count(),
53*c2e18aaaSAndroid Build Coastguard Worker         "Found timeout cmd, did not expect to\nn{:?}",
54*c2e18aaaSAndroid Build Coastguard Worker         device.raw_cmds()
55*c2e18aaaSAndroid Build Coastguard Worker     );
56*c2e18aaaSAndroid Build Coastguard Worker     // 2) A call to device.wait() that calls "adb timeout ..."
57*c2e18aaaSAndroid Build Coastguard Worker     // but the FakeDevice mocks this out.
58*c2e18aaaSAndroid Build Coastguard Worker     assert_eq!(0, device.wait_calls());
59*c2e18aaaSAndroid Build Coastguard Worker 
60*c2e18aaaSAndroid Build Coastguard Worker     Ok(())
61*c2e18aaaSAndroid Build Coastguard Worker }
62