Skip to content

Commit c3102e7

Browse files
committed
test: pass --locked to all cargo invocations
Passing --locked makes cargo fail if a command would cause an update to a Cargo.lock file. This can happen if, for example, someone modified a Cargo.toml file, yet forgot to check in the corresponding change to Cargo.lock. Signed-off-by: Patrick Roy <[email protected]>
1 parent 22b83e6 commit c3102e7

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

tests/host_tools/cargo_build.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
@with_filelock
3232
def cargo_build(path, extra_args="", src_dir="", extra_env=""):
3333
"""Trigger build depending on flags provided."""
34-
cmd = "CARGO_TARGET_DIR={} {} cargo build {}".format(path, extra_env, extra_args)
34+
cmd = "CARGO_TARGET_DIR={} {} cargo build --locked {}".format(
35+
path, extra_env, extra_args
36+
)
3537
if src_dir:
3638
cmd = "cd {} && {}".format(src_dir, cmd)
3739

@@ -43,7 +45,7 @@ def cargo_test(path, extra_args=""):
4345
path = os.path.join(path, CARGO_UNITTEST_REL_PATH)
4446
cmd = (
4547
"CARGO_TARGET_DIR={} RUST_TEST_THREADS=1 RUST_BACKTRACE=1 "
46-
'RUSTFLAGS="{}" cargo test {} --all --no-fail-fast'.format(
48+
'RUSTFLAGS="{}" cargo test --locked {} --all --no-fail-fast'.format(
4749
path, get_rustflags(), extra_args
4850
)
4951
)
@@ -66,8 +68,8 @@ def get_firecracker_binaries():
6668
if not fc_bin_path.exists():
6769
cd_cmd = "cd {}".format(FC_WORKSPACE_DIR)
6870
flags = 'RUSTFLAGS="{}"'.format(get_rustflags())
69-
cargo_default_cmd = f"cargo build --release --target {target}"
70-
cargo_jailer_cmd = f"cargo build -p jailer --release --target {target}"
71+
cargo_default_cmd = f"cargo build --locked --release --target {target}"
72+
cargo_jailer_cmd = f"cargo build --locked -p jailer --release --target {target}"
7173
cmd = "{0} && {1} {2} && {1} {3}".format(
7274
cd_cmd, flags, cargo_default_cmd, cargo_jailer_cmd
7375
)
@@ -100,7 +102,7 @@ def run_seccompiler_bin(bpf_path, json_path=defs.SECCOMP_JSON_DIR, basic=False):
100102
if json_path == defs.SECCOMP_JSON_DIR:
101103
json_path = json_path / "{}.json".format(cargo_target)
102104

103-
cmd = "cargo run -p seccompiler --target-dir {} --target {} --\
105+
cmd = "cargo run --locked -p seccompiler --target-dir {} --target {} --\
104106
--input-file {} --target-arch {} --output-file {}".format(
105107
defs.SECCOMPILER_TARGET_DIR,
106108
cargo_target,
@@ -127,7 +129,7 @@ def run_rebase_snap_bin(base_snap, diff_snap):
127129
"""
128130
cargo_target = "{}-unknown-linux-musl".format(platform.machine())
129131

130-
cmd = "cargo run -p rebase-snap --target {} --\
132+
cmd = "cargo run --locked -p rebase-snap --target {} --\
131133
--base-file {} --diff-file {}".format(
132134
cargo_target, base_snap, diff_snap
133135
)

tests/integration_tests/build/test_clippy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ def test_rust_clippy(target):
2525
@type: build
2626
"""
2727
utils.run_cmd(
28-
"cargo clippy --target {} --all --profile test" " -- -D warnings".format(target)
28+
"cargo clippy --locked --target {} --all --profile test"
29+
" -- -D warnings".format(target)
2930
)

tests/integration_tests/build/test_coverage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_coverage(monkeypatch, record_property, metrics):
6262
f'\
6363
RUSTFLAGS="-Cinstrument-coverage" \
6464
LLVM_PROFILE_FILE="coverage-%p-%m.profraw" \
65-
cargo test --all --target={TARGET} -- --test-threads=1 \
65+
cargo test --locked --all --target={TARGET} -- --test-threads=1 \
6666
'
6767
)
6868

tests/integration_tests/build/test_dependencies.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def test_licenses():
2626
toml_file = os.path.normpath(
2727
os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../Cargo.toml")
2828
)
29-
utils.run_cmd("cargo deny --manifest-path {} check licenses".format(toml_file))
29+
utils.run_cmd(
30+
"cargo deny --locked --manifest-path {} check licenses".format(toml_file)
31+
)
3032

3133

3234
@pytest.mark.parametrize("dep_file", ["framework/dependencies.txt"])
@@ -35,7 +37,9 @@ def test_num_dependencies(dep_file):
3537
3638
@type: build
3739
"""
38-
_, stdout, _ = utils.run_cmd("cargo tree --prefix none -e no-dev " "--workspace")
40+
_, stdout, _ = utils.run_cmd(
41+
"cargo tree --locked --prefix none -e no-dev " "--workspace"
42+
)
3943
deps = stdout.splitlines()
4044

4145
current_deps = set()

tests/integration_tests/performance/test_versioned_serialization_benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_serialization_benchmark(monkeypatch, record_property):
9191
monkeypatch.chdir(BENCHMARK_DIRECTORY)
9292

9393
# Run benchmark test
94-
cmd = "cargo bench --target {}".format(DEFAULT_BUILD_TARGET)
94+
cmd = "cargo bench --locked --target {}".format(DEFAULT_BUILD_TARGET)
9595
result = utils.run_cmd_sync(cmd)
9696
assert result.returncode == 0
9797

tests/integration_tests/security/test_sec_audit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ def test_cargo_audit():
2121
"""
2222
# Run command and raise exception if non-zero return code
2323
utils.run_cmd(
24-
"cargo audit --deny warnings -q --ignore RUSTSEC-2021-0145",
24+
"cargo audit --locked --deny warnings -q --ignore RUSTSEC-2021-0145",
2525
cwd=defs.FC_WORKSPACE_DIR,
2626
)

0 commit comments

Comments
 (0)