From d557863f525b836658d9837de247b4b154e5c4a6 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Wed, 11 Mar 2026 17:45:29 -0700 Subject: [PATCH 1/2] Move test helper examples to bin targets for build-dir compatibility Cargo's CARGO_BIN_EXE_* env vars (stabilized in 1.94) are only set for [[bin]] targets, not [[example]] targets. Moving test helpers from examples/ to src/bin/ ensures integration tests work correctly with build.build-dir and the upcoming new build-dir layout. - Move 17 example files from examples/ to src/bin/ - Update find_exec() to prefer CARGO_BIN_EXE_ with legacy fallback - Exclude test helper binaries from cargo publish via package.exclude Co-Authored-By: Claude Opus 4.6 --- Cargo.toml | 19 +++++++ {examples => src/bin}/pargs_penv.rs | 0 {examples => src/bin}/pcred_process.rs | 0 {examples => src/bin}/penv_setenv.rs | 0 {examples => src/bin}/pfiles_af_alg.rs | 0 {examples => src/bin}/pfiles_epoll.rs | 0 {examples => src/bin}/pfiles_matrix.rs | 0 .../bin}/pfiles_matrix_file_link.rs | 0 .../bin}/pfiles_matrix_unix_socket.rs | 0 {examples => src/bin}/pfiles_netlink.rs | 0 .../bin}/pfiles_sockopts_parent.rs | 7 ++- {examples => src/bin}/plgrp_process.rs | 0 {examples => src/bin}/plimit_process.rs | 0 {examples => src/bin}/psig_signals.rs | 0 {examples => src/bin}/pstack_process.rs | 0 {examples => src/bin}/pstop_prun_process.rs | 0 {examples => src/bin}/ptree_parent_child.rs | 0 {examples => src/bin}/pwait_process.rs | 0 tests/common/mod.rs | 14 +++-- tests/pargs_penv_test.rs | 52 ++++--------------- tests/pcred_test.rs | 6 +-- tests/pfiles_test.rs | 43 ++++----------- tests/plgrp_test.rs | 15 ++---- tests/plimit_test.rs | 35 +++---------- tests/psig_test.rs | 2 +- tests/pstack_test.rs | 29 ++--------- tests/pstop_prun_test.rs | 4 +- tests/ptime_test.rs | 2 +- tests/ptree_test.rs | 10 ++-- tests/pwait_test.rs | 4 +- 30 files changed, 86 insertions(+), 156 deletions(-) rename {examples => src/bin}/pargs_penv.rs (100%) rename {examples => src/bin}/pcred_process.rs (100%) rename {examples => src/bin}/penv_setenv.rs (100%) rename {examples => src/bin}/pfiles_af_alg.rs (100%) rename {examples => src/bin}/pfiles_epoll.rs (100%) rename {examples => src/bin}/pfiles_matrix.rs (100%) rename {examples => src/bin}/pfiles_matrix_file_link.rs (100%) rename {examples => src/bin}/pfiles_matrix_unix_socket.rs (100%) rename {examples => src/bin}/pfiles_netlink.rs (100%) rename {examples => src/bin}/pfiles_sockopts_parent.rs (93%) rename {examples => src/bin}/plgrp_process.rs (100%) rename {examples => src/bin}/plimit_process.rs (100%) rename {examples => src/bin}/psig_signals.rs (100%) rename {examples => src/bin}/pstack_process.rs (100%) rename {examples => src/bin}/pstop_prun_process.rs (100%) rename {examples => src/bin}/ptree_parent_child.rs (100%) rename {examples => src/bin}/pwait_process.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index b45ee14..6558717 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,25 @@ repository = "https://github.com/basil/ptools" license = "Apache-2.0" keywords = ["linux", "process", "procfs", "debugging", "cli"] categories = ["command-line-utilities", "development-tools::debugging"] +exclude = [ + "src/bin/pargs_penv.rs", + "src/bin/pcred_process.rs", + "src/bin/penv_setenv.rs", + "src/bin/pfiles_af_alg.rs", + "src/bin/pfiles_epoll.rs", + "src/bin/pfiles_matrix.rs", + "src/bin/pfiles_matrix_file_link.rs", + "src/bin/pfiles_matrix_unix_socket.rs", + "src/bin/pfiles_netlink.rs", + "src/bin/pfiles_sockopts_parent.rs", + "src/bin/plgrp_process.rs", + "src/bin/plimit_process.rs", + "src/bin/psig_signals.rs", + "src/bin/pstack_process.rs", + "src/bin/pstop_prun_process.rs", + "src/bin/ptree_parent_child.rs", + "src/bin/pwait_process.rs", +] [lints.clippy] uninlined_format_args = "warn" diff --git a/examples/pargs_penv.rs b/src/bin/pargs_penv.rs similarity index 100% rename from examples/pargs_penv.rs rename to src/bin/pargs_penv.rs diff --git a/examples/pcred_process.rs b/src/bin/pcred_process.rs similarity index 100% rename from examples/pcred_process.rs rename to src/bin/pcred_process.rs diff --git a/examples/penv_setenv.rs b/src/bin/penv_setenv.rs similarity index 100% rename from examples/penv_setenv.rs rename to src/bin/penv_setenv.rs diff --git a/examples/pfiles_af_alg.rs b/src/bin/pfiles_af_alg.rs similarity index 100% rename from examples/pfiles_af_alg.rs rename to src/bin/pfiles_af_alg.rs diff --git a/examples/pfiles_epoll.rs b/src/bin/pfiles_epoll.rs similarity index 100% rename from examples/pfiles_epoll.rs rename to src/bin/pfiles_epoll.rs diff --git a/examples/pfiles_matrix.rs b/src/bin/pfiles_matrix.rs similarity index 100% rename from examples/pfiles_matrix.rs rename to src/bin/pfiles_matrix.rs diff --git a/examples/pfiles_matrix_file_link.rs b/src/bin/pfiles_matrix_file_link.rs similarity index 100% rename from examples/pfiles_matrix_file_link.rs rename to src/bin/pfiles_matrix_file_link.rs diff --git a/examples/pfiles_matrix_unix_socket.rs b/src/bin/pfiles_matrix_unix_socket.rs similarity index 100% rename from examples/pfiles_matrix_unix_socket.rs rename to src/bin/pfiles_matrix_unix_socket.rs diff --git a/examples/pfiles_netlink.rs b/src/bin/pfiles_netlink.rs similarity index 100% rename from examples/pfiles_netlink.rs rename to src/bin/pfiles_netlink.rs diff --git a/examples/pfiles_sockopts_parent.rs b/src/bin/pfiles_sockopts_parent.rs similarity index 93% rename from examples/pfiles_sockopts_parent.rs rename to src/bin/pfiles_sockopts_parent.rs index 24cbd75..53aa960 100644 --- a/examples/pfiles_sockopts_parent.rs +++ b/src/bin/pfiles_sockopts_parent.rs @@ -25,6 +25,11 @@ use std::thread; use std::time::Duration; fn find_exec(name: &str) -> std::path::PathBuf { + let env_var = format!("CARGO_BIN_EXE_{name}"); + if let Some(p) = std::env::var_os(&env_var) { + return p.into(); + } + let this_exec = std::env::current_exe().expect("current exe"); let exec_dir = this_exec .parent() @@ -52,7 +57,7 @@ fn parent_main() { let ready_path = env::var("PTOOLS_TEST_READY_FILE").expect("PTOOLS_TEST_READY_FILE must be set"); - let mut child = Command::new(find_exec("examples/pfiles_sockopts_parent")) + let mut child = Command::new(find_exec("pfiles_sockopts_parent")) .arg("--child") .env("PTOOLS_TEST_READY_FILE", &ready_path) .stdin(Stdio::null()) diff --git a/examples/plgrp_process.rs b/src/bin/plgrp_process.rs similarity index 100% rename from examples/plgrp_process.rs rename to src/bin/plgrp_process.rs diff --git a/examples/plimit_process.rs b/src/bin/plimit_process.rs similarity index 100% rename from examples/plimit_process.rs rename to src/bin/plimit_process.rs diff --git a/examples/psig_signals.rs b/src/bin/psig_signals.rs similarity index 100% rename from examples/psig_signals.rs rename to src/bin/psig_signals.rs diff --git a/examples/pstack_process.rs b/src/bin/pstack_process.rs similarity index 100% rename from examples/pstack_process.rs rename to src/bin/pstack_process.rs diff --git a/examples/pstop_prun_process.rs b/src/bin/pstop_prun_process.rs similarity index 100% rename from examples/pstop_prun_process.rs rename to src/bin/pstop_prun_process.rs diff --git a/examples/ptree_parent_child.rs b/src/bin/ptree_parent_child.rs similarity index 100% rename from examples/ptree_parent_child.rs rename to src/bin/ptree_parent_child.rs diff --git a/examples/pwait_process.rs b/src/bin/pwait_process.rs similarity index 100% rename from examples/pwait_process.rs rename to src/bin/pwait_process.rs diff --git a/tests/common/mod.rs b/tests/common/mod.rs index e010a97..82cf4ae 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -26,13 +26,19 @@ use std::time::Duration; use std::time::SystemTime; use std::time::UNIX_EPOCH; -// Find an executable produced by the Cargo build +// Find an executable produced by the Cargo build. +// +// Cargo >=1.94 exposes `CARGO_BIN_EXE_` to integration tests, which +// works regardless of `build.build-dir` or layout changes. Older Cargo +// versions fall back to locating the binary relative to the test executable. pub fn find_exec(name: &str) -> PathBuf { - // Find the path where Cargo has placed the executables by looking at this test process's - // executable, which was also built by Cargo. + let env_var = format!("CARGO_BIN_EXE_{name}"); + if let Some(p) = std::env::var_os(&env_var) { + return p.into(); + } + let this_exec = std::env::current_exe().unwrap(); let exec_dir = this_exec.parent().unwrap().parent().unwrap(); - exec_dir.join(name) } diff --git a/tests/pargs_penv_test.rs b/tests/pargs_penv_test.rs index cbd92dd..e63fb92 100644 --- a/tests/pargs_penv_test.rs +++ b/tests/pargs_penv_test.rs @@ -41,14 +41,7 @@ fn pargs_matches_started_process_arguments() { "tabs\tinside", ]; - let output = common::run_ptool( - "pargs", - &[], - "examples/pargs_penv", - &expected_args, - &[], - false, - ); + let output = common::run_ptool("pargs", &[], "pargs_penv", &expected_args, &[], false); let stdout = common::assert_success_and_get_stdout(output); for arg in expected_args { @@ -76,14 +69,7 @@ fn pargs_l_matches_started_process_arguments_as_shell_command_line() { "tabs\tinside", ]; - let output = common::run_ptool( - "pargs", - &["-l"], - "examples/pargs_penv", - &expected_args, - &[], - false, - ); + let output = common::run_ptool("pargs", &["-l"], "pargs_penv", &expected_args, &[], false); let stdout = common::assert_success_and_get_stdout(output); let mut lines = stdout.lines(); @@ -96,9 +82,7 @@ fn pargs_l_matches_started_process_arguments_as_shell_command_line() { // pargs -l resolves argv[0] to the real executable path via /proc/[pid]/exe, // so the first token should be the canonical path to the example binary. - let exe_path = common::find_exec("examples/pargs_penv") - .canonicalize() - .unwrap(); + let exe_path = common::find_exec("pargs_penv").canonicalize().unwrap(); let expected_line = std::iter::once(exe_path.to_str().unwrap()) .chain(expected_args.iter().copied()) .map(shell_quote) @@ -116,14 +100,7 @@ fn penv_matches_started_process_environment() { ("PTOOLS_TEST_UNICODE", "✓"), ]; - let output = common::run_ptool( - "penv", - &[], - "examples/pargs_penv", - &[], - &expected_env, - false, - ); + let output = common::run_ptool("penv", &[], "pargs_penv", &[], &expected_env, false); let stdout = common::assert_success_and_get_stdout_allow_warnings(output); for (key, value) in expected_env { @@ -145,14 +122,7 @@ fn pargs_e_alias_matches_started_process_environment() { ("PTOOLS_TEST_UNICODE", "✓"), ]; - let output = common::run_ptool( - "pargs", - &["-e"], - "examples/pargs_penv", - &[], - &expected_env, - false, - ); + let output = common::run_ptool("pargs", &["-e"], "pargs_penv", &[], &expected_env, false); let stdout = common::assert_success_and_get_stdout_allow_warnings(output); for (key, value) in expected_env { @@ -167,7 +137,7 @@ fn pargs_e_alias_matches_started_process_environment() { #[test] fn pauxv_prints_auxv_entries() { - let output = common::run_ptool("pauxv", &[], "examples/pargs_penv", &[], &[], false); + let output = common::run_ptool("pauxv", &[], "pargs_penv", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); assert!( @@ -249,10 +219,10 @@ fn pauxv_prints_auxv_entries() { #[test] fn pargs_x_alias_matches_pauxv_output() { - let pauxv_output = common::run_ptool("pauxv", &[], "examples/pargs_penv", &[], &[], false); + let pauxv_output = common::run_ptool("pauxv", &[], "pargs_penv", &[], &[], false); let pauxv_stdout = common::assert_success_and_get_stdout(pauxv_output); - let pargs_output = common::run_ptool("pargs", &["-x"], "examples/pargs_penv", &[], &[], false); + let pargs_output = common::run_ptool("pargs", &["-x"], "pargs_penv", &[], &[], false); let pargs_stdout = common::assert_success_and_get_stdout(pargs_output); // Both should contain AT_PAGESZ @@ -287,7 +257,7 @@ fn penv_reflects_runtime_setenv() { let output = common::run_ptool( "penv", &[], - "examples/penv_setenv", + "penv_setenv", &[], &[("PTOOLS_TEST_OVERWRITE_VAR", "before")], false, @@ -318,7 +288,7 @@ fn pargs_e_reflects_runtime_setenv() { let output = common::run_ptool( "pargs", &["-e"], - "examples/penv_setenv", + "penv_setenv", &[], &[("PTOOLS_TEST_OVERWRITE_VAR", "before")], false, @@ -342,7 +312,7 @@ fn pargs_e_reflects_runtime_setenv() { #[test] fn pargs_x_prints_auxv_entries() { - let output = common::run_ptool("pargs", &["-x"], "examples/pargs_penv", &[], &[], false); + let output = common::run_ptool("pargs", &["-x"], "pargs_penv", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); assert!( diff --git a/tests/pcred_test.rs b/tests/pcred_test.rs index 9e54c17..12bdf0a 100644 --- a/tests/pcred_test.rs +++ b/tests/pcred_test.rs @@ -18,7 +18,7 @@ mod common; #[test] fn pcred_reports_condensed_credentials() { - let output = common::run_ptool("pcred", &[], "examples/pcred_process", &[], &[], false); + let output = common::run_ptool("pcred", &[], "pcred_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let mut lines = stdout.lines(); @@ -39,7 +39,7 @@ fn pcred_reports_condensed_credentials() { #[test] fn pcred_all_flag_shows_separate_credentials() { - let output = common::run_ptool("pcred", &["-a"], "examples/pcred_process", &[], &[], false); + let output = common::run_ptool("pcred", &["-a"], "pcred_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let mut lines = stdout.lines(); @@ -90,7 +90,7 @@ fn pcred_reports_groups_when_supplementary_groups_exist() { // The default mode may suppress the groups line if there is only one group // matching rgid, so verify with -a which shows groups unconditionally. - let output = common::run_ptool("pcred", &["-a"], "examples/pcred_process", &[], &[], false); + let output = common::run_ptool("pcred", &["-a"], "pcred_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); assert!( diff --git a/tests/pfiles_test.rs b/tests/pfiles_test.rs index 26ba717..e55f2eb 100644 --- a/tests/pfiles_test.rs +++ b/tests/pfiles_test.rs @@ -500,7 +500,7 @@ fn pfiles_prints_header_lines() { let output = common::run_ptool( "pfiles", &[], - "examples/pargs_penv", + "pargs_penv", &[], &[ ("PTOOLS_TEST_SET_RLIMIT_NOFILE_SOFT", "123"), @@ -534,7 +534,7 @@ fn pfiles_prints_header_lines() { #[test] fn pfiles_reports_epoll_anon_inode() { - let output = common::run_ptool("pfiles", &[], "examples/pfiles_epoll", &[], &[], false); + let output = common::run_ptool("pfiles", &[], "pfiles_epoll", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let fd_map = parse_fd_map(&stdout); @@ -553,7 +553,7 @@ fn pfiles_reports_epoll_anon_inode() { #[test] fn pfiles_non_verbose_mode_prints_fstat_only_descriptor_lines() { - let output = common::run_ptool("pfiles", &["-n"], "examples/pfiles_epoll", &[], &[], false); + let output = common::run_ptool("pfiles", &["-n"], "pfiles_epoll", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let fd_map = parse_fd_map(&stdout); @@ -585,7 +585,7 @@ fn pfiles_non_verbose_mode_prints_fstat_only_descriptor_lines() { fn pfiles_resolves_socket_metadata_for_target_net_namespace() { let ready = common::ReadySignal::new(false); - let example = common::find_exec("examples/pfiles_netlink"); + let example = common::find_exec("pfiles_netlink"); let mut unshare_cmd = Command::new("unshare"); unshare_cmd .arg("--net") @@ -652,7 +652,7 @@ fn pfiles_resolves_socket_metadata_for_target_net_namespace() { #[test] fn pfiles_reports_netlink_socket() { - let output = common::run_ptool("pfiles", &[], "examples/pfiles_netlink", &[], &[], false); + let output = common::run_ptool("pfiles", &[], "pfiles_netlink", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let fd_map = parse_fd_map(&stdout); @@ -690,14 +690,7 @@ fn pfiles_falls_back_to_sockprotoname_xattr_for_unknown_socket_family() { } } - let output = common::run_ptool( - "pfiles", - &[], - "examples/pfiles_af_alg", - &[&status_path], - &[], - false, - ); + let output = common::run_ptool("pfiles", &[], "pfiles_af_alg", &[&status_path], &[], false); assert!( output.status.success(), @@ -728,7 +721,7 @@ fn pfiles_falls_back_to_sockprotoname_xattr_for_unknown_socket_family() { #[test] fn pfiles_matrix_covers_file_types_and_socket_families() { - let output = common::run_ptool("pfiles", &[], "examples/pfiles_matrix", &[], &[], false); + let output = common::run_ptool("pfiles", &[], "pfiles_matrix", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let fd_map = parse_fd_map(&stdout); @@ -898,14 +891,7 @@ fn pfiles_matrix_covers_file_types_and_socket_families() { #[test] fn pfiles_matrix_unix_socket() { - let output = common::run_ptool( - "pfiles", - &[], - "examples/pfiles_matrix_unix_socket", - &[], - &[], - false, - ); + let output = common::run_ptool("pfiles", &[], "pfiles_matrix_unix_socket", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let fd_map = parse_fd_map(&stdout); @@ -939,7 +925,7 @@ fn pfiles_matrix_file_and_symlink_paths() { let output = common::run_ptool( "pfiles", &[], - "examples/pfiles_matrix_file_link", + "pfiles_matrix_file_link", &[matrix_file_path.as_str(), matrix_link_path.as_str()], &[], false, @@ -996,7 +982,7 @@ fn pfiles_reports_socket_options_when_target_is_child_of_inspector() { let output = common::run_ptool( "pfiles", &[], - "examples/pfiles_sockopts_parent", + "pfiles_sockopts_parent", &["--child"], &[], false, @@ -1049,14 +1035,7 @@ fn pfiles_reports_socket_options_when_target_is_child_of_inspector() { #[test] fn pfiles_exits_nonzero_when_any_pid_fails() { - let output = common::run_ptool( - "pfiles", - &["999999999"], - "examples/pargs_penv", - &[], - &[], - false, - ); + let output = common::run_ptool("pfiles", &["999999999"], "pargs_penv", &[], &[], false); assert!(!output.status.success()); let stderr = String::from_utf8_lossy(&output.stderr); diff --git a/tests/plgrp_test.rs b/tests/plgrp_test.rs index 0d34a16..25ce90e 100644 --- a/tests/plgrp_test.rs +++ b/tests/plgrp_test.rs @@ -18,7 +18,7 @@ mod common; #[test] fn plgrp_shows_home_node_for_all_threads() { - let output = common::run_ptool("plgrp", &[], "examples/plgrp_process", &[], &[], false); + let output = common::run_ptool("plgrp", &[], "plgrp_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); // Header line should contain NODE. @@ -52,7 +52,7 @@ fn plgrp_shows_single_thread_with_tid() { use std::process::Stdio; let ready = common::ReadySignal::new(false); - let mut example_cmd = Command::new(common::find_exec("examples/plgrp_process")); + let mut example_cmd = Command::new(common::find_exec("plgrp_process")); example_cmd .stdin(Stdio::null()) .stderr(Stdio::inherit()) @@ -85,14 +85,7 @@ fn plgrp_shows_single_thread_with_tid() { #[test] fn plgrp_affinity_flag_shows_affinity_column() { - let output = common::run_ptool( - "plgrp", - &["-a", "all"], - "examples/plgrp_process", - &[], - &[], - false, - ); + let output = common::run_ptool("plgrp", &["-a", "all"], "plgrp_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let header = stdout.lines().next().expect("expected header line"); @@ -115,7 +108,7 @@ fn plgrp_error_for_nonexistent_pid() { let output = common::run_ptool( "plgrp", &["999999999", "__NO_PID__"], - "examples/plgrp_process", + "plgrp_process", &[], &[], false, diff --git a/tests/plimit_test.rs b/tests/plimit_test.rs index 078f53d..9c3c610 100644 --- a/tests/plimit_test.rs +++ b/tests/plimit_test.rs @@ -18,7 +18,7 @@ mod common; #[test] fn plimit_displays_resource_limits() { - let output = common::run_ptool("plimit", &[], "examples/plimit_process", &[], &[], false); + let output = common::run_ptool("plimit", &[], "plimit_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); assert!( @@ -55,7 +55,7 @@ fn plimit_reports_known_nofile_limit() { let output = common::run_ptool( "plimit", &[], - "examples/plimit_process", + "plimit_process", &[], &[ ("PTOOLS_TEST_SET_RLIMIT_NOFILE_SOFT", "123"), @@ -82,14 +82,7 @@ fn plimit_reports_known_nofile_limit() { #[test] fn plimit_k_flag_shows_kilobytes() { - let output = common::run_ptool( - "plimit", - &["-k"], - "examples/plimit_process", - &[], - &[], - false, - ); + let output = common::run_ptool("plimit", &["-k"], "plimit_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let file_line = stdout @@ -113,14 +106,7 @@ fn plimit_k_flag_shows_kilobytes() { #[test] fn plimit_m_flag_shows_megabytes() { - let output = common::run_ptool( - "plimit", - &["-m"], - "examples/plimit_process", - &[], - &[], - false, - ); + let output = common::run_ptool("plimit", &["-m"], "plimit_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); for name in &["file", "data", "stack", "coredump", "vmemory"] { @@ -140,7 +126,7 @@ fn plimit_k_flag_converts_stack_bytes_to_kilobytes() { let output = common::run_ptool( "plimit", &["-k"], - "examples/plimit_process", + "plimit_process", &[], &[ ("PTOOLS_TEST_SET_RLIMIT_STACK_SOFT", "10485760"), @@ -164,14 +150,7 @@ fn plimit_k_flag_converts_stack_bytes_to_kilobytes() { #[test] fn plimit_rejects_missing_pid() { - let output = common::run_ptool( - "plimit", - &["__NO_PID__"], - "examples/plimit_process", - &[], - &[], - false, - ); + let output = common::run_ptool("plimit", &["__NO_PID__"], "plimit_process", &[], &[], false); let stderr = String::from_utf8_lossy(&output.stderr); assert!( !output.status.success(), @@ -188,7 +167,7 @@ fn plimit_rejects_invalid_pid() { let output = common::run_ptool( "plimit", &["__NO_PID__", "not_a_pid"], - "examples/plimit_process", + "plimit_process", &[], &[], false, diff --git a/tests/psig_test.rs b/tests/psig_test.rs index 5b3a71b..d16a1ea 100644 --- a/tests/psig_test.rs +++ b/tests/psig_test.rs @@ -25,7 +25,7 @@ fn find_line_for_signal<'a>(stdout: &'a str, name: &str) -> &'a str { #[test] fn psig_reports_default_ignored_and_caught_actions() { - let output = common::run_ptool("psig", &[], "examples/psig_signals", &[], &[], false); + let output = common::run_ptool("psig", &[], "psig_signals", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let mut lines = stdout.lines(); diff --git a/tests/pstack_test.rs b/tests/pstack_test.rs index 000cfa4..115642a 100644 --- a/tests/pstack_test.rs +++ b/tests/pstack_test.rs @@ -18,7 +18,7 @@ mod common; #[test] fn pstack_prints_stack_trace() { - let output = common::run_ptool("pstack", &[], "examples/pstack_process", &[], &[], false); + let output = common::run_ptool("pstack", &[], "pstack_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let mut lines = stdout.lines(); @@ -51,14 +51,7 @@ fn pstack_prints_stack_trace() { #[test] fn pstack_module_flag_shows_module_paths() { - let output = common::run_ptool( - "pstack", - &["-m"], - "examples/pstack_process", - &[], - &[], - false, - ); + let output = common::run_ptool("pstack", &["-m"], "pstack_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let frame_lines: Vec<&str> = stdout @@ -84,14 +77,7 @@ fn pstack_module_flag_shows_module_paths() { ignore = "optimized builds may inline source locations" )] fn pstack_verbose_shows_source_locations() { - let output = common::run_ptool( - "pstack", - &["-v"], - "examples/pstack_process", - &[], - &[], - false, - ); + let output = common::run_ptool("pstack", &["-v"], "pstack_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let frame_lines: Vec<&str> = stdout @@ -115,14 +101,7 @@ fn pstack_verbose_shows_source_locations() { #[test] fn pstack_n_limits_frame_count() { - let output = common::run_ptool( - "pstack", - &["-n", "2"], - "examples/pstack_process", - &[], - &[], - false, - ); + let output = common::run_ptool("pstack", &["-n", "2"], "pstack_process", &[], &[], false); assert!(output.status.success(), "pstack should exit 0"); let stdout = String::from_utf8_lossy(&output.stdout).into_owned(); diff --git a/tests/pstop_prun_test.rs b/tests/pstop_prun_test.rs index bd4b5da..fc15bfd 100644 --- a/tests/pstop_prun_test.rs +++ b/tests/pstop_prun_test.rs @@ -56,7 +56,7 @@ fn wait_for_state(pid: u32, expected: &[char], timeout_ms: u64) -> char { #[test] fn pstop_stops_a_running_process() { let ready = ReadySignal::new(false); - let mut example_cmd = Command::new(find_exec("examples/pstop_prun_process")); + let mut example_cmd = Command::new(find_exec("pstop_prun_process")); example_cmd .stdin(Stdio::null()) .stderr(Stdio::inherit()) @@ -97,7 +97,7 @@ fn pstop_stops_a_running_process() { #[test] fn prun_resumes_a_stopped_process() { let ready = ReadySignal::new(false); - let mut example_cmd = Command::new(find_exec("examples/pstop_prun_process")); + let mut example_cmd = Command::new(find_exec("pstop_prun_process")); example_cmd .stdin(Stdio::null()) .stderr(Stdio::inherit()) diff --git a/tests/ptime_test.rs b/tests/ptime_test.rs index 60f146f..268ba1b 100644 --- a/tests/ptime_test.rs +++ b/tests/ptime_test.rs @@ -184,7 +184,7 @@ fn ptime_snapshot_reports_timing() { let output = common::run_ptool( "ptime", &["-p", "__PID__"], - "examples/pcred_process", + "pcred_process", &[], &[], false, diff --git a/tests/ptree_test.rs b/tests/ptree_test.rs index 36d168b..ce35498 100644 --- a/tests/ptree_test.rs +++ b/tests/ptree_test.rs @@ -94,7 +94,7 @@ fn ptree_shows_parent_and_child_with_arguments() { let output = common::run_ptool( "ptree", &[], - "examples/ptree_parent_child", + "ptree_parent_child", &[parent_arg, child_arg], &[], true, @@ -191,7 +191,7 @@ fn ptree_accepts_username_operand() { let output = common::run_ptool( "ptree", &[username.as_str(), "__NO_PID__"], - "examples/ptree_parent_child", + "ptree_parent_child", &[parent_arg, child_arg], &[], true, @@ -218,7 +218,7 @@ fn ptree_truncates_lines_to_columns_width() { let child_arg = "TRUNCATION_TEST_CHILD_LONG_ARGUMENT"; let ready = common::ReadySignal::new(true); - let mut example_cmd = Command::new(common::find_exec("examples/ptree_parent_child")); + let mut example_cmd = Command::new(common::find_exec("ptree_parent_child")); example_cmd .args([parent_arg, child_arg]) .stdin(Stdio::null()) @@ -264,7 +264,7 @@ fn ptree_wrap_flag_disables_truncation() { let child_arg = "WRAP_TEST_CHILD"; let ready = common::ReadySignal::new(true); - let mut example_cmd = Command::new(common::find_exec("examples/ptree_parent_child")); + let mut example_cmd = Command::new(common::find_exec("ptree_parent_child")); example_cmd .args([parent_arg, child_arg]) .stdin(Stdio::null()) @@ -314,7 +314,7 @@ fn ptree_accepts_mixed_pid_and_user_operands() { let output = common::run_ptool( "ptree", &["__PID__", username.as_str()], - "examples/ptree_parent_child", + "ptree_parent_child", &[parent_arg, child_arg], &[], true, diff --git a/tests/pwait_test.rs b/tests/pwait_test.rs index 6908c87..d2f95c9 100644 --- a/tests/pwait_test.rs +++ b/tests/pwait_test.rs @@ -29,7 +29,7 @@ use common::ReadySignal; /// Returns the child and the ReadySignal for cleanup. fn spawn_example(env: &[(&str, &str)]) -> (std::process::Child, ReadySignal) { let ready = ReadySignal::new(false); - let mut cmd = Command::new(find_exec("examples/pwait_process")); + let mut cmd = Command::new(find_exec("pwait_process")); cmd.stdin(Stdio::null()) .stderr(Stdio::inherit()) .stdout(Stdio::inherit()) @@ -205,7 +205,7 @@ fn pwait_mixed_valid_and_invalid_exits_nonzero() { fn pwait_already_exited_process() { // Spawn a process that exits almost immediately. let ready = ReadySignal::new(false); - let mut cmd = Command::new(find_exec("examples/pwait_process")); + let mut cmd = Command::new(find_exec("pwait_process")); cmd.stdin(Stdio::null()) .stderr(Stdio::inherit()) .stdout(Stdio::inherit()) From 8322481a7df6c15957f108eded512b0a5a9153b9 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Wed, 11 Mar 2026 17:49:40 -0700 Subject: [PATCH 2/2] Add test_ prefix to test helper binary names Distinguishes test helper binaries from the real tool binaries and allows using a single glob pattern (src/bin/test_*.rs) in package.exclude. Also updates the pfiles peer name expectation to account for Linux comm truncation to 15 characters. Co-Authored-By: Claude Opus 4.6 --- Cargo.toml | 20 +--------- src/bin/{pargs_penv.rs => test_pargs_penv.rs} | 0 ...pcred_process.rs => test_pcred_process.rs} | 0 .../{penv_setenv.rs => test_penv_setenv.rs} | 0 ...pfiles_af_alg.rs => test_pfiles_af_alg.rs} | 0 .../{pfiles_epoll.rs => test_pfiles_epoll.rs} | 0 ...pfiles_matrix.rs => test_pfiles_matrix.rs} | 0 ...ink.rs => test_pfiles_matrix_file_link.rs} | 0 ...t.rs => test_pfiles_matrix_unix_socket.rs} | 0 ...iles_netlink.rs => test_pfiles_netlink.rs} | 0 ...rent.rs => test_pfiles_sockopts_parent.rs} | 2 +- ...plgrp_process.rs => test_plgrp_process.rs} | 0 ...imit_process.rs => test_plimit_process.rs} | 0 .../{psig_signals.rs => test_psig_signals.rs} | 0 ...tack_process.rs => test_pstack_process.rs} | 0 ..._process.rs => test_pstop_prun_process.rs} | 0 ...nt_child.rs => test_ptree_parent_child.rs} | 0 ...pwait_process.rs => test_pwait_process.rs} | 0 tests/pargs_penv_test.rs | 36 ++++++++++++----- tests/pcred_test.rs | 6 +-- tests/pfiles_test.rs | 40 +++++++++++++------ tests/plgrp_test.rs | 15 +++++-- tests/plimit_test.rs | 21 ++++++---- tests/psig_test.rs | 4 +- tests/pstack_test.rs | 17 +++++--- tests/pstop_prun_test.rs | 4 +- tests/ptime_test.rs | 2 +- tests/ptree_test.rs | 10 ++--- tests/pwait_test.rs | 4 +- 29 files changed, 106 insertions(+), 75 deletions(-) rename src/bin/{pargs_penv.rs => test_pargs_penv.rs} (100%) rename src/bin/{pcred_process.rs => test_pcred_process.rs} (100%) rename src/bin/{penv_setenv.rs => test_penv_setenv.rs} (100%) rename src/bin/{pfiles_af_alg.rs => test_pfiles_af_alg.rs} (100%) rename src/bin/{pfiles_epoll.rs => test_pfiles_epoll.rs} (100%) rename src/bin/{pfiles_matrix.rs => test_pfiles_matrix.rs} (100%) rename src/bin/{pfiles_matrix_file_link.rs => test_pfiles_matrix_file_link.rs} (100%) rename src/bin/{pfiles_matrix_unix_socket.rs => test_pfiles_matrix_unix_socket.rs} (100%) rename src/bin/{pfiles_netlink.rs => test_pfiles_netlink.rs} (100%) rename src/bin/{pfiles_sockopts_parent.rs => test_pfiles_sockopts_parent.rs} (97%) rename src/bin/{plgrp_process.rs => test_plgrp_process.rs} (100%) rename src/bin/{plimit_process.rs => test_plimit_process.rs} (100%) rename src/bin/{psig_signals.rs => test_psig_signals.rs} (100%) rename src/bin/{pstack_process.rs => test_pstack_process.rs} (100%) rename src/bin/{pstop_prun_process.rs => test_pstop_prun_process.rs} (100%) rename src/bin/{ptree_parent_child.rs => test_ptree_parent_child.rs} (100%) rename src/bin/{pwait_process.rs => test_pwait_process.rs} (100%) diff --git a/Cargo.toml b/Cargo.toml index 6558717..d6dcfcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,25 +9,7 @@ repository = "https://github.com/basil/ptools" license = "Apache-2.0" keywords = ["linux", "process", "procfs", "debugging", "cli"] categories = ["command-line-utilities", "development-tools::debugging"] -exclude = [ - "src/bin/pargs_penv.rs", - "src/bin/pcred_process.rs", - "src/bin/penv_setenv.rs", - "src/bin/pfiles_af_alg.rs", - "src/bin/pfiles_epoll.rs", - "src/bin/pfiles_matrix.rs", - "src/bin/pfiles_matrix_file_link.rs", - "src/bin/pfiles_matrix_unix_socket.rs", - "src/bin/pfiles_netlink.rs", - "src/bin/pfiles_sockopts_parent.rs", - "src/bin/plgrp_process.rs", - "src/bin/plimit_process.rs", - "src/bin/psig_signals.rs", - "src/bin/pstack_process.rs", - "src/bin/pstop_prun_process.rs", - "src/bin/ptree_parent_child.rs", - "src/bin/pwait_process.rs", -] +exclude = ["src/bin/test_*.rs"] [lints.clippy] uninlined_format_args = "warn" diff --git a/src/bin/pargs_penv.rs b/src/bin/test_pargs_penv.rs similarity index 100% rename from src/bin/pargs_penv.rs rename to src/bin/test_pargs_penv.rs diff --git a/src/bin/pcred_process.rs b/src/bin/test_pcred_process.rs similarity index 100% rename from src/bin/pcred_process.rs rename to src/bin/test_pcred_process.rs diff --git a/src/bin/penv_setenv.rs b/src/bin/test_penv_setenv.rs similarity index 100% rename from src/bin/penv_setenv.rs rename to src/bin/test_penv_setenv.rs diff --git a/src/bin/pfiles_af_alg.rs b/src/bin/test_pfiles_af_alg.rs similarity index 100% rename from src/bin/pfiles_af_alg.rs rename to src/bin/test_pfiles_af_alg.rs diff --git a/src/bin/pfiles_epoll.rs b/src/bin/test_pfiles_epoll.rs similarity index 100% rename from src/bin/pfiles_epoll.rs rename to src/bin/test_pfiles_epoll.rs diff --git a/src/bin/pfiles_matrix.rs b/src/bin/test_pfiles_matrix.rs similarity index 100% rename from src/bin/pfiles_matrix.rs rename to src/bin/test_pfiles_matrix.rs diff --git a/src/bin/pfiles_matrix_file_link.rs b/src/bin/test_pfiles_matrix_file_link.rs similarity index 100% rename from src/bin/pfiles_matrix_file_link.rs rename to src/bin/test_pfiles_matrix_file_link.rs diff --git a/src/bin/pfiles_matrix_unix_socket.rs b/src/bin/test_pfiles_matrix_unix_socket.rs similarity index 100% rename from src/bin/pfiles_matrix_unix_socket.rs rename to src/bin/test_pfiles_matrix_unix_socket.rs diff --git a/src/bin/pfiles_netlink.rs b/src/bin/test_pfiles_netlink.rs similarity index 100% rename from src/bin/pfiles_netlink.rs rename to src/bin/test_pfiles_netlink.rs diff --git a/src/bin/pfiles_sockopts_parent.rs b/src/bin/test_pfiles_sockopts_parent.rs similarity index 97% rename from src/bin/pfiles_sockopts_parent.rs rename to src/bin/test_pfiles_sockopts_parent.rs index 53aa960..02de911 100644 --- a/src/bin/pfiles_sockopts_parent.rs +++ b/src/bin/test_pfiles_sockopts_parent.rs @@ -57,7 +57,7 @@ fn parent_main() { let ready_path = env::var("PTOOLS_TEST_READY_FILE").expect("PTOOLS_TEST_READY_FILE must be set"); - let mut child = Command::new(find_exec("pfiles_sockopts_parent")) + let mut child = Command::new(find_exec("test_pfiles_sockopts_parent")) .arg("--child") .env("PTOOLS_TEST_READY_FILE", &ready_path) .stdin(Stdio::null()) diff --git a/src/bin/plgrp_process.rs b/src/bin/test_plgrp_process.rs similarity index 100% rename from src/bin/plgrp_process.rs rename to src/bin/test_plgrp_process.rs diff --git a/src/bin/plimit_process.rs b/src/bin/test_plimit_process.rs similarity index 100% rename from src/bin/plimit_process.rs rename to src/bin/test_plimit_process.rs diff --git a/src/bin/psig_signals.rs b/src/bin/test_psig_signals.rs similarity index 100% rename from src/bin/psig_signals.rs rename to src/bin/test_psig_signals.rs diff --git a/src/bin/pstack_process.rs b/src/bin/test_pstack_process.rs similarity index 100% rename from src/bin/pstack_process.rs rename to src/bin/test_pstack_process.rs diff --git a/src/bin/pstop_prun_process.rs b/src/bin/test_pstop_prun_process.rs similarity index 100% rename from src/bin/pstop_prun_process.rs rename to src/bin/test_pstop_prun_process.rs diff --git a/src/bin/ptree_parent_child.rs b/src/bin/test_ptree_parent_child.rs similarity index 100% rename from src/bin/ptree_parent_child.rs rename to src/bin/test_ptree_parent_child.rs diff --git a/src/bin/pwait_process.rs b/src/bin/test_pwait_process.rs similarity index 100% rename from src/bin/pwait_process.rs rename to src/bin/test_pwait_process.rs diff --git a/tests/pargs_penv_test.rs b/tests/pargs_penv_test.rs index e63fb92..1a47bfe 100644 --- a/tests/pargs_penv_test.rs +++ b/tests/pargs_penv_test.rs @@ -41,7 +41,7 @@ fn pargs_matches_started_process_arguments() { "tabs\tinside", ]; - let output = common::run_ptool("pargs", &[], "pargs_penv", &expected_args, &[], false); + let output = common::run_ptool("pargs", &[], "test_pargs_penv", &expected_args, &[], false); let stdout = common::assert_success_and_get_stdout(output); for arg in expected_args { @@ -69,7 +69,14 @@ fn pargs_l_matches_started_process_arguments_as_shell_command_line() { "tabs\tinside", ]; - let output = common::run_ptool("pargs", &["-l"], "pargs_penv", &expected_args, &[], false); + let output = common::run_ptool( + "pargs", + &["-l"], + "test_pargs_penv", + &expected_args, + &[], + false, + ); let stdout = common::assert_success_and_get_stdout(output); let mut lines = stdout.lines(); @@ -82,7 +89,7 @@ fn pargs_l_matches_started_process_arguments_as_shell_command_line() { // pargs -l resolves argv[0] to the real executable path via /proc/[pid]/exe, // so the first token should be the canonical path to the example binary. - let exe_path = common::find_exec("pargs_penv").canonicalize().unwrap(); + let exe_path = common::find_exec("test_pargs_penv").canonicalize().unwrap(); let expected_line = std::iter::once(exe_path.to_str().unwrap()) .chain(expected_args.iter().copied()) .map(shell_quote) @@ -100,7 +107,7 @@ fn penv_matches_started_process_environment() { ("PTOOLS_TEST_UNICODE", "✓"), ]; - let output = common::run_ptool("penv", &[], "pargs_penv", &[], &expected_env, false); + let output = common::run_ptool("penv", &[], "test_pargs_penv", &[], &expected_env, false); let stdout = common::assert_success_and_get_stdout_allow_warnings(output); for (key, value) in expected_env { @@ -122,7 +129,14 @@ fn pargs_e_alias_matches_started_process_environment() { ("PTOOLS_TEST_UNICODE", "✓"), ]; - let output = common::run_ptool("pargs", &["-e"], "pargs_penv", &[], &expected_env, false); + let output = common::run_ptool( + "pargs", + &["-e"], + "test_pargs_penv", + &[], + &expected_env, + false, + ); let stdout = common::assert_success_and_get_stdout_allow_warnings(output); for (key, value) in expected_env { @@ -137,7 +151,7 @@ fn pargs_e_alias_matches_started_process_environment() { #[test] fn pauxv_prints_auxv_entries() { - let output = common::run_ptool("pauxv", &[], "pargs_penv", &[], &[], false); + let output = common::run_ptool("pauxv", &[], "test_pargs_penv", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); assert!( @@ -219,10 +233,10 @@ fn pauxv_prints_auxv_entries() { #[test] fn pargs_x_alias_matches_pauxv_output() { - let pauxv_output = common::run_ptool("pauxv", &[], "pargs_penv", &[], &[], false); + let pauxv_output = common::run_ptool("pauxv", &[], "test_pargs_penv", &[], &[], false); let pauxv_stdout = common::assert_success_and_get_stdout(pauxv_output); - let pargs_output = common::run_ptool("pargs", &["-x"], "pargs_penv", &[], &[], false); + let pargs_output = common::run_ptool("pargs", &["-x"], "test_pargs_penv", &[], &[], false); let pargs_stdout = common::assert_success_and_get_stdout(pargs_output); // Both should contain AT_PAGESZ @@ -257,7 +271,7 @@ fn penv_reflects_runtime_setenv() { let output = common::run_ptool( "penv", &[], - "penv_setenv", + "test_penv_setenv", &[], &[("PTOOLS_TEST_OVERWRITE_VAR", "before")], false, @@ -288,7 +302,7 @@ fn pargs_e_reflects_runtime_setenv() { let output = common::run_ptool( "pargs", &["-e"], - "penv_setenv", + "test_penv_setenv", &[], &[("PTOOLS_TEST_OVERWRITE_VAR", "before")], false, @@ -312,7 +326,7 @@ fn pargs_e_reflects_runtime_setenv() { #[test] fn pargs_x_prints_auxv_entries() { - let output = common::run_ptool("pargs", &["-x"], "pargs_penv", &[], &[], false); + let output = common::run_ptool("pargs", &["-x"], "test_pargs_penv", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); assert!( diff --git a/tests/pcred_test.rs b/tests/pcred_test.rs index 12bdf0a..74c330a 100644 --- a/tests/pcred_test.rs +++ b/tests/pcred_test.rs @@ -18,7 +18,7 @@ mod common; #[test] fn pcred_reports_condensed_credentials() { - let output = common::run_ptool("pcred", &[], "pcred_process", &[], &[], false); + let output = common::run_ptool("pcred", &[], "test_pcred_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let mut lines = stdout.lines(); @@ -39,7 +39,7 @@ fn pcred_reports_condensed_credentials() { #[test] fn pcred_all_flag_shows_separate_credentials() { - let output = common::run_ptool("pcred", &["-a"], "pcred_process", &[], &[], false); + let output = common::run_ptool("pcred", &["-a"], "test_pcred_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let mut lines = stdout.lines(); @@ -90,7 +90,7 @@ fn pcred_reports_groups_when_supplementary_groups_exist() { // The default mode may suppress the groups line if there is only one group // matching rgid, so verify with -a which shows groups unconditionally. - let output = common::run_ptool("pcred", &["-a"], "pcred_process", &[], &[], false); + let output = common::run_ptool("pcred", &["-a"], "test_pcred_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); assert!( diff --git a/tests/pfiles_test.rs b/tests/pfiles_test.rs index e55f2eb..d5f0f23 100644 --- a/tests/pfiles_test.rs +++ b/tests/pfiles_test.rs @@ -500,7 +500,7 @@ fn pfiles_prints_header_lines() { let output = common::run_ptool( "pfiles", &[], - "pargs_penv", + "test_pargs_penv", &[], &[ ("PTOOLS_TEST_SET_RLIMIT_NOFILE_SOFT", "123"), @@ -534,7 +534,7 @@ fn pfiles_prints_header_lines() { #[test] fn pfiles_reports_epoll_anon_inode() { - let output = common::run_ptool("pfiles", &[], "pfiles_epoll", &[], &[], false); + let output = common::run_ptool("pfiles", &[], "test_pfiles_epoll", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let fd_map = parse_fd_map(&stdout); @@ -553,7 +553,7 @@ fn pfiles_reports_epoll_anon_inode() { #[test] fn pfiles_non_verbose_mode_prints_fstat_only_descriptor_lines() { - let output = common::run_ptool("pfiles", &["-n"], "pfiles_epoll", &[], &[], false); + let output = common::run_ptool("pfiles", &["-n"], "test_pfiles_epoll", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let fd_map = parse_fd_map(&stdout); @@ -585,7 +585,7 @@ fn pfiles_non_verbose_mode_prints_fstat_only_descriptor_lines() { fn pfiles_resolves_socket_metadata_for_target_net_namespace() { let ready = common::ReadySignal::new(false); - let example = common::find_exec("pfiles_netlink"); + let example = common::find_exec("test_pfiles_netlink"); let mut unshare_cmd = Command::new("unshare"); unshare_cmd .arg("--net") @@ -652,7 +652,7 @@ fn pfiles_resolves_socket_metadata_for_target_net_namespace() { #[test] fn pfiles_reports_netlink_socket() { - let output = common::run_ptool("pfiles", &[], "pfiles_netlink", &[], &[], false); + let output = common::run_ptool("pfiles", &[], "test_pfiles_netlink", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let fd_map = parse_fd_map(&stdout); @@ -690,7 +690,14 @@ fn pfiles_falls_back_to_sockprotoname_xattr_for_unknown_socket_family() { } } - let output = common::run_ptool("pfiles", &[], "pfiles_af_alg", &[&status_path], &[], false); + let output = common::run_ptool( + "pfiles", + &[], + "test_pfiles_af_alg", + &[&status_path], + &[], + false, + ); assert!( output.status.success(), @@ -721,7 +728,7 @@ fn pfiles_falls_back_to_sockprotoname_xattr_for_unknown_socket_family() { #[test] fn pfiles_matrix_covers_file_types_and_socket_families() { - let output = common::run_ptool("pfiles", &[], "pfiles_matrix", &[], &[], false); + let output = common::run_ptool("pfiles", &[], "test_pfiles_matrix", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let fd_map = parse_fd_map(&stdout); @@ -853,7 +860,7 @@ fn pfiles_matrix_covers_file_types_and_socket_families() { "expected exactly one IPv4 listening socket block" ); - let inet_peer_expected = "S_IFSOCK mode:0777 dev: ino: uid: gid: size:\n O_RDWR|O_CLOEXEC\n SOCK_STREAM\n SO_SNDBUF(),SO_RCVBUF()\n sockname: AF_INET 127.0.0.1 port: \n peer: pfiles_matrix[]\n peername: AF_INET 127.0.0.1 port: \n state: TCP_ESTABLISHED"; + let inet_peer_expected = "S_IFSOCK mode:0777 dev: ino: uid: gid: size:\n O_RDWR|O_CLOEXEC\n SOCK_STREAM\n SO_SNDBUF(),SO_RCVBUF()\n sockname: AF_INET 127.0.0.1 port: \n peer: test_pfiles_mat[]\n peername: AF_INET 127.0.0.1 port: \n state: TCP_ESTABLISHED"; assert!( count_normalized_blocks_ignoring_tcp_details(&fd_map, inet_peer_expected) >= 1, "expected at least one IPv4 established socket block" @@ -868,7 +875,7 @@ fn pfiles_matrix_covers_file_types_and_socket_families() { "expected exactly one IPv6 listening socket block" ); - let inet6_peer_expected = "S_IFSOCK mode:0777 dev: ino: uid: gid: size:\n O_RDWR|O_CLOEXEC\n SOCK_STREAM\n SO_SNDBUF(),SO_RCVBUF()\n sockname: AF_INET6 ::1 port: \n peer: pfiles_matrix[]\n peername: AF_INET6 ::1 port: \n state: TCP_ESTABLISHED"; + let inet6_peer_expected = "S_IFSOCK mode:0777 dev: ino: uid: gid: size:\n O_RDWR|O_CLOEXEC\n SOCK_STREAM\n SO_SNDBUF(),SO_RCVBUF()\n sockname: AF_INET6 ::1 port: \n peer: test_pfiles_mat[]\n peername: AF_INET6 ::1 port: \n state: TCP_ESTABLISHED"; assert!( count_normalized_blocks_ignoring_tcp_details(&fd_map, inet6_peer_expected) >= 1, "expected at least one IPv6 established socket block" @@ -891,7 +898,14 @@ fn pfiles_matrix_covers_file_types_and_socket_families() { #[test] fn pfiles_matrix_unix_socket() { - let output = common::run_ptool("pfiles", &[], "pfiles_matrix_unix_socket", &[], &[], false); + let output = common::run_ptool( + "pfiles", + &[], + "test_pfiles_matrix_unix_socket", + &[], + &[], + false, + ); let stdout = common::assert_success_and_get_stdout(output); let fd_map = parse_fd_map(&stdout); @@ -925,7 +939,7 @@ fn pfiles_matrix_file_and_symlink_paths() { let output = common::run_ptool( "pfiles", &[], - "pfiles_matrix_file_link", + "test_pfiles_matrix_file_link", &[matrix_file_path.as_str(), matrix_link_path.as_str()], &[], false, @@ -982,7 +996,7 @@ fn pfiles_reports_socket_options_when_target_is_child_of_inspector() { let output = common::run_ptool( "pfiles", &[], - "pfiles_sockopts_parent", + "test_pfiles_sockopts_parent", &["--child"], &[], false, @@ -1035,7 +1049,7 @@ fn pfiles_reports_socket_options_when_target_is_child_of_inspector() { #[test] fn pfiles_exits_nonzero_when_any_pid_fails() { - let output = common::run_ptool("pfiles", &["999999999"], "pargs_penv", &[], &[], false); + let output = common::run_ptool("pfiles", &["999999999"], "test_pargs_penv", &[], &[], false); assert!(!output.status.success()); let stderr = String::from_utf8_lossy(&output.stderr); diff --git a/tests/plgrp_test.rs b/tests/plgrp_test.rs index 25ce90e..28024b3 100644 --- a/tests/plgrp_test.rs +++ b/tests/plgrp_test.rs @@ -18,7 +18,7 @@ mod common; #[test] fn plgrp_shows_home_node_for_all_threads() { - let output = common::run_ptool("plgrp", &[], "plgrp_process", &[], &[], false); + let output = common::run_ptool("plgrp", &[], "test_plgrp_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); // Header line should contain NODE. @@ -52,7 +52,7 @@ fn plgrp_shows_single_thread_with_tid() { use std::process::Stdio; let ready = common::ReadySignal::new(false); - let mut example_cmd = Command::new(common::find_exec("plgrp_process")); + let mut example_cmd = Command::new(common::find_exec("test_plgrp_process")); example_cmd .stdin(Stdio::null()) .stderr(Stdio::inherit()) @@ -85,7 +85,14 @@ fn plgrp_shows_single_thread_with_tid() { #[test] fn plgrp_affinity_flag_shows_affinity_column() { - let output = common::run_ptool("plgrp", &["-a", "all"], "plgrp_process", &[], &[], false); + let output = common::run_ptool( + "plgrp", + &["-a", "all"], + "test_plgrp_process", + &[], + &[], + false, + ); let stdout = common::assert_success_and_get_stdout(output); let header = stdout.lines().next().expect("expected header line"); @@ -108,7 +115,7 @@ fn plgrp_error_for_nonexistent_pid() { let output = common::run_ptool( "plgrp", &["999999999", "__NO_PID__"], - "plgrp_process", + "test_plgrp_process", &[], &[], false, diff --git a/tests/plimit_test.rs b/tests/plimit_test.rs index 9c3c610..25d8f75 100644 --- a/tests/plimit_test.rs +++ b/tests/plimit_test.rs @@ -18,7 +18,7 @@ mod common; #[test] fn plimit_displays_resource_limits() { - let output = common::run_ptool("plimit", &[], "plimit_process", &[], &[], false); + let output = common::run_ptool("plimit", &[], "test_plimit_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); assert!( @@ -55,7 +55,7 @@ fn plimit_reports_known_nofile_limit() { let output = common::run_ptool( "plimit", &[], - "plimit_process", + "test_plimit_process", &[], &[ ("PTOOLS_TEST_SET_RLIMIT_NOFILE_SOFT", "123"), @@ -82,7 +82,7 @@ fn plimit_reports_known_nofile_limit() { #[test] fn plimit_k_flag_shows_kilobytes() { - let output = common::run_ptool("plimit", &["-k"], "plimit_process", &[], &[], false); + let output = common::run_ptool("plimit", &["-k"], "test_plimit_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let file_line = stdout @@ -106,7 +106,7 @@ fn plimit_k_flag_shows_kilobytes() { #[test] fn plimit_m_flag_shows_megabytes() { - let output = common::run_ptool("plimit", &["-m"], "plimit_process", &[], &[], false); + let output = common::run_ptool("plimit", &["-m"], "test_plimit_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); for name in &["file", "data", "stack", "coredump", "vmemory"] { @@ -126,7 +126,7 @@ fn plimit_k_flag_converts_stack_bytes_to_kilobytes() { let output = common::run_ptool( "plimit", &["-k"], - "plimit_process", + "test_plimit_process", &[], &[ ("PTOOLS_TEST_SET_RLIMIT_STACK_SOFT", "10485760"), @@ -150,7 +150,14 @@ fn plimit_k_flag_converts_stack_bytes_to_kilobytes() { #[test] fn plimit_rejects_missing_pid() { - let output = common::run_ptool("plimit", &["__NO_PID__"], "plimit_process", &[], &[], false); + let output = common::run_ptool( + "plimit", + &["__NO_PID__"], + "test_plimit_process", + &[], + &[], + false, + ); let stderr = String::from_utf8_lossy(&output.stderr); assert!( !output.status.success(), @@ -167,7 +174,7 @@ fn plimit_rejects_invalid_pid() { let output = common::run_ptool( "plimit", &["__NO_PID__", "not_a_pid"], - "plimit_process", + "test_plimit_process", &[], &[], false, diff --git a/tests/psig_test.rs b/tests/psig_test.rs index d16a1ea..a486671 100644 --- a/tests/psig_test.rs +++ b/tests/psig_test.rs @@ -25,7 +25,7 @@ fn find_line_for_signal<'a>(stdout: &'a str, name: &str) -> &'a str { #[test] fn psig_reports_default_ignored_and_caught_actions() { - let output = common::run_ptool("psig", &[], "psig_signals", &[], &[], false); + let output = common::run_ptool("psig", &[], "test_psig_signals", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let mut lines = stdout.lines(); @@ -33,7 +33,7 @@ fn psig_reports_default_ignored_and_caught_actions() { .next() .unwrap_or_else(|| panic!("Expected process summary line in psig output:\n{stdout}")); assert!( - summary.contains("psig_signals"), + summary.contains("test_psig_signals"), "Expected summary to contain psig_signals executable path:\n{stdout}" ); diff --git a/tests/pstack_test.rs b/tests/pstack_test.rs index 115642a..429a005 100644 --- a/tests/pstack_test.rs +++ b/tests/pstack_test.rs @@ -18,7 +18,7 @@ mod common; #[test] fn pstack_prints_stack_trace() { - let output = common::run_ptool("pstack", &[], "pstack_process", &[], &[], false); + let output = common::run_ptool("pstack", &[], "test_pstack_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let mut lines = stdout.lines(); @@ -26,7 +26,7 @@ fn pstack_prints_stack_trace() { .next() .unwrap_or_else(|| panic!("Expected process summary line in pstack output:\n{stdout}")); assert!( - summary.contains("pstack_process"), + summary.contains("test_pstack_process"), "Expected summary to contain pstack_process executable name:\n{stdout}" ); @@ -51,7 +51,7 @@ fn pstack_prints_stack_trace() { #[test] fn pstack_module_flag_shows_module_paths() { - let output = common::run_ptool("pstack", &["-m"], "pstack_process", &[], &[], false); + let output = common::run_ptool("pstack", &["-m"], "test_pstack_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let frame_lines: Vec<&str> = stdout @@ -77,7 +77,7 @@ fn pstack_module_flag_shows_module_paths() { ignore = "optimized builds may inline source locations" )] fn pstack_verbose_shows_source_locations() { - let output = common::run_ptool("pstack", &["-v"], "pstack_process", &[], &[], false); + let output = common::run_ptool("pstack", &["-v"], "test_pstack_process", &[], &[], false); let stdout = common::assert_success_and_get_stdout(output); let frame_lines: Vec<&str> = stdout @@ -101,7 +101,14 @@ fn pstack_verbose_shows_source_locations() { #[test] fn pstack_n_limits_frame_count() { - let output = common::run_ptool("pstack", &["-n", "2"], "pstack_process", &[], &[], false); + let output = common::run_ptool( + "pstack", + &["-n", "2"], + "test_pstack_process", + &[], + &[], + false, + ); assert!(output.status.success(), "pstack should exit 0"); let stdout = String::from_utf8_lossy(&output.stdout).into_owned(); diff --git a/tests/pstop_prun_test.rs b/tests/pstop_prun_test.rs index fc15bfd..025b983 100644 --- a/tests/pstop_prun_test.rs +++ b/tests/pstop_prun_test.rs @@ -56,7 +56,7 @@ fn wait_for_state(pid: u32, expected: &[char], timeout_ms: u64) -> char { #[test] fn pstop_stops_a_running_process() { let ready = ReadySignal::new(false); - let mut example_cmd = Command::new(find_exec("pstop_prun_process")); + let mut example_cmd = Command::new(find_exec("test_pstop_prun_process")); example_cmd .stdin(Stdio::null()) .stderr(Stdio::inherit()) @@ -97,7 +97,7 @@ fn pstop_stops_a_running_process() { #[test] fn prun_resumes_a_stopped_process() { let ready = ReadySignal::new(false); - let mut example_cmd = Command::new(find_exec("pstop_prun_process")); + let mut example_cmd = Command::new(find_exec("test_pstop_prun_process")); example_cmd .stdin(Stdio::null()) .stderr(Stdio::inherit()) diff --git a/tests/ptime_test.rs b/tests/ptime_test.rs index 268ba1b..6b21850 100644 --- a/tests/ptime_test.rs +++ b/tests/ptime_test.rs @@ -184,7 +184,7 @@ fn ptime_snapshot_reports_timing() { let output = common::run_ptool( "ptime", &["-p", "__PID__"], - "pcred_process", + "test_pcred_process", &[], &[], false, diff --git a/tests/ptree_test.rs b/tests/ptree_test.rs index ce35498..b97bb0b 100644 --- a/tests/ptree_test.rs +++ b/tests/ptree_test.rs @@ -94,7 +94,7 @@ fn ptree_shows_parent_and_child_with_arguments() { let output = common::run_ptool( "ptree", &[], - "ptree_parent_child", + "test_ptree_parent_child", &[parent_arg, child_arg], &[], true, @@ -191,7 +191,7 @@ fn ptree_accepts_username_operand() { let output = common::run_ptool( "ptree", &[username.as_str(), "__NO_PID__"], - "ptree_parent_child", + "test_ptree_parent_child", &[parent_arg, child_arg], &[], true, @@ -218,7 +218,7 @@ fn ptree_truncates_lines_to_columns_width() { let child_arg = "TRUNCATION_TEST_CHILD_LONG_ARGUMENT"; let ready = common::ReadySignal::new(true); - let mut example_cmd = Command::new(common::find_exec("ptree_parent_child")); + let mut example_cmd = Command::new(common::find_exec("test_ptree_parent_child")); example_cmd .args([parent_arg, child_arg]) .stdin(Stdio::null()) @@ -264,7 +264,7 @@ fn ptree_wrap_flag_disables_truncation() { let child_arg = "WRAP_TEST_CHILD"; let ready = common::ReadySignal::new(true); - let mut example_cmd = Command::new(common::find_exec("ptree_parent_child")); + let mut example_cmd = Command::new(common::find_exec("test_ptree_parent_child")); example_cmd .args([parent_arg, child_arg]) .stdin(Stdio::null()) @@ -314,7 +314,7 @@ fn ptree_accepts_mixed_pid_and_user_operands() { let output = common::run_ptool( "ptree", &["__PID__", username.as_str()], - "ptree_parent_child", + "test_ptree_parent_child", &[parent_arg, child_arg], &[], true, diff --git a/tests/pwait_test.rs b/tests/pwait_test.rs index d2f95c9..30893e4 100644 --- a/tests/pwait_test.rs +++ b/tests/pwait_test.rs @@ -29,7 +29,7 @@ use common::ReadySignal; /// Returns the child and the ReadySignal for cleanup. fn spawn_example(env: &[(&str, &str)]) -> (std::process::Child, ReadySignal) { let ready = ReadySignal::new(false); - let mut cmd = Command::new(find_exec("pwait_process")); + let mut cmd = Command::new(find_exec("test_pwait_process")); cmd.stdin(Stdio::null()) .stderr(Stdio::inherit()) .stdout(Stdio::inherit()) @@ -205,7 +205,7 @@ fn pwait_mixed_valid_and_invalid_exits_nonzero() { fn pwait_already_exited_process() { // Spawn a process that exits almost immediately. let ready = ReadySignal::new(false); - let mut cmd = Command::new(find_exec("pwait_process")); + let mut cmd = Command::new(find_exec("test_pwait_process")); cmd.stdin(Stdio::null()) .stderr(Stdio::inherit()) .stdout(Stdio::inherit())