12add0d91Sopenharmony_ciuse std::env;
22add0d91Sopenharmony_ciuse std::process::Command;
32add0d91Sopenharmony_ciuse std::path::{Path, PathBuf};
42add0d91Sopenharmony_ci
52add0d91Sopenharmony_cifn main() {
62add0d91Sopenharmony_ci    let args = env::args_os()
72add0d91Sopenharmony_ci        .skip(1)
82add0d91Sopenharmony_ci        .filter(|arg| arg != "--quiet")
92add0d91Sopenharmony_ci        .collect::<Vec<_>>();
102add0d91Sopenharmony_ci    assert_eq!(args.len(), 1);
112add0d91Sopenharmony_ci    let test = PathBuf::from(&args[0]);
122add0d91Sopenharmony_ci    let dst = Path::new("/data/local/tmp").join(test.file_name().unwrap());
132add0d91Sopenharmony_ci
142add0d91Sopenharmony_ci    let status = Command::new("adb")
152add0d91Sopenharmony_ci        .arg("wait-for-device")
162add0d91Sopenharmony_ci        .status()
172add0d91Sopenharmony_ci        .expect("failed to run: adb wait-for-device");
182add0d91Sopenharmony_ci    assert!(status.success());
192add0d91Sopenharmony_ci
202add0d91Sopenharmony_ci    let status = Command::new("adb")
212add0d91Sopenharmony_ci        .arg("push")
222add0d91Sopenharmony_ci        .arg(&test)
232add0d91Sopenharmony_ci        .arg(&dst)
242add0d91Sopenharmony_ci        .status()
252add0d91Sopenharmony_ci        .expect("failed to run: adb push");
262add0d91Sopenharmony_ci    assert!(status.success());
272add0d91Sopenharmony_ci
282add0d91Sopenharmony_ci    let output = Command::new("adb")
292add0d91Sopenharmony_ci        .arg("shell")
302add0d91Sopenharmony_ci        .arg("RUST_BACKTRACE=1")
312add0d91Sopenharmony_ci        .arg(&dst)
322add0d91Sopenharmony_ci        .output()
332add0d91Sopenharmony_ci        .expect("failed to run: adb shell");
342add0d91Sopenharmony_ci    assert!(status.success());
352add0d91Sopenharmony_ci
362add0d91Sopenharmony_ci    let stdout = String::from_utf8_lossy(&output.stdout);
372add0d91Sopenharmony_ci    let stderr = String::from_utf8_lossy(&output.stderr);
382add0d91Sopenharmony_ci
392add0d91Sopenharmony_ci    println!("status: {}\nstdout ---\n{}\nstderr ---\n{}",
402add0d91Sopenharmony_ci             output.status,
412add0d91Sopenharmony_ci             stdout,
422add0d91Sopenharmony_ci             stderr);
432add0d91Sopenharmony_ci
442add0d91Sopenharmony_ci    if !stderr.lines().any(|l| (l.starts_with("PASSED ") && l.contains(" tests")) || l.starts_with("test result: ok"))
452add0d91Sopenharmony_ci        && !stdout.lines().any(|l| (l.starts_with("PASSED ") && l.contains(" tests")) || l.starts_with("test result: ok"))
462add0d91Sopenharmony_ci    {
472add0d91Sopenharmony_ci        panic!("failed to find successful test run");
482add0d91Sopenharmony_ci    };
492add0d91Sopenharmony_ci}
50