Make machine configuration authoritative and restore native checkpoints exactly

This commit is contained in:
2026-09-18 09:09:41 +08:00
parent 6a69511276
commit 4a568f1f4c
94 changed files with 10882 additions and 301 deletions

View File

@@ -2,6 +2,8 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static float get_float(const char *name) {
sim_hal_value value = {0};
@@ -32,6 +34,19 @@ int sim_hal_test_run(void) {
assert(sim_hal_register_function("missing", "bad") == SIM_HAL_ERR_NOT_FOUND);
assert(sim_hal_step(5) == SIM_HAL_OK);
assert(sim_hal_tick() == 5 && sim_hal_function_calls("update") == 2);
const uint32_t saved_size = sim_hal_checkpoint_size();
uint8_t *saved = malloc(saved_size), *restored = malloc(saved_size);
assert(saved && restored);
assert(sim_hal_checkpoint_export(saved, saved_size) == SIM_HAL_OK);
assert(sim_hal_step(3) == SIM_HAL_OK);
assert(sim_hal_tick() == 8 && sim_hal_function_calls("update") == 4);
assert(sim_hal_checkpoint_restore(saved, saved_size - 1) == SIM_HAL_ERR_ARGUMENT);
assert(sim_hal_tick() == 8);
assert(sim_hal_checkpoint_restore(saved, saved_size) == SIM_HAL_OK);
assert(sim_hal_tick() == 5 && sim_hal_function_calls("update") == 2);
assert(sim_hal_checkpoint_export(restored, saved_size) == SIM_HAL_OK);
assert(memcmp(saved, restored, saved_size) == 0);
free(saved); free(restored);
assert(sim_hal_set_function_failure("update", 1) == SIM_HAL_OK);
assert(sim_hal_step(1) == SIM_HAL_ERR_FUNCTION);
assert(sim_hal_tick() == 5);