Skip to content

Commit abd5757

Browse files
committed
test: move gcc_compile
Move gcc_compile so it doesn't have to be imported from a conftest.py file. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 07e564c commit abd5757

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

tests/conftest.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def test_with_any_microvm(test_microvm_any):
105105
SUPPORTED_CPU_TEMPLATES,
106106
SUPPORTED_CUSTOM_CPU_TEMPLATES,
107107
)
108-
from framework.with_filelock import with_filelock
109108
from host_tools.ip_generator import network_config, subnet_generator
110109
from host_tools.metrics import get_metrics_logger
111110

@@ -255,15 +254,6 @@ def test_fc_session_root_path():
255254
shutil.rmtree(fc_session_root_path)
256255

257256

258-
@with_filelock
259-
def _gcc_compile(src_file, output_file, extra_flags="-static -O3"):
260-
"""Build a source file with gcc."""
261-
output_file = Path(output_file)
262-
if not output_file.exists():
263-
compile_cmd = f"gcc {src_file} -o {output_file} {extra_flags}"
264-
utils.run_cmd(compile_cmd)
265-
266-
267257
@pytest.fixture(scope="session")
268258
def bin_cloner_path(test_fc_session_root_path):
269259
"""Build a binary that `clone`s into the jailer.
@@ -272,15 +262,15 @@ def bin_cloner_path(test_fc_session_root_path):
272262
syscall directly.
273263
"""
274264
cloner_bin_path = os.path.join(test_fc_session_root_path, "newpid_cloner")
275-
_gcc_compile("host_tools/newpid_cloner.c", cloner_bin_path)
265+
build_tools.gcc_compile("host_tools/newpid_cloner.c", cloner_bin_path)
276266
yield cloner_bin_path
277267

278268

279269
@pytest.fixture(scope="session")
280270
def bin_vsock_path(test_fc_session_root_path):
281271
"""Build a simple vsock client/server application."""
282272
vsock_helper_bin_path = os.path.join(test_fc_session_root_path, "vsock_helper")
283-
_gcc_compile("host_tools/vsock_helper.c", vsock_helper_bin_path)
273+
build_tools.gcc_compile("host_tools/vsock_helper.c", vsock_helper_bin_path)
284274
yield vsock_helper_bin_path
285275

286276

@@ -290,7 +280,7 @@ def change_net_config_space_bin(test_fc_session_root_path):
290280
change_net_config_space_bin = os.path.join(
291281
test_fc_session_root_path, "change_net_config_space"
292282
)
293-
_gcc_compile(
283+
build_tools.gcc_compile(
294284
"host_tools/change_net_config_space.c",
295285
change_net_config_space_bin,
296286
extra_flags="-static",

tests/host_tools/cargo_build.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,12 @@ def run_rebase_snap_bin(base_snap, diff_snap):
145145
)
146146

147147
assert rc == 0
148+
149+
150+
@with_filelock
151+
def gcc_compile(src_file, output_file, extra_flags="-static -O3"):
152+
"""Build a source file with gcc."""
153+
output_file = Path(output_file)
154+
if not output_file.exists():
155+
compile_cmd = f"gcc {src_file} -o {output_file} {extra_flags}"
156+
utils.run_cmd(compile_cmd)

tools/create_snapshot_artifact/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# The test infra assumes it is running from the `tests` directory.
1818
os.chdir("tests")
1919
from conftest import ARTIFACTS_COLLECTION as ARTIFACTS
20-
from conftest import _gcc_compile
2120
from framework.artifacts import create_net_devices_configuration
2221
from framework.builder import MicrovmBuilder, SnapshotBuilder, SnapshotType
2322
from framework.defs import DEFAULT_TEST_SESSION_ROOT_PATH
@@ -28,6 +27,7 @@
2827
run_cmd,
2928
)
3029
from framework.utils_cpuid import CpuVendor, get_cpu_vendor
30+
from host_tools.cargo_build import gcc_compile
3131
from integration_tests.functional.test_cmd_line_start import _configure_vm_from_json
3232

3333
# restore directory
@@ -59,8 +59,7 @@ def compile_file(file_name, dest_path, bin_name):
5959

6060
source_file_path = os.path.join(host_tools_path, file_name)
6161
bin_file_path = os.path.join(dest_path, bin_name)
62-
_gcc_compile(source_file_path, bin_file_path)
63-
62+
gcc_compile(source_file_path, bin_file_path)
6463
return bin_file_path
6564

6665

0 commit comments

Comments
 (0)