mod common;
use transcribe_cpp::{devices, Backend, Error, Model, ModelOptions};
#[test]
fn loaded_model_reports_an_enumerated_device() {
let Some((model_path, _)) = common::smoke_fixtures("loaded_model_reports_an_enumerated_device")
else {
return;
};
let model = Model::load(&model_path).unwrap();
let dev = model.device().expect("model.device()");
assert_eq!(dev.index, None, "{dev:?}");
let all = devices();
let matched = all
.iter()
.any(|d| d.name == dev.name && (dev.device_id.is_none() || d.device_id == dev.device_id));
assert!(
matched,
"model device {dev:?} not found among enumerated devices {all:?}"
);
}
#[test]
fn negative_gpu_device_is_invalid_argument() {
let Some((model_path, _)) = common::smoke_fixtures("negative_gpu_device_is_invalid_argument")
else {
return;
};
let err = Model::load_with(
&model_path,
&ModelOptions {
gpu_device: -1,
..Default::default()
},
)
.unwrap_err();
assert!(matches!(err, Error::InvalidArgument(_)), "got {err:?}");
}
#[test]
fn out_of_range_gpu_device_is_invalid_argument() {
let Some((model_path, _)) =
common::smoke_fixtures("out_of_range_gpu_device_is_invalid_argument")
else {
return;
};
let out_of_range = devices().len() as i32 + 1000;
let err = Model::load_with(
&model_path,
&ModelOptions {
gpu_device: out_of_range,
..Default::default()
},
)
.unwrap_err();
assert!(matches!(err, Error::InvalidArgument(_)), "got {err:?}");
}
#[test]
fn gpu_device_with_cpu_backend_is_invalid_argument() {
let Some((model_path, _)) =
common::smoke_fixtures("gpu_device_with_cpu_backend_is_invalid_argument")
else {
return;
};
let err = Model::load_with(
&model_path,
&ModelOptions {
backend: Backend::Cpu,
gpu_device: 1,
},
)
.unwrap_err();
assert!(matches!(err, Error::InvalidArgument(_)), "got {err:?}");
}