aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-cli / tests / cpu_only_switch_test.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | //! sc#384 preflight: `AIEN_BACKEND=cpu` on a real `aien daemon` process. |
| 17 | //! Whatever the build, the daemon never reports the GB10 backend: |
| 18 | //! - GPU-capable build: refuses to start with the named error `CPU_ONLY_BUT_GPU_BUILD` |
| 19 | //! (before any model load or GPU session); |
| 20 | //! - CPU-stub build: the switch is accepted (the CPU backend is the only one possible); |
| 21 | //! here the start is stopped one step later by the approval-desk requirement, with no |
| 22 | //! desk key, so no model is needed and the test never touches the chip. |
| 23 | use std::process::{Command, Stdio}; |
| 24 | |
| 25 | fn run(extra: &[(&str, &str)]) -> (bool, String) { |
| 26 | let tmp = tempfile::Builder::new() |
| 27 | .prefix("co-") |
| 28 | .tempdir_in("/tmp") |
| 29 | .unwrap(); |
| 30 | let root = std::fs::canonicalize(tmp.path()).unwrap(); |
| 31 | for d in ["state", "home", "prov"] { |
| 32 | std::fs::create_dir_all(root.join(d)).unwrap(); |
| 33 | } |
| 34 | let mut c = Command::new(env!("CARGO_BIN_EXE_aien-cli")); |
| 35 | c.current_dir(&root) |
| 36 | .env("HOME", root.join("home")) |
| 37 | .env("NO_COLOR", "1") |
| 38 | .env("AIEN_RUNTIME_SOCK", root.join("s")) |
| 39 | .env("AIEN_RUNTIME_STATE_DIR", root.join("state")) |
| 40 | .env("AIEN_COMPOSE_DIR", root.join("compose")) |
| 41 | .env("AIEN_PROVENANCE_DIR", root.join("prov")) |
| 42 | .env("AIEN_REQUIRE_CHECKPOINT", "0"); |
| 43 | for k in [ |
| 44 | "AIEN_BACKEND", |
| 45 | "AIEN_REQUIRE_BLACKWELL", |
| 46 | "AIEN_GPU_BACKEND", |
| 47 | "AIEN_MODEL_PATH", |
| 48 | "AIEN_TOKENIZER_PATH", |
| 49 | "AIEN_MODEL_DIR", |
| 50 | "AIEN_DEV_FALLBACK", |
| 51 | "AIEN_COMPOSE_AUTHORIZE_REQUIRES_DESK", |
| 52 | ] { |
| 53 | c.env_remove(k); |
| 54 | } |
| 55 | for (k, v) in extra { |
| 56 | c.env(k, v); |
| 57 | } |
| 58 | let out = c |
| 59 | .arg("daemon") |
| 60 | .stdin(Stdio::null()) |
| 61 | .output() |
| 62 | .expect("run daemon"); |
| 63 | let text = format!( |
| 64 | "{}{}", |
| 65 | String::from_utf8_lossy(&out.stdout), |
| 66 | String::from_utf8_lossy(&out.stderr) |
| 67 | ); |
| 68 | (out.status.success(), text) |
| 69 | } |
| 70 | |
| 71 | #[test] |
| 72 | fn cpu_only_daemon_never_reports_gb10() { |
| 73 | let (ok, text) = run(&[("AIEN_BACKEND", "cpu")]); |
| 74 | assert!( |
| 75 | !ok, |
| 76 | "the start must be refused (named error or desk): {text}" |
| 77 | ); |
| 78 | assert!( |
| 79 | !text.contains("OmegaGb10Backend") && !text.contains("sm_121"), |
| 80 | "a CPU-only run reported the GB10 backend: {text}" |
| 81 | ); |
| 82 | if aien_omega_gpu::is_native() { |
| 83 | assert!(text.contains("CPU_ONLY_BUT_GPU_BUILD"), "{text}"); |
| 84 | } else { |
| 85 | assert!(!text.contains("CPU_ONLY_BUT_GPU_BUILD"), "{text}"); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | #[test] |
| 90 | fn force_cpu_stub_alone_is_not_the_runtime_switch() { |
| 91 | let (_ok, text) = run(&[("AIEN_FORCE_CPU_STUB", "1")]); |
| 92 | assert!(!text.contains("CPU_ONLY_BUT_GPU_BUILD"), "{text}"); |
| 93 | } |