tools: Make run_tests python3.8 compatible

One more script that needs to run on python 3.8 so we can run test
for windows on luci.

BUG=b:234173142
TEST=vpython3 tools/run_tests

Change-Id: I0348a567b2edec3b5e3fca77f316f39d1e924adc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3723037
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Dennis Kempin 2022-06-24 00:07:24 +00:00
parent e12a9aad61
commit 6e06b9f0e3
4 changed files with 29 additions and 28 deletions

View file

@ -3,6 +3,7 @@
# found in the LICENSE file.
import enum
from typing import List, Dict
class TestOption(enum.Enum):
@ -69,7 +70,7 @@ WIN64_DISABLED_CRATES = [
"x86_64",
]
CRATE_OPTIONS: dict[str, list[TestOption]] = {
CRATE_OPTIONS: Dict[str, List[TestOption]] = {
"base": [TestOption.SINGLE_THREADED, TestOption.LARGE],
"cros_async": [TestOption.LARGE],
"crosvm": [TestOption.SINGLE_THREADED],
@ -116,7 +117,7 @@ CRATE_OPTIONS: dict[str, list[TestOption]] = {
for name in WIN64_DISABLED_CRATES:
CRATE_OPTIONS[name] = CRATE_OPTIONS.get(name, []) + [TestOption.DO_NOT_BUILD_WIN64]
BUILD_FEATURES: dict[str, str] = {
BUILD_FEATURES: Dict[str, str] = {
"x86_64": "linux-x86_64",
"aarch64": "linux-aarch64",
"armhf": "linux-armhf",

View file

@ -138,8 +138,8 @@ def exclude_crosvm(target_arch: Arch):
def cargo(
cargo_command: str,
cwd: Path,
flags: list[str],
env: dict[str, str],
flags: List[str],
env: Dict[str, str],
build_arch: Arch,
) -> Iterable[Executable]:
"""
@ -207,7 +207,7 @@ def cargo(
def cargo_build_executables(
flags: list[str],
flags: List[str],
build_arch: Arch,
cwd: Path = Path("."),
env: Dict[str, str] = {},
@ -221,7 +221,7 @@ def cargo_build_executables(
yield from cargo("test", cwd, ["--no-run", *flags], env, build_arch)
def build_common_crate(build_env: dict[str, str], build_arch: Arch, crate: Crate):
def build_common_crate(build_env: Dict[str, str], build_arch: Arch, crate: Crate):
print(f"Building tests for: common/{crate.name}")
return list(cargo_build_executables([], build_arch, env=build_env, cwd=crate.path))
@ -282,7 +282,7 @@ def execute_test(target: TestTarget, executable: Executable):
Test output is hidden unless the test fails or VERBOSE mode is enabled.
"""
options = CRATE_OPTIONS.get(executable.crate_name, [])
args: list[str] = []
args: List[str] = []
if TestOption.SINGLE_THREADED in options:
args += ["--test-threads=1"]
@ -324,7 +324,7 @@ def execute_test(target: TestTarget, executable: Executable):
def execute_all(
executables: list[Executable],
executables: List[Executable],
target: test_target.TestTarget,
repeat: int,
):
@ -353,7 +353,7 @@ def execute_all(
print()
def find_crosvm_binary(executables: list[Executable]):
def find_crosvm_binary(executables: List[Executable]):
for executable in executables:
if not executable.is_test and executable.cargo_target == "crosvm":
return executable

View file

@ -5,7 +5,7 @@ import argparse
import platform
import subprocess
from pathlib import Path
from typing import Any, Literal, Optional, cast
from typing import Any, Literal, Optional, cast, List, Dict
import typing
import sys
from . import testvm
@ -63,9 +63,9 @@ class Ssh:
"""Wrapper around subprocess to execute commands remotely via SSH."""
hostname: str
opts: list[str]
opts: List[str]
def __init__(self, hostname: str, opts: list[str] = []):
def __init__(self, hostname: str, opts: List[str] = []):
self.hostname = hostname
self.opts = opts
@ -95,9 +95,9 @@ class Ssh:
check=True,
).stdout
def upload_files(self, files: list[Path], remote_dir: str = "", quiet: bool = False):
def upload_files(self, files: List[Path], remote_dir: str = "", quiet: bool = False):
"""Wrapper around SCP."""
flags: list[str] = []
flags: List[str] = []
if quiet:
flags.append("-q")
scp_cmd = [
@ -171,13 +171,13 @@ def find_rust_libs():
yield from lib_dir.glob("libtest-*")
def prepare_remote(ssh: Ssh, extra_files: list[Path] = []):
def prepare_remote(ssh: Ssh, extra_files: List[Path] = []):
print("Preparing remote")
ssh.upload_files(list(find_rust_libs()) + extra_files)
pass
def prepare_target(target: TestTarget, extra_files: list[Path] = []):
def prepare_target(target: TestTarget, extra_files: List[Path] = []):
if target.vm:
testvm.build_if_needed(target.vm)
testvm.wait(target.vm)
@ -204,7 +204,7 @@ def get_cargo_build_target(arch: Arch):
def get_cargo_env(target: TestTarget, build_arch: Arch):
"""Environment variables to make cargo use the test target."""
env: dict[str, str] = BUILD_ENV.copy()
env: Dict[str, str] = BUILD_ENV.copy()
cargo_target = get_cargo_build_target(build_arch)
upper_target = cargo_target.upper().replace("-", "_")
if build_arch != platform.machine():
@ -215,7 +215,7 @@ def get_cargo_env(target: TestTarget, build_arch: Arch):
return env
def write_envrc(values: dict[str, str]):
def write_envrc(values: Dict[str, str]):
with open(ENVRC_PATH, "w") as file:
for key, value in values.items():
file.write(f'export {key}="{value}"\n')
@ -234,8 +234,8 @@ def exec_file_on_target(
target: TestTarget,
filepath: Path,
timeout: int,
args: list[str] = [],
extra_files: list[Path] = [],
args: List[str] = [],
extra_files: List[Path] = [],
**kwargs: Any,
):
"""Executes a file on the test target.
@ -290,9 +290,9 @@ def exec_file_on_target(
def exec_file(
target: TestTarget,
filepath: Path,
args: list[str] = [],
args: List[str] = [],
timeout: int = 60,
extra_files: list[Path] = [],
extra_files: List[Path] = [],
):
if not filepath.exists():
raise Exception(f"File does not exist: {filepath}")

View file

@ -3,7 +3,7 @@
# found in the LICENSE file.
from pathlib import Path
from typing import Iterable, Optional, Literal
from typing import Iterable, Optional, Literal, Dict, List, Tuple
import argparse
import itertools
import os
@ -108,13 +108,13 @@ def rootfs_img_path(arch: Arch):
# List of ports to use for SSH for each architecture
SSH_PORTS: dict[Arch, int] = {
SSH_PORTS: Dict[Arch, int] = {
"x86_64": 9000,
"aarch64": 9001,
}
# QEMU arguments shared by all architectures
SHARED_ARGS: list[tuple[str, str]] = [
SHARED_ARGS: List[Tuple[str, str]] = [
("-display", "none"),
("-device", "virtio-net-pci,netdev=net0"),
("-smp", "8"),
@ -122,7 +122,7 @@ SHARED_ARGS: list[tuple[str, str]] = [
]
# Arguments to QEMU for each architecture
ARCH_TO_QEMU: dict[Arch, tuple[str, list[Iterable[str]]]] = {
ARCH_TO_QEMU: Dict[Arch, Tuple[str, List[Iterable[str]]]] = {
# arch: (qemu-binary, [(param, value), ...])
"x86_64": (
"qemu-system-x86_64",
@ -150,7 +150,7 @@ ARCH_TO_QEMU: dict[Arch, tuple[str, list[Iterable[str]]]] = {
}
def ssh_opts(arch: Arch) -> dict[str, str]:
def ssh_opts(arch: Arch) -> Dict[str, str]:
return {
"Port": str(SSH_PORTS[arch]),
"User": "crosvm",
@ -359,7 +359,7 @@ def clean(arch: Arch):
shutil.rmtree(data_dir(arch))
def main(arch: Arch, argv: list[str]):
def main(arch: Arch, argv: List[str]):
COMMANDS = [
"build",
"up",