/* SPDX-License-Identifier: LicenseRef-Starship-1.0 * Copyright (c) 2023-2026 Robert A. James */ /* test_heartbeat_export.c -- v3/src/heartbeat_export.c on the host (#142): the DoE row's per-tick * deltas -- cache_hits_delta and bucket_hits_delta from the VM's hot-words cache, beside * word_executions_delta -- are measured, not written as 0. A VM is built in memory with a cache * whose hit counters the test sets, and heartbeat_capture_tick_snapshot is run tick by tick. */ #include "harness.h" #include "vm.h" #include "physics_hotwords_cache.h" #include #include int main(void) { VM *vm = (VM *)calloc(1, sizeof *vm); HotwordsCache *cache = (HotwordsCache *)calloc(1, sizeof *cache); HeartbeatTickSnapshot s; vm->hotwords_cache = cache; cache->stats.cache_hits = 5; cache->stats.bucket_hits = 3; vm->heartbeat.words_executed = 40; memset(&s, 0, sizeof s); heartbeat_capture_tick_snapshot(vm, &s); CHECK(s.cache_hits_delta == 5 && s.bucket_hits_delta == 3 && s.word_executions_delta == 40, "#142: the first tick: 5 cache hits, 3 bucket hits, 40 words (%u, %u, %u)", s.cache_hits_delta, s.bucket_hits_delta, s.word_executions_delta); cache->stats.cache_hits = 12; cache->stats.bucket_hits = 10; vm->heartbeat.words_executed = 100; memset(&s, 0, sizeof s); heartbeat_capture_tick_snapshot(vm, &s); CHECK(s.cache_hits_delta == 7 && s.bucket_hits_delta == 7 && s.word_executions_delta == 60, "#142: the next tick: the deltas, 7, 7 and 60 (%u, %u, %u)", s.cache_hits_delta, s.bucket_hits_delta, s.word_executions_delta); cache->stats.cache_hits = 2; cache->stats.bucket_hits = 1; /* the cache's stats were reset */ memset(&s, 0, sizeof s); heartbeat_capture_tick_snapshot(vm, &s); CHECK(s.cache_hits_delta == 2 && s.bucket_hits_delta == 1, "#142: after the stats are reset, the count since then, as words_executed is (%u, %u)", s.cache_hits_delta, s.bucket_hits_delta); vm->hotwords_cache = 0; memset(&s, 0xFF, sizeof s); heartbeat_capture_tick_snapshot(vm, &s); CHECK(s.cache_hits_delta == 0 && s.bucket_hits_delta == 0, "#142: a VM with no cache: 0 hits, not garbage"); free(cache); free(vm); return DONE(); }