115 lines
3.3 KiB
Rust
115 lines
3.3 KiB
Rust
mod audio_mixer;
|
|
mod prometeu_runner;
|
|
mod fs_desktop_backend;
|
|
mod log_sink;
|
|
|
|
use crate::prometeu_runner::PrometeuRunner;
|
|
use winit::event_loop::EventLoop;
|
|
use prometeu_core::firmware::BootTarget;
|
|
use prometeu_core::telemetry::CertificationConfig;
|
|
|
|
fn load_cap_config(path: &str) -> Option<CertificationConfig> {
|
|
let content = std::fs::read_to_string(path).ok()?;
|
|
let mut config = CertificationConfig {
|
|
enabled: true,
|
|
..Default::default()
|
|
};
|
|
|
|
for line in content.lines() {
|
|
let line = line.trim();
|
|
if line.is_empty() || line.starts_with('#') { continue; }
|
|
let parts: Vec<&str> = line.split('=').collect();
|
|
if parts.len() != 2 { continue; }
|
|
let key = parts[0].trim();
|
|
let val = parts[1].trim();
|
|
|
|
match key {
|
|
"cycles_budget" => config.cycles_budget_per_frame = val.parse().ok(),
|
|
"max_syscalls" => config.max_syscalls_per_frame = val.parse().ok(),
|
|
"max_host_cpu_us" => config.max_host_cpu_us_per_frame = val.parse().ok(),
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
Some(config)
|
|
}
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let args: Vec<String> = std::env::args().collect();
|
|
let mut fs_root = None;
|
|
let mut cap_config = None;
|
|
let mut boot_target = BootTarget::Hub;
|
|
|
|
let mut i = 1; // Pula o nome do executável
|
|
while i < args.len() {
|
|
match args[i].as_str() {
|
|
"--run" => {
|
|
if i + 1 < args.len() {
|
|
boot_target = BootTarget::Cartridge {
|
|
path: args[i + 1].clone(),
|
|
debug: false,
|
|
};
|
|
i += 1;
|
|
}
|
|
}
|
|
"--debug" => {
|
|
if i + 1 < args.len() {
|
|
boot_target = BootTarget::Cartridge {
|
|
path: args[i + 1].clone(),
|
|
debug: true,
|
|
};
|
|
i += 1;
|
|
}
|
|
}
|
|
"--fs-root" => {
|
|
if i + 1 < args.len() {
|
|
fs_root = Some(args[i + 1].clone());
|
|
i += 1;
|
|
}
|
|
}
|
|
"--cap" => {
|
|
if i + 1 < args.len() {
|
|
cap_config = load_cap_config(&args[i + 1]);
|
|
i += 1;
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
i += 1;
|
|
}
|
|
|
|
let event_loop = EventLoop::new()?;
|
|
|
|
let mut runner = PrometeuRunner::new(fs_root, cap_config);
|
|
runner.set_boot_target(boot_target);
|
|
|
|
event_loop.run_app(&mut runner)?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_load_cap_config() {
|
|
let content = "cycles_budget=500\nmax_syscalls=10\n# comentário\nmax_host_cpu_us=2000";
|
|
let path = "test_cap.cfg";
|
|
std::fs::write(path, content).unwrap();
|
|
|
|
let config = load_cap_config(path).unwrap();
|
|
assert!(config.enabled);
|
|
assert_eq!(config.cycles_budget_per_frame, Some(500));
|
|
assert_eq!(config.max_syscalls_per_frame, Some(10));
|
|
assert_eq!(config.max_host_cpu_us_per_frame, Some(2000));
|
|
|
|
std::fs::remove_file(path).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn test_load_cap_config_not_found() {
|
|
let config = load_cap_config("non_existent.cfg");
|
|
assert!(config.is_none());
|
|
}
|
|
} |