CI tests can exit directly after taking a screenshot (#19806)
# Objective - Currently, CI tests take a screenshot at frame X and exits at frame Y with X < Y, and both number fixed - This means tests can take longer than they actually need when taking the screenshot is fast, and can fail to take the screenshot when it's taking too long ## Solution - Add a new event `ScreenshotAndExit` that exit directly after the screenshot is saved
This commit is contained in:
parent
04c2b32be8
commit
97dcb279fb
@ -37,6 +37,9 @@ pub enum CiTestingEvent {
|
|||||||
/// Takes a screenshot of the entire screen, and saves the results to
|
/// Takes a screenshot of the entire screen, and saves the results to
|
||||||
/// `screenshot-{current_frame}.png`.
|
/// `screenshot-{current_frame}.png`.
|
||||||
Screenshot,
|
Screenshot,
|
||||||
|
/// Takes a screenshot of the entire screen, saves the results to
|
||||||
|
/// `screenshot-{current_frame}.png`, and exits once the screenshot is taken.
|
||||||
|
ScreenshotAndExit,
|
||||||
/// Takes a screenshot of the entire screen, and saves the results to
|
/// Takes a screenshot of the entire screen, and saves the results to
|
||||||
/// `screenshot-{name}.png`.
|
/// `screenshot-{name}.png`.
|
||||||
NamedScreenshot(String),
|
NamedScreenshot(String),
|
||||||
|
|||||||
@ -21,6 +21,19 @@ pub(crate) fn send_events(world: &mut World, mut current_frame: Local<u32>) {
|
|||||||
world.send_event(AppExit::Success);
|
world.send_event(AppExit::Success);
|
||||||
info!("Exiting after {} frames. Test successful!", *current_frame);
|
info!("Exiting after {} frames. Test successful!", *current_frame);
|
||||||
}
|
}
|
||||||
|
CiTestingEvent::ScreenshotAndExit => {
|
||||||
|
let this_frame = *current_frame;
|
||||||
|
world.spawn(Screenshot::primary_window()).observe(
|
||||||
|
move |captured: On<bevy_render::view::screenshot::ScreenshotCaptured>,
|
||||||
|
mut exit_event: EventWriter<AppExit>| {
|
||||||
|
let path = format!("./screenshot-{}.png", this_frame);
|
||||||
|
save_to_disk(path)(captured);
|
||||||
|
info!("Exiting. Test successful!");
|
||||||
|
exit_event.write(AppExit::Success);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
info!("Took a screenshot at frame {}.", *current_frame);
|
||||||
|
}
|
||||||
CiTestingEvent::Screenshot => {
|
CiTestingEvent::Screenshot => {
|
||||||
let path = format!("./screenshot-{}.png", *current_frame);
|
let path = format!("./screenshot-{}.png", *current_frame);
|
||||||
world
|
world
|
||||||
|
|||||||
@ -55,6 +55,12 @@ enum Action {
|
|||||||
/// This defaults to frame 250. Set it to 0 to not stop the example automatically.
|
/// This defaults to frame 250. Set it to 0 to not stop the example automatically.
|
||||||
stop_frame: u32,
|
stop_frame: u32,
|
||||||
|
|
||||||
|
#[arg(long, default_value = "false")]
|
||||||
|
/// Automatically ends after taking a screenshot
|
||||||
|
///
|
||||||
|
/// Only works if `screenshot-frame` is set to non-0, and overrides `stop-frame`.
|
||||||
|
auto_stop_frame: bool,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
/// Which frame to take a screenshot at. Set to 0 for no screenshot.
|
/// Which frame to take a screenshot at. Set to 0 for no screenshot.
|
||||||
screenshot_frame: u32,
|
screenshot_frame: u32,
|
||||||
@ -150,6 +156,7 @@ fn main() {
|
|||||||
Action::Run {
|
Action::Run {
|
||||||
wgpu_backend,
|
wgpu_backend,
|
||||||
stop_frame,
|
stop_frame,
|
||||||
|
auto_stop_frame,
|
||||||
screenshot_frame,
|
screenshot_frame,
|
||||||
fixed_frame_time,
|
fixed_frame_time,
|
||||||
in_ci,
|
in_ci,
|
||||||
@ -183,11 +190,21 @@ fn main() {
|
|||||||
|
|
||||||
let mut extra_parameters = vec![];
|
let mut extra_parameters = vec![];
|
||||||
|
|
||||||
match (stop_frame, screenshot_frame) {
|
match (stop_frame, screenshot_frame, auto_stop_frame) {
|
||||||
// When the example does not automatically stop nor take a screenshot.
|
// When the example does not automatically stop nor take a screenshot.
|
||||||
(0, 0) => (),
|
(0, 0, _) => (),
|
||||||
|
// When the example automatically stops at an automatic frame.
|
||||||
|
(0, _, true) => {
|
||||||
|
let mut file = File::create("example_showcase_config.ron").unwrap();
|
||||||
|
file.write_all(
|
||||||
|
format!("(setup: (fixed_frame_time: Some({fixed_frame_time})), events: [({screenshot_frame}, ScreenshotAndExit)])").as_bytes(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
extra_parameters.push("--features");
|
||||||
|
extra_parameters.push("bevy_ci_testing");
|
||||||
|
}
|
||||||
// When the example does not automatically stop.
|
// When the example does not automatically stop.
|
||||||
(0, _) => {
|
(0, _, false) => {
|
||||||
let mut file = File::create("example_showcase_config.ron").unwrap();
|
let mut file = File::create("example_showcase_config.ron").unwrap();
|
||||||
file.write_all(
|
file.write_all(
|
||||||
format!("(setup: (fixed_frame_time: Some({fixed_frame_time})), events: [({screenshot_frame}, Screenshot)])").as_bytes(),
|
format!("(setup: (fixed_frame_time: Some({fixed_frame_time})), events: [({screenshot_frame}, Screenshot)])").as_bytes(),
|
||||||
@ -197,15 +214,25 @@ fn main() {
|
|||||||
extra_parameters.push("bevy_ci_testing");
|
extra_parameters.push("bevy_ci_testing");
|
||||||
}
|
}
|
||||||
// When the example does not take a screenshot.
|
// When the example does not take a screenshot.
|
||||||
(_, 0) => {
|
(_, 0, _) => {
|
||||||
let mut file = File::create("example_showcase_config.ron").unwrap();
|
let mut file = File::create("example_showcase_config.ron").unwrap();
|
||||||
file.write_all(format!("(events: [({stop_frame}, AppExit)])").as_bytes())
|
file.write_all(format!("(events: [({stop_frame}, AppExit)])").as_bytes())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
extra_parameters.push("--features");
|
extra_parameters.push("--features");
|
||||||
extra_parameters.push("bevy_ci_testing");
|
extra_parameters.push("bevy_ci_testing");
|
||||||
}
|
}
|
||||||
|
// When the example both automatically stops at an automatic frame and takes a screenshot.
|
||||||
|
(_, _, true) => {
|
||||||
|
let mut file = File::create("example_showcase_config.ron").unwrap();
|
||||||
|
file.write_all(
|
||||||
|
format!("(setup: (fixed_frame_time: Some({fixed_frame_time})), events: [({screenshot_frame}, ScreenshotAndExit)])").as_bytes(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
extra_parameters.push("--features");
|
||||||
|
extra_parameters.push("bevy_ci_testing");
|
||||||
|
}
|
||||||
// When the example both automatically stops and takes a screenshot.
|
// When the example both automatically stops and takes a screenshot.
|
||||||
(_, _) => {
|
(_, _, false) => {
|
||||||
let mut file = File::create("example_showcase_config.ron").unwrap();
|
let mut file = File::create("example_showcase_config.ron").unwrap();
|
||||||
file.write_all(
|
file.write_all(
|
||||||
format!("(setup: (fixed_frame_time: Some({fixed_frame_time})), events: [({screenshot_frame}, Screenshot), ({stop_frame}, AppExit)])").as_bytes(),
|
format!("(setup: (fixed_frame_time: Some({fixed_frame_time})), events: [({screenshot_frame}, Screenshot), ({stop_frame}, AppExit)])").as_bytes(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user