From 48331c92623aa3c3992a2dd827f9891bc00d276b Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 11 Jan 2023 00:38:16 -0500 Subject: Fix writing of test results Update the TestResultsMap we read in and write that out, instead of writing out TestResultsVec; this avoids dropping results for commits we aren't considering. Signed-off-by: Kent Overstreet --- src/main.rs | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 20b668d..2ddb26d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,8 +48,7 @@ fn results_read(fname: &str) -> Result> { Ok(r) } -fn results_write(fname: &str, r: &TestResultsVec) -> Result<(), Box> { - let r = results_mapped(&r); +fn results_write(fname: &str, r: &TestResultsMap) -> Result<(), Box> { let file_contents = toml::to_string(&r)?; std::fs::write(fname, file_contents)?; @@ -88,18 +87,6 @@ fn results_new(repo: &git2::Repository, range: &str) -> Result TestResultsMap { - let mut mapped = HashMap::new(); - - for i in r { - if i.data_points.len() != 0 { - mapped.insert(i.commit.clone(), i.data_points.clone()); - } - } - - TestResultsMap { d: mapped } -} - fn results_merge(r1: &mut TestResultsVec, r2: &TestResultsMap) { for r1e in r1.iter_mut() { let r2e = r2.d.get(&r1e.commit); @@ -184,10 +171,8 @@ fn parse_test_output(output: &str) -> Option { fn run_tests(repo: &git2::Repository, range: &str, test: &str) { let mut results = results_new(&repo, range).unwrap(); - let existing = results_read(RESULTS); - if let Ok(existing) = existing { - results_merge(&mut results, &existing); - } + let mut existing = results_read(RESULTS).unwrap_or(TestResultsMap { d: HashMap::new() }); + results_merge(&mut results, &existing); while let Some(idx) = pick_commit_to_test(&results, test) { let output = Command::new("benchmark-git-commit.sh") @@ -205,14 +190,22 @@ fn run_tests(repo: &git2::Repository, range: &str, test: &str) { if let Some(result) = result { results[idx].data_points.insert(test.to_string(), result); - results_write(RESULTS, &results).unwrap(); + let commit = results[idx].commit.to_string(); + + if existing.d.get(&commit).is_none() { + existing.d.insert(commit.clone(), HashMap::new()); + } + + existing.d.get_mut(&commit).unwrap().insert(test.to_string(), result); + + results_write(RESULTS, &existing).unwrap(); } else { eprintln!("Error parsing test output"); break; } } - results_write(RESULTS, &results).unwrap(); + results_write(RESULTS, &existing).unwrap(); } fn log_with_results(repo: &git2::Repository, -- cgit v1.2.3