skip to content
==> tests/mailbox.c <==
1/* Words, bytes, windows and the pipe words over a test mailbox. */
2#include "mesh/check.h"
3#include "mesh/mailbox.h"
4
5#include <stdlib.h>
6#include <string.h>
7
8int main(void) {
9    mesh_mailbox m = mesh_mailbox_test();
10    mesh_mailbox_set(m, 0x100, 5);
11    CHECK_U(mesh_mailbox_get(m, 0x100), 5);
12    CHECK_U(mesh_mailbox_fetch_add(m, 0x100, 2), 5);
13    CHECK_U(mesh_mailbox_cas(m, 0x100, 7, 9), 7);
14    CHECK_U(mesh_mailbox_cas(m, 0x100, 7, 11), 9);
15    mesh_mailbox_publish64(m, 0x108, UINT64_C(0x1122334455667788));
16    CHECK_U(mesh_mailbox_get64(m, 0x108), UINT64_C(0x1122334455667788));
17    CHECK_U(mesh_mailbox_fetch_add64(m, 0x108, 1), UINT64_C(0x1122334455667788));
18    CHECK_U(mesh_mailbox_get8(m, 0x108), 0x89);
19    mesh_mailbox_set8(m, 0x10b, 0xab);
20    CHECK_U(mesh_mailbox_get(m, 0x108), 0xab667789);
21    const uint8_t hello[] = "hello";
22    mesh_mailbox_write(m, 0x200, hello, 5, 12);
23    uint8_t out[12];
24    mesh_mailbox_read(m, 0x200, out, 12);
25    CHECK(memcmp(out, "hello\0\0\0\0\0\0\0", 12) == 0);
26    mesh_mailbox_read(m, 0x200, out, 3);
27    CHECK(memcmp(out, "hel", 3) == 0);
28    mesh_mailbox_zero(m, 0x200, 8);
29    CHECK_U(mesh_mailbox_get(m, 0x200), 0);
30    mesh_words w = mesh_mailbox_words(m);
31    CHECK_U(mesh_words_load(&w, 0x100), 9);
32    mesh_words_store(&w, 0x104, 3);
33    CHECK_U(mesh_mailbox_get(m, 0x104), 3);
34    free(m.base);
35    return mesh_check_done();
36}