HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
test_client_strope.c
Go to the documentation of this file.
1 #include <assert.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 
6 #include <stdint.h>
7 
8 #include <hipc/client.h>
9 
10 static void test_strcspn(void)
11 {
12  assert(0 == strcspn("", ""));
13  assert(0 == strcspn("", "a"));
14  assert(1 == strcspn("a", ""));
15  assert(0 == strcspn("", "abc"));
16  assert(3 == strcspn("abc", ""));
17  assert(0 == strcspn("a", "abc"));
18  assert(0 == strcspn("abc", "a"));
19  assert(1 == strcspn("abc", "b"));
20  assert(2 == strcspn("abc", "c"));
21  assert(3 == strcspn("abc", "x"));
22 
23  assert(8 == strcspn("test_ctl.enable", "."));
24 
25  return;
26 }
27 
28 static void test_arysize(void)
29 {
30  struct {
31  int32_t i;
32  int8_t a;
33  } sary[3][5]; /* ary of structs */
34 
35  uint8_t bary[7][9]; /* ary of bytes */
36 
37  assert(sizeof(sary[0]) == 5 * sizeof(sary[0][0]));
38  assert(sizeof(sary) == 3 * 5 * sizeof(sary[0][0]));
39 
40  assert(sizeof(bary[0]) == 9 * sizeof(bary[0][0]));
41  assert(sizeof(bary) == 7 * 9 * sizeof(bary[0][0]));
42 
43  return;
44 }
45 
46 /* Start of hipc_client static initialization */
47 const struct HIPC_cl_indp_mbr b_test_ctl[] = {
48  {HIPC_MBR_SIMPLE, "enable"},
49  {HIPC_MBR_SIMPLE, "diff"},
50 };
51 
52 const size_t b_ary0_elm_max_idxs[] = { 2, 3, 4 }; /* ary0[4][3][2] */
53 const size_t b_ary1_elm_max_idxs[] = { 5 };
54 const struct HIPC_cl_indp_mbr b_test_sa[] = {
57  0},
58  {HIPC_MBR_STRUCT, "ctl", 0},
59 };
60 
62  {HIPC_MBR_SIMPLE, "dummy"},
63  {HIPC_MBR_SIMPLE, "target"},
64  {HIPC_MBR_SIMPLE, "enable"},
65 };
66 
67 const size_t b_inv_elm_max_idxs[] = { 2 };
68 const struct HIPC_cl_indp_mbr b_inv[] = {
69  {HIPC_MBR_ARRAY, "dim", 0, 0, NULL, HIPC_MBR_SIMPLE},
70  {HIPC_MBR_ARRAY, "snode", 0, 1, b_inv_elm_max_idxs, 128},
71  {HIPC_MBR_SIMPLE, "offset"},
72 };
73 
74 const struct HIPC_cl_indp_stru b_indp_s[] = {
75  {2, "test_ctl", b_test_ctl},
76  {3, "sa", b_test_sa},
77  {3, "pid_ctrl", HIPCUD_pidctrl_indp_member_pid_ctrl},
78  {3, "inv", b_inv},
79 };
80 const struct HIPC_cl_indp b_indp = { NULL, 0, 5, 4, b_indp_s };
81 
82 unsigned char b_test_ctl_offset[] = { 0, 4 };
83 unsigned char b_test_ctl_size[] = { 1, 4 };
84 unsigned char b_test_sa_offset[] = { 0, 24, 64 };
85 unsigned char b_test_sa_size[] = { 24, 40, 8 };
87  0, 6, 7,
88 };
90  6, 1, 1,
91 };
92 unsigned char b_inv_offset[] = { 0, 4, 8 };
93 unsigned char b_inv_size[] = { 4, 4, 255 };
94 
101 };
102 
104  0, 8, 9,
105 };
106 
108  8, 1, 1,
109 };
110 
117 };
118 
119 unsigned char b_cmdp_strctsizes[] = { 8, 72, 8, 12 };
120 unsigned char b_smdp_strctsizes[] = { 8, 72, 12, 12 };
122  { 0x6c /* 'l' */ , b_cmdp_strctsizes, b_cmdp_s };
124  { 0x6c /* 'l' */ , b_smdp_strctsizes, b_smdp_s };
125 
126 
127 struct HIPC_client b_ri = {
128  0,
129  &b_indp,
130  &b_cmdp,
131  &b_smdp,
132 };
133 
134 /* End of struct HIPC_client static initialization */
135 
136 static void test_hipcClientGetStrutpl(void)
137 {
138  unsigned char strctnum;
139  size_t offset;
140  size_t size;
141 
143  hipcClientGetStrutpl(&b_ri, "inv.offset",
144  &strctnum, &offset, &size));
145 
146  assert(HIPC_ERR_INTERNAL_ERROR ==
147  hipcClientGetStrutpl(&b_ri, "inv.dim[0]",
148  &strctnum, &offset, &size));
149  assert(0 ==
150  strcmp("Number of dimensions is zero: mbr_p->ary_dim is zero",
151  b_ri.err_detail_str));
152 
153  assert(HIPC_ERR_INTERNAL_ERROR == /* elm_type of snode has wrong value. */
154  hipcClientGetStrutpl(&b_ri, "inv.snode[0][0]",
155  &strctnum, &offset, &size));
156  assert(0 == strcmp("Invalid member type: invalid value in mbr_p->type",
157  b_ri.err_detail_str));
158 
159  assert(HIPC_SUCCESS ==
160  hipcClientGetStrutpl(&b_ri, "test_ctl",
161  &strctnum, &offset, &size));
162  assert(0 == strctnum);
163 
164  assert(HIPC_SUCCESS ==
165  hipcClientGetStrutpl(&b_ri, "test_ctl.enable",
166  &strctnum, &offset, &size));
167  assert(0 == strctnum);
168  assert(0 == offset);
169  assert(1 == size);
170 
171  assert(HIPC_ERR_INV_ID_STR ==
172  hipcClientGetStrutpl(&b_ri, "test_foo.ary[3].foo",
173  &strctnum, &offset, &size));
174  assert(0 == strcmp("Unknown structure name: test_foo",
175  b_ri.err_detail_str));
176 
177 
178  assert(HIPC_SUCCESS ==
179  hipcClientGetStrutpl(&b_ri, "sa", &strctnum, &offset, &size));
180  assert(1 == strctnum);
181  assert(0 == offset);
182  assert(72 == size);
183 
184  assert(HIPC_SUCCESS ==
185  hipcClientGetStrutpl(&b_ri, "sa.ary0",
186  &strctnum, &offset, &size));
187  assert(1 == strctnum);
188  assert(0 == offset);
189  assert(24 == size);
190 
191  assert(HIPC_ERR_INV_ID_STR ==
192  hipcClientGetStrutpl(&b_ri, "sa.ary0[x]",
193  &strctnum, &offset, &size));
194  assert(0 == strcmp("Failed to extract index from: [x]",
195  b_ri.err_detail_str));
196 
197  assert(HIPC_ERR_INV_ID_STR ==
198  hipcClientGetStrutpl(&b_ri,
199  "sa.ary0[18446744073709551616]",
200  &strctnum, &offset, &size));
201  assert(0 ==
202  strcmp("Failed to extract index from: [18446744073709551616]",
203  b_ri.err_detail_str));
204 
205  assert(HIPC_SUCCESS ==
206  hipcClientGetStrutpl(&b_ri, "sa.ary0[0]",
207  &strctnum, &offset, &size));
208  assert(1 == strctnum);
209  assert(0 == offset);
210  assert(6 == size);
211  assert(HIPC_SUCCESS ==
212  hipcClientGetStrutpl(&b_ri, "sa.ary0[1]",
213  &strctnum, &offset, &size));
214  assert(1 == strctnum);
215  assert(6 == offset);
216  assert(6 == size);
217  assert(HIPC_SUCCESS ==
218  hipcClientGetStrutpl(&b_ri, "sa.ary0[3]",
219  &strctnum, &offset, &size));
220  assert(1 == strctnum);
221  assert(18 == offset);
222  assert(6 == size);
223 
224  assert(HIPC_ERR_INV_ID_STR ==
225  hipcClientGetStrutpl(&b_ri, "sa.ary0[4]",
226  &strctnum, &offset, &size));
227  assert(0 ==
228  strcmp("The index is out of range: [4]", b_ri.err_detail_str));
229 
230  assert(HIPC_ERR_INV_ID_STR ==
231  hipcClientGetStrutpl(&b_ri, "sa.ary0.1]",
232  &strctnum, &offset, &size));
233  assert(0 ==
234  strcmp("No left bracket following the array name: .1]",
235  b_ri.err_detail_str));
236 
237  assert(HIPC_ERR_INV_ID_STR ==
238  hipcClientGetStrutpl(&b_ri, "sa.ary0[1[2]",
239  &strctnum, &offset, &size));
240  assert(0 ==
241  strcmp("No right bracket following the index number: [1[2]",
242  b_ri.err_detail_str));
243 
244  assert(HIPC_SUCCESS ==
245  hipcClientGetStrutpl(&b_ri, "sa.ary0[1][2]",
246  &strctnum, &offset, &size));
247  assert(1 == strctnum);
248  assert(10 == offset);
249  assert(2 == size);
250 
251  assert(HIPC_SUCCESS ==
252  hipcClientGetStrutpl(&b_ri, "sa.ary0[1][2][0]",
253  &strctnum, &offset, &size));
254  assert(1 == strctnum);
255  assert(10 == offset);
256  assert(1 == size);
257 
258  assert(HIPC_ERR_INV_ID_STR ==
259  hipcClientGetStrutpl(&b_ri, "sa.ary0[1][2][0][0]",
260  &strctnum, &offset, &size));
261  assert(0 == strcmp("Inappropriate string: [0]", b_ri.err_detail_str));
262  assert(HIPC_ERR_INV_ID_STR ==
263  hipcClientGetStrutpl(&b_ri, "sa.ary0[1][2][0]foo",
264  &strctnum, &offset, &size));
265  assert(0 == strcmp("Inappropriate string: foo", b_ri.err_detail_str));
266 
267  assert(HIPC_SUCCESS ==
268  hipcClientGetStrutpl(&b_ri, "sa.ary1",
269  &strctnum, &offset, &size));
270  assert(1 == strctnum);
271  assert(24 == offset);
272  assert(40 == size);
273 
274  assert(HIPC_SUCCESS == hipcClientGetStrutpl(&b_ri, "sa.ary1[2]",
275  &strctnum, &offset,
276  &size));
277  assert(1 == strctnum);
278  assert(40 == offset);
279  assert(8 == size);
280 
281  assert(HIPC_SUCCESS ==
282  hipcClientGetStrutpl(&b_ri, "sa.ary1[2].diff", &strctnum,
283  &offset, &size));
284  assert(1 == strctnum);
285  assert(44 == offset);
286  assert(4 == size);
287 
288  assert(HIPC_ERR_INV_ID_STR ==
289  hipcClientGetStrutpl(&b_ri, "sa.ary1[2]diff",
290  &strctnum, &offset, &size));
291  assert(0 ==
292  strcmp("No period before the member name: diff",
293  b_ri.err_detail_str));
294 
295  assert(HIPC_ERR_INV_ID_STR ==
296  hipcClientGetStrutpl(&b_ri, "sa.ary1[3].foo",
297  &strctnum, &offset, &size));
298  assert(0 == strcmp("Unknown member name: foo", b_ri.err_detail_str));
299 
300  assert(HIPC_SUCCESS ==
301  hipcClientGetStrutpl(&b_ri, "pid_ctrl.target", &strctnum,
302  &offset, &size));
303  assert(2 == strctnum);
304  assert(8 == offset);
305  assert(1 == size);
306 
307  return;
308 }
309 
311 {
312  char buf[HIPC_IMG_ALLOCSIZE + 4];
313  unsigned int i;
314  const char *str;
315  size_t offset;
316  size_t size;
317  unsigned char strctnum;
318 
319  for (i = 0; i < HIPC_IMG_ALLOCSIZE; ++i) {
320  buf[i] = 'a';
321  }
322  buf[HIPC_IMG_ALLOCSIZE] = '.';
323  buf[HIPC_IMG_ALLOCSIZE + 1] = '\0';
324  assert(HIPC_ERR_INV_ID_STR ==
325  hipcClientGetStrutpl(&b_ri, buf, &strctnum, &offset, &size));
326  str = hipcClientGetErrDtlStr(&b_ri);
327  assert(0 == memcmp("Unknown structure name: ", str, 24));
328  for (i = 24; i < HIPC_IMG_ALLOCSIZE - 1; ++i) {
329  assert('a' == str[i]);
330  }
331  assert('\0' == str[HIPC_IMG_ALLOCSIZE - 1]);
332 
333  buf[0] = 's';
334  buf[1] = 'a';
335  buf[2] = '.';
336  for (i = 3; i < HIPC_IMG_ALLOCSIZE + 3; ++i) {
337  buf[i] = 'a';
338  }
339  buf[HIPC_IMG_ALLOCSIZE + 3] = '\0';
340  assert(HIPC_ERR_INV_ID_STR ==
341  hipcClientGetStrutpl(&b_ri, buf, &strctnum, &offset, &size));
342  str = hipcClientGetErrDtlStr(&b_ri);
343  assert(0 == memcmp("Unknown member name: ", str, 21));
344  for (i = 21; i < HIPC_IMG_ALLOCSIZE - 1; ++i) {
345  assert('a' == str[i]);
346  }
347  assert('\0' == str[HIPC_IMG_ALLOCSIZE - 1]);
348 
349  return;
350 }
351 
352 int main(int argc, char *argv[])
353 {
354  if (2 != argc) {
355  fprintf(stderr, "Usage: %s test_id\n", argv[0]);
356  exit(EXIT_FAILURE);
357  }
358 
359  switch (argv[1][0]) {
360  case 'a':
361  test_strcspn();
362  test_arysize();
363  break;
364  case 'b':
366  break;
367  case 'c':
369  break;
370  default:
371  fprintf(stderr, "Invalid test_id: %s \n", argv[1]);
372  exit(EXIT_FAILURE);
373  }
374 
375  return 0;
376 }
unsigned char b_smdp_strctsizes[]
struct HIPC_cl_dp_stru b_cmdp_s[]
Machine-dependent information of a structure used in a client.
Definition: client.h:55
int main(int argc, char *argv[])
Machine-independent information of a member of a structure used in a client.
Definition: client.h:18
Machine-independent information of a client.
Definition: client.h:44
const struct HIPC_cl_indp_mbr HIPCUD_pidctrl_indp_member_pid_ctrl[]
#define HIPC_IMG_ALLOCSIZE
Definition: hipc.h:46
unsigned char HIPCUD_pidctrl_smdp_pid_ctrl_offset[]
unsigned char HIPCUD_pidctrl_cmdp_pid_ctrl_size[]
char err_detail_str[HIPC_IMG_ALLOCSIZE]
Definition: client.h:86
const size_t b_ary1_elm_max_idxs[]
const char * hipcClientGetErrDtlStr(const struct HIPC_client *const cl_p)
Gets a string describing details of an error that has been set to a HIPC client.
Definition: client.c:171
struct HIPC_cl_dp_stru b_smdp_s[]
Machine-independent information of a structure used in a client.
Definition: client.h:35
unsigned char b_test_sa_offset[]
unsigned char HIPCUD_pidctrl_smdp_pid_ctrl_size[]
unsigned char b_inv_size[]
static void test_arysize(void)
const size_t b_inv_elm_max_idxs[]
static void test_hipcClientGetStrutpl_tooLargeName(void)
struct HIPC_client b_ri
const struct HIPC_cl_indp_mbr b_test_sa[]
unsigned char b_cmdp_strctsizes[]
const struct HIPC_cl_indp_mbr b_inv[]
const struct HIPC_cl_indp_mbr b_test_ctl[]
enum HIPC_errno hipcClientGetStrutpl(struct HIPC_client *const cl_p, char const *const str, unsigned char *struno_p, size_t *offset_p, size_t *size_p)
Gets structure number, offset, and size from ID string.
Definition: client.c:698
const struct HIPC_cl_indp_stru b_indp_s[]
unsigned char HIPCUD_pidctrl_cmdp_pid_ctrl_offset[]
const struct HIPC_cl_indp b_indp
unsigned char b_test_ctl_size[]
struct HIPC_cl_dp b_cmdp
Machine-dependent information of a client.
Definition: client.h:63
unsigned char b_test_sa_size[]
const size_t b_ary0_elm_max_idxs[]
static void test_hipcClientGetStrutpl(void)
struct HIPC_cl_dp b_smdp
unsigned char b_test_ctl_offset[]
static void test_strcspn(void)
unsigned char b_inv_offset[]