skip to content
==> tests/words_host.c <==
1/* mesh_words_host: loads, stores, CAS and add see each other; byte copies are little-endian words. */
2#include "mesh/words_host.h"
3#include "mesh/check.h"
4
5int main(void) {
6    _Alignas(4) static uint8_t mem[64];
7    mesh_words w = mesh_words_host(mem);
8    mesh_words_store(&w, 8, 0x11223344u);
9    CHECK_U(mesh_words_load(&w, 8), 0x11223344u);
10    CHECK_U(mem[8], 0x44); /* little-endian on this host, as the mailbox is */
11    CHECK_U(mesh_words_cas(&w, 8, 1, 2), 0x11223344u); /* fails: returns what it saw */
12    CHECK_U(mesh_words_cas(&w, 8, 0x11223344u, 7), 0x11223344u);
13    CHECK_U(mesh_words_add(&w, 8, 3), 7);
14    CHECK_U(mesh_words_add(&w, 8, UINT32_MAX), 10); /* -1 */
15    CHECK_U(mesh_words_load(&w, 8), 9);
16    const uint8_t in[6] = {1, 2, 3, 4, 5, 6};
17    uint8_t out[6] = {0};
18    mesh_words_write(&w, 16, in, 6);
19    CHECK_U(mesh_words_load(&w, 16), 0x04030201u);
20    CHECK_U(mesh_words_load(&w, 20), 0x0605u); /* a partial last word: the rest is zero */
21    mesh_words_read(&w, 16, out, 6);
22    CHECK(memcmp(in, out, 6) == 0);
23    mesh_words_fence(&w);
24    return mesh_check_done();
25}