Skip to content

Commit e09cd46

Browse files
roypatpb8o
authored andcommitted
test: add 'no-block-pr' pytest marker
The marker works identically to the 'nonci' marker, but with different meaning: It is supposed to be used on tests that will run on every PR, but whose failure should not block merging. Additionally, switch from the --nonci option to using pytest's built-in, marker-based test filtering. This has the advantage that instead of skipping tests, we deselect them, reducing the log spam due to skipped tests (which was particularly noticable in the performance tests). pytest.ini defines a default argument of `-m 'not nonci and not no-block-pr'`, which deselects all nonci and optional tests. This can be overwritten when invoking pytest (through devtool test) by setting -m, for example to '-m optional' to only run optional tests, or to '-m nonci' to only run nonci tests. Signed-off-by: Patrick Roy <[email protected]>
1 parent 8b484d0 commit e09cd46

File tree

10 files changed

+35
-43
lines changed

10 files changed

+35
-43
lines changed

.buildkite/pipeline_cpu_template.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class BkStep(str, Enum):
2424
cpu_template_test = {
2525
"rdmsr": {
2626
BkStep.COMMAND: [
27-
"tools/devtool -y test -- -s -ra --nonci --log-cli-level=INFO integration_tests/functional/test_cpu_features.py -k 'test_cpu_rdmsr' "
27+
"tools/devtool -y test -- -s -ra -m nonci --log-cli-level=INFO integration_tests/functional/test_cpu_features.py -k 'test_cpu_rdmsr' "
2828
],
2929
BkStep.LABEL: "📖 rdmsr",
3030
"instances": ["m5d.metal", "m6a.metal", "m6i.metal"],
@@ -33,7 +33,7 @@ class BkStep(str, Enum):
3333
"cpuid_wrmsr": {
3434
"snapshot": {
3535
BkStep.COMMAND: [
36-
"tools/devtool -y test -- -s -ra --nonci --log-cli-level=INFO integration_tests/functional/test_cpu_features.py -k 'test_cpu_wrmsr_snapshot or test_cpu_cpuid_snapshot'",
36+
"tools/devtool -y test -- -s -ra -m nonci --log-cli-level=INFO integration_tests/functional/test_cpu_features.py -k 'test_cpu_wrmsr_snapshot or test_cpu_cpuid_snapshot'",
3737
"mkdir -pv tests/snapshot_artifacts_upload/{instance}_{os}_{kv}",
3838
"sudo mv tests/snapshot_artifacts/* tests/snapshot_artifacts_upload/{instance}_{os}_{kv}",
3939
],
@@ -45,7 +45,7 @@ class BkStep(str, Enum):
4545
BkStep.COMMAND: [
4646
"buildkite-agent artifact download tests/snapshot_artifacts_upload/{instance}_{os}_{kv}/**/* .",
4747
"mv tests/snapshot_artifacts_upload/{instance}_{os}_{kv} tests/snapshot_artifacts",
48-
"tools/devtool -y test -- -s -ra --nonci --log-cli-level=INFO integration_tests/functional/test_cpu_features.py -k 'test_cpu_wrmsr_restore or test_cpu_cpuid_restore'",
48+
"tools/devtool -y test -- -s -ra -m nonci --log-cli-level=INFO integration_tests/functional/test_cpu_features.py -k 'test_cpu_wrmsr_restore or test_cpu_cpuid_restore'",
4949
],
5050
BkStep.LABEL: "📸 load snapshot artifacts created on {instance} {snapshot_os} {snapshot_kv} to {restore_instance} {restore_os} {restore_kv}",
5151
BkStep.TIMEOUT: 30,
@@ -58,7 +58,7 @@ class BkStep(str, Enum):
5858
},
5959
"aarch64_cpu_templates": {
6060
BkStep.COMMAND: [
61-
"tools/devtool -y test -- -s -ra --nonci --log-cli-level=INFO integration_tests/functional/test_cpu_features_aarch64.py"
61+
"tools/devtool -y test -- -s -ra -m nonci --log-cli-level=INFO integration_tests/functional/test_cpu_features_aarch64.py"
6262
],
6363
BkStep.LABEL: "📖 cpu templates",
6464
"instances": ["m6g.metal", "c7g.metal"],

.buildkite/pipeline_cross.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def restore_step(label, src_instance, src_kv, dst_instance, dst_os, dst_kv):
2626
"command": [
2727
f"buildkite-agent artifact download snapshots/{src_instance}_{src_kv}/* .",
2828
f"mv -v snapshots/{src_instance}_{src_kv} snapshot_artifacts",
29-
f"./tools/devtool -y test -- --nonci {k_val} integration_tests/functional/test_snapshot_restore_cross_kernel.py",
29+
f"./tools/devtool -y test -- -m nonci {k_val} integration_tests/functional/test_snapshot_restore_cross_kernel.py",
3030
],
3131
"label": label,
3232
"timeout": 30,

.buildkite/pipeline_perf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def build_group(test):
4646
test_path = test.pop("test_path")
4747
return group(
4848
label=test.pop("label"),
49-
command=f"./tools/devtool -y test {devtool_opts} -- --nonci {test_path}",
49+
command=f"./tools/devtool -y test {devtool_opts} -- -m nonci {test_path}",
5050
agent_tags=["ag=1"],
5151
artifacts=["./test_results/*"],
5252
instances=test.pop("instances"),

tests/conftest.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def test_with_any_microvm(test_microvm_any):
9292

9393
import pytest
9494

95-
import framework.utils_cpuid as cpuid_utils
9695
import host_tools.cargo_build as build_tools
9796
from framework import defs, utils
9897
from framework.artifacts import ArtifactCollection, DiskArtifact, FirecrackerArtifact
@@ -126,32 +125,6 @@ def test_with_any_microvm(test_microvm_any):
126125
METRICS = get_metrics_logger()
127126

128127

129-
def pytest_configure(config):
130-
"""Pytest hook - initialization"""
131-
config.addinivalue_line("markers", "nonci: mark test as nonci.")
132-
133-
134-
def pytest_addoption(parser):
135-
"""Pytest hook. Add command line options."""
136-
parser.addoption("--nonci", action="store_true", help="run tests marked with nonci")
137-
138-
139-
def pytest_collection_modifyitems(config, items):
140-
"""Pytest hook. Skip some tests."""
141-
skip_markers = {}
142-
143-
for skip_marker_name in ["nonci"]:
144-
if not config.getoption(f"--{skip_marker_name}"):
145-
skip_markers[skip_marker_name] = pytest.mark.skip(
146-
reason=f"Skipping {skip_marker_name} test"
147-
)
148-
149-
for item in items:
150-
for skip_marker_name, skip_marker in skip_markers.items():
151-
if skip_marker_name in item.keywords:
152-
item.add_marker(skip_marker)
153-
154-
155128
@pytest.fixture(scope="function", autouse=True)
156129
def record_props(request, record_property):
157130
"""Decorate test results with additional properties.
@@ -511,23 +484,13 @@ def rootfs_msrtools(request, record_property):
511484
def cpu_template(request, record_property):
512485
"""Return all CPU templates supported by the vendor."""
513486
record_property("cpu_template", request.param)
514-
if (
515-
cpuid_utils.get_cpu_vendor() == cpuid_utils.CpuVendor.ARM
516-
and not request.config.getoption("--nonci")
517-
):
518-
pytest.skip("temporary skip on usual CI")
519487
return request.param
520488

521489

522490
@pytest.fixture(params=SUPPORTED_CUSTOM_CPU_TEMPLATES)
523491
def custom_cpu_template(request, record_property):
524492
"""Return all dummy custom CPU templates supported by the vendor."""
525493
record_property("custom_cpu_template", request.param)
526-
if (
527-
cpuid_utils.get_cpu_vendor() == cpuid_utils.CpuVendor.ARM
528-
and not request.config.getoption("--nonci")
529-
):
530-
pytest.skip("temporary skip on usual CI")
531494
return request.param
532495

533496

tests/framework/utils_cpu_templates.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import json
77
from pathlib import Path
88

9+
import pytest
10+
911
import framework.utils_cpuid as cpuid_utils
1012

1113
# All existing CPU templates available on Intel
@@ -77,3 +79,10 @@ def name_list_to_tmpl_list(name_list):
7779

7880

7981
SUPPORTED_CUSTOM_CPU_TEMPLATES = get_supported_custom_cpu_templates()
82+
83+
84+
def nonci_on_arm(func):
85+
"""Temporary decorator used to mark specific cpu template related tests as nonci on ARM platforms"""
86+
if cpuid_utils.get_cpu_vendor() == cpuid_utils.CpuVendor.ARM:
87+
return pytest.mark.nonci(func)
88+
return func

tests/integration_tests/functional/test_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from framework.artifacts import NetIfaceConfig, SnapshotType
1919
from framework.builder import MicrovmBuilder, SnapshotBuilder
2020
from framework.utils import get_firecracker_version_from_toml, is_io_uring_supported
21+
from framework.utils_cpu_templates import nonci_on_arm
2122

2223
MEM_LIMIT = 1000000000
2324

@@ -474,6 +475,7 @@ def test_api_machine_config(test_microvm_with_api):
474475
assert json["machine-config"]["smt"] is False
475476

476477

478+
@nonci_on_arm
477479
def test_api_cpu_config(test_microvm_with_api, custom_cpu_template):
478480
"""
479481
Test /cpu-config PUT scenarios.

tests/integration_tests/functional/test_cpu_features_aarch64.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pytest
1010

1111
import framework.utils_cpuid as cpuid_utils
12+
from framework.utils_cpu_templates import nonci_on_arm
1213

1314
PLATFORM = platform.machine()
1415

@@ -95,6 +96,7 @@ def test_default_cpu_features(test_microvm_with_api, network_config):
9596
PLATFORM != "aarch64",
9697
reason="This is aarch64 specific test.",
9798
)
99+
@nonci_on_arm
98100
def test_cpu_features_with_static_template(
99101
test_microvm_with_api, network_config, cpu_template
100102
):
@@ -113,6 +115,7 @@ def test_cpu_features_with_static_template(
113115
PLATFORM != "aarch64",
114116
reason="This is aarch64 specific test.",
115117
)
118+
@nonci_on_arm
116119
def test_cpu_features_with_custom_template(
117120
test_microvm_with_api, network_config, custom_cpu_template
118121
):

tests/integration_tests/functional/test_cpu_template_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ def test_host_fingerprint_change(test_microvm_with_api, cpu_template_helper, tmp
394394
)
395395

396396

397+
@nonci_on_arm
397398
def test_json_static_templates(
398399
test_microvm_with_api, cpu_template_helper, tmp_path, custom_cpu_template
399400
):

tests/integration_tests/security/test_vulnerabilities.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from framework import utils
1515
from framework.artifacts import DEFAULT_NETMASK
1616
from framework.properties import global_props
17+
from framework.utils_cpu_templates import nonci_on_arm
1718

1819
CHECKER_URL = "https://meltdown.ovh"
1920
CHECKER_FILENAME = "spectre-meltdown-checker.sh"
@@ -154,6 +155,7 @@ def test_spectre_meltdown_checker_on_restored_guest(
154155
global_props.instance == "c7g.metal" and global_props.host_linux_version == "4.14",
155156
reason="c7g host 4.14 requires modifications to the 5.10 guest kernel to boot successfully.",
156157
)
158+
@nonci_on_arm
157159
def test_spectre_meltdown_checker_on_guest_with_template(
158160
spectre_meltdown_checker,
159161
test_microvm_with_spectre_meltdown,
@@ -177,6 +179,7 @@ def test_spectre_meltdown_checker_on_guest_with_template(
177179
global_props.instance == "c7g.metal" and global_props.host_linux_version == "4.14",
178180
reason="c7g host 4.14 requires modifications to the 5.10 guest kernel to boot successfully.",
179181
)
182+
@nonci_on_arm
180183
def test_spectre_meltdown_checker_on_guest_with_custom_template(
181184
spectre_meltdown_checker,
182185
test_microvm_with_spectre_meltdown,
@@ -202,6 +205,7 @@ def test_spectre_meltdown_checker_on_guest_with_custom_template(
202205
global_props.instance == "c7g.metal" and global_props.host_linux_version == "4.14",
203206
reason="c7g host 4.14 requires modifications to the 5.10 guest kernel to boot successfully.",
204207
)
208+
@nonci_on_arm
205209
def test_spectre_meltdown_checker_on_restored_guest_with_template(
206210
spectre_meltdown_checker,
207211
test_microvm_with_spectre_meltdown,
@@ -228,6 +232,7 @@ def test_spectre_meltdown_checker_on_restored_guest_with_template(
228232
global_props.instance == "c7g.metal" and global_props.host_linux_version == "4.14",
229233
reason="c7g host 4.14 requires modifications to the 5.10 guest kernel to boot successfully.",
230234
)
235+
@nonci_on_arm
231236
def test_spectre_meltdown_checker_on_restored_guest_with_custom_template(
232237
spectre_meltdown_checker,
233238
test_microvm_with_spectre_meltdown,
@@ -292,6 +297,7 @@ def test_vulnerabilities_files_on_restored_guest(
292297
check_vulnerabilities_files_on_guest(dst_vm)
293298

294299

300+
@nonci_on_arm
295301
def test_vulnerabilities_files_on_guest_with_template(
296302
test_microvm_with_api,
297303
network_config,
@@ -305,6 +311,7 @@ def test_vulnerabilities_files_on_guest_with_template(
305311
check_vulnerabilities_files_on_guest(microvm)
306312

307313

314+
@nonci_on_arm
308315
def test_vulnerabilities_files_on_guest_with_custom_template(
309316
test_microvm_with_api,
310317
network_config,
@@ -322,6 +329,7 @@ def test_vulnerabilities_files_on_guest_with_custom_template(
322329
check_vulnerabilities_files_on_guest(microvm)
323330

324331

332+
@nonci_on_arm
325333
def test_vulnerabilities_files_on_restored_guest_with_template(
326334
test_microvm_with_api,
327335
network_config,
@@ -340,6 +348,7 @@ def test_vulnerabilities_files_on_restored_guest_with_template(
340348
check_vulnerabilities_files_on_guest(dst_vm)
341349

342350

351+
@nonci_on_arm
343352
def test_vulnerabilities_files_on_restored_guest_with_custom_template(
344353
test_microvm_with_api,
345354
network_config,

tests/pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ addopts =
44
--tb=short
55
--durations=10
66
--showlocals
7+
-m 'not nonci and not no_block_pr'
8+
9+
markers =
10+
no_block_pr: tests whose failure does not block PR merging.
11+
nonci: mark test as nonci.
712

813
; Overwrite the default norecursedirs, which includes 'build'.
914
norecursedirs = .*

0 commit comments

Comments
 (0)