==> tests/load_prog.c <==1/* load.rs's program_sampler_reads_records_and_trace. */
2#include "mesh/check.h"
3#include "mesh/load_prog.h"
4
5#include <stdlib.h>
6#include <string.h>
7
8static float F(const uint8_t *r, size_t o) { float f; memcpy(&f, r + o, 4); return f; }
9static uint32_t U(const uint8_t *r, size_t o) { uint32_t u; memcpy(&u, r + o, 4); return u; }
10static bool zero_after(const uint8_t *r, size_t from) { for (size_t i = from; i < MESH_PLOAD_BYTES; i++) if (r[i]) return false; return true; }
11
12int main(void) {
13 mesh_mailbox mb = mesh_mailbox_test();
14 uint32_t s = 3;
15 mesh_mailbox_set(mb, mesh_prog_entry(s) + MESH_PT_STATE, MESH_ST_RUNNING);
16 mesh_mailbox_set(mb, mesh_prog_entry(s) + MESH_PT_NODES, 2);
17 mesh_mailbox_set64(mb, mesh_prog_entry(s) + MESH_PT_PTX_HASH, 0xabc);
18 static mesh_prog_sampler p;
19 uint8_t rec[MESH_PLOAD_BYTES];
20 mesh_nl d;
21 uint32_t mg;
22 mesh_prog_sample(&p, mb, s, 1.0, 0, rec, &d, &mg);
23 CHECK_U(rec[MESH_PL_FLAGS], MESH_PLF_LOADED);
24 CHECK(zero_after(rec, 4));
25 size_t r0 = mesh_node_load(s, 0);
26 mesh_mailbox_set64(mb, r0 + MESH_NL_OBS_NS, 1000000000ull);
27 mesh_mailbox_set64(mb, r0 + MESH_NL_LOST_NS, 500000000ull);
28 mesh_mailbox_set(mb, r0 + MESH_NL_GAPS, 400);
29 mesh_mailbox_set(mb, r0 + MESH_NL_MAX_GAP_NS, 2500000);
30 mesh_mailbox_set(mb, r0 + MESH_NL_WIN, 0);
31 mesh_mailbox_set64(mb, mesh_node_rec(s, 1) + MESH_N_BUSY_NS, 20000000);
32 mesh_mailbox_set(mb, mesh_node_rec(s, 1) + MESH_N_TASKS, 10);
33 mesh_mailbox_set(mb, mesh_prog_ctl(s) + MESH_P_DONE, 10);
34 for (uint32_t i = 0; i < 10; i++) {
35 size_t r = mesh_trace_rec(s, i);
36 mesh_mailbox_set(mb, r, s | 1u << 8);
37 mesh_mailbox_set(mb, r + 8, 1000 * i);
38 mesh_mailbox_set(mb, r + 12, 1000 * i + 1000000 + 100000 * i);
39 }
40 size_t r = mesh_trace_rec(s, 10);
41 mesh_mailbox_set(mb, r, s | MESH_OP_INIT << 16);
42 mesh_mailbox_set(mb, r + 12, 50000000);
43 mesh_mailbox_set(mb, mesh_prog_ctl(s) + MESH_P_TRACE_N, 11);
44 mesh_prog_sample(&p, mb, s, 1.0, 0, rec, &d, &mg);
45 CHECK_U(U(rec, MESH_PL_FLAGS), MESH_PLF_LOADED | MESH_PLF_GPU | MESH_PLF_LAT | MESH_PLF_TASK);
46 CHECK(F(rec, MESH_PL_SHARE) == 0.5f && F(rec, MESH_PL_SHARE10) == 0.5f);
47 CHECK(F(rec, MESH_PL_MAX_GAP_US) == 2500.0f && mg == 2500000);
48 CHECK_U(d.gaps, 400);
49 CHECK_U(U(rec, MESH_PL_LAT_N), 10);
50 CHECK(F(rec, MESH_PL_P50_US) == 1500.0f && F(rec, MESH_PL_MAX_US) == 1900.0f);
51 CHECK(F(rec, MESH_PL_TASK_US) == 2000.0f && F(rec, MESH_PL_TASKS_S) == 10.0f);
52 CHECK(F(rec, MESH_PL_BUSY) > 0.00999f && F(rec, MESH_PL_BUSY) < 0.01001f);
53 mesh_prog_sample(&p, mb, s, 1.0, 1, rec, &d, &mg);
54 CHECK(F(rec, MESH_PL_MAX_GAP_US) == 0.0f);
55 CHECK(F(rec, MESH_PL_SHARE) == 0.5f);
56 mesh_mailbox_set(mb, mesh_prog_entry(s) + MESH_PT_LOADS, 2);
57 mesh_prog_sample(&p, mb, s, 1.0, 2, rec, &d, &mg);
58 CHECK(zero_after(rec, 4));
59 mesh_prog_sampler_reset(&p);
60 free(mb.base);
61 return mesh_check_done();
62}