mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-06 02:25:23 +00:00
Add SEPARATE_WORKSPACE requirement for run_tests
The io_uring and fuzz crate cannot be tested in the same workspace via `cargo test -p io_uring -p fuzz`. This change allows test_runner.py to run tests independently by cd'ing into the crates directory and running cargo test in there. BUG=b:181672910 BUG=b:181673923 TEST=Tests for the above mentioned crates can be enabled and run, but test failures prevent them from being enabled so far. Change-Id: Ia03868d53e508549fe2f071da399b982359a8834 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2749772 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
parent
f217c0fb46
commit
dcf540be92
1 changed files with 65 additions and 15 deletions
|
@ -52,12 +52,18 @@ class Requirements(enum.Enum):
|
||||||
# Test is disabled explicitly.
|
# Test is disabled explicitly.
|
||||||
DISABLED = "disabled"
|
DISABLED = "disabled"
|
||||||
|
|
||||||
# Test needs to be executed with expanded privileges for device access.
|
# Test needs to be executed with expanded privileges for device access and
|
||||||
|
# will be run inside a VM.
|
||||||
PRIVILEGED = "privileged"
|
PRIVILEGED = "privileged"
|
||||||
|
|
||||||
# Test needs to run single-threaded
|
# Test needs to run single-threaded
|
||||||
SINGLE_THREADED = "single_threaded"
|
SINGLE_THREADED = "single_threaded"
|
||||||
|
|
||||||
|
# Separate workspaces that have dev-dependencies cannot be built from the
|
||||||
|
# crosvm workspace and need to be built separately.
|
||||||
|
# Note: Separate workspaces are built with no features enabled.
|
||||||
|
SEPARATE_WORKSPACE = "separate_workspace"
|
||||||
|
|
||||||
|
|
||||||
BUILD_TIME_REQUIREMENTS = [
|
BUILD_TIME_REQUIREMENTS = [
|
||||||
Requirements.AARCH64,
|
Requirements.AARCH64,
|
||||||
|
@ -209,7 +215,7 @@ def results_summary(results: Union[RunResults, CrateResults]):
|
||||||
num_pass = results.count(TestResult.PASS)
|
num_pass = results.count(TestResult.PASS)
|
||||||
num_skip = results.count(TestResult.SKIP)
|
num_skip = results.count(TestResult.SKIP)
|
||||||
num_fail = results.count(TestResult.FAIL)
|
num_fail = results.count(TestResult.FAIL)
|
||||||
msg = []
|
msg: List[str] = []
|
||||||
if num_pass:
|
if num_pass:
|
||||||
msg.append(f"{num_pass} passed")
|
msg.append(f"{num_pass} passed")
|
||||||
if num_skip:
|
if num_skip:
|
||||||
|
@ -220,8 +226,9 @@ def results_summary(results: Union[RunResults, CrateResults]):
|
||||||
|
|
||||||
|
|
||||||
def cargo_test_process(
|
def cargo_test_process(
|
||||||
crates: List[CrateInfo],
|
cwd: str,
|
||||||
features: Set[str],
|
crates: List[CrateInfo] = [],
|
||||||
|
features: Set[str] = set(),
|
||||||
run: bool = True,
|
run: bool = True,
|
||||||
single_threaded: bool = False,
|
single_threaded: bool = False,
|
||||||
use_vm: bool = False,
|
use_vm: bool = False,
|
||||||
|
@ -233,6 +240,11 @@ def cargo_test_process(
|
||||||
cmd += ["--no-run"]
|
cmd += ["--no-run"]
|
||||||
if features:
|
if features:
|
||||||
cmd += ["--no-default-features", "--features", ",".join(features)]
|
cmd += ["--no-default-features", "--features", ",".join(features)]
|
||||||
|
|
||||||
|
# Skip doc tests as these cannot be run in the VM.
|
||||||
|
if use_vm:
|
||||||
|
cmd += ["--bins", "--tests"]
|
||||||
|
|
||||||
for crate in sorted(crate.name for crate in crates):
|
for crate in sorted(crate.name for crate in crates):
|
||||||
cmd += ["-p", crate]
|
cmd += ["-p", crate]
|
||||||
|
|
||||||
|
@ -247,6 +259,7 @@ def cargo_test_process(
|
||||||
|
|
||||||
process = subprocess.run(
|
process = subprocess.run(
|
||||||
cmd,
|
cmd,
|
||||||
|
cwd=cwd,
|
||||||
env=env,
|
env=env,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
@ -261,9 +274,33 @@ def cargo_test_process(
|
||||||
|
|
||||||
def cargo_build_tests(crates: List[CrateInfo], features: Set[str]):
|
def cargo_build_tests(crates: List[CrateInfo], features: Set[str]):
|
||||||
"""Runs cargo test --no-run to build all listed `crates`."""
|
"""Runs cargo test --no-run to build all listed `crates`."""
|
||||||
print("Building: ", ", ".join(crate.name for crate in crates))
|
separate_workspace_crates = [
|
||||||
process = cargo_test_process(crates, features, run=False)
|
crate
|
||||||
return process.returncode == 0
|
for crate in crates
|
||||||
|
if Requirements.SEPARATE_WORKSPACE in crate.requirements
|
||||||
|
]
|
||||||
|
workspace_crates = [
|
||||||
|
crate
|
||||||
|
for crate in crates
|
||||||
|
if Requirements.SEPARATE_WORKSPACE not in crate.requirements
|
||||||
|
]
|
||||||
|
|
||||||
|
print(
|
||||||
|
"Building workspace: ",
|
||||||
|
", ".join(crate.name for crate in workspace_crates),
|
||||||
|
)
|
||||||
|
process = cargo_test_process(
|
||||||
|
cwd=".", crates=workspace_crates, features=features, run=False
|
||||||
|
)
|
||||||
|
if process.returncode != 0:
|
||||||
|
return False
|
||||||
|
|
||||||
|
for crate in separate_workspace_crates:
|
||||||
|
print("Building:", crate.name)
|
||||||
|
process = cargo_test_process(cwd=crate.name, run=False)
|
||||||
|
if process.returncode != 0:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def cargo_test(
|
def cargo_test(
|
||||||
|
@ -279,16 +316,29 @@ def cargo_test(
|
||||||
msg.append("in vm")
|
msg.append("in vm")
|
||||||
if single_threaded:
|
if single_threaded:
|
||||||
msg.append("(single-threaded)")
|
msg.append("(single-threaded)")
|
||||||
|
if Requirements.SEPARATE_WORKSPACE in crate.requirements:
|
||||||
|
msg.append("(separate workspace)")
|
||||||
sys.stdout.write(f"{' '.join(msg)}... ")
|
sys.stdout.write(f"{' '.join(msg)}... ")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
process = cargo_test_process(
|
|
||||||
[crate],
|
if Requirements.SEPARATE_WORKSPACE in crate.requirements:
|
||||||
features,
|
process = cargo_test_process(
|
||||||
run=True,
|
cwd=crate.name,
|
||||||
single_threaded=single_threaded,
|
run=True,
|
||||||
use_vm=use_vm,
|
single_threaded=single_threaded,
|
||||||
timeout=TEST_TIMEOUT_SECS,
|
use_vm=use_vm,
|
||||||
)
|
timeout=TEST_TIMEOUT_SECS,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
process = cargo_test_process(
|
||||||
|
cwd=".",
|
||||||
|
crates=[crate],
|
||||||
|
features=features,
|
||||||
|
run=True,
|
||||||
|
single_threaded=single_threaded,
|
||||||
|
use_vm=use_vm,
|
||||||
|
timeout=TEST_TIMEOUT_SECS,
|
||||||
|
)
|
||||||
results = CrateResults(
|
results = CrateResults(
|
||||||
crate.name, process.returncode == 0, process.stdout
|
crate.name, process.returncode == 0, process.stdout
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue