Skip to content

Commit

Permalink
No uses_gpu config property. Automatic config parse test.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwalski committed Mar 26, 2024
1 parent 6030f80 commit 85be431
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 96 deletions.
9 changes: 3 additions & 6 deletions src/offer_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ struct OfferTemplate {
constraints: String,
}
pub(crate) fn gpu_detection<CONFIG: RuntimeConfig>(config: &CONFIG) -> anyhow::Result<Option<Gpu>> {
if config.uses_gpu() {
let gpu_detection = gpu_detection::GpuDetection::init()?;
let gpu = gpu_detection.detect(config.gpu_uuid())?;
return Ok(Some(gpu));
}
Ok(None)
let gpu_detection = gpu_detection::GpuDetection::init()?;
let gpu = gpu_detection.detect(config.gpu_uuid())?;
Ok(Some(gpu))
}

pub(crate) fn template<CONFIG: RuntimeConfig>(
Expand Down
1 change: 0 additions & 1 deletion src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub(crate) trait Runtime: Sized {

pub(crate) trait RuntimeConfig: DeserializeOwned + Default + Debug + Clone {
fn gpu_uuid(&self) -> Option<String>;
fn uses_gpu(&self) -> bool;
}

#[derive(Clone)]
Expand Down
23 changes: 15 additions & 8 deletions src/process/automatic/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,12 @@ pub(crate) struct Config {
pub monitored_msgs_w_trace_lvl: Vec<String>,

pub gpu_uuid: Option<String>,

// Property for testing purposes
pub uses_gpu: bool,
}

impl RuntimeConfig for Config {
fn gpu_uuid(&self) -> Option<String> {
self.gpu_uuid.clone()
}

fn uses_gpu(&self) -> bool {
self.uses_gpu
}
}

impl Default for Config {
Expand All @@ -70,7 +63,21 @@ impl Default for Config {
"\"GET / HTTP/1.1\" 404 Not Found".into(),
],
gpu_uuid: None,
uses_gpu: true,
}
}
}

#[cfg(test)]
mod config_tests {
use std::{fs, path::PathBuf};

use super::Config;

#[test]
fn config_test() {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("tests/resources/runtime_config.json");
let config = fs::read_to_string(path).unwrap();
serde_json::from_str::<Config>(&config).expect("Can parse config");
}
}
4 changes: 0 additions & 4 deletions src/process/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ impl RuntimeConfig for Config {
fn gpu_uuid(&self) -> Option<String> {
None
}

fn uses_gpu(&self) -> bool {
false
}
}

#[async_trait]
Expand Down
77 changes: 0 additions & 77 deletions tests/runtime_config.rs

This file was deleted.

0 comments on commit 85be431

Please sign in to comment.