#![cfg(feature = "cuda")]
fn gpu_usable() -> bool {
let usable = cujson::cuda_info().is_ok();
if usable {
eprintln!("skipped: a usable GPU is present");
}
usable
}
fn assert_cuda_or_no_device(err: cujson::Error, label: &str) {
match err {
cujson::Error::Cuda { code, .. } => {
assert!(
code > 0,
"{label}: Cuda error with non-positive code {code}"
);
}
cujson::Error::NoDevice => {}
other => panic!("{label}: expected Error::Cuda or Error::NoDevice, got {other:?}"),
}
}
#[test]
fn parse_standard_reports_cuda_error_not_internal() {
if gpu_usable() {
return;
}
let err = cujson::parse(br#"{"a":1}"#).unwrap_err();
assert_cuda_or_no_device(err, "parse");
}
#[test]
fn parse_lines_reports_cuda_error_not_internal() {
if gpu_usable() {
return;
}
let err = cujson::parse_lines(b"{\"a\":1}\n", cujson::LinesOptions::default()).unwrap_err();
assert_cuda_or_no_device(err, "parse_lines");
}