Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/scripts/qemu_ck_osh_op_test.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / scripts / qemu_ck_osh_op_test.sh` 186 lines ยท 13470 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # SPDX-License-Identifier: Apache-2.0 3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # AIENOS_CK_OSH_OP gate (OSH-AIENOS-OP, aien-architecture#158): a REAL capability-authorized operation through the shared 18 # OSH interface. The same three compiled shell units (lex_run, parse_run, expand_run) run as admitted EL0 tasks; on a ready 19 # pipeline the request record goes to the adapter's operation layer (native/kernel/core/osh_op.c) instead of a fake status. 20 # Operation: `klog ` writes "osh_op_out: " to the console. Capability: WRITE on the console-log resource in 21 # the session's kernel IPC capability table (domain 1). The OSH_CORE gate (qemu_ck_osh_core_test.sh, fixture traces) is 22 # unchanged and separate; this gate does not run the fixtures. 23 # 24 # Label: QEMU (aarch64 virt), TEST signer, not physical. Nothing here ran on a Spark or any real machine. 25 # Cases (one boot, CK_SEED0B_TEST_ANCHOR=1 CK_OSH_TEST=1 CK_OSH_OP_TEST=1): 26 # allow WRITE held: two lines and two "grant used" receipts on the console (the second shows $? = the real status 0 flowing back into the shell core) 27 # deny_no_cap no capability: DENIED, no bytes, outcome FAILED_NO_EFFECT, a security receipt line 28 # deny_read_only READ only: DENIED, no bytes 29 # revoked revoked between request build and effect: REVOKED, no bytes 30 # interrupt interrupt before pipeline 2 of 3: pipeline 1 done, 2 CANCELLED, 3 never runs, status 130 31 # lost adapter lost after the effect: bytes appear once; restart reports OUTCOME_UNKNOWN with the digest, never replays 32 # after_restart a new request after the loss is a new decision and runs 33 # unsupported pipe, redirection, unknown command: NOT_SUPPORTED / NOT_FOUND before any effect 34 # every case: capability released at the end, no EL0 task slot left held. 35 # Last line: AIENOS_CK_OSH_OP: PASS|FAIL|NOT_RUN. 36 set -euo pipefail 37 38 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 39 cd "${repo_root}" 40 verdict=AIENOS_CK_OSH_OP 41 code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" 42 vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" 43 command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; echo "${verdict}: NOT_RUN"; exit 2; } 44 [[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; echo "${verdict}: NOT_RUN"; exit 2; } 45 46 # Machine quiet flag (read only) and the QEMU gate lock (one gate at a time): 47 # scripts/lib_gate_hold.sh (aienos#278). 48 . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib_gate_hold.sh" 49 if ! gh_quiet_check || ! gh_lock_take "qemu_ck_osh_op_test" "${AIENOS_GATE_MINUTES:-60}"; then 50 echo "NOT_RUN ${gh_why}" 51 echo "${verdict}: NOT_RUN" 52 exit 3 53 fi 54 # Release only this run's own gate lock record, at most once. 55 release_flag() { gh_lock_release; } 56 work="$(mktemp -d)" 57 cleanup() { rm -rf "${work}"; release_flag; } 58 trap cleanup EXIT 59 failed=0 60 pass() { echo "PASS $1"; } 61 fail() { echo "FAIL $1"; failed=1; } 62 63 cross="" 64 if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi 65 commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" 66 out_prod="${AIENOS_CK_OUT_PROD:-${repo_root}/target/native-kernel}" 67 out_osh="${AIENOS_CK_OUT_OSH:-${repo_root}/target/native-kernel-osh-op-test}" 68 mk() { make -s -C native/kernel CROSS="${cross}" AIENOS_COMMIT="${commit}" "$@" >/dev/null; } 69 70 fix="native/kernel/tests/fixtures/osh" 71 mk OUT="${out_osh}" CK_SEED0B_TEST_ANCHOR=1 CK_OSH_TEST=1 CK_OSH_OP_TEST=1 full 72 make -s -C native/kernel OUT="${out_prod}" store-image gpt-image >/dev/null 73 simg="${out_prod}/host/ck_store_image" 74 75 # aienos#383: each launch needs the unit's realization receipt 76 files=("${fix}/osh_lex.unit" "${fix}/osh_parse.unit" "${fix}/osh_expand.unit" "${fix}/../osc_receipt/osh_lex.rcpt" "${fix}/../osc_receipt/osh_parse.rcpt" "${fix}/../osc_receipt/osh_expand.rcpt") 77 disk="${work}/nvme.img" 78 "${out_prod}/host/ck_gpt_image" create "${disk}" 512 64 aienos-middle >/dev/null || fail "GPT boot disk image created" 79 if "${simg}" build "${disk}" 512 "${files[@]}" >"${work}/build.txt" 2>&1; then pass "boot disk built: $(head -1 "${work}/build.txt")" 80 else fail "boot disk build: $(head -3 "${work}/build.txt" | tr '\n' ' ')"; fi 81 82 boot() { # image, serial text output, disk image 83 local esp="${work}/esp" log="${work}/serial.log" started status 84 rm -rf "${esp}" 85 mkdir -p "${esp}/EFI/BOOT" "${esp}/EFI/AIENOS" 86 touch "${esp}/EFI/AIENOS/BOOTREPORT.TXT" 87 cp "$1" "${esp}/EFI/BOOT/BOOTAA64.EFI" 88 cp "${vars_fd}" "${work}/vars.fd" 89 started=$(date +%s) 90 set +e 91 nice -n 10 timeout "${AIENOS_QEMU_TIMEOUT:-900}" qemu-system-aarch64 \ 92 -M virt,virtualization=on,gic-version=3,iommu=smmuv3 -accel tcg,thread=single -cpu max -smp 4 -m 2048 \ 93 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ 94 -drive if=pflash,format=raw,file="${work}/vars.fd" \ 95 -drive if=none,id=esp,format=raw,file=fat:rw:"${esp}" \ 96 -device virtio-blk-pci,drive=esp \ 97 -drive if=none,id=nvme0,format=raw,file="$3" \ 98 -device nvme,drive=nvme0,serial=aienos-nvme-test \ 99 -device ramfb -display none -nic none \ 100 -serial file:"${log}" -no-reboot 101 status=$? 102 set -e 103 tr -d '\r' <"${log}" >"$2" 104 echo "qemu exit ${status} after $(( $(date +%s) - started )) s (commit ${commit:0:12})" 105 [[ "${status}" == 0 ]] || fail "QEMU exit status ${status} (124 = timeout)" 106 } 107 has() { grep -qE -- "$2" "$1"; } 108 check() { if has "$1" "$3"; then pass "$2"; else fail "$2"; fi; } 109 110 serial="${work}/serial.txt" 111 boot "${out_osh}/full/BOOTAA64.EFI" "${serial}" "${disk}" 112 release_flag 113 114 label='QEMU \(aarch64 virt\), TEST signer, not physical' 115 count() { grep -cE -- "$2" "$1" || true; } 116 exact() { # description, regex, expected count 117 local n; n="$(count "${serial}" "$2")" 118 if [[ "${n}" == "$3" ]]; then pass "$1 (${n})"; else fail "$1: expected $3, got ${n}"; fi 119 } 120 check "${serial}" "left firmware and entered the kernel" "kernel: alive" 121 check "${serial}" "kernel read all six candidates (three units, three receipts) from the boot disk Store" "^artifact_candidates: 6$" 122 for u in osh_lex osh_parse osh_expand; do 123 check "${serial}" "${u} admitted (real oscc output, TEST signer)" "^osc_unit: ${u}\\.unit ACCEPT unit_digest=[0-9a-f]{64} program_id=[0-9a-f]{64} funcs=[0-9]+ caps=0 signer=TEST$" 124 done 125 check "${serial}" "core line: 3 units" "^osh_core: units=3 ws_cells=11456 ws_pages=23 input_max=4096; ${label}\$" 126 check "${serial}" "report reached the console" "report_kind: final" 127 if has "${serial}" "report_kind: (panic|fault)"; then fail "panic or fault reported"; else pass "no kernel panic or fault report"; fi 128 if has "${serial}" "^osh_fault:"; then fail "a shell launch did not return"; else pass "every shell launch returned"; fi 129 exact "no fixture trace ran in this build" "^osh_script_begin" 0 130 check "${serial}" "all eight cases ran" "^osh_op_done: cases=8; ${label}\$" 131 132 P="^osh_op_pipeline: case=" 133 E="^osh_op_end: case=" 134 # allow 135 exact "allow: the real effect, line 1 on the console" "^osh_op_out: hello from osh\$" 1 136 exact "allow: line 2 carries \$? = the real status 0 back through the shell core" "^osh_op_out: status=0\$" 1 137 exact "allow: both pipelines COMPLETED with status 0" "${P}allow n=[12] status=0 error=OK outcome=COMPLETED stop=0 crashed=0 request_digest=[0-9a-f]{64}; ${label}\$" 2 138 check "${serial}" "allow: 2 console writes, no task slot held, capability released" "${E}allow rc=0 final_status=0 sink_calls=2 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; ${label}\$" 139 # denials 140 for c in deny_no_cap deny_read_only; do 141 check "${serial}" "${c}: refused DENIED before any effect (status 126, FAILED_NO_EFFECT)" "${P}${c} n=1 status=126 error=DENIED outcome=FAILED_NO_EFFECT stop=0 crashed=0 request_digest=[0-9a-f]{64}; ${label}\$" 142 check "${serial}" "${c}: no console write, capability released" "${E}${c} rc=0 final_status=126 sink_calls=0 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; ${label}\$" 143 check "${serial}" "${c}: a security receipt names the denial, principal and capability" "^osh_op_receipt: seq=1 op=console_write result=DENIED request_digest=[0-9a-f]{64} effect=none principal=[0-9a-f]{64} cap_domain=1 cap_index=[0-9]+ cap_generation=[0-9]+ resource_class=1 operation=1 case=${c}; ${label}\$" 144 done 145 check "${serial}" "revoked: REVOKED at the effect boundary, FAILED_NO_EFFECT" "${P}revoked n=1 status=126 error=REVOKED outcome=FAILED_NO_EFFECT stop=0 crashed=0 " 146 check "${serial}" "revoked: no console write, capability released" "${E}revoked rc=0 final_status=126 sink_calls=0 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; " 147 check "${serial}" "revoked: receipt names REVOKED" "^osh_op_receipt: seq=1 op=console_write result=REVOKED " 148 exact "no refused case wrote any secret marker" "^osh_op_out: .*SECRET" 0 149 # interrupt 150 check "${serial}" "interrupt: pipeline 1 completed" "${P}interrupt n=1 status=0 error=OK outcome=COMPLETED " 151 check "${serial}" "interrupt: pipeline 2 INTERRUPTED, CANCELLED, list stops, status 130" "${P}interrupt n=2 status=130 error=INTERRUPTED outcome=CANCELLED stop=1 crashed=0 " 152 exact "interrupt: pipeline 3 never ran" "${P}interrupt n=3 " 0 153 check "${serial}" "interrupt: one console write, status 130, capability released, no task slot held" "${E}interrupt rc=1 final_status=130 sink_calls=1 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; " 154 exact "interrupt: 'one' printed, 'two' and 'three' not" "^osh_op_out: one\$" 1 155 exact "interrupt: 'two'/'three' absent" "^osh_op_out: (two|three)\$" 0 156 # lost 157 exact "lost: the effect happened exactly once" "^osh_op_out: LOST-MARKER\$" 1 158 check "${serial}" "lost: outcome open (OUTCOME_UNKNOWN, crashed)" "${P}lost n=1 status=70 error=OUTCOME_UNKNOWN outcome=OUTCOME_UNKNOWN stop=1 crashed=1 " 159 check "${serial}" "lost: restart reports the open intent as OUTCOME_UNKNOWN with its digest, replayed=0" "^osh_op_record: seq=1 outcome=OUTCOME_UNKNOWN request_digest=[0-9a-f]{64} replayed=0 case=lost; " 160 check "${serial}" "lost: restart found 1 open intent, a 2nd scan 0, no console write added, restarted adapter holds no capability" "^osh_op_restart: case=lost open_intents=1 second_scan=0 sink_calls_before=1 sink_calls_after=1 held_cap=0; " 161 exact "lost: still exactly one LOST-MARKER after restart (never replayed)" "^osh_op_out: LOST-MARKER\$" 1 162 check "${serial}" "lost: capability released" "${E}lost rc=1 final_status=70 sink_calls=1 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; " 163 exact "after_restart: a new request is a new decision and runs" "^osh_op_out: fresh decision\$" 1 164 # unsupported 165 check "${serial}" "unsupported: a pipe is NOT_SUPPORTED before any effect" "${P}unsupported n=1 status=126 error=NOT_SUPPORTED outcome=NOT_STARTED " 166 check "${serial}" "unsupported: a redirection is NOT_SUPPORTED" "${P}unsupported n=2 status=126 error=NOT_SUPPORTED outcome=NOT_STARTED " 167 check "${serial}" "unsupported: an unknown command is NOT_FOUND (127)" "${P}unsupported n=3 status=127 error=NOT_FOUND outcome=NOT_STARTED " 168 check "${serial}" "unsupported: no console write, no task slot held" "${E}unsupported rc=0 final_status=127 sink_calls=0 launches=[0-9]+ slots_held=0 cap_table_empty=1 cap_released=1; " 169 # totals 170 G="^osh_op_receipt: seq=[0-9]+ op=console_write result=OK request_digest=[0-9a-f]{64} effect=console_write principal=[0-9a-f]{64} cap_domain=1 cap_index=[0-9]+ cap_generation=[0-9]+ resource_class=1 operation=1" 171 exact "grant used: one security receipt per console write, 5 in all" "${G} case=[a-z_]+; ${label}\$" 5 172 exact "grant used: allow wrote 2 lines, 2 receipts" "${G} case=allow; " 2 173 exact "grant used: even the lost-after-effect case has its receipt" "${G} case=lost; " 1 174 exact "grant used: no receipt for a refused case" "^osh_op_receipt: .* result=OK .* case=(deny_no_cap|deny_read_only|revoked|unsupported); " 0 175 exact "the whole boot wrote exactly five console lines through the operation" "^osh_op_out: " 5 176 exact "no case leaked a task slot" "^osh_op_end: .* slots_held=[1-9]" 0 177 exact "every case released its capability" "^osh_op_end: .* cap_released=1; " 8 178 # control: a wrong expectation must turn the check red, then the right one green 179 if has "${serial}" "^osh_op_out: hello from osh DOES-NOT-APPEAR\$"; then fail "control: the gate cannot go red"; else pass "control: a deliberately wrong expected console line is not found (red), the real one is (above)"; fi 180 181 if [[ -n "${AIENOS_LOG_DIR:-}" ]]; then cp "${serial}" "${AIENOS_LOG_DIR}/qemu_ck_osh_op_serial.log"; fi 182 if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then 183 echo "---- serial (osh_op lines) ----"; grep -E "^(osc_|osh_|artifact|kernel|report_kind|panic|fault)" "${serial}" | head -120 || true 184 fi 185 echo "label: QEMU (aarch64 virt), TEST signer, not physical" 186 if [[ "${failed}" == 0 ]]; then echo "${verdict}: PASS"; else echo "${verdict}: FAIL"; exit 1; fi