Skip to content

Development and Testing

André Borchert edited this page Nov 13, 2026 · 15 revisions

Development and Testing

The contributor loop for both libraries. Run every command from the repository root unless a step says otherwise. The two libraries share a repository and nothing else: a Swift change never needs a C99 build, and vice versa.

Toolchain

Library Needs
Swift macOS 26+, Xcode 27+, Swift 6.4 (Swift language mode 6). ./Swift/check-toolchain.sh defaults to those floors; CI passes them explicitly.
C99 CMake 3.28+, Ninja, OpenSSL 3.0, a C99 compiler (clang, gcc or mingw-w64).
./Swift/check-toolchain.sh 6.4 27.0

Swift loop

swift build
swift test
swift run WebTransportClient --scenario all
swift run WebTransportServer --scenario all

Formatting is described by .swift-format and enforced as a blocking gate. The gate covers both manifests as well as the sources and tests:

swift format lint --strict --recursive --parallel Swift/Sources Swift/Tests Package.swift Swift/Package.swift
swift format --in-place --recursive Swift/Sources Swift/Tests Package.swift Swift/Package.swift

A plain swift build does not turn warnings into errors; CI does. Reproduce CI's diagnostics locally:

swift build \
  -Xswiftc -warnings-as-errors \
  -Xswiftc -strict-concurrency=complete \
  -Xswiftc -require-explicit-sendable
swift build --package-path Swift \
  -Xswiftc -warnings-as-errors \
  -Xswiftc -strict-concurrency=complete \
  -Xswiftc -require-explicit-sendable

Focused test suites:

swift test --filter WebTransportTests
swift test --filter WebTransportNetworkRuntimeTests
swift test --filter WebTransportHTTP3CoreTests
swift test --filter WebTransportQUICCoreTests
swift test --filter WebTransportTLSCoreTests
swift test --filter WebTransportCryptoAppleTests
swift test --filter WebTransportUDPAppleTests
swift test --package-path Swift --filter WebTransportTestSupportTests

Sanitizers:

# Peer-input parsers, large deterministic budget, AddressSanitizer
WEBTRANSPORT_FUZZ_ITERATIONS=20000 swift test --sanitize=address \
  --filter 'peerFacingParsers|huffmanDecoder'

# The whole in-process suite under AddressSanitizer, which is the memory half.
# The two subprocess suites spawn binaries the sanitizer cannot observe.
swift test --sanitize=address --skip CLIProcess --skip ReleaseArtifacts

# The same suite under Thread Sanitizer. The subprocess suites are skipped:
# their wall-clock timeouts are exceeded by TSan's slowdown.
swift test --sanitize=thread --skip CLIProcess --skip ReleaseArtifacts

Every parser that consumes peer bytes must be driven by the fuzz corpus: a trap in any of them is remotely reachable, because they all run before a session exists. The generator is seeded, so a CI failure replays exactly.

Soak and interop runners:

./Swift/run-soak.sh 400
./Swift/run-docker-interop.sh
cd Swift && ./run-third-party-interop.sh
cd Swift && ./run-vps-third-party-interop.sh

soak.yml runs run-soak.sh nightly and on manual dispatch, not per pull request: it watches resident memory and thread count for sustained growth across 400 connections, and a loaded shared runner can move those numbers with nothing wrong.

API and release validation:

cd Swift
./check-api-compatibility.sh
./build-release-apple-silicon.sh

check-api-compatibility.sh builds an external package that imports the public products. build-release-apple-silicon.sh performs two clean arm64 builds, asserts lipo -archs is exactly arm64, compares normalized Mach-O hashes, and writes the artifacts under .build/release-artifacts/.

C99 loop

C99/scripts/build-and-test.sh              # Debug  -> C99/out/<platform>/build
C99/scripts/build-and-test.sh --release    # Release-> C99/out/<platform>/build-release
C99/scripts/build-and-test.sh --sanitize   # ASan+UBSan -> C99/out/<platform>/build-sanitize
C99/scripts/build-and-test.sh --all        # all three, in order

<platform> is macos26, debian, freebsd or unknown. The equivalent by hand, exactly as CI configures it:

cmake -S C99 -B C99/out/ci/build -G Ninja \
  -DCMAKE_BUILD_TYPE=Debug -DWEBTRANSPORT_C99_BUILD_APPS=ON
cmake --build C99/out/ci/build
ctest --test-dir C99/out/ci/build --output-on-failure

The individual gates:

C99/scripts/check-vectors.sh           # re-derives every RFC vector and diffs the committed headers
C99/scripts/check-matrix.sh            # every symbol and test name in the compliance matrix exists
C99/scripts/score-matrix.sh            # counts matrix statuses and the Definition-of-Done rows
C99/scripts/check-package.sh           # installs the tree, builds a find_package consumer, runs the tools
C99/scripts/check-portability.sh       # every platform-adapted POSIX call is named in docs/PORTABILITY.md
C99/scripts/check-static-analysis.sh   # Clang Static Analyzer over library and tools
C99/scripts/check-cppcheck.sh          # cppcheck over the same set
python3 C99/scripts/check-workflows.py .github/workflows

