use std::ops::AddAssign;
use serde::{Deserialize, Serialize};
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct LeaseId(pub i64);
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct SessionKey(pub String);
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Holder {
pub session: SessionKey,
pub pid: u32,
pub pid_start_time: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
pub struct Rolling {
pub avg_1s: f32,
pub avg_10s: f32,
pub avg_60s: f32,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CpuStats {
pub logical_cores: u32,
pub usage_pct: Rolling,
pub per_core_pct: Vec<f32>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct MemStats {
pub total_mb: u64,
pub used_mb: u64,
pub available_mb: u64,
pub commit_used_mb: u64,
pub commit_limit_mb: u64,
#[serde(default)]
pub reclaimable_mb: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
pub struct GpuEngines {
pub three_d_pct: Rolling,
pub compute_pct: Rolling,
pub copy_pct: Rolling,
pub video_pct: Rolling,
}
impl GpuEngines {
pub fn busiest(&self, pick: fn(&Rolling) -> f32) -> f32 {
[
self.three_d_pct,
self.compute_pct,
self.copy_pct,
self.video_pct,
]
.iter()
.map(pick)
.fold(0.0, f32::max)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GpuAdapter {
pub name: String,
pub luid: String,
pub engines: GpuEngines,
pub dedicated_used_mb: u64,
pub dedicated_total_mb: Option<u64>,
pub shared_used_mb: u64,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub unified_memory: bool,
#[serde(default, skip_serializing_if = "is_default")]
pub source: GpuSource,
#[serde(default, skip_serializing_if = "is_default")]
pub process_load: Accuracy,
#[serde(default, skip_serializing_if = "is_default")]
pub process_memory: Accuracy,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum GpuSource {
#[default]
Pdh,
Nvml,
DrmFdinfo,
Iokit,
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Accuracy {
#[default]
Exact,
Estimated,
Unavailable,
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
pub struct ResourceUsage {
pub cores: f32,
pub ram_mb: u64,
pub gpu_pct: f32,
pub vram_mb: u64,
}
impl AddAssign for ResourceUsage {
fn add_assign(&mut self, other: Self) {
self.cores += other.cores;
self.ram_mb += other.ram_mb;
self.gpu_pct += other.gpu_pct;
self.vram_mb += other.vram_mb;
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ProcessUsage {
pub pid: u32,
pub name: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub exe: Option<String>,
pub usage: ResourceUsage,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SessionUsage {
pub holder: Holder,
pub usage: ResourceUsage,
#[serde(default)]
pub cores_10s: f32,
pub processes: Vec<ProcessUsage>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Snapshot {
pub taken_at_ms: i64,
pub cpu: CpuStats,
pub memory: MemStats,
pub gpus: Vec<GpuAdapter>,
pub sessions: Vec<SessionUsage>,
pub unattributed: ResourceUsage,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub drives: Vec<DriveUsage>,
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DriveUsage {
pub name: String,
pub total_mb: u64,
pub used_mb: u64,
pub read_bytes_per_sec: u64,
pub write_bytes_per_sec: u64,
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct JobProfile {
pub cores: f32,
pub ram_mb: u64,
pub gpu_pct: f32,
pub vram_mb: u64,
pub est_secs: u64,
}
impl JobProfile {
pub fn invalid_reason(&self) -> Option<&'static str> {
if !(self.cores.is_finite() && self.cores >= 0.0) {
Some("cores must be a finite number of at least 0")
} else if !(0.0..=100.0).contains(&self.gpu_pct) {
Some("gpu_pct must be between 0 and 100")
} else {
None
}
}
pub fn default_min_cores(&self) -> f32 {
(self.cores / 2.0).max(self.cores.min(1.0))
}
pub fn min_cores_reason(&self, min_cores: f32) -> Option<&'static str> {
if !(min_cores.is_finite() && min_cores > 0.0) {
Some("min_cores must be a finite number above 0")
} else if min_cores > self.cores {
Some("min_cores must be at most cores")
} else {
None
}
}
pub fn is_quick(&self) -> bool {
self.est_secs <= QUICK_MAX_SECS
}
pub fn is_low_impact(&self) -> bool {
self.cores <= LOW_IMPACT_MAX_CORES
&& self.ram_mb <= LOW_IMPACT_MAX_RAM_MB
&& self.gpu_pct == 0.0
&& self.vram_mb == 0
}
}
pub const QUICK_MAX_SECS: u64 = 15;
pub const LOW_IMPACT_MAX_CORES: f32 = 0.25;
pub const LOW_IMPACT_MAX_RAM_MB: u64 = 256;
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum JobClass {
Light,
CpuHeavy,
GpuHeavy,
Mixed,
}
impl JobClass {
pub const ALL: [Self; 4] = [Self::Light, Self::CpuHeavy, Self::GpuHeavy, Self::Mixed];
pub fn as_str(self) -> &'static str {
match self {
Self::Light => "light",
Self::CpuHeavy => "cpu_heavy",
Self::GpuHeavy => "gpu_heavy",
Self::Mixed => "mixed",
}
}
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum LeaseKind {
Normal,
BenchmarkExclusive,
}
impl LeaseKind {
pub const ALL: [Self; 2] = [Self::Normal, Self::BenchmarkExclusive];
pub fn as_str(self) -> &'static str {
match self {
Self::Normal => "normal",
Self::BenchmarkExclusive => "benchmark_exclusive",
}
}
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum LeaseState {
Queued,
Active,
Released,
Expired,
}
impl LeaseState {
pub const ALL: [Self; 4] = [Self::Queued, Self::Active, Self::Released, Self::Expired];
pub fn as_str(self) -> &'static str {
match self {
Self::Queued => "queued",
Self::Active => "active",
Self::Released => "released",
Self::Expired => "expired",
}
}
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum EndCause {
Released,
Expired,
Killed,
Removed,
}
impl EndCause {
pub const ALL: [Self; 4] = [Self::Released, Self::Expired, Self::Killed, Self::Removed];
pub fn as_str(self) -> &'static str {
match self {
Self::Released => "released",
Self::Expired => "expired",
Self::Killed => "killed",
Self::Removed => "removed",
}
}
pub fn ended_state(self) -> LeaseState {
match self {
Self::Released => LeaseState::Released,
Self::Expired | Self::Killed | Self::Removed => LeaseState::Expired,
}
}
pub fn is_notice(self) -> bool {
matches!(self, Self::Killed | Self::Removed)
}
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Lease {
pub id: LeaseId,
pub holder: Holder,
pub kind: LeaseKind,
pub state: LeaseState,
pub class: Option<JobClass>,
pub profile: JobProfile,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub asked_cores: Option<f32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub min_cores: Option<f32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub declared_cores: Option<f32>,
pub label: String,
#[serde(default)]
pub cwd: String,
pub requested_at_ms: i64,
pub granted_at_ms: Option<i64>,
pub ended_at_ms: Option<i64>,
pub expires_at_ms: i64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub end_cause: Option<EndCause>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub binding: Option<LeaseBinding>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub isolation: Option<LeaseIsolation>,
}
impl Lease {
pub fn asked_profile(&self) -> JobProfile {
JobProfile {
cores: self.asked_cores.unwrap_or(self.profile.cores),
..self.profile
}
}
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct LeaseIsolation {
pub kind: IsolationKind,
pub scope: Option<String>,
pub limits: EnforcedLimits,
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum IsolationKind {
Cgroup,
Tree,
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
pub struct EnforcedLimits {
pub cpu_cores: Option<f32>,
pub memory_high_mb: Option<u64>,
pub memory_max_mb: Option<u64>,
}
pub(crate) fn is_default<T: Default + PartialEq>(value: &T) -> bool {
*value == T::default()
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct LeaseBinding {
pub tool_use_id: String,
pub bound_at_ms: i64,
pub root: Option<BoundProcess>,
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct BoundProcess {
pub pid: u32,
pub start_time: u64,
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct NoiseReport {
pub avg_cpu_pct: f32,
pub peak_cpu_pct: f32,
pub avg_gpu_pct: f32,
pub peak_gpu_pct: f32,
pub quiet_at_start: bool,
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct BusyUsage {
pub cores: f32,
pub gpu_pct: f32,
}
#[cfg_attr(any(feature = "schema", test), derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct JobRun {
pub lease_id: Option<LeaseId>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub session: Option<SessionKey>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub end_cause: Option<EndCause>,
pub fingerprint: String,
pub command: String,
pub cwd: String,
pub declared: JobProfile,
pub peak: ResourceUsage,
pub avg: ResourceUsage,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub busy: Option<BusyUsage>,
pub started_at_ms: i64,
pub ended_at_ms: i64,
pub noise: Option<NoiseReport>,
pub overlapped: bool,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_support::{assert_json_round_trip, sample_lease, sample_snapshot};
fn profile_with(cores: f32, gpu_pct: f32) -> JobProfile {
JobProfile {
cores,
ram_mb: 1024,
gpu_pct,
vram_mb: 0,
est_secs: 60,
}
}
#[test]
fn test_snapshot_json_round_trip_preserves_every_field() {
assert_json_round_trip(&sample_snapshot());
}
#[test]
fn test_lease_json_round_trip_preserves_every_field() {
assert_json_round_trip(&sample_lease());
}
#[test]
fn test_lease_json_uses_snake_case_enums_and_bare_ids() {
let value = serde_json::to_value(sample_lease()).unwrap();
assert_eq!(value["id"], 7);
assert_eq!(value["holder"]["session"], "3f2a9c1e-session");
assert_eq!(value["kind"], "benchmark_exclusive");
assert_eq!(value["state"], "active");
assert_eq!(value["class"], "cpu_heavy");
}
#[test]
fn test_enum_as_str_matches_serde_name() {
for class in JobClass::ALL {
assert_eq!(serde_json::to_value(class).unwrap(), class.as_str());
}
for kind in LeaseKind::ALL {
assert_eq!(serde_json::to_value(kind).unwrap(), kind.as_str());
}
for state in LeaseState::ALL {
assert_eq!(serde_json::to_value(state).unwrap(), state.as_str());
}
for cause in EndCause::ALL {
assert_eq!(serde_json::to_value(cause).unwrap(), cause.as_str());
}
}
#[test]
fn test_lease_with_end_cause_round_trips_and_writes_snake_case() {
let lease = Lease {
state: LeaseState::Released,
ended_at_ms: Some(1_793_000_090_000),
end_cause: Some(EndCause::Killed),
..sample_lease()
};
assert_json_round_trip(&lease);
assert_eq!(serde_json::to_value(&lease).unwrap()["end_cause"], "killed");
}
#[test]
fn test_lease_without_end_cause_omits_the_field() {
let value = serde_json::to_value(sample_lease()).unwrap();
assert!(value.get("end_cause").is_none());
assert!(value.get("binding").is_none());
}
#[test]
fn test_lease_with_asked_and_min_cores_round_trips_and_omits_them_when_unknown() {
let lease = Lease {
asked_cores: Some(8.0),
min_cores: Some(4.0),
declared_cores: None,
..sample_lease()
};
assert_json_round_trip(&lease);
let value = serde_json::to_value(&lease).unwrap();
assert_eq!(value["asked_cores"], 8.0);
assert_eq!(value["min_cores"], 4.0);
let unknown = serde_json::to_value(sample_lease()).unwrap();
assert!(unknown.get("asked_cores").is_none());
assert!(unknown.get("min_cores").is_none());
}
#[test]
fn test_lease_with_binding_round_trips_with_and_without_root() {
let pending = LeaseBinding {
tool_use_id: "toolu_01AbC".into(),
bound_at_ms: 1_793_000_013_000,
root: None,
};
let bound = LeaseBinding {
root: Some(BoundProcess {
pid: 30_112,
start_time: 1_793_000_013,
}),
..pending.clone()
};
for binding in [pending, bound] {
assert_json_round_trip(&Lease {
binding: Some(binding),
..sample_lease()
});
}
}
#[test]
fn test_v0_1_shapes_decode_without_new_fields() {
let mut lease = serde_json::to_value(sample_lease()).unwrap();
lease.as_object_mut().unwrap().remove("end_cause");
let lease: Lease = serde_json::from_value(lease).unwrap();
assert_eq!(lease.end_cause, None);
assert_eq!(lease.binding, None);
assert_eq!(lease.isolation, None);
assert_eq!((lease.asked_cores, lease.min_cores), (None, None));
let mut snapshot = serde_json::to_value(sample_snapshot()).unwrap();
snapshot.as_object_mut().unwrap().remove("drives");
snapshot["sessions"][0]["processes"][0]
.as_object_mut()
.unwrap()
.remove("exe");
let snapshot: Snapshot = serde_json::from_value(snapshot).unwrap();
assert!(snapshot.drives.is_empty());
assert_eq!(snapshot.sessions[0].processes[0].exe, None);
}
#[test]
fn test_windows_adapter_and_lease_omit_every_cross_platform_field() {
let snapshot = serde_json::to_value(sample_snapshot()).unwrap();
let gpu = snapshot["gpus"][0].as_object().unwrap();
for field in ["unified_memory", "source", "process_load", "process_memory"] {
assert!(gpu.get(field).is_none(), "{field}");
}
let lease = serde_json::to_value(sample_lease()).unwrap();
assert!(lease.get("isolation").is_none());
}
#[test]
fn test_adapter_from_an_older_allotd_is_a_windows_adapter() {
let mut value = serde_json::to_value(&sample_snapshot().gpus[0]).unwrap();
let object = value.as_object_mut().unwrap();
for field in ["unified_memory", "source", "process_load", "process_memory"] {
object.remove(field);
}
let gpu: GpuAdapter = serde_json::from_value(value).unwrap();
assert!(!gpu.unified_memory);
assert_eq!(gpu.source, GpuSource::Pdh);
assert_eq!(gpu.process_load, Accuracy::Exact);
assert_eq!(gpu.process_memory, Accuracy::Exact);
}
#[test]
fn test_unified_adapter_round_trips_and_writes_snake_case() {
let gpu = GpuAdapter {
name: "Apple M3 Max".into(),
luid: "4294969310".into(),
dedicated_used_mb: 9_216,
dedicated_total_mb: None,
shared_used_mb: 0,
unified_memory: true,
source: GpuSource::Iokit,
process_load: Accuracy::Estimated,
process_memory: Accuracy::Unavailable,
..sample_snapshot().gpus[0].clone()
};
assert_json_round_trip(&gpu);
let value = serde_json::to_value(&gpu).unwrap();
assert_eq!(value["unified_memory"], true);
assert_eq!(value["source"], "iokit");
assert_eq!(value["process_load"], "estimated");
assert_eq!(value["process_memory"], "unavailable");
let fdinfo = serde_json::to_value(GpuSource::DrmFdinfo).unwrap();
assert_eq!(fdinfo, "drm_fdinfo");
}
#[test]
fn test_lease_with_isolation_round_trips_for_cgroup_and_tree() {
let cgroup = LeaseIsolation {
kind: IsolationKind::Cgroup,
scope: Some("allot-lease-7.scope".into()),
limits: EnforcedLimits {
cpu_cores: Some(8.0),
memory_high_mb: Some(4096),
memory_max_mb: Some(6144),
},
};
let tree = LeaseIsolation {
kind: IsolationKind::Tree,
scope: None,
limits: EnforcedLimits::default(),
};
for isolation in [cgroup, tree] {
assert_json_round_trip(&Lease {
isolation: Some(isolation),
..sample_lease()
});
}
let value = serde_json::to_value(Lease {
isolation: Some(LeaseIsolation {
kind: IsolationKind::Tree,
scope: None,
limits: EnforcedLimits::default(),
}),
..sample_lease()
})
.unwrap();
assert_eq!(value["isolation"]["kind"], "tree");
assert!(value["isolation"]["scope"].is_null());
assert!(value["isolation"]["limits"]["memory_max_mb"].is_null());
}
#[test]
fn test_snapshot_without_drives_and_exe_omits_both_fields() {
let mut snapshot = sample_snapshot();
snapshot.drives.clear();
snapshot.sessions[0].processes[0].exe = None;
let value = serde_json::to_value(snapshot).unwrap();
assert!(value.get("drives").is_none());
assert!(value["sessions"][0]["processes"][0].get("exe").is_none());
}
#[test]
fn test_gpu_engines_busiest_reads_the_picked_window_of_the_busiest_group() {
let rolling = |avg_1s, avg_10s| Rolling {
avg_1s,
avg_10s,
avg_60s: 0.0,
};
let engines = GpuEngines {
three_d_pct: rolling(12.0, 40.0),
compute_pct: rolling(55.5, 20.0),
copy_pct: rolling(1.0, 1.0),
video_pct: rolling(0.0, 0.0),
};
assert_eq!(engines.busiest(|load| load.avg_1s), 55.5);
assert_eq!(engines.busiest(|load| load.avg_10s), 40.0);
assert_eq!(GpuEngines::default().busiest(|load| load.avg_1s), 0.0);
}
#[test]
fn test_resource_usage_add_assign_sums_every_field() {
let mut total = ResourceUsage {
cores: 1.5,
ram_mb: 100,
gpu_pct: 10.0,
vram_mb: 64,
};
total += ResourceUsage {
cores: 2.25,
ram_mb: 50,
gpu_pct: 5.5,
vram_mb: 0,
};
assert_eq!(
total,
ResourceUsage {
cores: 3.75,
ram_mb: 150,
gpu_pct: 15.5,
vram_mb: 64,
}
);
}
#[test]
fn test_noise_report_json_round_trip_preserves_every_field() {
assert_json_round_trip(&NoiseReport {
avg_cpu_pct: 2.5,
peak_cpu_pct: 9.0,
avg_gpu_pct: 0.5,
peak_gpu_pct: 3.25,
quiet_at_start: false,
});
}
#[test]
fn test_lease_without_cwd_field_deserializes_with_empty_cwd() {
let mut value = serde_json::to_value(sample_lease()).unwrap();
value.as_object_mut().unwrap().remove("cwd");
let lease: Lease = serde_json::from_value(value).unwrap();
assert_eq!(lease.cwd, "");
}
#[test]
fn test_job_run_json_round_trip_preserves_every_field() {
let usage = ResourceUsage {
cores: 6.5,
ram_mb: 2800,
gpu_pct: 0.0,
vram_mb: 0,
};
assert_json_round_trip(&JobRun {
lease_id: Some(LeaseId(3)),
session: Some(SessionKey("3f2a9c1e-session".into())),
end_cause: Some(EndCause::Killed),
fingerprint: r"cargo build -p allotd|e:\work\app".into(),
command: "cargo build -p allotd 2>&1".into(),
cwd: r"E:\work\app".into(),
declared: profile_with(8.0, 0.0),
peak: usage,
avg: usage,
busy: Some(BusyUsage {
cores: 7.25,
gpu_pct: 0.0,
}),
started_at_ms: 1_793_000_000_000,
ended_at_ms: 1_793_000_095_000,
noise: None,
overlapped: true,
});
}
#[test]
fn test_job_profile_invalid_reason_in_range_is_none() {
assert_eq!(profile_with(0.0, 0.0).invalid_reason(), None);
assert_eq!(profile_with(16.0, 100.0).invalid_reason(), None);
}
#[test]
fn test_job_profile_invalid_reason_out_of_range_names_field() {
assert!(
profile_with(-1.0, 0.0)
.invalid_reason()
.unwrap()
.contains("cores")
);
assert!(
profile_with(f32::NAN, 0.0)
.invalid_reason()
.unwrap()
.contains("cores")
);
assert!(
profile_with(1.0, 101.0)
.invalid_reason()
.unwrap()
.contains("gpu_pct")
);
assert!(
profile_with(1.0, f32::NAN)
.invalid_reason()
.unwrap()
.contains("gpu_pct")
);
}
}