Skip to content

Commit 13519e0

Browse files
roypatpb8o
authored andcommitted
test: Add optional test that ensures benchmarks dont regress
This test replaces our existing baseline-based and CI-failing benchmark tests with a single optional test that will not cause CI to fail, and also uses criterions statistical engine to detect regressions instead of hardcoded baseline files. Signed-off-by: Patrick Roy <[email protected]>
1 parent e09cd46 commit 13519e0

File tree

3 files changed

+48
-97
lines changed

3 files changed

+48
-97
lines changed

tests/integration_tests/functional/test_cpu_template_helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from framework import defs, utils
1212
from framework.defs import SUPPORTED_HOST_KERNELS
1313
from framework.properties import global_props
14+
from framework.utils_cpu_templates import nonci_on_arm
1415
from framework.utils_cpuid import get_guest_cpuid
1516
from host_tools import cargo_build
1617

@@ -250,6 +251,7 @@ def get_guest_msrs(microvm, msr_index_list):
250251
"System registers are not accessible on aarch64."
251252
),
252253
)
254+
@nonci_on_arm
253255
def test_cpu_config_dump_vs_actual(
254256
test_microvm_with_api_and_msrtools,
255257
cpu_template_helper,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Optional benchmarks-do-not-regress test"""
4+
5+
import os
6+
import platform
7+
8+
import pytest
9+
10+
from framework import utils
11+
from host_tools.cargo_build import cargo
12+
13+
TARGET_BRANCH = os.environ.get("BUILDKITE_PULL_REQUEST_BASE_BRANCH") or "main"
14+
15+
16+
@pytest.mark.no_block_pr
17+
@pytest.mark.timeout(600)
18+
def test_no_regression_relative_to_target_branch():
19+
"""
20+
Run the microbenchmarks in this repository, comparing results from pull
21+
request target branch against what's achieved on HEAD
22+
"""
23+
# First, run benchmarks on pull request target branch (usually main). For this, cache the commit at which
24+
# the test was originally executed
25+
_, pr_head_commit_sha, _ = utils.run_cmd("git rev-parse HEAD")
26+
utils.run_cmd(f"git switch {TARGET_BRANCH}")
27+
cargo("bench", f"--all --quiet --target {platform.machine()}-unknown-linux-musl")
28+
29+
# Switch back to pull request, and run benchmarks again. Criterion will automatically notice that
30+
# data from a previous run exists, and do a comparison
31+
utils.run_cmd(f"git checkout {pr_head_commit_sha}")
32+
_, criterion_output, _ = cargo(
33+
"bench", f"--all --quiet --target {platform.machine()}-unknown-linux-musl"
34+
)
35+
36+
# Criterion separates reports for benchmarks by two newlines. We filter and print the ones
37+
# that contain the string 'Performance has regression.', which criterion uses to indicate a regression
38+
regressions_only = "\n\n".join(
39+
result
40+
for result in criterion_output.split("\n\n")
41+
if "Performance has regressed." in result
42+
)
43+
44+
# If this string is anywhere in stdout, then at least one of our benchmarks
45+
# is now performing worse with the PR changes.
46+
assert not regressions_only, "\n" + regressions_only

tests/integration_tests/performance/test_cpu_template_benchmark.py

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)