summaryrefslogtreecommitdiffstats
path: root/third_party/rust/minidump-writer/tests/common
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/minidump-writer/tests/common
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/minidump-writer/tests/common')
-rw-r--r--third_party/rust/minidump-writer/tests/common/mod.rs95
1 files changed, 95 insertions, 0 deletions
diff --git a/third_party/rust/minidump-writer/tests/common/mod.rs b/third_party/rust/minidump-writer/tests/common/mod.rs
new file mode 100644
index 0000000000..2c1ded5f20
--- /dev/null
+++ b/third_party/rust/minidump-writer/tests/common/mod.rs
@@ -0,0 +1,95 @@
+use std::error;
+use std::io::{BufRead, BufReader, Write};
+use std::process::{Child, Command, Stdio};
+use std::result;
+
+#[allow(unused)]
+type Error = Box<dyn error::Error + std::marker::Send + std::marker::Sync>;
+#[allow(unused)]
+pub type Result<T> = result::Result<T, Error>;
+
+#[allow(unused)]
+pub fn spawn_child(command: &str, args: &[&str]) {
+ let mut cmd_object = Command::new("cargo");
+ let mut cmd_ref = cmd_object
+ .env("RUST_BACKTRACE", "1")
+ .arg("run")
+ .arg("-q")
+ .arg("--bin")
+ .arg("test")
+ .arg("--")
+ .arg(command);
+ for arg in args {
+ cmd_ref = cmd_ref.arg(arg);
+ }
+ let child = cmd_ref.output().expect("failed to execute child");
+
+ println!("Child output:");
+ std::io::stdout().write_all(&child.stdout).unwrap();
+ std::io::stdout().write_all(&child.stderr).unwrap();
+ assert_eq!(child.status.code().expect("No return value"), 0);
+}
+
+fn start_child_and_wait_for_threads_helper(cmd: &str, num: usize) -> Child {
+ let mut child = Command::new("cargo")
+ .env("RUST_BACKTRACE", "1")
+ .arg("run")
+ .arg("-q")
+ .arg("--bin")
+ .arg("test")
+ .arg("--")
+ .arg(cmd)
+ .arg(format!("{}", num))
+ .stdout(Stdio::piped())
+ .spawn()
+ .expect("failed to execute child");
+
+ wait_for_threads(&mut child, num);
+ child
+}
+
+#[allow(unused)]
+pub fn start_child_and_wait_for_threads(num: usize) -> Child {
+ start_child_and_wait_for_threads_helper("spawn_and_wait", num)
+}
+
+#[allow(unused)]
+pub fn start_child_and_wait_for_named_threads(num: usize) -> Child {
+ start_child_and_wait_for_threads_helper("spawn_name_wait", num)
+}
+
+#[allow(unused)]
+pub fn wait_for_threads(child: &mut Child, num: usize) {
+ let mut f = BufReader::new(child.stdout.as_mut().expect("Can't open stdout"));
+ let mut lines = 0;
+ while lines < num {
+ let mut buf = String::new();
+ match f.read_line(&mut buf) {
+ Ok(_) => {
+ if buf == "1\n" {
+ lines += 1;
+ }
+ }
+ Err(e) => {
+ std::panic::panic_any(e);
+ }
+ }
+ }
+}
+
+#[allow(unused)]
+pub fn start_child_and_return(args: &[&str]) -> Child {
+ let mut child = Command::new("cargo")
+ .env("RUST_BACKTRACE", "1")
+ .arg("run")
+ .arg("-q")
+ .arg("--bin")
+ .arg("test")
+ .arg("--")
+ .args(args)
+ .stdout(Stdio::piped())
+ .spawn()
+ .expect("failed to execute child");
+
+ child
+}