1/*
2 * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <assert.h>
8#include <camkes.h>
9#include "my_struct.h"
10#include <stdio.h>
11#include <string.h>
12
13int run() {
14    /* First test calling the `refin` primitive function. */
15    int x = 42;
16    printf("%s: calling p_echo(&x) with x = %d\n", get_instance_name(), x);
17    int result = p_echo(&x);
18    printf("%s: result was %d\n", get_instance_name(), result);
19    assert(result == x);
20
21    /* Now test calling the `refin` complex function. */
22    MyStruct a;
23    for (unsigned int i = 0; i < sizeof(a.data) / sizeof(a.data[0]); i++) {
24        a.data[i] = (int)i;
25    }
26    MyStruct b;
27    memset(&b, 0, sizeof(b));
28    printf("%s: calling c_echo(&a, &b) with a = {%d..%d}\n", get_instance_name(),
29        a.data[0], a.data[sizeof(a.data) / sizeof(a.data[0]) - 1]);
30    c_echo(&a, &b);
31    printf("%s: result was b = {%d..%d}\n", get_instance_name(), b.data[0],
32        b.data[sizeof(b.data) / sizeof(b.data[0]) - 1]);
33    for (unsigned int i = 0; i < sizeof(a.data) / sizeof(a.data[0]); i++) {
34        assert(a.data[i] == b.data[i]);
35    }
36
37    return 0;
38}
39