Run one test by name while working:

ctest --test-dir C99/out/macos26/build -R test_http3_driver --output-on-failure

The gates, and what each one proves

Gate Command Proves
Toolchain floor ./Swift/check-toolchain.sh 6.4 27.0 The build is exercised on the mandated compiler, not whatever the runner image carries.
Manifest agreement ./Swift/check-manifest-sync.sh The two SwiftPM manifests agree on every shared target's path, type and dependencies. Requires jq.
Version lockstep ./Swift/check-version-sync.sh VERSION, the C99 WT_VERSION_* macros and WebTransportVersion.library all agree. The C99 CMake configure fails on the same mismatch.
Declared imports ./Swift/check-target-imports.sh Every module a target imports is a declared dependency. Requires jq.
Unsafe build flags ./Swift/check-unsafe-flags.sh No target in either manifest sets unsafeFlags. SwiftPM refuses those for a version-based dependency but not for a path-based one, so the API-compatibility check — which consumes the package by path — cannot see this class at all.
Keychain-free identity ./Swift/check-pkcs12-keychain-free.sh Resolving a PKCS#12 identity succeeds while the default keychain is locked — the only state that distinguishes the memory-only import from one that files the caller's key. It restores the runner's keychain on every exit path, including a signal.
Formatting swift format lint --strict … The tree matches .swift-format, manifests included.
Warning-free build swift build -Xswiftc -warnings-as-errors … No warnings; complete concurrency checking; every public type explicitly Sendable.
DocC swift build -Xswiftc -emit-symbol-graph … + xcrun docc convert … The public documentation catalog still compiles against the public API.
API compatibility ./check-api-compatibility.sh An external consumer of the public products still builds.
Reproducible release ./build-release-apple-silicon.sh Two clean arm64 builds hash identically; only arm64.
Package tests swift test … Public API, runtime, protocol cores, crypto, UDP, process, stress. CI sets WEBTRANSPORT_REQUIRE_CLI_BINARIES=1 and WEBTRANSPORT_REQUIRE_RELEASE_ARTIFACTS=1.
Nested test target swift test --package-path Swift --filter WebTransportTestSupportTests The one test target the root manifest does not declare.
Library smoke pair ./Swift/run-library-smoke.sh The nested manifest's two smoke executables run against each other.
CLI conformance swift run WebTransportClient --scenario all (and server) 40 positive and negative scenarios per peer.
Fuzz under ASan WEBTRANSPORT_FUZZ_ITERATIONS=20000 swift test --sanitize=address --filter 'peerFacingParsers|huffmanDecoder' Peer-facing parsers return or throw and never trap, on a large deterministic corpus.
Suite under ASan swift test --sanitize=address --skip CLIProcess --skip ReleaseArtifacts The whole in-process suite under the memory sanitizer, not only the parsers. The two skipped suites spawn uninstrumented binaries, which a sanitizer runtime inside the test process cannot observe.
Thread Sanitizer swift test --sanitize=thread --skip CLIProcess --skip ReleaseArtifacts No data race in the in-process runtime, protocol and crypto state.
C99 workflow files python3 C99/scripts/check-workflows.py .github/workflows Workflow YAML parses and has no duplicate keys (which yaml.safe_load silently accepts and GitHub rejects).
C99 unit and integration tests cmake … + ctest 105 CTest tests: 92 unit programs, the 200,000-input parser fuzz run, and the app-level scenario/CLI tests.
RFC vectors C99/scripts/check-vectors.sh Every committed vector is what the RFC text says, re-derived by the extractor.
Compliance matrix C99/scripts/check-matrix.sh + score-matrix.sh No symbol or test in the matrix has stopped existing; the score is counted, not remembered.
Package consumer C99/scripts/check-package.sh The install tree is findable, links, and the three installed tools run from it.
C99 formatting C99/scripts/check-format.sh Every C source matches the committed .clang-format; the generated QPACK tables and the RFC vectors are named exclusions, because they are written by extractors rather than by hand.
Dead locals python3 C99/scripts/check-unused-locals.py No local is assigned and never read with a (void) cast hiding it. (void)name; counts as a use to the compiler, so -Wunused-but-set-variable cannot see these; an unused parameter is a deliberate suppression and is skipped.
C99 coverage C99/scripts/measure-coverage.sh The library's line coverage, measured from an instrumented build of the shared library — the same subject every test links.
Portability inventory C99/scripts/check-portability.sh Every name on the check's own list that the library uses is named in docs/PORTABILITY.md. The list is hand-maintained, so a POSIX-only call nobody added to it passes this check: what catches that is the Windows half of the matrix, which compiles the library for MSVC, Clang-CL and MINGW64.
Static analysis C99/scripts/check-static-analysis.sh Symbolic execution over all 106 library and tool sources, using the build's own compile commands.
cppcheck C99/scripts/check-cppcheck.sh A second analyser with different heuristics over the same set.
Windows compile / link / run check-windows-platform.sh, check-windows-build.sh, check-windows-wine.sh The _WIN32 branch compiles, the whole tree links into PE32+ executables, and every test binary runs under Wine. The native windows-latest job settles what Wine cannot, and the msvc and clang-cl jobs run the same configure, build and ctest under the two compilers the plan's Phase 12 matrix names.
FreeBSD the freebsd CI job (vmactions/freebsd-vm) Boots a FreeBSD 15.1 VM on an Ubuntu runner and runs the same configure, build and ctest there, so a FreeBSD-only regression fails a pull request. pkg install -y cmake ninja python3 is the whole setup, and python3 is the harness dependency the first hand pass found the hard way.

