Skip to content

ci: added test log format for ci #135355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions src/bootstrap/src/utils/render_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::io::{BufRead, BufReader, Read, Write};
use std::process::{ChildStdout, Stdio};
use std::time::Duration;

use build_helper::ci::CiEnv;
use termcolor::{Color, ColorSpec, WriteColor};

use crate::core::builder::Builder;
Expand Down Expand Up @@ -91,7 +92,9 @@ struct Renderer<'a> {
/// Number of tests that were skipped due to already being up-to-date
/// (i.e. no relevant changes occurred since they last ran).
up_to_date_tests: usize,
ignored_tests: usize,
terse_tests_in_line: usize,
ci_latest_logged_percentage: f64,
}

impl<'a> Renderer<'a> {
Expand All @@ -104,7 +107,9 @@ impl<'a> Renderer<'a> {
tests_count: None,
executed_tests: 0,
up_to_date_tests: 0,
ignored_tests: 0,
terse_tests_in_line: 0,
ci_latest_logged_percentage: 0.0,
}
}

Expand Down Expand Up @@ -159,9 +164,12 @@ impl<'a> Renderer<'a> {
fn render_test_outcome(&mut self, outcome: Outcome<'_>, test: &TestOutcome) {
self.executed_tests += 1;

// Keep this in sync with the "up-to-date" ignore message inserted by compiletest.
if let Outcome::Ignored { reason: Some("up-to-date") } = outcome {
self.up_to_date_tests += 1;
if let Outcome::Ignored { reason } = outcome {
self.ignored_tests += 1;
// Keep this in sync with the "up-to-date" ignore message inserted by compiletest.
if reason == Some("up-to-date") {
self.up_to_date_tests += 1;
}
}

#[cfg(feature = "build-metrics")]
Expand All @@ -179,6 +187,8 @@ impl<'a> Renderer<'a> {

if self.builder.config.verbose_tests {
self.render_test_outcome_verbose(outcome, test);
} else if CiEnv::is_ci() {
self.render_test_outcome_ci(outcome, test);
} else {
self.render_test_outcome_terse(outcome, test);
}
Expand Down Expand Up @@ -209,6 +219,31 @@ impl<'a> Renderer<'a> {
let _ = std::io::stdout().flush();
}

fn render_test_outcome_ci(&mut self, outcome: Outcome<'_>, test: &TestOutcome) {
if let Some(total) = self.tests_count {
let percent = self.executed_tests as f64 / total as f64;

if self.ci_latest_logged_percentage + 0.10 < percent {
let total = total.to_string();
let executed = format!("{:>width$}", self.executed_tests, width = total.len());
let pretty_percent = format!("{:.0}%", percent * 100.0);
let passed_tests = self.executed_tests - (self.failures.len() + self.ignored_tests);
println!(
"{:<4} -- {executed}/{total}, {:>total_indent$} passed, {} failed, {} ignored",
pretty_percent,
passed_tests,
self.failures.len(),
self.ignored_tests,
total_indent = total.len()
);
self.ci_latest_logged_percentage += 0.10;
}
}

self.builder.colored_stdout(|stdout| outcome.write_ci(stdout, &test.name)).unwrap();
let _ = std::io::stdout().flush();
}

fn render_suite_outcome(&self, outcome: Outcome<'_>, suite: &SuiteOutcome) {
// The terse output doesn't end with a newline, so we need to add it ourselves.
if !self.builder.config.verbose_tests {
Expand Down Expand Up @@ -378,6 +413,17 @@ impl Outcome<'_> {
}
writer.reset()
}

fn write_ci(&self, writer: &mut dyn WriteColor, name: &str) -> Result<(), std::io::Error> {
match self {
Outcome::Ok | Outcome::BenchOk | Outcome::Ignored { .. } => {}
Outcome::Failed => {
writer.set_color(ColorSpec::new().set_fg(Some(Color::Red)))?;
writeln!(writer, " {name} ... FAILED")?;
}
}
writer.reset()
}
}

#[derive(serde_derive::Deserialize)]
Expand Down
Loading