diff --git a/tests/cases/README.md b/tests/cases/README.md index 361d21b9..6206caec 100644 --- a/tests/cases/README.md +++ b/tests/cases/README.md @@ -14,3 +14,20 @@ Bare WebAssembly and freestanding targets exclude this case in `cases.toml` because they have no process environment provider. WASI still compiles it; its runtime selector classifies this native-only case as unsupported rather than counting it as executed. + +## Target identities and CPU profiles + +`cases.toml` version 3 separates base architectures in `[supported]` and +`[ci]` from optional processor profiles in `[profiles]` + +Rhea uses the `arm64` base ISA; SHAKTI, XiangShan and T-Head use `riscv64` +These Linux profiles remain disabled until their compiler/runtime contracts exist + +A base target runs `shared`, `shared/`, then `/` +A profile target also inherits `shared/` and `/` +after the corresponding base-architecture suite of each kind + +A supported profile requires an explicit `[[target]]` entry with matching +`os`, base `arch` and `profile` fields, plus an explicit target runner +Profile identity does not imply new compiler target triples or ISA support +Existing CI-enabled base targets and their matrices are unchanged diff --git a/tests/cases/cases.toml b/tests/cases/cases.toml index 61438113..cab7956a 100644 --- a/tests/cases/cases.toml +++ b/tests/cases/cases.toml @@ -1,4 +1,4 @@ -version = 2 +version = 3 # List only existing OS ports or publicly documented porting work. Every listed # cell must appear in both tables; false means planned in Wave, not an invented @@ -13,7 +13,7 @@ version = 2 # Fuchsia RISC-V: https://fuchsia.dev/fuchsia-src/contribute/governance/rfcs/0211_fuchsia_on_risc-v # iOS amd64 is reserved for the simulator, not physical iOS devices (Wave #473). [supported] -linux = { amd64 = true, arm64 = true, riscv64 = true, loong64 = true, rhea = false, shakti = false, xiangshan = false, t-head = false } +linux = { amd64 = true, arm64 = true, riscv64 = true, loong64 = true } macos = { amd64 = true, arm64 = true } windows = { amd64 = true, arm64 = true } freebsd = { amd64 = true, arm64 = true, riscv64 = true } @@ -28,7 +28,7 @@ wasm = { wasm32 = true, wasm64 = true } wasi = { wasm32 = true, wasm64 = false } [ci] -linux = { amd64 = true, arm64 = true, riscv64 = true, loong64 = true, rhea = false, shakti = false, xiangshan = false, t-head = false } +linux = { amd64 = true, arm64 = true, riscv64 = true, loong64 = true } macos = { amd64 = true, arm64 = true } windows = { amd64 = true, arm64 = true } freebsd = { amd64 = true, arm64 = true, riscv64 = true } @@ -42,9 +42,18 @@ ios = { amd64 = false, arm64 = false } wasm = { wasm32 = true, wasm64 = true } wasi = { wasm32 = true, wasm64 = false } +# Processor names are profiles of base ISAs, not architectures or compiler +# targets. They remain disabled until the compiler and runtime support them. +[profiles] +rhea = { os = "linux", arch = "arm64", supported = false, ci = false } +shakti = { os = "linux", arch = "riscv64", supported = false, ci = false } +xiangshan = { os = "linux", arch = "riscv64", supported = false, ci = false } +t-head = { os = "linux", arch = "riscv64", supported = false, ci = false } + # Only supported=true cells need execution details below. Every target gets -# shared, shared/, and / suites automatically. Support=false -# cells become disabled planned targets. +# shared, shared/, and / suites automatically. Profile targets +# also get shared/ and / after the base suites. +# Support=false entries remain disabled planned targets. [[target]] id = "linux-amd64" diff --git a/tools/src/cases.rs b/tools/src/cases.rs index b55ce582..297ea5cc 100644 --- a/tools/src/cases.rs +++ b/tools/src/cases.rs @@ -14,7 +14,9 @@ const CAPABILITIES: &[&str] = pub struct Target { pub id: String, pub os: String, + /// Base ISA, independent of the optional processor profile. pub arch: String, + pub profile: Option, pub executor: String, pub runner: Option, pub group: Option, @@ -29,7 +31,15 @@ pub struct Target { impl Target { pub fn suites(&self) -> Vec { - vec!["shared".into(), format!("shared/{}", self.arch), format!("{}/{}", self.os, self.arch)] + let mut suites = vec!["shared".into(), format!("shared/{}", self.arch)]; + if let Some(profile) = &self.profile { + suites.push(format!("shared/{profile}")); + } + suites.push(format!("{}/{}", self.os, self.arch)); + if let Some(profile) = &self.profile { + suites.push(format!("{}/{profile}", self.os)); + } + suites } pub fn rust_target(&self) -> Result { @@ -62,8 +72,16 @@ impl Target { ("id", Value::string(&self.id)), ("os", Value::string(&self.os)), ("arch", Value::string(&self.arch)), + ("profile", Value::optional_string(self.profile.as_deref())), ("executor", Value::string(&self.executor)), - ("suite", Value::string(format!("{}/{}", self.os, self.arch))), + ( + "suite", + Value::string(format!( + "{}/{}", + self.os, + self.profile.as_deref().unwrap_or(&self.arch) + )), + ), ("suites", Value::strings(self.suites())), ( "status", @@ -94,6 +112,14 @@ pub struct Manifest { pub root: PathBuf, } +#[derive(Debug)] +struct Profile { + os: String, + arch: String, + enabled: bool, + ci: bool, +} + fn name(value: &str) -> bool { !value.is_empty() && value.bytes().enumerate().all(|(i, b)| { @@ -162,8 +188,11 @@ fn matrix(value: &toml::Value, key: &str) -> Result Result, +) -> Result> { + let table = data + .get("profiles") + .and_then(toml::Value::as_table) + .ok_or_else(|| error("missing [profiles] table"))?; + let mut result = BTreeMap::new(); + for (profile, fields) in table { + let base_arch = match profile.as_str() { + "rhea" => "arm64", + "shakti" | "xiangshan" | "t-head" => "riscv64", + _ => return Err(error(format!("unknown CPU profile: {profile}"))), + }; + let fields = + fields.as_table().ok_or_else(|| error(format!("invalid CPU profile: {profile}")))?; + if fields.keys().any(|key| !matches!(key.as_str(), "os" | "arch" | "supported" | "ci")) { + return Err(error(format!("unknown field in CPU profile: {profile}"))); + } + let os = required(fields, "os")?; + let arch = required(fields, "arch")?; + let enabled = fields + .get("supported") + .and_then(toml::Value::as_bool) + .ok_or_else(|| error(format!("missing boolean support for profile: {profile}")))?; + let ci = fields + .get("ci") + .and_then(toml::Value::as_bool) + .ok_or_else(|| error(format!("missing boolean CI for profile: {profile}")))?; + if os != "linux" + || arch != base_arch + || !supported.contains_key(&(os.clone(), arch.clone())) + || enabled && !supported[&(os.clone(), arch.clone())] + || ci && !enabled + { + return Err(error(format!( + "invalid base architecture or status for profile: {profile}" + ))); + } + result.insert(profile.clone(), Profile { os, arch, enabled, ci }); + } + Ok(result) +} + impl Manifest { pub fn load(root: &Path, validate_layout: bool) -> Result { Self::parse( @@ -186,10 +260,9 @@ impl Manifest { pub fn parse(text: &str, root: PathBuf, validate_layout: bool) -> Result { let data: toml::Value = text.parse()?; let table = data.as_table().ok_or_else(|| error("manifest must be a table"))?; - if table - .keys() - .any(|key| !matches!(key.as_str(), "version" | "supported" | "ci" | "target")) - || data.get("version").and_then(toml::Value::as_integer) != Some(2) + if table.keys().any(|key| { + !matches!(key.as_str(), "version" | "supported" | "ci" | "profiles" | "target") + }) || data.get("version").and_then(toml::Value::as_integer) != Some(3) { return Err(error("unknown manifest fields or unsupported version")); } @@ -198,6 +271,7 @@ impl Manifest { if supported.keys().ne(ci.keys()) || supported.iter().any(|(k, v)| ci[k] && !*v) { return Err(error("support/CI matrices disagree")); } + let profiles = profiles(&data, &supported)?; let mut targets = Vec::new(); let mut configured = BTreeSet::new(); let mut ids = BTreeSet::new(); @@ -212,6 +286,7 @@ impl Manifest { k.as_str(), "id" | "os" | "arch" + | "profile" | "executor" | "runner" | "ci_group" @@ -227,11 +302,25 @@ impl Manifest { let id = required(raw, "id")?; let os = required(raw, "os")?; let arch = required(raw, "arch")?; + let profile = optional(raw, "profile")?; let pair = (os.clone(), arch.clone()); + let (enabled, target_ci) = if let Some(profile_name) = &profile { + let defined = profiles + .get(profile_name) + .ok_or_else(|| error(format!("unknown CPU profile: {profile_name}")))?; + if defined.os != os || defined.arch != arch { + return Err(error(format!( + "profile {profile_name} does not match target {id} base architecture" + ))); + } + (defined.enabled, defined.ci) + } else { + (supported.get(&pair) == Some(&true), ci.get(&pair).copied().unwrap_or(false)) + }; if !name(&id) || !ids.insert(id.clone()) - || !configured.insert(pair.clone()) - || supported.get(&pair) != Some(&true) + || !configured.insert((os.clone(), arch.clone(), profile.clone())) + || !enabled { return Err(error(format!("invalid/duplicate/unsupported target {id}"))); } @@ -240,6 +329,7 @@ impl Manifest { id, os, arch, + profile, executor, runner: optional(raw, "runner")?, group: optional(raw, "ci_group")?, @@ -249,7 +339,7 @@ impl Manifest { exclude: strings(raw, "exclude")?, capabilities: strings(raw, "capabilities")?, enabled: true, - ci: ci[&pair], + ci: target_ci, }; if !["native", "compile", "qemu", "wasm"].contains(&target.executor.as_str()) || target.executor != "native" && target.triple.is_none() @@ -297,7 +387,7 @@ impl Manifest { targets.push(target); } for ((os, arch), enabled) in &supported { - if *enabled && !configured.contains(&(os.clone(), arch.clone())) { + if *enabled && !configured.contains(&(os.clone(), arch.clone(), None)) { return Err(error("supported target has no execution table")); } if !enabled { @@ -309,6 +399,42 @@ impl Manifest { id, os: os.clone(), arch: arch.clone(), + profile: None, + executor: "none".into(), + runner: None, + group: None, + triple: None, + smoke_case: None, + smoke_stdout: None, + exclude: vec![], + capabilities: vec![], + enabled: false, + ci: false, + }); + } + } + for (profile_name, profile) in &profiles { + if profile.enabled + && !configured.contains(&( + profile.os.clone(), + profile.arch.clone(), + Some(profile_name.clone()), + )) + { + return Err(error(format!( + "supported CPU profile has no execution table: {profile_name}" + ))); + } + if !profile.enabled { + let id = format!("{}-{profile_name}", profile.os); + if !ids.insert(id.clone()) { + return Err(error("duplicate planned CPU profile ID")); + } + targets.push(Target { + id, + os: profile.os.clone(), + arch: profile.arch.clone(), + profile: Some(profile_name.clone()), executor: "none".into(), runner: None, group: None, @@ -343,7 +469,13 @@ impl Manifest { let matches: Vec<_> = self .targets .iter() - .filter(|t| t.enabled && t.executor == "native" && t.os == os && t.arch == arch) + .filter(|t| { + t.enabled + && t.profile.is_none() + && t.executor == "native" + && t.os == os + && t.arch == arch + }) .collect(); if matches.len() != 1 { return Err(error("expected one native target for this host")); @@ -546,6 +678,9 @@ impl Manifest { ("shard_index", Value::integer(index)), ("shard_count", Value::integer(2)), ]); + if let Some(profile) = &target.profile { + config::field(&mut value, "profile", Value::string(profile))?; + } for (key, item) in [ ("target", &target.triple), ("smoke_case", &target.smoke_case), diff --git a/tools/tests/case_profiles.rs b/tools/tests/case_profiles.rs new file mode 100644 index 00000000..9399c5d5 --- /dev/null +++ b/tools/tests/case_profiles.rs @@ -0,0 +1,127 @@ +//! CPU profiles refine base architectures without changing enabled CI cells. +use std::path::PathBuf; +use wave_tools::cases::Manifest; + +const MANIFEST: &str = r#" +version = 3 +[supported] +linux = { arm64 = true, riscv64 = true } +[ci] +linux = { arm64 = false, riscv64 = false } +[profiles] +rhea = { os = "linux", arch = "arm64", supported = false, ci = false } +shakti = { os = "linux", arch = "riscv64", supported = false, ci = false } +xiangshan = { os = "linux", arch = "riscv64", supported = false, ci = false } +t-head = { os = "linux", arch = "riscv64", supported = false, ci = false } +[[target]] +id = "linux-arm64" +os = "linux" +arch = "arm64" +executor = "native" +[[target]] +id = "linux-riscv64" +os = "linux" +arch = "riscv64" +executor = "native" +"#; + +fn parse(value: &str) -> Result { + Manifest::parse(value, PathBuf::from("not-used"), false).map_err(|e| e.to_string()) +} + +#[test] +fn profiles_inherit_base_suites_and_retain_separate_identities() { + let manifest = parse(MANIFEST).unwrap(); + let base = manifest.target("linux-arm64").unwrap(); + assert_eq!(base.suites(), ["shared", "shared/arm64", "linux/arm64"]); + assert_eq!(base.profile, None); + let expected = + [("rhea", "arm64"), ("shakti", "riscv64"), ("xiangshan", "riscv64"), ("t-head", "riscv64")]; + for (name, arch) in expected { + let target = manifest.target(&format!("linux-{name}")).unwrap(); + assert_eq!(target.arch, arch); + assert_eq!(target.profile.as_deref(), Some(name)); + assert_eq!( + target.suites(), + [ + "shared".to_string(), + format!("shared/{arch}"), + format!("shared/{name}"), + format!("linux/{arch}"), + format!("linux/{name}"), + ] + ); + assert!(!target.enabled); + assert!(!target.ci); + assert!(target.rust_target().is_err()); + let value = target.value(); + assert_eq!(value.get_str("arch"), Some(arch)); + assert_eq!(value.get_str("profile"), Some(name)); + assert_eq!(value.get_str("suite"), Some(format!("linux/{name}").as_str())); + } +} + +#[test] +fn invalid_profile_architecture_status_and_names_are_rejected() { + for invalid in [ + MANIFEST.replace( + "rhea = { os = \"linux\", arch = \"arm64\"", + "rhea = { os = \"linux\", arch = \"riscv64\"", + ), + MANIFEST.replace("rhea = {", "unknown = {"), + MANIFEST.replace("shakti = { os = \"linux\"", "shakti = { os = \"windows\""), + MANIFEST.replace("supported = false, ci = false }", "supported = false, ci = true }"), + MANIFEST.replace( + "rhea = { os = \"linux\", arch = \"arm64\", supported = false", + "rhea = { os = \"linux\", arch = \"arm64\", supported = true", + ), + MANIFEST.replace("arch = \"arm64\"\nexecutor", "arch = \"rhea\"\nexecutor"), + MANIFEST.replace("version = 3", "version = 2"), + ] { + assert!(parse(&invalid).is_err(), "accepted invalid manifest: {invalid}"); + } +} + +#[test] +fn profile_target_tables_must_match_the_profile_mapping() { + let enabled = MANIFEST.replace( + "rhea = { os = \"linux\", arch = \"arm64\", supported = false", + "rhea = { os = \"linux\", arch = \"arm64\", supported = true", + ); + assert!(parse(&enabled).is_err(), "enabled profile without execution table"); + + let valid = format!( + "{enabled} +[[target]] +id = \"linux-rhea\" +os = \"linux\" +arch = \"arm64\" +profile = \"rhea\" +executor = \"compile\" +target = \"aarch64-unknown-linux-gnu\" +" + ); + let parsed = parse(&valid).unwrap(); + let target = parsed.target("linux-rhea").unwrap(); + assert!(target.enabled); + assert_eq!(target.profile.as_deref(), Some("rhea")); + assert_eq!(target.arch, "arm64"); + assert_eq!(target.rust_target().unwrap(), "aarch64-unknown-linux-gnu"); + + let mismatch = valid + .replace("arch = \"arm64\"\nprofile = \"rhea\"", "arch = \"riscv64\"\nprofile = \"rhea\""); + assert!(parse(&mismatch).is_err(), "accepted mismatched profile base"); + let unknown = valid.replace("profile = \"rhea\"", "profile = \"other\""); + assert!(parse(&unknown).is_err(), "accepted unknown target profile"); +} + +#[test] +fn repository_enabled_matrices_remain_at_thirty_jobs() { + let manifest = Manifest::load(&wave_tools::root(), true).unwrap(); + let matrix = manifest.matrices().unwrap(); + let utils::wson::Value::Object(groups) = matrix else { panic!("matrix groups") }; + assert_eq!(groups.iter().map(|(_, v)| v.get_arr("include").unwrap().len()).sum::(), 30); + let rhea = manifest.target("linux-rhea").unwrap(); + assert_eq!(rhea.profile.as_deref(), Some("rhea")); + assert!(!rhea.enabled); +}