Skip to content
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

Fix nightly pr failures #4206

Merged
merged 5 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
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
53 changes: 12 additions & 41 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import inspect
import os
import platform
import re
import shutil
import sys
Expand Down Expand Up @@ -196,8 +195,8 @@ def change_net_config_space_bin(test_fc_session_root_path):
yield change_net_config_space_bin


@pytest.fixture(scope="session")
def bin_seccomp_paths(test_fc_session_root_path):
@pytest.fixture
def bin_seccomp_paths():
"""Build jailers and jailed binaries to test seccomp.

They currently consist of:
Expand All @@ -206,48 +205,20 @@ def bin_seccomp_paths(test_fc_session_root_path):
* a jailed binary that follows the seccomp rules;
* a jailed binary that breaks the seccomp rules.
"""
seccomp_build_path = (
Path(test_fc_session_root_path) / build_tools.CARGO_RELEASE_REL_PATH
)
release_binaries_path = seccomp_build_path / build_tools.RELEASE_BINARIES_REL_PATH

seccomp_examples = ["jailer", "harmless", "malicious", "panic"]

demos = {}

for example in seccomp_examples:
build_tools.cargo_build(
seccomp_build_path,
f"--release --target {platform.machine()}-unknown-linux-musl --example seccomp_{example}",
)

demos[f"demo_{example}"] = release_binaries_path / f"examples/seccomp_{example}"

demos = {
f"demo_{example}": build_tools.get_example(f"seccomp_{example}")
for example in ["jailer", "harmless", "malicious", "panic"]
}
yield demos


@pytest.fixture(scope="session")
def uffd_handler_paths(test_fc_session_root_path):
@pytest.fixture
def uffd_handler_paths():
"""Build UFFD handler binaries."""
uffd_build_path = (
Path(test_fc_session_root_path) / build_tools.CARGO_RELEASE_REL_PATH
)
release_binaries_path = uffd_build_path / build_tools.RELEASE_BINARIES_REL_PATH

uffd_handlers = ["malicious", "valid"]

handlers = {}

for handler in uffd_handlers:
build_tools.cargo_build(
uffd_build_path,
f"--release --target {platform.machine()}-unknown-linux-musl --example uffd_{handler}_handler",
)

handlers[f"{handler}_handler"] = (
release_binaries_path / f"examples/uffd_{handler}_handler"
)

handlers = {
f"{handler}_handler": build_tools.get_example(f"uffd_{handler}_handler")
for handler in ["malicious", "valid"]
}
yield handlers


Expand Down
3 changes: 2 additions & 1 deletion tests/framework/ab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ def git_ab_test_host_command_if_pr(
command: str,
*,
comparator: Callable[[CommandReturn, CommandReturn], bool] = default_comparator,
**kwargs,
):
"""Runs the given bash command as an A/B-Test if we're in a pull request context (asserting that its stdout and
stderr did not change across the PR). Otherwise runs the command, asserting it returns a zero exit code
"""
if is_pr():
git_ab_test_host_command(command, comparator=comparator)
else:
utils.run_cmd(command)
utils.run_cmd(command, **kwargs, cwd=Path.cwd().parent)


def git_ab_test_host_command(
Expand Down
13 changes: 11 additions & 2 deletions tests/host_tools/cargo_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,20 @@ def cargo_test(path, extra_args=""):


@with_filelock
def get_binary(name, *, workspace_dir=FC_WORKSPACE_DIR):
def get_binary(name, *, workspace_dir=FC_WORKSPACE_DIR, example=False):
"""Build a binary"""
target = DEFAULT_BUILD_TARGET
target_dir = workspace_dir / "build" / "cargo_target"
bin_path = target_dir / target / "release" / name
cmd = f"-p {name}"
if example:
bin_path = target_dir / target / "release" / "examples" / name
cmd = f"--example {name}"
if not bin_path.exists():
env = {"RUSTFLAGS": get_rustflags()}
cargo(
"build",
f"-p {name} --release --target {target}",
f"--release --target {target} {cmd}",
env=env,
cwd=workspace_dir,
)
Expand All @@ -95,6 +99,11 @@ def get_firecracker_binaries(*, workspace_dir=FC_WORKSPACE_DIR):
)


def get_example(name, *args, **kwargs):
"""Build an example binary"""
return get_binary(name, *args, **kwargs, example=True)


@with_filelock
def run_seccompiler_bin(bpf_path, json_path=defs.SECCOMP_JSON_DIR, basic=False):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"dcpodp i8mm bf16 dgh rng".split(" ")
)

DEFAULT_G3_FEATURES_NO_SSBS_4_14 = DEFAULT_G3_FEATURES_5_10 - {"ssbs"}
DEFAULT_G3_FEATURES_NO_SSBS_5_10 = DEFAULT_G3_FEATURES_NO_SSBS_4_14
DEFAULT_G3_FEATURES_NO_SSBS_4_14 = DEFAULT_G3_FEATURES_4_14 - {"ssbs"}
DEFAULT_G3_FEATURES_NO_SSBS_5_10 = DEFAULT_G3_FEATURES_5_10 - {"ssbs"}

DEFAULT_G3_FEATURES_WITH_SVE_AND_PAC_4_14 = DEFAULT_G3_FEATURES_4_14
DEFAULT_G3_FEATURES_WITH_SVE_AND_PAC_5_10 = DEFAULT_G3_FEATURES_5_10 | set(
Expand Down
5 changes: 4 additions & 1 deletion tests/integration_tests/security/test_vulnerabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def configure_microvm(
microvm.basic_config(vcpu_count=2, mem_size_mib=256, cpu_template=cpu_template)
if custom_cpu_template:
microvm.api.cpu_config.put(**custom_cpu_template["template"])
microvm.cpu_template = cpu_template or custom_cpu_template
microvm.cpu_template = cpu_template
if cpu_template is None and custom_cpu_template is not None:
microvm.cpu_template = custom_cpu_template["name"]
microvm.add_net_iface()
microvm.start()
return microvm
Expand Down Expand Up @@ -178,6 +180,7 @@ def test_spectre_meltdown_checker_on_host(spectre_meltdown_checker):
comparator=set_did_not_grow_comparator(
spectre_meltdown_reported_vulnerablities
),
ignore_return_code=True,
pb8o marked this conversation as resolved.
Show resolved Hide resolved
)


Expand Down