Skip to content

Commit a8f38cb

Browse files
committed
refactor(test): make uffd_handle_paths not be a fixture
There's really no use in having this be a fixture, it's just a dictionary - it used to be a fixture because we were building the binaries inside of the test framework (and so each call to it as a function would trigger compilations), but now that we pre-compile everything that's no longer something to worry about. Signed-off-by: Patrick Roy <[email protected]>
1 parent 7e90988 commit a8f38cb

File tree

4 files changed

+17
-34
lines changed

4 files changed

+17
-34
lines changed

tests/conftest.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,6 @@ def bin_seccomp_paths():
252252
yield demos
253253

254254

255-
@pytest.fixture
256-
def uffd_handler_paths():
257-
"""Build UFFD handler binaries."""
258-
handlers = {
259-
f"{handler}_handler": build_tools.get_example(f"uffd_{handler}_handler")
260-
for handler in ["malicious", "valid", "fault_all"]
261-
}
262-
yield handlers
263-
264-
265255
@pytest.fixture(scope="session")
266256
def netns_factory(worker_id):
267257
"""A network namespace factory

tests/framework/utils_uffd.py

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

1111
from framework.utils import chroot
12+
from host_tools import cargo_build
1213

1314
SOCKET_PATH = "/firecracker-uffd.sock"
1415

@@ -90,3 +91,8 @@ def spawn_pf_handler(vm, handler_path, mem_path):
9091
uffd_handler.spawn(vm.jailer.uid, vm.jailer.gid)
9192

9293
return uffd_handler
94+
95+
96+
def uffd_handler(handler_name):
97+
"""Retrieves the uffd handler with the given name"""
98+
return cargo_build.get_example(f"uffd_{handler_name}_handler")

tests/integration_tests/functional/test_uffd.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import requests
1010

1111
from framework.utils import Timeout, check_output
12-
from framework.utils_uffd import SOCKET_PATH, spawn_pf_handler
12+
from framework.utils_uffd import SOCKET_PATH, spawn_pf_handler, uffd_handler
1313

1414

1515
@pytest.fixture(scope="function", name="snapshot")
@@ -83,7 +83,7 @@ def test_unbinded_socket(uvm_plain, snapshot):
8383
vm.mark_killed()
8484

8585

86-
def test_valid_handler(uvm_plain, snapshot, uffd_handler_paths):
86+
def test_valid_handler(uvm_plain, snapshot):
8787
"""
8888
Test valid uffd handler scenario.
8989
"""
@@ -92,9 +92,7 @@ def test_valid_handler(uvm_plain, snapshot, uffd_handler_paths):
9292
vm.spawn()
9393

9494
# Spawn page fault handler process.
95-
_pf_handler = spawn_pf_handler(
96-
vm, uffd_handler_paths["valid_handler"], snapshot.mem
97-
)
95+
_pf_handler = spawn_pf_handler(vm, uffd_handler("valid"), snapshot.mem)
9896

9997
vm.restore_from_snapshot(snapshot, resume=True, uffd_path=SOCKET_PATH)
10098

@@ -111,7 +109,7 @@ def test_valid_handler(uvm_plain, snapshot, uffd_handler_paths):
111109
vm.ssh.check_output("true")
112110

113111

114-
def test_malicious_handler(uvm_plain, snapshot, uffd_handler_paths):
112+
def test_malicious_handler(uvm_plain, snapshot):
115113
"""
116114
Test malicious uffd handler scenario.
117115
@@ -127,9 +125,7 @@ def test_malicious_handler(uvm_plain, snapshot, uffd_handler_paths):
127125
vm.spawn()
128126

129127
# Spawn page fault handler process.
130-
_pf_handler = spawn_pf_handler(
131-
vm, uffd_handler_paths["malicious_handler"], snapshot.mem
132-
)
128+
_pf_handler = spawn_pf_handler(vm, uffd_handler("malicious"), snapshot.mem)
133129

134130
# We expect Firecracker to freeze while resuming from a snapshot
135131
# due to the malicious handler's unavailability.

tests/integration_tests/performance/test_huge_pages.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from framework.microvm import HugePagesConfig
1111
from framework.properties import global_props
1212
from framework.utils_ftrace import ftrace_events
13-
from framework.utils_uffd import SOCKET_PATH, spawn_pf_handler
13+
from framework.utils_uffd import SOCKET_PATH, spawn_pf_handler, uffd_handler
1414

1515

1616
def check_hugetlbfs_in_use(pid: int, allocation_name: str):
@@ -69,9 +69,7 @@ def test_hugetlbfs_boot(uvm_plain):
6969
)
7070

7171

72-
def test_hugetlbfs_snapshot(
73-
microvm_factory, guest_kernel_linux_5_10, rootfs, uffd_handler_paths
74-
):
72+
def test_hugetlbfs_snapshot(microvm_factory, guest_kernel_linux_5_10, rootfs):
7573
"""
7674
Test hugetlbfs snapshot restore via uffd
7775
"""
@@ -95,16 +93,14 @@ def test_hugetlbfs_snapshot(
9593
vm.spawn()
9694

9795
# Spawn page fault handler process.
98-
_pf_handler = spawn_pf_handler(
99-
vm, uffd_handler_paths["valid_handler"], snapshot.mem
100-
)
96+
_pf_handler = spawn_pf_handler(vm, uffd_handler("valid"), snapshot.mem)
10197

10298
vm.restore_from_snapshot(snapshot, resume=True, uffd_path=SOCKET_PATH)
10399

104100
check_hugetlbfs_in_use(vm.firecracker_pid, "/anon_hugepage")
105101

106102

107-
def test_hugetlbfs_diff_snapshot(microvm_factory, uvm_plain, uffd_handler_paths):
103+
def test_hugetlbfs_diff_snapshot(microvm_factory, uvm_plain):
108104
"""
109105
Test hugetlbfs differential snapshot support.
110106
@@ -139,9 +135,7 @@ def test_hugetlbfs_diff_snapshot(microvm_factory, uvm_plain, uffd_handler_paths)
139135
vm.spawn()
140136

141137
# Spawn page fault handler process.
142-
_pf_handler = spawn_pf_handler(
143-
vm, uffd_handler_paths["valid_handler"], snapshot_merged.mem
144-
)
138+
_pf_handler = spawn_pf_handler(vm, uffd_handler("valid"), snapshot_merged.mem)
145139

146140
vm.restore_from_snapshot(snapshot_merged, resume=True, uffd_path=SOCKET_PATH)
147141

@@ -153,7 +147,6 @@ def test_ept_violation_count(
153147
microvm_factory,
154148
guest_kernel_linux_5_10,
155149
rootfs,
156-
uffd_handler_paths,
157150
metrics,
158151
huge_pages,
159152
):
@@ -200,9 +193,7 @@ def test_ept_violation_count(
200193
vm.spawn()
201194

202195
# Spawn page fault handler process.
203-
_pf_handler = spawn_pf_handler(
204-
vm, uffd_handler_paths["fault_all_handler"], snapshot.mem
205-
)
196+
_pf_handler = spawn_pf_handler(vm, uffd_handler("fault_all"), snapshot.mem)
206197

207198
with ftrace_events("kvm:*"):
208199
vm.restore_from_snapshot(snapshot, resume=True, uffd_path=SOCKET_PATH)

0 commit comments

Comments
 (0)