skip to content
==> tests/load_share.c <==
1/* load.rs's gpu_share_maths. */
2#include "mesh/check.h"
3#include "mesh/load_share.h"
4
5#include <math.h>
6
7int main(void) {
8    mesh_nl d = {2000000000ull, 1044000000ull, 458, 0};
9    mesh_share s = mesh_share_of(&d);
10    CHECK(s.has_share && fabsf(s.share - 0.478f) < 1e-3f);
11    CHECK(fabsf(s.gap_us - 2279.5f) < 1.0f);
12    CHECK(fabsf(s.slice_us - 2087.3f) < 1.0f);
13    mesh_nl zero = {0, 0, 0, 0};
14    CHECK(!mesh_share_of(&zero).has_share);
15    mesh_nl lone = {1000000000ull, 0, 0, 0};
16    s = mesh_share_of(&lone);
17    CHECK(s.share == 1.0f && s.slice_us == 0 && s.gap_us == 0);
18    mesh_nl a = {100, 40, 2, 7}, b = {300, 90, 5, 10};
19    mesh_nl x = mesh_nl_delta(&b, &a);
20    CHECK(x.obs == 200 && x.lost == 50 && x.gaps == 3 && x.queue_us == 3);
21    x = mesh_nl_delta(&a, &b);
22    CHECK(x.obs == 0 && x.lost == 0 && x.gaps == 0 && x.queue_us == 0);
23    mesh_nl sum = {0, 0, 0, 0}, big = {10, 50, 1, 0};
24    mesh_nl_add(&sum, &big);
25    CHECK_U(sum.lost, 10);
26    mesh_nl m = {4360000, 1420000, 10, 900};
27    s = mesh_share_of(&m);
28    CHECK(fabsf(s.share - 0.6743f) < 1e-3f);
29    CHECK(s.queue_us == 90.0f);
30    const uint32_t q[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
31    CHECK_U(mesh_quantile(q, 10, 0.5), 6);
32    CHECK_U(mesh_quantile(q, 10, 0.99), 10);
33    CHECK_U(mesh_quantile(q, 0, 0.5), 0);
34    return mesh_check_done();
35}