MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / is_program_coverage_correct

Method is_program_coverage_correct

src/execution/sanitize.rs:102–138  ·  view source on GitHub ↗
(&self, program_path: &Path)

Source from the content-addressed store, hash-verified

100 }
101
102 pub fn is_program_coverage_correct(&self, program_path: &Path) -> Result<Option<ProgramError>> {
103 log::trace!("test program is coverage correct: {program_path:?}");
104 let work_dir = get_file_dirname(program_path);
105 let time_logger = TimeUsage::new(work_dir.clone());
106
107 // compile fuzzer with coverage instrumented library.
108 let fuzzer_binary = program_path.with_extension("cov.out");
109 self.compile(vec![program_path], &fuzzer_binary, super::Compile::COVERAGE)?;
110
111 // Run the fuzzer on the previous synthesized corpus and collect coverage.
112 let corpus_dir: PathBuf = [work_dir.clone(), "corpus".into()].iter().collect();
113 let coverage = self.collect_code_coverage(
114 Some(program_path),
115 &fuzzer_binary,
116 vec![&corpus_dir, &self.deopt.get_library_shared_corpus_dir()?],
117 )?;
118
119 // Sanitize the fuzzer by its reached lines
120 let has_err = if get_config().disable_coverage_check {
121 log::warn!("Skip coverage sanitization since the config disable_coverage_check is set to true.");
122 false
123 } else {
124 sanitize_by_fuzzer_coverage(program_path, &self.deopt, &coverage)?
125 };
126 time_logger.log("coverage")?;
127 self.evolve_corpus(program_path)?;
128 // remove the profraw dir to avoid the huge disk cost.
129 if let Err(e) = std::fs::remove_dir_all(&corpus_dir) {
130 log::warn!("Failed to remove corpus dir {:?}: {}", corpus_dir, e);
131 }
132
133 if !has_err {
134 return Ok(None);
135 }
136 let err_msg = dump_fuzzer_coverage(&fuzzer_binary)?;
137 Ok(Some(ProgramError::Coverage(format!("The program cannot cover the callees along the path that contains maximum callees.\n{err_msg}"))))
138 }
139
140 pub fn check_program_is_correct(&self, seed_path: &Path) -> Result<Option<ProgramError>> {
141 if let Some(err) = self.is_program_syntax_correct(seed_path)? {

Callers 1

Calls 8

get_file_dirnameFunction · 0.85
get_configFunction · 0.85
dump_fuzzer_coverageFunction · 0.85
collect_code_coverageMethod · 0.80
logMethod · 0.80
evolve_corpusMethod · 0.80
compileMethod · 0.45

Tested by

no test coverage detected