8000 blackwall/docs/project/testing.md at main · hmmhmmhm/blackwall · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
169 lines (131 loc) · 11.6 KB

testing.md

File metadata and controls

169 lines (131 loc) · 11.6 KB

Contributor tests

This guide runs the repository's Python unittest suite in a new virtual environment. The setup uses the project's local wheel bundle, verifies both wheel hashes, and installs with pip offline. The pip subprocess receives PIP_CONFIG_FILE set to the platform's null device, so inherited global, user, and site pip configuration cannot add remote wheel sources; it preserves the caller's other environment values. The environment report records network_install: false. It does not need firmware, private captures, Docker, or Renode for the default unit suite.

Supported offline environment

The pinned wheel set currently supports macOS arm64 with GIL-enabled CPython 3.14. The setup script rejects free-threaded CPython builds and checks the host, Python version, wheel tags, metadata, filenames, and SHA-256 hashes before creating the environment. The lock is in tools/simulator-wheels.json; the installer is tools/setup_simulator.py.

An explicitly selected second target supports Linux ARM64 with musl libc 1.2 or newer and GIL-enabled CPython 3.12. It is tested in the digest-pinned Python 3.12 Alpine 3.24.4 ARM64 image below. The macOS target remains the default. The Linux target checks Linux, aarch64, Python 3.12, and the actual musl loader mapped by the running Python process before creating a venv. Other Linux distributions, glibc, Python versions, and architectures are unsupported by these wheel locks.

Linux ARM64 Alpine run

Run this from the repository root on a Docker host that already has the pinned image. To acquire the exact image before the offline test run, pull the digest explicitly, then verify the local image identity and platform:

docker pull --platform linux/arm64 \
  python@sha256:c5ba3deef00c7758561a0f03c26f44f10589263d40e732b8748e0d1f38f6dd89
docker image inspect \
  python@sha256:c5ba3deef00c7758561a0f03c26f44f10589263d40e732b8748e0d1f38f6dd89 \
  --format '{{.Id}} {{.Os}}/{{.Architecture}}'

The runner itself does not pull or build an image. Create the scratch directory with mode 0700, owned by the user running the command. It requires rootful Docker without user namespace remapping, starts the container as the caller's UID:GID, and verifies that a scratch bind-mount probe retains that ownership before starting tests. It stops if the daemon mode or live mapping cannot be verified, so accepted runs do not leave root-owned outputs.

Obtain the exact wheels listed in tools/simulator-wheels-linux-arm64-musl-py312.json. These direct PyPI file URLs and SHA-256 values identify the published release files; the hashes verify downloaded bytes against those files. Save them under a new private directory outside the repository. This example uses macOS shasum to check each file before giving it the .whl name:

set -eu
umask 077
wheel_root="$HOME/Library/Application Support/Blackwall/simulator/wheels"
restore_id="$(date +%Y%m%d-%H%M%S)-$$"
wheel_dir="$wheel_root/linux-arm64-musl-py312-$restore_id"
mkdir -p "$wheel_root"
mkdir "$wheel_dir"

