The header scan (Captain Bob, 2026-11-10): 788 source files -- 351 with the
SL-1.0 header, 12 with the old name (docs/working/experiments, kept by
ruling), 31 under someone else's licence (tools/kconfig, Linux's, GPL-2.0:
kept), and 394 with none. Ruled: the SPDX form; capsules (.4th, .f18) and
proofs (.thy) left for a ruling of their own (mkcapsule's 64x16 block format,
content-addressed capsules).
253 files now begin
SPDX-License-Identifier: LicenseRef-Starship-1.0
Copyright (c) 2023-2026 Robert A. James
as a /* */ block (C, headers, assembly, linker scripts) or # lines (scripts,
Makefiles, Kconfig; below a shebang or a coding line); tools/mkcapsule.c,
which had the copyright line, gets the SPDX line only.
Not touched: docs/working/ (archive and old campaign material, as the
ruling kept the experiments); v4/system/post_cases.c (generated by
v4/tools/mkpost.py, "do not edit" -- the generator has the header).
Comments only: the kernel builds on amd64, aarch64, riscv64; make -C v4
test-32: 39 programs, 0 failures; every changed script parses.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GE3SDvQn5EoxdGufk84zz2
113 lines
3.6 KiB
C
113 lines
3.6 KiB
C
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
|
|
* Copyright (c) 2023-2026 Robert A. James
|
|
*/
|
|
/* test_heat.c -- heat and anti-clock. */
|
|
#include "v4/heat.h"
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static int failures = 0;
|
|
static int checks = 0;
|
|
|
|
#define CHECK(cond, ...) \
|
|
do { \
|
|
checks++; \
|
|
if (!(cond)) { \
|
|
failures++; \
|
|
printf(" FAIL %s:%d: ", __FILE__, __LINE__); \
|
|
printf(__VA_ARGS__); \
|
|
printf("\n"); \
|
|
} \
|
|
} while (0)
|
|
|
|
static void test_reset(void)
|
|
{
|
|
v4_heat h;
|
|
memset(&h, 0xFF, sizeof h);
|
|
v4_heat_reset(&h);
|
|
|
|
for (unsigned i = 0; i < V4_OPCODE_COUNT; i++) {
|
|
CHECK(h.op[i] == 0, "op %u heat non-zero after reset", i);
|
|
}
|
|
for (unsigned i = 0; i < V4_HEAT_MAX_CALL_TARGETS; i++) {
|
|
CHECK(h.call[i] == 0, "call target %u heat non-zero after reset", i);
|
|
CHECK(!v4_heat_call_is_frozen(&h, (v4_cell)i),
|
|
"call target %u frozen after reset", i);
|
|
}
|
|
v4_uheat_t ac = 999;
|
|
v4_heat_on_retire(&h, V4_OP_NOP, &ac);
|
|
CHECK(ac == 1000, "anticlock not advanced");
|
|
CHECK(h.op[V4_OP_NOP] == 1, "nop heat");
|
|
}
|
|
|
|
static void test_retire_advances_anticlock_and_opcode(void)
|
|
{
|
|
v4_heat h;
|
|
v4_heat_reset(&h);
|
|
v4_uheat_t ac = 0;
|
|
for (int i = 0; i < 100; i++) {
|
|
v4_heat_on_retire(&h, V4_OP_ADD, &ac);
|
|
}
|
|
CHECK(ac == 100, "anticlock");
|
|
CHECK(h.op[V4_OP_ADD] == 100, "add heat");
|
|
for (unsigned i = 0; i < V4_OPCODE_COUNT; i++) {
|
|
if (i == V4_OP_ADD) continue;
|
|
CHECK(h.op[i] == 0, "other op %u", i);
|
|
}
|
|
}
|
|
|
|
static void test_call_advances_target(void)
|
|
{
|
|
v4_heat h;
|
|
v4_heat_reset(&h);
|
|
v4_heat_on_call(&h, 10);
|
|
v4_heat_on_call(&h, 10);
|
|
v4_heat_on_call(&h, 5);
|
|
CHECK(v4_heat_call_get(&h, 10) == 2, "target 10");
|
|
CHECK(v4_heat_call_get(&h, 5) == 1, "target 5");
|
|
CHECK(v4_heat_call_get(&h, 1) == 0, "target 1");
|
|
}
|
|
|
|
static void test_freeze(void)
|
|
{
|
|
v4_heat h;
|
|
v4_heat_reset(&h);
|
|
v4_heat_on_call(&h, 7);
|
|
v4_heat_call_freeze(&h, 7);
|
|
CHECK(v4_heat_call_is_frozen(&h, 7), "frozen");
|
|
v4_heat_on_call(&h, 7);
|
|
CHECK(v4_heat_call_get(&h, 7) == 1, "still 1");
|
|
CHECK(v4_heat_call_set(&h, 7, 100) == 0, "set returns 0 when frozen");
|
|
CHECK(v4_heat_call_get(&h, 7) == 1, "unchanged");
|
|
v4_heat_call_unfreeze(&h, 7);
|
|
CHECK(!v4_heat_call_is_frozen(&h, 7), "unfrozen");
|
|
CHECK(v4_heat_call_set(&h, 7, 42) == 1, "set allowed");
|
|
CHECK(v4_heat_call_get(&h, 7) == 42, "changed");
|
|
}
|
|
|
|
static void test_out_of_range_ignored(void)
|
|
{
|
|
v4_heat h;
|
|
v4_heat_reset(&h);
|
|
v4_heat_on_call(&h, (v4_cell)V4_HEAT_MAX_CALL_TARGETS + 5);
|
|
CHECK(v4_heat_call_get(&h, (v4_cell)V4_HEAT_MAX_CALL_TARGETS + 5) == 0,
|
|
"out of range call ignored");
|
|
CHECK(v4_heat_call_set(&h, (v4_cell)-1, 123) == 0, "set out of range");
|
|
CHECK(v4_heat_call_is_frozen(&h, (v4_cell)-1) == 0, "frozen check");
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
printf("v4 heat tests: V4_CELL_BITS=%d\n", V4_CELL_BITS);
|
|
|
|
test_reset();
|
|
test_retire_advances_anticlock_and_opcode();
|
|
test_call_advances_target();
|
|
test_freeze();
|
|
test_out_of_range_ignored();
|
|
|
|
printf(" %d checks, %d failures\n", checks, failures);
|
|
return failures ? 1 : 0;
|
|
}
|