about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-03-25 20:34:45 -0400
committerGitHub <noreply@github.com>2025-03-25 20:34:45 -0400
commit277902bd1d9c62018a7247e5767ccd2fab96f0ae (patch)
treea5b60cd6d2523f3ddbc1b1e5f782786b0d73683c
parent1c84c063f0e5353af46a80ec40d1de5e5f35d063 (diff)
parente9ddf54d16ea4563714185cf744fd753c734261a (diff)
downloadrust-277902bd1d9c62018a7247e5767ccd2fab96f0ae.tar.gz
rust-277902bd1d9c62018a7247e5767ccd2fab96f0ae.zip
Rollup merge of #138834 - Kobzol:test-diff-group-by-stage, r=marcoieni
Group test diffs by stage in post-merge analysis

I think that this is clearer than including the stage in the test name.

To test e.g. on [this PR](https://github.com/rust-lang/rust/pull/138523):
```bash
$ curl https://ci-artifacts.rust-lang.org/rustc-builds/282865097d138c7f0f7a7566db5b761312dd145c/metrics-aarch64-gnu.json > metrics.json
$ cargo run --manifest-path src/ci/citool/Cargo.toml postprocess-metrics metrics.json --job-name aarch64-gnu --parent d9e5539a39192028a7b15ae596a8685017faecee > out.md
```

r? `@marcoieni`
-rw-r--r--src/ci/citool/src/analysis.rs43
1 files changed, 25 insertions, 18 deletions
diff --git a/src/ci/citool/src/analysis.rs b/src/ci/citool/src/analysis.rs
index 2088ce29620..98e9be0f35a 100644
--- a/src/ci/citool/src/analysis.rs
+++ b/src/ci/citool/src/analysis.rs
@@ -210,6 +210,7 @@ struct TestSuiteData {
 #[derive(Hash, PartialEq, Eq, Debug, Clone)]
 struct Test {
     name: String,
+    stage: u8,
     is_doctest: bool,
 }
 
@@ -218,27 +219,24 @@ fn aggregate_tests(metrics: &JsonRoot) -> TestSuiteData {
     let mut tests = HashMap::new();
     let test_suites = get_test_suites(&metrics);
     for suite in test_suites {
+        let stage = match suite.metadata {
+            TestSuiteMetadata::CargoPackage { stage, .. } => stage,
+            TestSuiteMetadata::Compiletest { stage, .. } => stage,
+        } as u8;
         for test in &suite.tests {
             // Poor man's detection of doctests based on the "(line XYZ)" suffix
             let is_doctest = matches!(suite.metadata, TestSuiteMetadata::CargoPackage { .. })
                 && test.name.contains("(line");
-            let test_entry = Test { name: generate_test_name(&test.name, &suite), is_doctest };
+            let test_entry = Test { name: generate_test_name(&test.name), stage, is_doctest };
             tests.insert(test_entry, test.outcome.clone());
         }
     }
     TestSuiteData { tests }
 }
 
-/// Normalizes Windows-style path delimiters to Unix-style paths
-/// and adds suite metadata to the test name.
-fn generate_test_name(name: &str, suite: &TestSuite) -> String {
-    let name = name.replace('\\', "/");
-    let stage = match suite.metadata {
-        TestSuiteMetadata::CargoPackage { stage, .. } => stage,
-        TestSuiteMetadata::Compiletest { stage, .. } => stage,
-    };
-
-    format!("{name} (stage {stage})")
+/// Normalizes Windows-style path delimiters to Unix-style paths.
+fn generate_test_name(name: &str) -> String {
+    name.replace('\\', "/")
 }
 
 /// Prints test changes in Markdown format to stdout.
@@ -321,16 +319,25 @@ fn report_test_diffs(diff: AggregatedTestDiffs) {
     // Sort diffs by job group and test name
     grouped_diffs.sort_by(|(d1, g1), (d2, g2)| g1.cmp(&g2).then(d1.test.name.cmp(&d2.test.name)));
 
+    // Now group the tests by stage
+    let mut grouped_by_stage: BTreeMap<u8, Vec<(&TestDiff, u64)>> = Default::default();
+    for (diff, group) in grouped_diffs {
+        grouped_by_stage.entry(diff.test.stage).or_default().push((diff, group))
+    }
+
     output_details(
         &format!("Show {} test {}\n", original_diff_count, pluralize("diff", original_diff_count)),
         || {
-            for (diff, job_group) in grouped_diffs {
-                println!(
-                    "- `{}`: {} ({})",
-                    diff.test.name,
-                    format_diff(&diff.diff),
-                    format_job_group(job_group)
-                );
+            for (stage, diffs) in grouped_by_stage {
+                println!("## Stage {stage}");
+                for (diff, job_group) in diffs {
+                    println!(
+                        "- `{}`: {} ({})",
+                        diff.test.name,
+                        format_diff(&diff.diff),
+                        format_job_group(job_group)
+                    );
+                }
             }
 
             let extra_diffs = diffs.len().saturating_sub(max_diff_count);