use vyre_conform::backend::DispatchConfig;
use vyre_conform::{certify, CertificateStrength, Strictness, VyreBackend};
struct CpuMirrorBackend;
impl VyreBackend for CpuMirrorBackend {
fn name(&self) -> &str {
"cpu-mirror"
}
fn version(&self) -> &str {
"test"
}
fn dispatch(
&self,
_wgsl: &str,
input: &[u8],
_output_size: usize,
_config: DispatchConfig,
) -> Result<Vec<u8>, String> {
if input.len() < 8 {
return Ok(vec![0; 4]);
}
let left = u32::from_le_bytes([input[0], input[1], input[2], input[3]]);
let right = u32::from_le_bytes([input[4], input[5], input[6], input[7]]);
Ok((left ^ right).to_le_bytes().to_vec())
}
}
#[test]
fn integer_only_certificate_has_only_integer_track() {
let cert = certify(
&CpuMirrorBackend,
&[vyre_conform::specs::primitive::xor::spec()],
CertificateStrength::FastCheck,
)
.unwrap();
assert_eq!(cert.integer_track().ops().len(), 1);
assert_eq!(cert.integer_track().ops()[0].id(), "primitive.bitwise.xor");
assert!(cert.float_track().is_none());
assert!(cert.approximate_track().is_none());
}
#[test]
fn approximate_spec_routes_to_approximate_track() {
let mut approx = vyre_conform::specs::primitive::xor::spec();
approx.id = "test.approximate.xor";
approx.strictness = Strictness::Approximate { max_ulps: 4 };
let cert = certify(&CpuMirrorBackend, &[approx], CertificateStrength::FastCheck).unwrap();
let approximate_track = cert.approximate_track().as_ref().unwrap();
assert!(cert.integer_track().ops().is_empty());
assert!(cert.float_track().is_none());
assert_eq!(approximate_track.ops().len(), 1);
assert_eq!(approximate_track.ops()[0].id(), "test.approximate.xor");
}
#[test]
fn same_op_id_cannot_be_declared_strict_and_approximate() {
let mut strict = vyre_conform::specs::primitive::xor::spec();
strict.id = "test.mixed.xor";
let mut approximate = vyre_conform::specs::primitive::xor::spec();
approximate.id = "test.mixed.xor";
approximate.strictness = Strictness::Approximate { max_ulps: 1 };
let err = certify(
&CpuMirrorBackend,
&[strict, approximate],
CertificateStrength::FastCheck,
)
.unwrap_err();
assert_eq!(
err,
"Fix: op test.mixed.xor declared Strict AND Approximate. Split into two spec entries with different ids."
);
}