Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ docs/
# vendor 아래의 파일은 위 규칙에 걸려도 전부 추적함. cargo가 크레이트의 모든
# 파일을 체크섬으로 확인하므로 하나라도 빠지면 오프라인 빌드가 실패함
!vendor/**

# Lean build output
proofs/lean/.lake/
18 changes: 15 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ $ cargo build -p k0-kernel --features console --offline
$ tools/qemu-boot-test.sh # boot under QEMU and check the self-tests
```

`tools/host-test.sh` runs the tests of `k0-abi`, `k0-cap`, `k0-boot`, `k0-efi`, `k0-conin`, `k0-slice`, `k0-vault` and `k0-term` on any host (377 tests on an AArch64 host, 289 elsewhere). `k0-slice` has 9 tests: they run the rule that decides whether a tick cuts the running task on a model of the scheduler. It runs `k0-vault` twice, with and without the algorithm feature `vault-ed25519`, which gives 20 and 11 tests. It runs `k0-term` with and without the vault feature, which gives 24 and 21 tests. The tests of `k0-mm` contain AArch64 inline assembly, so they only run on an AArch64 host (Apple Silicon or Linux arm64). The script runs them for both the 4 KiB and the 16 KiB granule.
`tools/host-test.sh` runs the tests of `k0-abi`, `k0-cap`, `k0-boot`, `k0-efi`, `k0-conin`, `k0-slice`, `k0-part`, `k0-vault` and `k0-term` on any host (415 tests on an AArch64 host, 327 elsewhere). `k0-slice` has 9 tests: they run the rule that decides whether a tick cuts the running task on a model of the scheduler. `k0-part` has 36 tests: they run the scheduler's decisions under a time partition table on a model of the kernel, check the arithmetic of tick instants, and compare the Rust code with the recorded results of a Lean model (see "Changing the scheduler core" below). It runs `k0-vault` twice, with and without the algorithm feature `vault-ed25519`, which gives 20 and 11 tests. It runs `k0-term` with and without the vault feature, which gives 24 and 21 tests. The tests of `k0-mm` contain AArch64 inline assembly, so they only run on an AArch64 host (Apple Silicon or Linux arm64). The script runs them for both the 4 KiB and the 16 KiB granule.

`tools/qemu-boot-test.sh` boots the debug kernel, checks the boot log line by line in a fixed order, fails on any error marker, and stops QEMU as soon as the root task reports `root: sched tests pass`. Besides the pass lines, it expects `k0: kernel reserve ` before the `k0: untyped ` lines, `k0: idle (waiting for a timeout)` and `root: timeout tests pass` after `root: teardown tests pass`, and `root: kernel reserve tests pass` after `root: revocation tests pass`. Any line that starts with `k0: all tasks` is a failure. It also counts the timer tick lines between `root: teardown tests pass` and `root: timeout tests pass` and wants at least 4, because EL0 has no clock and this is how the lower bound of a timeout is checked. The timeout tests wait for real ticks, so a boot takes about 4 seconds longer than it did before. The time slice test runs twice (a task that got the CPU by `YIELD`, then one that got it by blocking) and takes about 4 seconds in all where the preemption test it replaced took about 1. It also expects `root: slice test yield pass` and `root: slice test block pass`, in this order, before `root: preempt test pass`. Set `K0_BOOT_TIMEOUT` (seconds) on slow machines. It reads the serial port, so it needs an image with a console driver. To test an image without console, use `K0_BOOT_MEMLOG`, `K0_BOOT_SERIAL=empty` and `K0_BOOT_CONSOLE_PAGE`, which are described in "Testing an image without console" in [USAGE.md](USAGE.md#testing-an-image-without-console).
`tools/qemu-boot-test.sh` boots the debug kernel, checks the boot log line by line in a fixed order, fails on any error marker, and stops QEMU as soon as the root task reports `root: sched tests pass`. Besides the pass lines, it expects `k0: kernel reserve ` before the `k0: untyped ` lines, `k0: idle (waiting for a timeout)` and `root: timeout tests pass` after `root: teardown tests pass`, and `root: kernel reserve tests pass` after `root: revocation tests pass`. Any line that starts with `k0: all tasks` is a failure. It also counts the timer tick lines between `root: teardown tests pass` and `root: timeout tests pass` and wants at least 4, because EL0 has no clock and this is how the lower bound of a timeout is checked. The timeout tests wait for real ticks, so a boot takes about 4 seconds longer than it did before. The time slice test runs twice (a task that got the CPU by `YIELD`, then one that got it by blocking) and takes about 4 seconds in all where the preemption test it replaced took about 1. It also expects `root: slice test yield pass` and `root: slice test block pass`, in this order, before `root: preempt test pass`. After that come `root: partition refusal pass` and `root: partition window pass`, and `root: partition sealed` comes before `root: sched tests pass`. The time partition test lets a table of 9 ticks run one round, so it adds about 15 seconds to every boot. If the host stalls QEMU for more than a second during it, the test runs once more and the script reports `boot-test: partition window retries: 1` without failing. `tools/boot-matrix.sh` runs such a boot row again and fails it when the second run needed the retry too. Set `K0_BOOT_TIMEOUT` (seconds) on slow machines. It reads the serial port, so it needs an image with a console driver. To test an image without console, use `K0_BOOT_MEMLOG`, `K0_BOOT_SERIAL=empty` and `K0_BOOT_CONSOLE_PAGE`, which are described in "Testing an image without console" in [USAGE.md](USAGE.md#testing-an-image-without-console).

An image with the signing oracle (`vault` or `vault-ed25519`) has two more intended faults, so it prints 8 `k0: task fault` lines instead of 6. Run the test with `K0_BOOT_FAULTS=8` and require `root: oracle tests pass` with `K0_BOOT_REQUIRE`. The boot matrix has the rows `vault`, `vault-max`, `vault-el2`, `vault-16k`, `vault-no-alg`, `hvf-vault` and the static check `vault-symbols` for it, and 82 rows in total on a Mac with HVF and 71 in CI. The rows `input-*` and `term-*` cover console input and the terminal. A terminal image prints two more `k0: task fault` lines (8 without the vault, 10 with it), and `tools/term-test.py <image>` runs its scripted serial session. [USAGE.md](USAGE.md) describes the rows.

Expand Down Expand Up @@ -130,6 +130,7 @@ In the following table, you can see where each area is tested.
| `k0-efi` memory plan from the UEFI memory map, DTB rewrite, independent check, ACPI table reader and tree synthesis | yes, plus fuzzing | yes, through the `uefi-*` rows of the boot matrix |
| `loader` (UEFI application: firmware calls, cache flush, MMU off, jump) | no | yes, through the `uefi-*` rows, plus the static check `tools/pe-check.py` |
| `k0-mm` page tables and W^X attributes | yes, on AArch64 hosts | yes |
| `k0-slice` tick rule and `k0-part` scheduling decisions, table decoding and tick arithmetic | yes, including the comparison with the recorded results of the Lean model | yes, through the slice test and the partition test, by the order of events only |
| `k0-arch`, `k0-task`, `k0-sched`, `k0-ipc` | no | yes |

`k0-arch` assembles with ELF-only directives and the scheduler and IPC paths read system registers, so they are only exercised by booting. If you change them, extend the root task self-tests in `userspace/root-task/src/main.rs` and add the new pass line to the expected list in `tools/qemu-boot-test.sh`.
Expand All @@ -153,6 +154,15 @@ With `-p k0-efi` it runs three more fuzzers, which work the same way. The UEFI m

`K0_FUZZ_ITERS`, `K0_FUZZ_SEED` and `K0_FUZZ_CASE` work the same for all of them. `K0_FUZZ_SEED` changes the base seed. Different base seeds give unrelated streams of cases. When a case fails, the test prints a `K0_FUZZ_CASE=0x...` value. Run the same command with that variable set to replay only that case and dump the input.

### Changing the scheduler core

`crates/k0-part` holds every scheduling decision (`Core`) and the arithmetic of tick instants (`clock`). `proofs/lean` holds Lean 4 proofs about a model of it, and `crates/k0-part/src/model_vectors.txt` holds 1600 event scripts with the result the model gives for each. The host test `core_gives_the_lines_of_the_lean_model_on_every_recorded_script` runs those scripts through the real `Core` and fails when the two differ. CI runs that test. CI does not run the proofs.

> [!IMPORTANT]
> If you change what `Core` does, make the same change in `proofs/lean/K0Part.lean`, get `lake build` to pass again, and write the hashes again from the model. Never edit a hash by hand to make the test pass. [proofs/lean/README.md](proofs/lean/README.md) has the steps under "When the Rust code or the model changes on purpose".

The proofs are about the model, not about the Rust code. Do not describe a change as proved because the Lean files build. `k0-sched`, `k0-ipc` and the kernel binary have no host tests, and no test sees the guard, the hold before the return to EL0 or the TLB flush at a change of domain, so a change there needs a careful review and a description of how you checked it.

### Running exactly what CI runs

CI builds the container image from `ci/Dockerfile` and then runs the tests inside it with networking disabled. This proves that building and testing need nothing outside the repository. You can run it as follows:
Expand All @@ -163,11 +173,13 @@ $ docker run --rm --network none k0-ci tools/host-test.sh
$ docker run --rm --network none k0-ci tools/boot-matrix.sh
```

The CI job has a limit of 45 minutes. With the time partition test in every boot, a run is estimated at about 30 minutes. That is an estimate, not a measurement on CI.

Run this from **a clean checkout**, because the build context is the working directory. The following list describes how the image is made.

- **Base image**: it is pinned by the digest of its multi-architecture index (`debian:bookworm@sha256:...`).
- **Rust toolchain**: the image does not use rustup. `ci/install-toolchain.py` pins the SHA-256 of the Rust 1.89.0 channel manifest and checks every package it installs (rustc, cargo, rust-std for the host and for `aarch64-unknown-none-softfloat` and `aarch64-unknown-uefi`, rust-src and llvm-tools) against the hashes in that manifest. A mismatch fails the image build.
- **Build context**: `.dockerignore` is an allowlist, so nothing enters the image unless it is listed there. **A new top-level file or directory** that the build or the tests need must be added to it. `.git` is kept in the image.
- **Build context**: `.dockerignore` is an allowlist, so nothing enters the image unless it is listed there. **A new top-level file or directory** that the build or the tests need must be added to it. `.git` is kept in the image. `proofs/` is not listed, so the Lean files are not in the image.

> [!NOTE]
> Not everything is pinned. The versions of the Debian packages float (apt checks them with the archive keys inside the pinned base image), and so do the GitHub runner images. The GitHub Actions used by the workflows are pinned by commit hash.
Expand Down
Loading