fetch_wheel() {
  filename="$1"
  url="$2"
  expected_sha="$3"
  partial="$wheel_dir/$filename.part"
  if ! curl --fail --location --proto '=https' --proto-redir '=https' --tlsv1.2 \
      --output "$partial" "$url"; then
    rm -f "$partial"
    echo "Wheel download failed: $filename" >&2
    return 1
  fi
  if ! (cd "$wheel_dir" && printf '%s  %s\n' "$expected_sha
815E
" "$filename.part" \
      | shasum -a 256 -c >/dev/null); then
    rm -f "$partial"
    echo "Wheel SHA-256 mismatch: $filename" >&2
    return 1
  fi
  mv "$partial" "$wheel_dir/$filename"
}

fetch_wheel \
  'unicorn-2.1.4-cp37-abi3-musllinux_1_2_aarch64.whl' \
  'https://files.pythonhosted.org/packages/70/38/ba5a051c844026e59ab6e0017db8cec77dbe20ab5f1d6edae1ce9d885b06/unicorn-2.1.4-cp37-abi3-musllinux_1_2_aarch64.whl' \
  '01d744ba01c5cc68f1d7afe3d183f1868720fd440ec4eaedc4d1d5d9bf54b84c'
fetch_wheel \
  'capstone-5.0.9-py3-none-musllinux_1_2_aarch64.whl' \
  'https://files.pythonhosted.org/packages/b9/74/c178ac241892bb3668b633065bdbe6dc719c2aa54668d68a8e23a6753525/capstone-5.0.9-py3-none-musllinux_1_2_aarch64.whl' \
  '69064219c814ad64af35469a7c4ddd19b730cacb96a1a796435ccde0e1567d05'

test_root="$HOME/Library/Application Support/Blackwall/simulator/contributor-linux-tests-$restore_id"
mkdir "$test_root"
mkdir -m 700 "$test_root/scratch"
tools/run_linux_arm64_tests.sh "$wheel_dir" "$test_root/scratch"

The runner requires the exact preloaded python:3.12-alpine ARM64 image digest recorded in the script. It uses --pull=never, --network none, a read-only root filesystem, read-only repository and wheel mounts, and only the fresh scratch directory as writable bind storage. /tmp is a separate writable 128 MiB tmpfs for programs that use it directly; its contents disappear with the container. TMPDIR points to /scratch/tmp, and the venv and retained test output stay in scratch. The runner starts both its access probe and test container as the invoking host UID:GID, then verifies that a private 0700 probe directory on the bind mount retains that UID:GID before removing it and proceeding. It rejects rootless Docker and user namespace remapping. This run verified rootful Docker Desktop; a native-Linux Docker daemon must also pass the same daemon-mode and live ownership checks before the suite starts. It does not mount the host home directory, Docker socket, or devices. It needs Docker available on the host, but package installation and test execution do not use network access.

The Linux run is an explicit opt-in; pass --target linux-arm64-musl-py312 when invoking setup_simulator.py directly. A plain python3 tools/setup_simulator.py ... continues to select the existing macOS arm64 Python 3.14 lock.

From the repository root, create a new output path outside Git. Set blackwall_assets to the local Blackwall simulator support directory. The example adds a timestamp and process ID so each run gets a fresh path.

python3 --version
uname -sm

blackwall_assets="$HOME/Library/Application Support/Blackwall/simulator"
blackwall_test_root="$blackwall_assets/contributor-tests-$(date +%Y%m%d-%H%M%S)-$$"

python3 tools/setup_simulator.py \
  --wheels "$blackwall_assets/wheels/macos-arm64-py314-01" \
  --output "$blackwall_test_root/venv"

mkdir -p "$blackwall_test_root/tmp"
TMPDIR="$blackwall_test_root/tmp" \
  "$blackwall_test_root/venv/bin/python" -B -m unittest discover -s tests

The setup requires these exact packages:

Package Version SHA-256
Unicorn 2.1.4 d6c93e0f60328d8f4a1792af3f834137a28050fcc2305f2ec01efe8558a9844e
Capstone 5.0.9 fc269c5082e17d7f9f265cd6980e2fdc6ab572df913951d76db0357e06b8001d

setup_simulator.py uses --no-index and --require-hashes; it does not download packages. If a wheel is missing or has the wrong hash, it stops before installing. A plain system Python may not have Unicorn or Capstone; run the suite with the new environment's bin/python shown above.

Restore the wheel bundle

If storage cleanup removed the local wheels, download the exact files below from PyPI's HTTPS file host into a new directory. The SHA-256 values are PyPI's published release-file hashes and match tools/simulator-wheels.json. They verify that the downloaded bytes match those PyPI files; PyPI lists these releases without build provenance. See the Unicorn 2.1.4 and Capstone 5.0.9 release pages.

Run this from the repository root on macOS arm64. mkdir fails if the generated destination already exists. A failed download or hash check removes the .part file and stops before setup; only hash-verified files receive their .whl names.

set -eu
umask 077
blackwall_assets="$HOME/Library/Application Support/Blackwall/simulator"
restore_id="$(date +%Y%m%d-%H%M%S)-$$"
wheel_dir="$blackwall_assets/wheels/macos-arm64-py314-restored-$restore_id"
blackwall_test_root="$blackwall_assets/contributor-tests-$restore_id"
mkdir -p "$blackwall_assets/wheels"
mkdir "$wheel_dir"

fetch_wheel() {
  filename="$1"
  url="$2"
  expected_sha="$3"
  partial="$wheel_dir/$filename.part"
  if ! curl --fail --location --proto '=https' --proto-redir '=https' --tlsv1.2 \
      --output "$partial" "$url"; then
    rm -f "$partial"
    echo "Wheel download failed: $filename" >&2
    return 1
  fi
  if ! (cd "$wheel_dir" && printf '%s  %s\n' "$expected_sha" "$filename.part" \
      | shasum -a 256 -c >/dev/null); then
    rm -f "$partial"
    echo "Wheel SHA-256 mismatch: $filename" >&2
    return 1
  fi
  mv "$partial" "$wheel_dir/$filename"
}

fetch_wheel \
  'unicorn-2.1.4-cp37-abi3-macosx_11_0_arm64.whl' \
  'https://files.pythonhosted.org/packages/6c/ae/4943c6f8524d729ec7d5e69df6407ea05d710fe77471d91cecf3fc64eb57/unicorn-2.1.4-cp37-abi3-macosx_11_0_arm64.whl' \
  'd6c93e0f60328d8f4a1792af3f834137a28050fcc2305f2ec01efe8558a9844e'
fetch_wheel \
  'capstone-5.0.9-py3-none-macosx_11_0_arm64.whl' \
  'https://files.pythonhosted.org/packages/42/9a/4eecfbc94961cda70301fd13de69042be1943bee456e37bc1369840601b1/capstone-5.0.9-py3-none-macosx_11_0_arm64.whl' \
  'fc269c5082e17d7f9f265cd6980e2fdc6ab572df913951d76db0357e06b8001d'

python3 tools/setup_simulator.py \
  --wheels "$wheel_dir" \
  --output "$blackwall_test_root/venv"

The setup script rechecks the wheel lock and installs offline. Keep the restored wheel directory if you may need to rebuild the environment later.

What the command runs

This command discovers Python unittest tests under tests/. It does not run the separate JavaScript .test.mjs files or C# Renode fixtures. It also does not install firmware, start a physical device, or require a Docker service.

Some tests use saved private captures or pinned firmware if their local files or opt-in BLACKWALL_* variables are present. Renode integration checks require their explicit BLACKWALL_RENODE_*_UNIT=1 flags and the pinned Docker image. Without those prerequisites, those tests report as skipped; do not point them at unrelated captures or enable them just to reduce the skip count. Skips vary by host and available private inputs.

The latest complete macOS arm64/Python 3.14.4 run executed 688 tests with 38 skipped on 2026-12-03, with no failures. The latest complete Linux ARM64 Alpine run executed 664 tests with 69 skipped on the same date, with no failures. Linux skips include checks requiring macOS CommonCrypto or LLVM tools absent from the pinned image. Both runs also skip opt-in Renode checks, private captures and firmware fixtures when their explicit inputs are absent, and platform-specific checks such as APFS clone support. No private assets or Renode flags were supplied to the Linux run. These counts are snapshots; optional inputs, host support, and future tests can change them. Read the final summary and skip reasons; a skipped optional test is not a pass.

Common setup errors

  • This wheel set requires macOS arm64 and Python 3.14: use that host and interpreter, or arrange a separately reviewed wheel lock for the target platform.
  • Missing pinned wheel: check the --wheels directory against the filenames in tools/simulator-wheels.json.
  • Wheel SHA256 mismatch: restore the exact wheel bundle; do not bypass the hash check.
  • No module named 'unicorn' or No module named 'capstone': confirm that the test command uses blackwall_test_root/venv/bin/python, not the system interpreter.

The repository's broader firmware and private-capture workflows have separate prerequisites. See the fresh simulator workspace guide for those execution workflows.

0