use a shared headers cache

This commit is contained in:
Pietro Albini 2023-04-14 12:14:19 +02:00
parent 0f364ac382
commit 0f8a06b6c0
No known key found for this signature in database
GPG Key ID: CD76B35F7734769E
3 changed files with 28 additions and 9 deletions

View File

@ -11,6 +11,7 @@ use tracing::*;
use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
use crate::header::cfg::parse_cfg_name_directive;
use crate::header::cfg::MatchOutcome;
use crate::header::needs::CachedNeedsConditions;
use crate::{extract_cdb_version, extract_gdb_version};
mod cfg;
@ -18,6 +19,16 @@ mod needs;
#[cfg(test)]
mod tests;
pub struct HeadersCache {
needs: CachedNeedsConditions,
}
impl HeadersCache {
pub fn load(config: &Config) -> Self {
Self { needs: CachedNeedsConditions::load(config) }
}
}
/// Properties which must be known very early, before actually running
/// the test.
#[derive(Default)]
@ -849,6 +860,7 @@ where
pub fn make_test_description<R: Read>(
config: &Config,
cache: &HeadersCache,
name: test::TestName,
path: &Path,
src: R,
@ -859,8 +871,6 @@ pub fn make_test_description<R: Read>(
let mut ignore_message = None;
let mut should_fail = false;
let needs_cache = needs::CachedNeedsConditions::load(config);
iter_header(path, src, &mut |revision, ln, line_number| {
if revision.is_some() && revision != cfg {
return;
@ -888,7 +898,7 @@ pub fn make_test_description<R: Read>(
decision!(cfg::handle_ignore(config, ln));
decision!(cfg::handle_only(config, ln));
decision!(needs::handle_needs(&needs_cache, config, ln));
decision!(needs::handle_needs(&cache.needs, config, ln));
decision!(ignore_llvm(config, ln));
decision!(ignore_cdb(config, ln));
decision!(ignore_gdb(config, ln));

View File

@ -2,7 +2,7 @@ use std::io::Read;
use std::path::Path;
use crate::common::{Config, Debugger};
use crate::header::{parse_normalization_string, EarlyProps};
use crate::header::{parse_normalization_string, EarlyProps, HeadersCache};
fn make_test_description<R: Read>(
config: &Config,
@ -11,8 +11,10 @@ fn make_test_description<R: Read>(
src: R,
cfg: Option<&str>,
) -> test::TestDesc {
let cache = HeadersCache::load(config);
let mut poisoned = false;
let test = crate::header::make_test_description(config, name, path, src, cfg, &mut poisoned);
let test =
crate::header::make_test_description(config, &cache, name, path, src, cfg, &mut poisoned);
if poisoned {
panic!("poisoned!");
}

View File

@ -25,6 +25,7 @@ use tracing::*;
use walkdir::WalkDir;
use self::header::{make_test_description, EarlyProps};
use crate::header::HeadersCache;
use std::sync::Arc;
#[cfg(test)]
@ -556,9 +557,11 @@ pub fn make_tests(
panic!("modified_tests got error from dir: {}, error: {}", config.src_base.display(), err)
});
let cache = HeadersCache::load(&config);
let mut poisoned = false;
collect_tests_from_dir(
config.clone(),
&cache,
&config.src_base,
&PathBuf::new(),
&inputs,
@ -636,6 +639,7 @@ fn modified_tests(config: &Config, dir: &Path) -> Result<Vec<PathBuf>, String> {
fn collect_tests_from_dir(
config: Arc<Config>,
cache: &HeadersCache,
dir: &Path,
relative_dir_path: &Path,
inputs: &Stamp,
@ -654,7 +658,7 @@ fn collect_tests_from_dir(
file: dir.to_path_buf(),
relative_dir: relative_dir_path.parent().unwrap().to_path_buf(),
};
tests.extend(make_test(config, &paths, inputs, poisoned));
tests.extend(make_test(config, cache, &paths, inputs, poisoned));
return Ok(());
}
@ -680,13 +684,14 @@ fn collect_tests_from_dir(
let paths =
TestPaths { file: file_path, relative_dir: relative_dir_path.to_path_buf() };
tests.extend(make_test(config.clone(), &paths, inputs, poisoned))
tests.extend(make_test(config.clone(), cache, &paths, inputs, poisoned))
} else if file_path.is_dir() {
let relative_file_path = relative_dir_path.join(file.file_name());
if &file_name != "auxiliary" {
debug!("found directory: {:?}", file_path.display());
collect_tests_from_dir(
config.clone(),
cache,
&file_path,
&relative_file_path,
inputs,
@ -718,6 +723,7 @@ pub fn is_test(file_name: &OsString) -> bool {
fn make_test(
config: Arc<Config>,
cache: &HeadersCache,
testpaths: &TestPaths,
inputs: &Stamp,
poisoned: &mut bool,
@ -745,8 +751,9 @@ fn make_test(
std::fs::File::open(&test_path).expect("open test file to parse ignores");
let cfg = revision.map(|v| &**v);
let test_name = crate::make_test_name(&config, testpaths, revision);
let mut desc =
make_test_description(&config, test_name, &test_path, src_file, cfg, poisoned);
let mut desc = make_test_description(
&config, cache, test_name, &test_path, src_file, cfg, poisoned,
);
// Ignore tests that already run and are up to date with respect to inputs.
if !config.force_rerun {
desc.ignore |= is_up_to_date(