aura  0.1
 All Data Structures Functions Variables Modules Pages
dummy-serdes-test.c
1 #include <aura/aura.h>
2 
3 
4 void test_u16(struct aura_node *n)
5 {
6  slog(0, SLOG_INFO, __FUNCTION__);
7  int ret;
8  struct aura_buffer *retbuf;
9  ret = aura_call(n, "echo_u16", &retbuf, 0xdead);
10  if (ret)
11  BUG(n, "Call failed");
12  uint16_t out = aura_buffer_get_u16(retbuf);
13  if (out != 0xdead)
14  BUG(n, "Unexpected data from buffer");
15  aura_buffer_release(retbuf);
16 }
17 
18 void test_u32(struct aura_node *n)
19 {
20  slog(0, SLOG_INFO, __FUNCTION__);
21  int ret;
22  struct aura_buffer *retbuf;
23  ret = aura_call(n, "echo_u32", &retbuf, 0xdeadb00b);
24  if (ret)
25  BUG(n, "Call failed");
26  uint32_t out = aura_buffer_get_u32(retbuf);
27  if (out != 0xdeadb00b)
28  BUG(n, "Unexpected data from buffer");
29  aura_buffer_release(retbuf);
30 }
31 
32 void test_seq(struct aura_node *n)
33 {
34  slog(0, SLOG_INFO, __FUNCTION__);
35  int ret;
36  struct aura_buffer *retbuf;
37  ret = aura_call(n, "echo_seq", &retbuf, 0xdeadb00b, 0xdead, 0xde);
38  if (ret)
39  BUG(n, "Call failed");
40  uint32_t out32 = aura_buffer_get_u32(retbuf);
41  uint16_t out16 = aura_buffer_get_u16(retbuf);
42  uint8_t out8 = aura_buffer_get_u8(retbuf);
43  if ((out32 != 0xdeadb00b) || (out16 != 0xdead) || (out8 != 0xde)) {
44  aura_hexdump("out buffer", retbuf->data, retbuf->size);
45  slog(0, SLOG_ERROR, "===> 0x%x 0x%x 0x%x", out32, (uint32_t) out16, (uint32_t) out8);
46  BUG(n, "Unexpected data from buffer");
47  }
48  aura_buffer_release(retbuf);
49 }
50 
51 
52 void test_bin_32_32(struct aura_node *n )
53 {
54  unsigned char src0[32];
55  unsigned char src1[32];
56  const unsigned char *dst;
57  int ret;
58  struct aura_buffer *retbuf;
59 
60  slog(0, SLOG_INFO, __FUNCTION__);
61 
62  memset(src0, 0xa, 32);
63  memset(src1, 0xb, 32);
64 
65  ret = aura_call(n, "echo_bin", &retbuf, src0, src1);
66  if (ret != 0)
67  BUG(n, "Call failed!");
68 
69  dst=aura_buffer_get_bin(retbuf, 32);
70 
71  if (0 != memcmp(src0, dst, 32)) {
72  aura_hexdump("retbuf", retbuf->data, retbuf->size);
73  BUG(n, "src0 mismatch");
74  }
75 
76  dst=aura_buffer_get_bin(retbuf, 32);
77  if (0 != memcmp(src1, dst, 32)) {
78  aura_hexdump("retbuf", retbuf->data, retbuf->size);
79  BUG(n, "src1 mismatch");
80  }
81 
82  aura_buffer_release(retbuf);
83 }
84 
85 
86 int main() {
87  slog_init(NULL, 18);
88  struct aura_node *n = aura_open("dummy", NULL);
89  aura_wait_status(n, AURA_STATUS_ONLINE);
90 
91  test_u16(n);
92  test_u32(n);
93  test_seq(n);
94  test_bin_32_32(n);
95  aura_close(n);
96 
97  return 0;
98 }
99 
100 
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.
uint16_t aura_buffer_get_u16(struct aura_buffer *buf)
Get an unsigned 16 bit integer from aura buffer.
int aura_call(struct aura_node *node, const char *name, struct aura_buffer **retbuf,...)
Definition: aura.c:666
uint8_t aura_buffer_get_u8(struct aura_buffer *buf)
Get an unsigned 8 bit integer from aura buffer.
struct aura_node * aura_open(const char *name, const char *opts)
Definition: aura.c:34
const void * aura_buffer_get_bin(struct aura_buffer *buf, int len)
Get a pointer to the binary data block within buffer and advance internal pointer by len bytes...
Definition: retparse.c:60
int size
Definition: aura.h:337
void aura_buffer_release(struct aura_buffer *buf)
Definition: buffer.c:80
void aura_close(struct aura_node *node)
Definition: aura.c:102
char * data
Definition: aura.h:347