mirror of
https://github.com/ivall/xcl.git
synced 2026-11-24 05:14:57 +01:00
Merge PR #148
This commit is contained in:
@@ -76,6 +76,8 @@ impl Config {
|
||||
pub fn resolve(&mut self, manifest: Option<&crate::manifest::Manifest>) -> Vec<String> {
|
||||
let mut from = Vec::new();
|
||||
let series_s = self.is_series_s();
|
||||
// "Auto" / "Advanced" in xcl.toml: read in any case, as device_type and the manifest (#106)
|
||||
self.title_memory = self.title_memory.trim().to_ascii_lowercase();
|
||||
if self.title_memory == "auto" {
|
||||
let m = manifest.and_then(|m| if series_s { m.lockhart_memory.clone() } else { m.anaconda_memory.clone() });
|
||||
if let Some(m) = &m {
|
||||
@@ -338,6 +340,16 @@ mod tests {
|
||||
assert_eq!((c.title_memory.as_str(), c.title_memory_mb), ("standard", 13_824));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn title_memory_is_read_in_any_case() {
|
||||
let manifest = crate::manifest::Manifest { anaconda_memory: Some("Advanced".into()), ..Default::default() };
|
||||
for (setting, m) in [("Auto", Some(&manifest)), ("ADVANCED", None)] {
|
||||
let mut c = Config { title_memory: setting.into(), ..Config::default() };
|
||||
c.resolve(m);
|
||||
assert_eq!((c.title_memory.as_str(), c.uma_mb), ("advanced", 4095), "{setting}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raytracing_tier_parsing() {
|
||||
assert_eq!(parse_raytracing_tier("auto"), None);
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::{Mutex, MutexGuard, TryLockError};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -143,16 +144,32 @@ pub fn build() -> Report {
|
||||
}
|
||||
}
|
||||
|
||||
/// `m.try_lock()`, retried for `wait`: never an endless wait – the holder may be this very
|
||||
/// thread, crashed inside `build()`.
|
||||
fn lock_within<T>(m: &Mutex<T>, wait: Duration) -> Option<MutexGuard<'_, T>> {
|
||||
let end = Instant::now() + wait;
|
||||
loop {
|
||||
match m.try_lock() {
|
||||
Ok(g) => return Some(g),
|
||||
Err(TryLockError::WouldBlock) if Instant::now() < end => std::thread::sleep(Duration::from_millis(10)),
|
||||
Err(_) => return None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Write `report.json` (host side). `crash` is remembered for later writes.
|
||||
pub fn write_final(crash: Option<String>) {
|
||||
// the process ends: a cursor held in the XCL window is let go
|
||||
crate::hle::kbm::release();
|
||||
let Ok(_g) = WRITE_LOCK.try_lock() else { return };
|
||||
// a crash is kept even while another thread writes the report, and is written once that
|
||||
// thread is done – the process ends right after (#106); other calls give way at once
|
||||
let wait = if crash.is_some() { Duration::from_secs(2) } else { Duration::ZERO };
|
||||
if let Some(c) = crash {
|
||||
if let Ok(mut g) = CRASH.lock() {
|
||||
if let Some(mut g) = lock_within(&CRASH, wait) {
|
||||
g.get_or_insert(c);
|
||||
}
|
||||
}
|
||||
let Some(_g) = lock_within(&WRITE_LOCK, wait) else { return };
|
||||
let Some(boot) = crate::state::boot() else { return };
|
||||
let r = build();
|
||||
if let Ok(s) = serde_json::to_string_pretty(&r) {
|
||||
@@ -163,3 +180,24 @@ pub fn write_final(crash: Option<String>) {
|
||||
pub fn load(path: &std::path::Path) -> Option<Report> {
|
||||
serde_json::from_str(&std::fs::read_to_string(path).ok()?).ok()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_crash_is_kept_while_another_thread_writes_the_report() {
|
||||
let (held, wait_held) = std::sync::mpsc::channel();
|
||||
let writer = std::thread::spawn(move || {
|
||||
let _g = WRITE_LOCK.lock().unwrap();
|
||||
held.send(()).unwrap();
|
||||
std::thread::sleep(Duration::from_millis(100));
|
||||
});
|
||||
wait_held.recv().unwrap();
|
||||
// no boot record in unit tests: nothing is written to disk
|
||||
write_final(Some("boom".into()));
|
||||
writer.join().unwrap();
|
||||
assert_eq!(CRASH.lock().unwrap().as_deref(), Some("boom"));
|
||||
*CRASH.lock().unwrap() = None;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user