Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions crates/connetto-test-harness/src/bin/connetto-android-proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,24 +931,39 @@ fn parse_bounds(text: &str) -> Option<(i32, i32, i32, i32)> {

#[cfg(test)]
mod tests {
use std::os::unix::fs::PermissionsExt as _;
use std::path::{Path, PathBuf};
use std::time::Duration;

use super::Device;

/// A stand-in `adb` that runs `body` with `$state` naming a scratch directory.
fn fake_adb(dir: &Path, body: &str) -> PathBuf {
use std::io::Write as _;
let path = dir.join("adb");
std::fs::write(
&path,
format!(
"#!/bin/sh\nstate={}\necho \"$*\" >>\"$state/calls\"\n{body}\n",
dir.display()
),
)
.expect("write the fake adb");
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).expect("chmod");
let script = format!(
"#!/bin/sh\nstate={}\necho \"$*\" >>\"$state/calls\"\n{body}\n",
dir.display()
);
// A child process writes the script, so no descriptor open for
// writing it lives in this process, where another test's fork could
// inherit it and make the exec fail with "Text file busy".
let mut writer = std::process::Command::new("sh")
.arg("-c")
.arg("cat >\"$0\" && chmod 755 \"$0\"")
.arg(&path)
.stdin(std::process::Stdio::piped())
.spawn()
.expect("start the writer");
writer
.stdin
.take()
.expect("the writer's input")
.write_all(script.as_bytes())
.expect("write the fake adb");
assert!(
writer.wait().expect("the writer ends").success(),
"the writer fails"
);
path
}

Expand Down
Loading