Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/spark-rsi-mv/blob/main/src/not_run.rs # spark-rsi-mv Native Rust recursive self-improvement engine with paired bootstrap evaluation and cryptographic ledger Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `spark-rsi-mv / src / not_run.rs` 73 lines ยท 3277 bytes Raw Blame History 1 //! Test support: NOT_RUN for tests whose path needs something this host may not offer. 2 //! 3 //! libtest has no runtime skip, so a NOT_RUN test still counts as `ok` in the summary. The 4 //! `NOT_RUN : ...` line on stderr is the record that the test asserted nothing, never a 5 //! pass. The line is written with `std::io::stderr()` rather than `eprintln!`, which libtest 6 //! captures and hides for a test that returns, so a plain `cargo test` shows it. 7 8 use std::io::Write; 9 use std::sync::LazyLock; 10 11 static USER_SCOPE: LazyLock = 12 LazyLock::new(crate::isolation::cargo_sandbox::user_scope_available); 13 14 fn not_run(test: &str, reason: &str) -> bool { 15 let _ = writeln!( 16 std::io::stderr(), 17 "NOT_RUN {test}: {reason}; nothing was asserted" 18 ); 19 false 20 } 21 22 /// For a test whose path starts a transient systemd user scope (`systemd-run --user --scope`, 23 /// `isolation::cargo_sandbox`). Without a reachable user manager (no user bus, for example in a 24 /// container whose pid 1 is not systemd) every such launch fails closed, so the test would fail 25 /// for a reason that says nothing about the code, or a refusal test would pass without the 26 /// sandbox ever running. True when the scope starts; otherwise reports NOT_RUN and returns 27 /// false, and the caller returns before doing anything. With `RSI_REQUIRE_USER_SCOPE` set a 28 /// missing user manager is a failure instead; the Spark test gate (`tests/gates/run.sh test`) 29 /// sets it. 30 pub fn user_scope_or_not_run(test: &str) -> bool { 31 if *USER_SCOPE { 32 return true; 33 } 34 assert!( 35 std::env::var_os("RSI_REQUIRE_USER_SCOPE").is_none(), 36 "RSI_REQUIRE_USER_SCOPE is set but `systemd-run --user --scope` cannot start here" 37 ); 38 not_run( 39 test, 40 "no reachable systemd user manager (`systemd-run --user --scope` failed), so the \ 41 sandboxed path cannot start", 42 ) 43 } 44 45 /// For a test that compiles and runs CUDA on the GPU. GPU tests are opt-in: they run only with 46 /// `SPARK_RSI_GPU_TESTS=1`, set by an operator inside an authorized GPU window, and otherwise 47 /// report NOT_RUN, whatever hardware is present. Once opted in, a missing `nvcc` or an NVIDIA 48 /// device this process cannot open is a failure, not a skip. 49 pub fn gpu_or_not_run(test: &str) -> bool { 50 if std::env::var("SPARK_RSI_GPU_TESTS").as_deref() != Ok("1") { 51 return not_run( 52 test, 53 "GPU tests are opt-in (set SPARK_RSI_GPU_TESTS=1 inside an authorized GPU window)", 54 ); 55 } 56 let nvcc = std::process::Command::new("nvcc") 57 .arg("--version") 58 .output() 59 .is_ok_and(|o| o.status.success()) 60 || std::path::Path::new("/usr/local/cuda/bin/nvcc").exists(); 61 assert!(nvcc, "SPARK_RSI_GPU_TESTS=1 but nvcc is not available"); 62 // The device nodes can exist yet be closed to this process (a sandbox with a closed device 63 // policy, or a user outside the video group). Only a device we can open counts as a GPU. 64 for dev in ["/dev/nvidiactl", "/dev/nvidia0"] { 65 let open = std::fs::OpenOptions::new().read(true).write(true).open(dev); 66 assert!( 67 open.is_ok(), 68 "SPARK_RSI_GPU_TESTS=1 but {dev} cannot be opened: {:?}", 69 open.err() 70 ); 71 } 72 true 73 }