/* SPDX-License-Identifier: LicenseRef-Starship-1.0 * Copyright (c) 2023-2026 Robert A. James */ /* test_heat.c -- heat and anti-clock. A call's target is counted through exec.h's hook * (test_exec.c), not here: the per-call-target table is gone (#189). */ #include "v4/heat.h" #include #include #include 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); } 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); } } int main(void) { printf("v4 heat tests: V4_CELL_BITS=%d\n", V4_CELL_BITS); test_reset(); test_retire_advances_anticlock_and_opcode(); printf(" %d checks, %d failures\n", checks, failures); return failures ? 1 : 0; }