1/*
2 * Copyright 2016, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(D61_BSD)
11 */
12
13#include <autoconf.h>
14#ifdef CONFIG_REFOS_RUN_TESTS
15
16#include <sys/types.h>
17#include <sys/stat.h>
18#include <fcntl.h>
19#include "test_anon_ram.h"
20
21
22/* -------------------------------- RAM Dataspace tests -------------------------------------- */
23
24static int
25test_anon_dspace()
26{
27    test_start("anon dataspace");
28
29    /* Open an anonymous dataspace and map it entirely in our VSpace. */
30    data_mapping_t anon = data_open_map(REFOS_PROCSERV_EP, "anon", 0x0, 0, 0x2000, -1);
31    test_assert(anon.err == ESUCCESS);
32    test_assert(anon.size == 0x2000);
33    test_assert(anon.sizeNPages == (0x2000 / REFOS_PAGE_SIZE));
34    test_assert(anon.session == REFOS_PROCSERV_EP);
35    test_assert(anon.dataspace != 0);
36    test_assert(anon.window != 0);
37    test_assert(anon.vaddr != NULL);
38
39    /* Write to and read from anon dataspace. */
40    strcpy(anon.vaddr, "hello world!");
41    int cmp = strcmp(anon.vaddr, "hello world!");
42    tvprintf("anon dataspace contents: [%s]\n", anon.vaddr);
43    test_assert(cmp == 0);
44
45    /* Test resize. */
46    int error = data_expand(REFOS_PROCSERV_EP, anon.dataspace, 0x3000);
47    test_assert(error == ESUCCESS);
48    test_assert(data_get_size(REFOS_PROCSERV_EP, anon.dataspace) == 0x3000);
49
50    /* Clean up. */
51    error = data_mapping_release(anon);
52    test_assert(error == ESUCCESS);
53    return test_success();
54}
55
56void
57test_anon_dataspace(void)
58{
59    test_anon_dspace();
60}
61
62#endif /* CONFIG_REFOS_RUN_TESTS */
63