Skip to content

Commit

Permalink
Retrieve feature-based results for Test262 runs (#1980)
Browse files Browse the repository at this point in the history
This Pull Request fixes/closes #1645.

It changes the following:

- Add `features` field to `SuiteResult` structure
- Fetch features from `TestSuite` and propagate them via `SuiteResult`
- Add `FeaturesInfo` structure and serialize it to `features.json`
  • Loading branch information
NorbertGarfield authored and Razican committed Jun 8, 2022
1 parent 2537ac6 commit e70b50b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
9 changes: 9 additions & 0 deletions boa_tester/src/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ impl TestSuite {
.collect()
};

let mut features = Vec::new();
for test_iter in self.tests.iter() {
for feature_iter in test_iter.features.iter() {
features.push(feature_iter.to_string());
}
}

if verbose != 0 {
println!();
}
Expand All @@ -67,6 +74,7 @@ impl TestSuite {
passed += suite.passed;
ignored += suite.ignored;
panic += suite.panic;
features.append(&mut suite.features.clone());
}

if verbose != 0 {
Expand Down Expand Up @@ -95,6 +103,7 @@ impl TestSuite {
panic,
suites,
tests,
features,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions boa_tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ struct SuiteResult {
#[serde(rename = "t")]
#[serde(skip_serializing_if = "Vec::is_empty", default)]
tests: Vec<TestResult>,
#[serde(rename = "f")]
#[serde(skip_serializing_if = "Vec::is_empty", default)]
features: Vec<String>,
}

/// Outcome of a test.
Expand Down
54 changes: 53 additions & 1 deletion boa_tester/src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,45 @@ impl From<ResultInfo> for ReducedResultInfo {
}
}

#[derive(Debug, Clone, Deserialize, Serialize)]
struct FeaturesInfo {
#[serde(rename = "c")]
commit: Box<str>,
#[serde(rename = "u")]
test262_commit: Box<str>,
#[serde(rename = "n")]
suite_name: Box<str>,
#[serde(rename = "f")]
features: Vec<String>,
}

fn remove_duplicates(features_vec: &[String]) -> Vec<String> {
let mut result = features_vec.to_vec();
result.sort();
result.dedup();
result
}

impl From<ResultInfo> for FeaturesInfo {
fn from(info: ResultInfo) -> Self {
Self {
commit: info.commit,
test262_commit: info.test262_commit,
suite_name: info.results.name,
features: remove_duplicates(&info.results.features),
}
}
}

/// File name of the "latest results" JSON file.
const LATEST_FILE_NAME: &str = "latest.json";

/// File name of the "all results" JSON file.
const RESULTS_FILE_NAME: &str = "results.json";

/// File name of the "features" JSON file.
const FEATURES_FILE_NAME: &str = "features.json";

/// Writes the results of running the test suite to the given JSON output file.
///
/// It will append the results to the ones already present, in an array.
Expand Down Expand Up @@ -108,14 +141,33 @@ pub(crate) fn write_json(
Vec::new()
};

all_results.push(new_results.into());
all_results.push(new_results.clone().into());

let output = BufWriter::new(fs::File::create(&all_path)?);
serde_json::to_writer(output, &all_results)?;

if verbose != 0 {
println!("Results written correctly");
}

// Write the full list of features, existing features go first.

let features_path = path.join(FEATURES_FILE_NAME);

let mut all_features: Vec<FeaturesInfo> = if features_path.exists() {
serde_json::from_reader(BufReader::new(fs::File::open(&features_path)?))?
} else {
Vec::new()
};

all_features.push(new_results.into());

let features_output = BufWriter::new(fs::File::create(&features_path)?);
serde_json::to_writer(features_output, &all_features)?;

if verbose != 0 {
println!("Features written correctly");
}
}

Ok(())
Expand Down

0 comments on commit e70b50b

Please sign in to comment.