Skip to content

Commit 94a7835

Browse files
authored
Rollup merge of #108354 - djkoloski:update_fuchsia_test_runner, r=djkoloski
Update `fuchsia-test-runner.py` and docs This updates the test runner to the latest version of the SDK and fixes debugging support for Rust source code. r? ``@tmandry``
2 parents 313219c + 6e7902b commit 94a7835

File tree

2 files changed

+149
-27
lines changed

2 files changed

+149
-27
lines changed

src/ci/docker/scripts/fuchsia-test-runner.py

+69-13
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,8 @@ def start(self):
507507
bin/{exe_name}={bin_path}
508508
lib/{libstd_name}={rust_dir}/lib/rustlib/{rustlib_dir}/lib/{libstd_name}
509509
lib/{libtest_name}={rust_dir}/lib/rustlib/{rustlib_dir}/lib/{libtest_name}
510-
lib/ld.so.1={sdk_dir}/arch/{target_arch}/sysroot/lib/libc.so
511-
lib/libzircon.so={sdk_dir}/arch/{target_arch}/sysroot/lib/libzircon.so
512-
lib/libfdio.so={sdk_dir}/arch/{target_arch}/lib/libfdio.so
510+
lib/ld.so.1={sdk_dir}/arch/{target_arch}/sysroot/dist/lib/ld.so.1
511+
lib/libfdio.so={sdk_dir}/arch/{target_arch}/dist/libfdio.so
513512
"""
514513

515514
TEST_ENV_VARS: ClassVar[List[str]] = [
@@ -844,23 +843,34 @@ def debug(self, args):
844843
"--",
845844
"--build-id-dir",
846845
os.path.join(self.sdk_dir, ".build-id"),
847-
"--build-id-dir",
848-
os.path.join(self.libs_dir(), ".build-id"),
849846
]
850847

851-
# Add rust source if it's available
852-
if args.rust_src is not None:
848+
libs_build_id_path = os.path.join(self.libs_dir(), ".build-id")
849+
if os.path.exists(libs_build_id_path):
850+
# Add .build-id symbols if installed libs have been stripped into a
851+
# .build-id directory
853852
command += [
854-
"--build-dir",
855-
args.rust_src,
853+
"--build-id-dir",
854+
libs_build_id_path,
855+
]
856+
else:
857+
# If no .build-id directory is detected, then assume that the shared
858+
# libs contain their debug symbols
859+
command += [
860+
f"--symbol-path={self.rust_dir}/lib/rustlib/{self.target}/lib",
856861
]
857862

863+
# Add rust source if it's available
864+
rust_src_map = None
865+
if args.rust_src is not None:
866+
# This matches the remapped prefix used by compiletest. There's no
867+
# clear way that we can determine this, so it's hard coded.
868+
rust_src_map = f"/rustc/FAKE_PREFIX={args.rust_src}"
869+
858870
# Add fuchsia source if it's available
871+
fuchsia_src_map = None
859872
if args.fuchsia_src is not None:
860-
command += [
861-
"--build-dir",
862-
os.path.join(args.fuchsia_src, "out", "default"),
863-
]
873+
fuchsia_src_map = f"./../..={args.fuchsia_src}"
864874

865875
# Load debug symbols for the test binary and automatically attach
866876
if args.test is not None:
@@ -883,7 +893,28 @@ def debug(self, args):
883893
test_name,
884894
)
885895

896+
# The fake-test-src-base directory maps to the suite directory
897+
# e.g. tests/ui/foo.rs has a path of rust/fake-test-src-base/foo.rs
898+
fake_test_src_base = os.path.join(
899+
args.rust_src,
900+
"fake-test-src-base",
901+
)
902+
real_test_src_base = os.path.join(
903+
args.rust_src,
904+
"tests",
905+
args.test.split(os.path.sep)[0],
906+
)
907+
test_src_map = f"{fake_test_src_base}={real_test_src_base}"
908+
886909
with open(self.zxdb_script_path(), mode="w", encoding="utf-8") as f:
910+
print(f"set source-map += {test_src_map}", file=f)
911+
912+
if rust_src_map is not None:
913+
print(f"set source-map += {rust_src_map}", file=f)
914+
915+
if fuchsia_src_map is not None:
916+
print(f"set source-map += {fuchsia_src_map}", file=f)
917+
887918
print(f"attach {test_name[:31]}", file=f)
888919

889920
command += [
@@ -900,6 +931,20 @@ def debug(self, args):
900931
# Connect to the running emulator with zxdb
901932
subprocess.run(command, env=self.ffx_cmd_env(), check=False)
902933

934+
def syslog(self, args):
935+
subprocess.run(
936+
[
937+
self.tool_path("ffx"),
938+
"--config",
939+
self.ffx_user_config_path(),
940+
"log",
941+
"--since",
942+
"now",
943+
],
944+
env=self.ffx_cmd_env(),
945+
check=False,
946+
)
947+
903948

904949
def start(args):
905950
test_env = TestEnvironment.from_args(args)
@@ -933,6 +978,12 @@ def debug(args):
933978
return 0
934979

935980

981+
def syslog(args):
982+
test_env = TestEnvironment.read_from_file()
983+
test_env.syslog(args)
984+
return 0
985+
986+
936987
def main():
937988
parser = argparse.ArgumentParser()
938989

@@ -1028,6 +1079,11 @@ def print_help(args):
10281079
)
10291080
debug_parser.set_defaults(func=debug)
10301081

1082+
syslog_parser = subparsers.add_parser(
1083+
"syslog", help="prints the device syslog"
1084+
)
1085+
syslog_parser.set_defaults(func=syslog)
1086+
10311087
args = parser.parse_args()
10321088
return args.func(args)
10331089

src/doc/rustc/src/platform-support/fuchsia.md

+80-14
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,9 @@ Rust compiler locally. See "[Targeting Fuchsia with a compiler built from source
687687
for the steps to build locally.
688688

689689
You'll also need to download a copy of the Fuchsia SDK. The current minimum
690-
supported SDK version is [9.20220726.1.1](https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/core/linux-amd64/+/version:9.20220726.1.1).
690+
supported SDK version is [10.20221207.2.89][minimum_supported_sdk_version].
691+
692+
[minimum_supported_sdk_version]: https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/core/linux-amd64/+/version:10.20221207.2.89
691693

692694
Fuchsia's test runner interacts with the Fuchsia emulator and is located at
693695
`src/ci/docker/scripts/fuchsia-test-runner.py`. We can use it to start our
@@ -697,7 +699,7 @@ test environment with:
697699
src/ci/docker/scripts/fuchsia-test-runner.py start
698700
--rust ${RUST_SRC_PATH}/install
699701
--sdk ${SDK_PATH}
700-
--target-triple {x86_64-unknown-fuchsia|aarch64-unknown-fuchsia}
702+
--target {x86_64-unknown-fuchsia|aarch64-unknown-fuchsia}
701703
```
702704

703705
Where `${RUST_SRC_PATH}/install` is the `prefix` set in `config.toml` and
@@ -717,17 +719,11 @@ run the full `tests/ui` test suite:
717719
--target x86_64-unknown-fuchsia \
718720
--run=always --jobs 1 \
719721
--test-args --target-rustcflags \
720-
--test-args -L \
721-
--test-args --target-rustcflags \
722-
--test-args ${SDK_PATH}/arch/{x64|arm64}/sysroot/lib \
723-
--test-args --target-rustcflags \
724-
--test-args -L \
722+
--test-args -Lnative=${SDK_PATH}/arch/{x64|arm64}/sysroot/lib \
725723
--test-args --target-rustcflags \
726-
--test-args ${SDK_PATH}/arch/{x64|arm64}/lib \
724+
--test-args -Lnative=${SDK_PATH}/arch/{x64|arm64}/lib \
727725
--test-args --target-rustcflags \
728-
--test-args -Cpanic=abort \
729-
--test-args --target-rustcflags \
730-
--test-args -Zpanic_abort_tests \
726+
--test-args -Clink-arg=--undefined-version \
731727
--test-args --remote-test-client \
732728
--test-args src/ci/docker/scripts/fuchsia-test-runner.py \
733729
)
@@ -736,7 +732,18 @@ run the full `tests/ui` test suite:
736732
*Note: The test suite cannot be run in parallel at the moment, so `x.py`
737733
must be run with `--jobs 1` to ensure only one test runs at a time.*
738734

739-
When finished, the test runner can be used to stop the test environment:
735+
By default, `x.py` compiles test binaries with `panic=unwind`. If you built your
736+
Rust toolchain with `-Cpanic=abort`, you need to tell `x.py` to compile test
737+
binaries with `panic=abort` as well:
738+
739+
```sh
740+
--test-args --target-rustcflags \
741+
--test-args -Cpanic=abort \
742+
--test-args --target-rustcflags \
743+
--test-args -Zpanic_abort_tests \
744+
```
745+
746+
When finished testing, the test runner can be used to stop the test environment:
740747

741748
```sh
742749
src/ci/docker/scripts/fuchsia-test-runner.py stop
@@ -764,8 +771,9 @@ ${SDK_PATH}/tools/${ARCH}/ffx debug connect -- \
764771
* `--symbol-path` gets required symbol paths, which are
765772
necessary for stepping through your program.
766773

767-
The "[displaying source code in `zxdb`](#displaying-source-code-in-zxdb)" section describes how you can
768-
display Rust and/or Fuchsia source code in your debugging session.
774+
The "[displaying source code in `zxdb`](#displaying-source-code-in-zxdb)"
775+
section describes how you can display Rust and/or Fuchsia source code in your
776+
debugging session.
769777

770778
### Using `zxdb`
771779

@@ -866,6 +874,64 @@ ${SDK_PATH}/tools/${ARCH}/ffx debug connect -- \
866874
Linking to a Fuchsia checkout can help with debugging Fuchsia libraries,
867875
such as [fdio].
868876

877+
### Debugging the compiler test suite
878+
879+
Debugging the compiler test suite requires some special configuration:
880+
881+
First, we have to properly configure zxdb so it will be able to find debug
882+
symbols and source information for our test. The test runner can do this for us
883+
with:
884+
885+
```sh
886+
src/ci/docker/scripts/fuchsia-test-runner.py debug \
887+
--rust-src ${RUST_SRC_PATH} \
888+
--fuchsia-src ${FUCHSIA_SRC_PATH} \
889+
--test ${TEST}
890+
```
891+
892+
where `${TEST}` is relative to Rust's `tests` directory (e.g. `ui/abi/...`).
893+
894+
This will start a zxdb session that is properly configured for the specific test
895+
being run. All three arguments are optional, so you can omit `--fuchsia-src` if
896+
you don't have it downloaded. Now is a good time to set any desired breakpoints,
897+
like `b main`.
898+
899+
Next, we have to tell `x.py` not to optimize or strip debug symbols from our
900+
test suite binaries. We can do this by passing some new arguments to `rustc`
901+
through our `x.py` invocation. The full invocation is:
902+
903+
```sh
904+
( \
905+
source config-env.sh && \
906+
./x.py \
907+
--config config.toml \
908+
--stage=2 \
909+
test tests/${TEST} \
910+
--target x86_64-unknown-fuchsia \
911+
--run=always --jobs 1 \
912+
--test-args --target-rustcflags \
913+
--test-args -Lnative=${SDK_PATH}/arch/{x64|arm64}/sysroot/lib \
914+
--test-args --target-rustcflags \
915+
--test-args -Lnative=${SDK_PATH}/arch/{x64|arm64}/lib \
916+
--test-args --target-rustcflags \
917+
--test-args -Clink-arg=--undefined-version \
918+
--test-args --target-rustcflags \
919+
--test-args -Cdebuginfo=2 \
920+
--test-args --target-rustcflags \
921+
--test-args -Copt-level=0 \
922+
--test-args --target-rustcflags \
923+
--test-args -Cstrip=none \
924+
--test-args --remote-test-client \
925+
--test-args src/ci/docker/scripts/fuchsia-test-runner.py \
926+
)
927+
```
928+
929+
*If you built your Rust toolchain with `panic=abort`, make sure to include the
930+
previous flags so your test binaries are also compiled with `panic=abort`.*
931+
932+
Upon running this command, the test suite binary will be run and zxdb will
933+
attach and load any relevant debug symbols.
934+
869935
[Fuchsia team]: https://team-api.infra.rust-lang.org/v1/teams/fuchsia.json
870936
[Fuchsia]: https://fuchsia.dev/
871937
[source tree]: https://fuchsia.dev/fuchsia-src/get-started/learn/build

0 commit comments

Comments
 (0)