==> tests/tick.c <==1/* tick on the simulator: init lays the pattern, ticks overwrite word t mod W,
2 * verify finds no mismatch; a corrupted word is found; a relaunch (as after a
3 * migration, no OP_INIT) carries on from the view. */
4#include "mesh/check.h"
5#include "mesh/rt/sim_mailbox.h"
6
7#include "../src/tick.c"
8
9int main(void) {
10 uint8_t *mb = mesh_sim_mailbox();
11 mesh_sim_prog p = {.name = "tick", .view_bytes = 0x10000};
12 uint8_t *view = mesh_sim_install(mb, 2, &p);
13 mesh_sim_launch *l = mesh_sim_launch_prog(mb, 2, &p, mesh_main);
14 CHECK_U(mesh_sim_call(mb, 2, MESH_OP_INIT, 0), MESH_R_NONE);
15 CHECK_U(mesh_sim_u32(view), TICK_MAGIC);
16 CHECK_U(mesh_sim_u32(view + TICK_INITS), 1);
17 uint32_t w = (0x10000 - TICK_REGION) / 4;
18 for (uint32_t i = 0; i < w; i++)
19 if (mesh_sim_u32(view + TICK_REGION + 4 * i) != tick_pattern(i)) { CHECK(0); break; }
20 for (uint32_t i = 0; i < 100; i++) mesh_sim_call(mb, 2, MESH_OP_TASK, 0);
21 CHECK_U(mesh_sim_u32(view + TICK_TICKS), 100);
22 CHECK_U(mesh_sim_call(mb, 2, TICK_OP_VERIFY, 0), 0);
23 CHECK_U(mesh_sim_u32(view + TICK_REGION + 4 * 99), tick_pattern(99) ^ 100);
24 /* A migration: halt, relaunch without OP_INIT: the ticks continue. */
25 mesh_sim_halt(mb, 2, l);
26 l = mesh_sim_launch_prog(mb, 2, &p, mesh_main);
27 for (uint32_t i = 0; i < 28; i++) mesh_sim_call(mb, 2, MESH_OP_TASK, 0);
28 CHECK_U(mesh_sim_u32(view + TICK_TICKS), 128);
29 CHECK_U(mesh_sim_u32(view + TICK_INITS), 1);
30 CHECK_U(mesh_sim_call(mb, 2, TICK_OP_VERIFY, 0), 0);
31 /* A word that is not this view's own (one of the last 64 ticks'). */
32 /* Word 126 is one of the last 64 ticks' and not sampled: found once. */
33 mesh_sim_set_u32(view + TICK_REGION + 4 * 126, 0);
34 CHECK_U(mesh_sim_call(mb, 2, TICK_OP_VERIFY, 0), 1);
35 CHECK_U(mesh_sim_u32(view + TICK_MISMATCH), 1);
36 /* Word 127 is both (sample 32 lands on it): found twice. */
37 mesh_sim_set_u32(view + TICK_REGION + 4 * 127, 0);
38 CHECK_U(mesh_sim_call(mb, 2, TICK_OP_VERIFY, 0), 3);
39 CHECK_U(mesh_sim_call(mb, 2, 7, 0), MESH_R_BAD_OP);
40 CHECK_U(tick_expect(5, 3, 10), tick_pattern(5));
41 CHECK_U(tick_expect(5, 6, 10), tick_pattern(5) ^ 6);
42 CHECK_U(tick_expect(5, 16, 10), tick_pattern(5) ^ 16);
43 mesh_sim_halt(mb, 2, l);
44 mesh_sim_mailbox_free(mb);
45 return mesh_check_done();
46}