34 lines
1.7 KiB
C
34 lines
1.7 KiB
C
#include "sim_scheduler.h"
|
|
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int main(void) {
|
|
sim_scheduler fast = {0};
|
|
sim_scheduler stepped = {0};
|
|
sim_scheduler restored = {0};
|
|
uint32_t phases[SIM_SCHEDULER_PHASE_COUNT] = {0, 1, 2, 3, 4, 5, 6, 7};
|
|
char canonical[SIM_SCHEDULER_CANONICAL_CAPACITY] = {0};
|
|
uint64_t fast_hash;
|
|
|
|
assert(sim_scheduler_init(&fast, 100) == SIM_SCHEDULER_OK);
|
|
assert(sim_scheduler_init(&stepped, 100) == SIM_SCHEDULER_OK);
|
|
assert(sim_scheduler_step(&fast, 10) == SIM_SCHEDULER_OK);
|
|
for (int index = 0; index < 10; ++index) assert(sim_scheduler_step(&stepped, 1) == SIM_SCHEDULER_OK);
|
|
assert(sim_scheduler_tick(&fast) == 10 && sim_scheduler_tick(&stepped) == 10);
|
|
fast_hash = sim_scheduler_state_hash(&fast);
|
|
assert(fast_hash == sim_scheduler_state_hash(&stepped));
|
|
assert(sim_scheduler_step(&fast, 101) == SIM_SCHEDULER_ERR_BUDGET);
|
|
assert(sim_scheduler_tick(&fast) == 10);
|
|
assert(sim_scheduler_restore(&restored, fast.tick, fast.budget, fast.last_cycles, phases, SIM_SCHEDULER_PHASE_COUNT) == SIM_SCHEDULER_OK);
|
|
assert(sim_scheduler_state_hash(&restored) == fast_hash);
|
|
assert(sim_scheduler_canonical(&fast, canonical, sizeof(canonical)) > 1);
|
|
assert(strstr(canonical, "reconcile") != NULL && strstr(canonical, "publish") != NULL);
|
|
assert(sim_scheduler_init(&restored, 0) == SIM_SCHEDULER_ERR_RANGE);
|
|
assert(sim_scheduler_restore(&restored, 0, 100, 0, phases, 2) == SIM_SCHEDULER_ERR_ARGUMENT);
|
|
printf("{\"schema\":\"sim-scheduler-samples.v1\",\"tick\":%u,\"budget\":%u,\"state_hash\":%llu,\"canonical\":%s}\n",
|
|
fast.tick, fast.budget, (unsigned long long)fast_hash, canonical);
|
|
return 0;
|
|
}
|