Rollup merge of #107608 - P1n3appl3:master, r=tmandry

Use triple rather than arch for fuchsia test-runner

This allows the user of the test-runner script to specify a full triple rather than just an architecture which helps with the transition from the two component to three component target triples for fuchsia.
This commit is contained in:
Matthias Krüger 2023-02-03 06:30:25 +01:00 committed by GitHub
commit b6e8ebf33b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 29 deletions

View File

@ -19,18 +19,18 @@ import shutil
import signal import signal
import subprocess import subprocess
import sys import sys
from typing import ClassVar, List from typing import ClassVar, List, Optional
@dataclass @dataclass
class TestEnvironment: class TestEnvironment:
rust_dir: str rust_dir: str
sdk_dir: str sdk_dir: str
target_arch: str target: str
package_server_pid: int = None package_server_pid: Optional[int] = None
emu_addr: str = None emu_addr: Optional[str] = None
libstd_name: str = None libstd_name: Optional[str] = None
libtest_name: str = None libtest_name: Optional[str] = None
verbose: bool = False verbose: bool = False
@staticmethod @staticmethod
@ -40,6 +40,15 @@ class TestEnvironment:
return os.path.abspath(tmp_dir) return os.path.abspath(tmp_dir)
return os.path.join(os.path.dirname(__file__), "tmp~") return os.path.join(os.path.dirname(__file__), "tmp~")
@staticmethod
def triple_to_arch(triple):
if "x86_64" in triple:
return "x64"
elif "aarch64" in triple:
return "arm64"
else:
raise Exception(f"Unrecognized target triple {triple}")
@classmethod @classmethod
def env_file_path(cls): def env_file_path(cls):
return os.path.join(cls.tmp_dir(), "test_env.json") return os.path.join(cls.tmp_dir(), "test_env.json")
@ -49,7 +58,7 @@ class TestEnvironment:
return cls( return cls(
os.path.abspath(args.rust), os.path.abspath(args.rust),
os.path.abspath(args.sdk), os.path.abspath(args.sdk),
args.target_arch, args.target,
verbose=args.verbose, verbose=args.verbose,
) )
@ -60,7 +69,7 @@ class TestEnvironment:
return cls( return cls(
test_env["rust_dir"], test_env["rust_dir"],
test_env["sdk_dir"], test_env["sdk_dir"],
test_env["target_arch"], test_env["target"],
libstd_name=test_env["libstd_name"], libstd_name=test_env["libstd_name"],
libtest_name=test_env["libtest_name"], libtest_name=test_env["libtest_name"],
emu_addr=test_env["emu_addr"], emu_addr=test_env["emu_addr"],
@ -68,13 +77,6 @@ class TestEnvironment:
verbose=test_env["verbose"], verbose=test_env["verbose"],
) )
def image_name(self):
if self.target_arch == "x64":
return "qemu-x64"
if self.target_arch == "arm64":
return "qemu-arm64"
raise Exception(f"Unrecognized target architecture {self.target_arch}")
def write_to_file(self): def write_to_file(self):
with open(self.env_file_path(), "w", encoding="utf-8") as f: with open(self.env_file_path(), "w", encoding="utf-8") as f:
f.write(json.dumps(self.__dict__)) f.write(json.dumps(self.__dict__))
@ -108,13 +110,6 @@ class TestEnvironment:
def repo_dir(self): def repo_dir(self):
return os.path.join(self.tmp_dir(), self.TEST_REPO_NAME) return os.path.join(self.tmp_dir(), self.TEST_REPO_NAME)
def rustlib_dir(self):
if self.target_arch == "x64":
return "x86_64-unknown-fuchsia"
if self.target_arch == "arm64":
return "aarch64-unknown-fuchsia"
raise Exception(f"Unrecognized target architecture {self.target_arch}")
def libs_dir(self): def libs_dir(self):
return os.path.join( return os.path.join(
self.rust_dir, self.rust_dir,
@ -125,7 +120,7 @@ class TestEnvironment:
return os.path.join( return os.path.join(
self.libs_dir(), self.libs_dir(),
"rustlib", "rustlib",
self.rustlib_dir(), self.target,
"lib", "lib",
) )
@ -384,7 +379,7 @@ class TestEnvironment:
"--emulator-log", "--emulator-log",
self.emulator_log_path(), self.emulator_log_path(),
"--image-name", "--image-name",
self.image_name(), "qemu-" + self.triple_to_arch(self.target),
], ],
stdout=self.subprocess_output(), stdout=self.subprocess_output(),
stderr=self.subprocess_output(), stderr=self.subprocess_output(),
@ -642,11 +637,11 @@ class TestEnvironment:
package_dir=package_dir, package_dir=package_dir,
package_name=package_name, package_name=package_name,
rust_dir=self.rust_dir, rust_dir=self.rust_dir,
rustlib_dir=self.rustlib_dir(), rustlib_dir=self.target,
sdk_dir=self.sdk_dir, sdk_dir=self.sdk_dir,
libstd_name=self.libstd_name, libstd_name=self.libstd_name,
libtest_name=self.libtest_name, libtest_name=self.libtest_name,
target_arch=self.target_arch, target_arch=self.triple_to_arch(self.target),
) )
) )
for shared_lib in shared_libs: for shared_lib in shared_libs:
@ -969,8 +964,8 @@ def main():
action="store_true", action="store_true",
) )
start_parser.add_argument( start_parser.add_argument(
"--target-arch", "--target",
help="the architecture of the image to test", help="the target platform to test",
required=True, required=True,
) )
start_parser.set_defaults(func=start) start_parser.set_defaults(func=start)

View File

@ -697,7 +697,7 @@ test environment with:
src/ci/docker/scripts/fuchsia-test-runner.py start src/ci/docker/scripts/fuchsia-test-runner.py start
--rust ${RUST_SRC_PATH}/install --rust ${RUST_SRC_PATH}/install
--sdk ${SDK_PATH} --sdk ${SDK_PATH}
--target-arch {x64,arm64} --target-triple {x86_64-unknown-fuchsia|aarch64-unknown-fuchsia}
``` ```
Where `${RUST_SRC_PATH}/install` is the `prefix` set in `config.toml` and Where `${RUST_SRC_PATH}/install` is the `prefix` set in `config.toml` and