Skip to content

Commit

Permalink
Save combined results through merge
Browse files Browse the repository at this point in the history
  • Loading branch information
adpaco-aws committed Aug 29, 2024
1 parent dd53e38 commit ad632f3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tools/kani-cov/src/merge.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use std::{collections::BTreeMap, fs::File, io::BufReader, os::linux::raw, path::PathBuf};
use std::{collections::BTreeMap, fs::File, io::{BufReader, BufWriter}, os::linux::raw, path::PathBuf};

use anyhow::Result;

Expand All @@ -10,11 +10,11 @@ use crate::{args::MergeArgs, coverage::{CheckStatus, CombinedCoverageResults, Co
pub fn merge_main(args: &MergeArgs) -> Result<()> {
let raw_results = parse_raw_results(&args.files)?;
let combined_results = combine_raw_results(&raw_results);
// save_combined_results(combined_results, args.output)?;
save_combined_results(&combined_results, &args.output)?;
Ok(())
}

pub fn validate_merge_args(args: &MergeArgs) -> Result<()> {
pub fn validate_merge_args(_args: &MergeArgs) -> Result<()> {
Ok(())
}

Expand All @@ -33,7 +33,7 @@ fn parse_raw_results(paths: &Vec<PathBuf>) -> Result<Vec<CoverageResults>> {

fn combine_raw_results(results: &Vec<CoverageResults>) -> CombinedCoverageResults {
let all_function_names = function_names_from_results(results);
println!("{:?}", all_function_names);

let mut new_data = BTreeMap::new();
for fun_name in all_function_names {
let mut this_fun_checks: Vec<&CoverageCheck> = Vec::new();
Expand Down Expand Up @@ -62,6 +62,16 @@ fn combine_raw_results(results: &Vec<CoverageResults>) -> CombinedCoverageResult
CombinedCoverageResults { data: new_data }
}

fn save_combined_results(results: &CombinedCoverageResults, output: &Option<PathBuf>) -> Result<()> {
let output_path = if let Some(out) = output { out } else { &PathBuf::from("default_kanicov.json") };
let file = File::create(output_path)?;
let writer = BufWriter::new(file);

serde_json::to_writer(writer, results)?;

Ok(())
}

fn function_names_from_results(results: &Vec<CoverageResults>) -> Vec<String> {
results.iter().map(|result| result.data.keys().cloned().collect()).collect()
}

0 comments on commit ad632f3

Please sign in to comment.