From 21f0fb69690126e65fcfa0d753c2fe9d52502b11 Mon Sep 17 00:00:00 2001 From: Bayanasar Khurd <83147732+bayanasar@users.noreply.github.com> Date: Fri, 4 Dec 2026 12:58:10 -0800 Subject: [PATCH] feat(udp): build noq-udp for Fuchsia, and test it daily on an emulator noq-udp doesn't build for Fuchsia with libc as released: libc lacks IPV6_PKTINFO and IPV6_DONTFRAG there, and its Fuchsia cmsghdr has a padding field that Fuchsia's doesn't, so the unix backend would read and write control messages at the wrong offsets. Put Fuchsia on posix_minimal, as ESP-IDF and WASI are; it needs nothing more from libc. On Fuchsia that gives up ECN, packet info and, since the socket may fragment, MTU discovery. The daily workflow gains a job that runs noq-udp's tests on a Fuchsia emulator (x64, KVM): the core SDK from CIPD, the minimal product of the same version, and each test executable as a test component run with `ffx test run`. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/daily.yaml | 55 +++++++++++- .../fuchsia-run-tests-on-emulator.sh | 87 +++++++++++++++++++ noq-udp/build.rs | 2 +- 3 files changed, 141 insertions(+), 3 deletions(-) create mode 100755 .github/workflows/fuchsia-run-tests-on-emulator.sh diff --git a/.github/workflows/daily.yaml b/.github/workflows/daily.yaml index 0e5ae50a97..ad3b9c72b1 100644 --- a/.github/workflows/daily.yaml +++ b/.github/workflows/daily.yaml @@ -138,6 +138,55 @@ jobs: . "$HOME/.cargo/env" cargo build --locked --all-targets && cargo test --locked && cargo test --locked -- --ignored stress && cargo test --locked -p noq-udp --benches + test-fuchsia: + # noq-udp's tests on a Fuchsia emulator (x64, KVM), each test executable + # as a test component; see fuchsia-run-tests-on-emulator.sh + timeout-minutes: 45 + name: test noq-udp on fuchsia + runs-on: ubuntu-latest + env: + FUCHSIA_SDK_VERSION: "34.20261204.5.1" + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + persist-credentials: false + + - uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # v1 + with: + toolchain: stable + targets: x86_64-unknown-fuchsia + + - name: Download the Fuchsia SDK + run: | + sdk="$RUNNER_TEMP/fuchsia-sdk" + curl -sSfL -o "$RUNNER_TEMP/sdk.zip" \ + "https://chrome-infra-packages.appspot.com/dl/fuchsia/sdk/core/linux-amd64/+/version:$FUCHSIA_SDK_VERSION" + # The x64 tools, sysroot and libraries are enough; the rest is most of its 9 GB. + # The emulator is aemu_internal (it boots with qemu_uefi_internal's firmware), so + # qemu_internal is left out as well. + unzip -q "$RUNNER_TEMP/sdk.zip" -d "$sdk" \ + -x 'obj/*' 'packages/*' 'arch/arm64/*' 'arch/riscv64/*' 'tools/arm64/*' 'tools/x64/qemu_internal/*' + rm "$RUNNER_TEMP/sdk.zip" + echo "FUCHSIA_SDK=$sdk" >>"$GITHUB_ENV" + echo "RUSTFLAGS=$RUSTFLAGS -Lnative=$sdk/arch/x64/sysroot/lib -Lnative=$sdk/arch/x64/lib" >>"$GITHUB_ENV" + + - name: Build noq-udp's tests for Fuchsia + run: cargo test --locked -p noq-udp --target x86_64-unknown-fuchsia --no-run + + - name: Enable KVM group perms + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + - name: Run noq-udp's tests on the Fuchsia emulator + env: + FUCHSIA_WORK: ${{ runner.temp }}/fx + run: | + tests=$(cargo test --locked -p noq-udp --target x86_64-unknown-fuchsia --no-run --message-format=json \ + | jq -r 'select(.executable != null and .profile.test) | .executable') + .github/workflows/fuchsia-run-tests-on-emulator.sh $tests + features: name: Feature powerset check timeout-minutes: 60 @@ -177,7 +226,7 @@ jobs: notify: timeout-minutes: 45 - needs: [proptests, test-freebsd, build-solaris, test-illumos, features] + needs: [proptests, test-freebsd, build-solaris, test-illumos, test-fuchsia, features] if: ${{ always() }} runs-on: ubuntu-latest steps: @@ -191,10 +240,11 @@ jobs: freebsd_result=$(echo "$NEEDS_JSON" | jq -r '.["test-freebsd"].result') solaris_result=$(echo "$NEEDS_JSON" | jq -r '.["build-solaris"].result') illumos_result=$(echo "$NEEDS_JSON" | jq -r '.["test-illumos"].result') + fuchsia_result=$(echo "$NEEDS_JSON" | jq -r '.["test-fuchsia"].result') features_result=$(echo "$NEEDS_JSON" | jq -r '.features.result') # Check if any failed - if [ "$proptests_result" = "failure" ] || [ "$freebsd_result" = "failure" ] || [ "$solaris_result" = "failure" ] || [ "$illumos_result" = "failure" ] || [ "$features_result" = "failure" ]; then + if [ "$proptests_result" = "failure" ] || [ "$freebsd_result" = "failure" ] || [ "$solaris_result" = "failure" ] || [ "$illumos_result" = "failure" ] || [ "$fuchsia_result" = "failure" ] || [ "$features_result" = "failure" ]; then echo "TESTS_RESULT=failure" >>"$GITHUB_ENV" else echo "TESTS_RESULT=success" >>"$GITHUB_ENV" @@ -206,6 +256,7 @@ jobs: [ "$freebsd_result" = "failure" ] && details="${details}- FreeBSD tests failed\n" [ "$solaris_result" = "failure" ] && details="${details}- Solaris build failed\n" [ "$illumos_result" = "failure" ] && details="${details}- Illumos tests failed\n" + [ "$fuchsia_result" = "failure" ] && details="${details}- Fuchsia tests failed\n" [ "$features_result" = "failure" ] && details="${details}- Feature powerset check failed\n" echo "FAILURE_DETAILS<>"$GITHUB_ENV" diff --git a/.github/workflows/fuchsia-run-tests-on-emulator.sh b/.github/workflows/fuchsia-run-tests-on-emulator.sh new file mode 100755 index 0000000000..aa3c62cf7b --- /dev/null +++ b/.github/workflows/fuchsia-run-tests-on-emulator.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# Runs test executables on a Fuchsia emulator, each as a test component of its +# own through `ffx test run`. +# +# Usage: fuchsia-run-tests-on-emulator.sh TEST_EXECUTABLE... +# +# FUCHSIA_SDK is an unpacked Fuchsia core SDK. The emulator runs the minimal +# product of the same version, downloaded here. FUCHSIA_WORK is where the +# product, the package repository and ffx's state go; keep it short, as qemu +# takes sockets under it. +set -euo pipefail + +sdk=${FUCHSIA_SDK:?set FUCHSIA_SDK to an unpacked Fuchsia core SDK} +work=${FUCHSIA_WORK:-/tmp/fx} +if [[ $# -eq 0 ]]; then + echo "no test executables given" >&2 + exit 1 +fi + +mkdir -p "$work/home" "$work/isolate" "$work/pkg" +export HOME="$work/home" FFX_ISOLATE_DIR="$work/isolate" +ffx() { "$sdk/tools/x64/ffx" "$@"; } +json() { python3 -c "import json, sys; print(json.load(sys.stdin)$1)"; } + +ffx config analytics disable >/dev/null +ffx config set log.dir "$work/log" + +version=$(json '["id"]' <"$sdk/meta/manifest.json") +url=$(ffx --machine json product lookup minimal.x64 "$version" \ + --base-url "gs://fuchsia/development/$version" | json '["transfer_manifest_url"]') +ffx product download "$url" "$work/product" + +ffx emu start "$work/product" --headless --net user --accel auto --log "$work/emulator.log" +trap 'ffx emu stop --all || true; ffx repository server stop --all || true' EXIT + +repo=noq-tests +ffx repository create "$work/repo" +ffx repository server start --background --address '[::]:0' --repo-path "$work/repo" --repository "$repo" +ffx target repository register --repository "$repo" +api_level=$(ffx --machine json version | json '["tool_version"]["api_level"]') + +any_failures=0 +for test in "$@"; do + # Package names take lowercase letters, digits, `-`, `_` and `.`: drop + # cargo's hash suffix, the rest of a crate's name fits. + name=$(basename "$test" | sed 's/-[0-9a-f]*$//' | tr '[:upper:]' '[:lower:]') + pkg="$work/pkg/$name" + mkdir -p "$pkg/meta" + printf '{"name": "%s", "version": "0"}\n' "$name" >"$pkg/meta/package" + # elf_test_runner passes the suite when the binary exits with 0. A system + # test may use the system's netstack, which the tests' sockets need. + cat >"$pkg/$name.cml" <"$pkg/manifest" <