Environment traps

Trap What happens What to do
Two C99 build-directory conventions C99/scripts/build-and-test.sh writes C99/out/<platform>/build{,-release,-sanitize} with Ninja. C99/platform/*/compile-*.sh write out/<platform>/build-install and install to out/<platform>/install. Keep them apart. Pointing one at the other's directory fails with "Does not match the generator used previously".
Sanitizers need their own configure directory CMake caches compiler flags, so adding -DWEBTRANSPORT_C99_SANITIZE=ON to an existing directory does nothing and the run is silently not sanitized. Configure a fresh directory for the sanitizer build, as build-and-test.sh --sanitize does.
Darwin has no LeakSanitizer Requesting detect_leaks aborts the process with "detect_leaks is not supported on this platform". Leaks are found by the Linux CI leg. A green local macOS sanitizer run does not check for leaks.
Two CLI conformance scenarios read the working directory release-products reads Package.swift and release-script-stale-spikes reads Swift/build-release-apple-silicon.sh. Outside a checkout both are reported skipped; the run reads passed=38 failed=0 skipped=2 total=40 and exits 3. Run the suite from the repository root. Exit 3 is an incomplete run, not a failure.
check-manifest-sync.sh is not a version gate It diffs target paths, types and dependencies; it exits 1 when jq is not on PATH. Use check-version-sync.sh for the version. Install jq before the manifest check.
A debug log suppresses the establishment failure Enabling WEBTRANSPORT_INTEROP_DEBUG dropped the intermittent ~1% establishment failure to zero in 400 connections, so a measurement taken with it on measures the instrument. Observe a stuck process from outside (below) instead of adding logging.
Formatting gate covers the manifests Formatting only Swift/Sources and Swift/Tests still fails CI. Use the in-place command that names Package.swift and Swift/Package.swift too.
C99 packaging vs. dev generator The packaging scripts and the dev loop use different generators. Same as the first row: separate directories.

Diagnosing a hung session

A session that stops making progress and then times out cannot be investigated by adding logging (see the trap above). Observe the process after it is already stuck:

# Which await each task is suspended on — the useful one
swift-inspect dump-concurrency <pid>

# Thread stacks — necessary but not sufficient
sample <pid> 2 -file /tmp/hang.txt
  • swift-inspect cannot attach to a release binary as shipped, because it is ad-hoc signed and task_for_pid fails with (os/kern) failure 0x5. Re-sign a copy with an entitlements file containing com.apple.security.get-task-allow:

    codesign -f -s - --entitlements debuggable.entitlements WebTransportServer
  • A thread sample alone misleads: a suspended Swift task has no OS thread stack, so the process shows idle threads and "nothing happening" rather than "everything parked". Only dump-concurrency shows the suspension points.

  • Capture both peers. Reading the two dumps together is what distinguishes a lost delivery from slowness.

  • These failures are load-dependent. Saturate the host deliberately (for i in $(seq 1 16); do yes > /dev/null & done) and state the load a measurement was taken under.

Validation by change type

Change Minimum evidence
Documentation Fact-check against source and config; link check; rendered Markdown review.
Public Swift API Build, full tests, check-api-compatibility.sh, DocC conversion.
Swift CLI Full tests plus both 40-scenario suites.
Runtime or trust Runtime, public API and process tests, plus IPv4 and IPv6 packet loopback.
HTTP/3, QPACK or sessions WebTransportHTTP3CoreTests and the relevant scenarios.
QUIC, TLS, crypto or UDP The owning target's tests plus an integration path.
A parser reading peer bytes The fuzz suite, plus a case for the new shape.
Concurrency or task lifetime Thread Sanitizer, plus run-soak.sh when connection state is involved.
Anything a peer negotiates ./Swift/run-docker-interop.sh. Internal tests exercise this implementation against itself, so a defect both sides share is invisible to all of them.
C99 layer The matching C99/tests/unit/test_*.c plus check-matrix.sh; re-run --sanitize if it parses peer bytes.
C99 public header or install rule check-package.sh, and the header count if one was added.
Release tooling Reproducible release build and a CI review.

Contributor workflow

  1. Identify the owning module (Architecture) and read its nearest tests.
  2. Check the effects on public API, protocol behaviour, trust rules, logging, the manifests, CI and documentation.
  3. Make the smallest coherent change, and cover the important negative paths.
  4. Run the focused checks, then the broader evidence the change requires.
  5. Review the diff for generated output, credentials, stale claims and unrelated edits.
  6. Update the documentation whenever setup, API, behaviour, trust, workflow or release evidence changes. Open work belongs on the Project Tracker, not in a TODO.

Clone this wiki locally