aura  0.1
 All Data Structures Functions Variables Modules Pages
test-nmc.c
1 #include <aura/aura.h>
2 
3 void test_u32(struct aura_node *n)
4 {
5  int ret;
6  struct aura_buffer *retbuf;
7  ret = aura_call(n, "echo32", &retbuf, 0xbeefc0de);
8  if (ret != 0)
9  BUG(n, "Call failed!");
10 
11  uint32_t v = aura_buffer_get_u32(retbuf);
12  if (v != 0xbeefc0de) {
13  slog(0, SLOG_ERROR, "U32 test NOT ok: %llx vs %llx", v, 0xbeefc0de);
14  }
15  aura_buffer_release(retbuf);
16  slog(0, SLOG_INFO, "U32 echo test passed");
17 }
18 
19 void test_bin(struct aura_node *n)
20 {
21  char buf[64];
22  int ret;
23  FILE *fd = fopen("/dev/urandom", "r+");
24  fread(buf, 64, 1, fd);
25  fclose(fd);
26  struct aura_buffer *retbuf;
27 
28  ret = aura_call(n, "echobin", &retbuf, buf);
29  if (ret != 0)
30  BUG(n, "Call failed!");
31 
32  if (0 != memcmp(buf, retbuf->data, 64))
33  slog(0, SLOG_ERROR, "BIN test NOT ok");
34  aura_hexdump("Out buffer", buf, 64);
35  aura_hexdump("In buffer", retbuf->data, 64);
36  slog(0, SLOG_INFO, "BIN test passed");
37 }
38 
39 void test_u64(struct aura_node *n)
40 {
41  int ret;
42  struct aura_buffer *retbuf;
43  ret = aura_call(n, "echo64", &retbuf, 0xbeefc0deb00bc0de);
44  if (ret != 0)
45  BUG(n, "Call failed!");
46 
47  uint64_t v = aura_buffer_get_u64(retbuf);
48  if (v != 0xbeefc0deb00bc0de)
49  slog(0, SLOG_ERROR, "U64 test NOT ok: %llx vs %llx", v, 0xbeefc0deb00bc0de);
50  aura_buffer_release(retbuf);
51  slog(0, SLOG_INFO, "U64 echo test passed");
52 }
53 
54 void test_buf(struct aura_node *n)
55 {
56  int ret;
57  struct aura_buffer *retbuf;
58  struct aura_buffer *iobuf = aura_buffer_request(n, 80);
59  uint32_t test = 0xdeadf00d;
60  memcpy(iobuf->data, &test, sizeof(test));
61 
62  ret = aura_call(n, "echo_buf", &retbuf, iobuf);
63  slog(0, SLOG_DEBUG, "call ret %d", ret);
64  if (ret)
65  BUG(n, "call failed");
66 
67  struct aura_buffer *tmp = aura_buffer_get_buf(retbuf);
68  if (tmp != iobuf)
69  BUG(n, "test not ok");
70 
71  aura_buffer_release(retbuf);
73  slog(0, SLOG_INFO, "BUF test passed");
74 }
75 
76 void test_u32u32(struct aura_node *n)
77 {
78  int ret;
79  struct aura_buffer *retbuf;
80  ret = aura_call(n, "echou32u32", &retbuf, 0xbeefc0de, 0xdeadc0de);
81  if (ret != 0)
82  BUG(n, "Call failed!");
83 
84  uint32_t v1 = aura_buffer_get_u32(retbuf);
85  uint32_t v2 = aura_buffer_get_u32(retbuf);
86 
87  if ((v1 != 0xbeefc0de) && (v2 != 0xdeadc0de)) {
88  slog(0, SLOG_ERROR, "U32 test NOT ok: %llx,%llx vs %llx,%llx",
89  v1, v2, 0xbeefc0de, 0xdeadc0de);
90  }
91 
92  aura_buffer_release(retbuf);
93  slog(0, SLOG_INFO, "U32U32 echo test passed");
94 }
95 
96 
97 int main() {
98 
99  slog_init(NULL, 18);
100 
101  struct aura_node *n = aura_open("nmc", "./aura-test.abs");
102  if (!n) {
103  slog (0, SLOG_ERROR, "Failed to open node");
104  exit(1);
105  }
106  aura_wait_status(n, AURA_STATUS_ONLINE);
107 
108  test_u32(n);
109  test_u64(n);
110  test_u32u32(n);
111  test_bin(n);
112  test_buf(n);
113 
114  aura_close(n);
115 
116  return 0;
117 }
118 
119 
struct aura_buffer * aura_buffer_request(struct aura_node *nd, int size)
Definition: buffer.c:40
void aura_wait_status(struct aura_node *node, int status)
Definition: aura.c:607
uint32_t aura_buffer_get_u32(struct aura_buffer *buf)
Get an unsigned 32 bit integer from aura buffer.
int aura_call(struct aura_node *node, const char *name, struct aura_buffer **retbuf,...)
Definition: aura.c:666
struct aura_node * aura_open(const char *name, const char *opts)
Definition: aura.c:34
uint64_t aura_buffer_get_u64(struct aura_buffer *buf)
Get an unsigned 64 bit integer from aura buffer.
void aura_buffer_release(struct aura_buffer *buf)
Definition: buffer.c:80
void aura_close(struct aura_node *node)
Definition: aura.c:102
struct aura_buffer * aura_buffer_get_buf(struct aura_buffer *buf)
Retrieve aura_buffer pointer from within the buffer and advance internal pointer by it's size...
Definition: retparse.c:83
char * data
Definition: aura.h:347