HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
test_client_pack.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 #define IMG_SIZE 256U
11 
12 /* Start of hipc_client static initialization */
14  {HIPC_MBR_SIMPLE, "m0"},
15  {HIPC_MBR_SIMPLE, "m1"},
16  {HIPC_MBR_SIMPLE, "m2"},
17  {HIPC_MBR_SIMPLE, "m3"},
18 };
20  {HIPC_MBR_SIMPLE, "m0"},
21  {HIPC_MBR_SIMPLE, "m1"},
22 };
23 const size_t Mock_indp_member_idxs_ary[] = { 3, 2 };
24 const size_t Mock_indp_member_idxs_as[] = { 2 };
25 
27  = {
28  {HIPC_MBR_SIMPLE, "m0"},
29  {HIPC_MBR_SIMPLE, "m1"},
30  {HIPC_MBR_STRUCT, "stru", 0},
33  {HIPC_MBR_SIMPLE, "m5"},
34 };
35 
37  {4, "s0", Mock_indp_member_s0},
38  {2, "s1", Mock_indp_member_s1},
39  {6, "base", Mock_indp_member_base},
40 };
41 
42 const struct HIPC_cl_indp Mock_indp = {
43  NULL, 0, 7, 3, Mock_indp_struct
44 };
45 
46 unsigned char Mock_smdp_s0_offset[] = { 0,1,2,3 };
47 unsigned char Mock_smdp_s0_size[] = { 1,1,1,1 };
48 unsigned char Mock_cmdp_s0_offset[] = { 0,1,2,3 };
49 unsigned char Mock_cmdp_s0_size[] = { 1,1,1,1 };
50 unsigned char Mock_smdp_s1_offset[] = { 0,2 };
51 unsigned char Mock_smdp_s1_size[] = { 2,1 };
52 unsigned char Mock_cmdp_s1_offset[] = { 0,4 };
53 unsigned char Mock_cmdp_s1_size[] = { 4,1 };
54 unsigned char Mock_smdp_base_offset[] = { 0,1,2, 6, 12,26 };
55 unsigned char Mock_smdp_base_size[] = { 1,1,4,1*6,6*2, 4 };
56 unsigned char Mock_cmdp_base_offset[] = { 0,4,8, 12, 24,44 };
57 unsigned char Mock_cmdp_base_size[] = { 1,4,4,1*6,8*2, 4 };
58 
59 unsigned char Mock_lstructsizes[] = { 4,8,48 };
60 unsigned char Mock_rstructsizes[] = { 4,6,30 };
61 
66 };
71 };
73  { '\0', Mock_lstructsizes, Mock_cmdp_struct };
75  { '\0', Mock_rstructsizes, Mock_smdp_struct };
76 struct HIPC_client mock = { 0, &Mock_indp, &Mock_cmdp, &Mock_smdp };
77 /* End of struct HIPC_client static initialization */
78 
79 struct log {
80  size_t scur_p;
81  size_t ccur_p;
82  size_t n;
83 };
84 
85 struct {
86  unsigned int nl;
87  struct log l[256];
88 } lgr;
89 
90 static void loggerInit()
91 {
92  lgr.nl = 0;
93  return;
94 }
95 
96 static void loggerAdd(void *const scur_p, void *const ccur_p,
97  const size_t n)
98 {
99  fprintf(stderr, "%d: scur_p, ccur_p, n: %lu, %lu, %lu\n", lgr.nl,
100  (size_t) scur_p, (size_t) ccur_p, n);
101  if (256 <= lgr.nl) {
102  fprintf(stderr, "logger is full.");
103  exit(EXIT_FAILURE);
104  }
105  lgr.l[lgr.nl].scur_p = (size_t) scur_p;
106  lgr.l[lgr.nl].ccur_p = (size_t) ccur_p;
107  lgr.l[lgr.nl].n = n;
108  ++(lgr.nl);
109  return;
110 }
111 
112 static int loggerCmp(const struct log l[], const unsigned int nl)
113 {
114  unsigned int i;
115 
116  if (nl != lgr.nl) {
117 #ifdef DEBUG
118  fprintf(stderr, "different numbers of items: %u!=%u\n", nl,
119  lgr.nl);
120 #endif
121  return 1;
122  }
123  for (i = 0; i < nl; ++i) {
124  if (l[i].scur_p != lgr.l[i].scur_p) {
125 #ifdef DEBUG
126  fprintf(stderr, "i:%u, scur_p:%lu!=%lu\n", i, l[i].scur_p,
127  lgr.l[i].scur_p);
128 #endif
129  return 1;
130  }
131  if (l[i].ccur_p != lgr.l[i].ccur_p) {
132 #ifdef DEBUG
133  fprintf(stderr, "i:%u, ccur_p:%lu!=%lu\n", i, l[i].ccur_p,
134  lgr.l[i].ccur_p);
135 #endif
136  return 1;
137  }
138  if (l[i].n != lgr.l[i].n) {
139 #ifdef DEBUG
140  fprintf(stderr, "i:%u, n:%lu!=%lu\n", i, l[i].n, lgr.l[i].n);
141 #endif
142  return 1;
143  }
144  }
145  return 0;
146 }
147 
148 static void test_logger(void)
149 {
150  loggerInit();
151  {
152  assert(0 == loggerCmp(NULL, 0));
153  }
154 
155  loggerInit();
156  loggerAdd((void *) 1U, (void *) 2U, 3);
157  {
158  assert(0 != loggerCmp(NULL, 0));
159  }
160  {
161  struct log l[] = { {0, 0, 0} };
162  assert(0 != loggerCmp(l, sizeof(l) / sizeof(l[0])));
163  }
164  {
165  struct log l[] = { {1, 0, 0} };
166  assert(0 != loggerCmp(l, sizeof(l) / sizeof(l[0])));
167  }
168  {
169  struct log l[] = { {1, 2, 0} };
170  assert(0 != loggerCmp(l, sizeof(l) / sizeof(l[0])));
171  }
172  {
173  struct log l[] = { {1, 2, 3} };
174  assert(0 == loggerCmp(l, sizeof(l) / sizeof(l[0])));
175  }
176 
177  loggerAdd((void *) 4U, (void *) 5U, 6);
178  {
179  struct log l[] = { {1, 2, 3} };
180  assert(0 != loggerCmp(l, sizeof(l) / sizeof(l[0])));
181  }
182  {
183  struct log l[] = { {1, 2, 3}, {4, 5, 6} };
184  assert(0 == loggerCmp(l, sizeof(l) / sizeof(l[0])));
185  }
186  return;
187 }
188 
189 static int routine_hipcClientEachMbr(const size_t offset,
190  const size_t size,
191  const struct log l[],
192  const unsigned int nl)
193 {
194  struct HIPC_client cl;
195  struct HIPC_cl_indp_mbr mbr;
196  unsigned char *scur_p = (void *) 1000;
197  unsigned char *ccur_p = (void *) 2000;
198 
199  mbr.type = HIPC_MBR_STRUCT;
200  mbr.struno = 2;
201 
202  loggerInit();
203  assert(HIPC_SUCCESS == hipcClientInit(&cl, &mock));
204  assert(HIPC_SUCCESS == hipcClientEachMbr(&cl, &mbr,
205  scur_p + offset,
206  scur_p + offset + size,
207  scur_p, ccur_p, 0, 0,
208  loggerAdd));
209  hipcClientTerminate(&cl);
210 
211  return loggerCmp(l, nl);
212 }
213 
214 static void test_hipcClientEachMbr(void)
215 {
216  assert(0 == routine_hipcClientEachMbr(0, 0, NULL, 0));
217  {
218  struct log l[]= {{1000, 2000, 1},
219  };
220  assert(0==routine_hipcClientEachMbr(0,1, l, sizeof(l)/sizeof(l[0])));
221  }
222  {
223  struct log l[]= {{1000, 2000, 1},
224  {1001, 2004, 1},
225  };
226  assert(0==routine_hipcClientEachMbr(0,2, l, sizeof(l)/sizeof(l[0])));
227  }
228  {
229  struct log l[]= {{1000, 2000, 1},
230  {1001, 2004, 1},
231  {1002, 2008, 1},
232  };
233  assert(0==routine_hipcClientEachMbr(0,3, l, sizeof(l)/sizeof(l[0])));
234  }
235  {
236  struct log l[]= {{1012, 2024, 2},
237  {1014, 2028, 1},
238  {1018, 2032, 2},
239  {1020, 2036, 1},
240  };
241  assert(0==routine_hipcClientEachMbr(12,12, l, sizeof(l)/sizeof(l[0])));
242  }
243  {
244  struct log l[]= {{1007, 2013, 1},
245  {1008, 2014, 1},
246  {1009, 2015, 1},
247  {1010, 2016, 1},
248  {1011, 2017, 1},
249 
250  {1012, 2024, 2},
251  {1014, 2028, 1},
252  {1018, 2032, 2},
253  };
254  assert(0==routine_hipcClientEachMbr(7,13, l, sizeof(l)/sizeof(l[0])));
255  }
256  {
257  struct log l[]= {{1000, 2000, 1},
258  {1001, 2004, 1},
259 
260  {1002, 2008, 1},
261  {1003, 2009, 1},
262  {1004, 2010, 1},
263  {1005, 2011, 1},
264 
265  {1006, 2012, 1},
266  {1007, 2013, 1},
267  {1008, 2014, 1},
268  {1009, 2015, 1},
269  {1010, 2016, 1},
270  {1011, 2017, 1},
271 
272  {1012, 2024, 2},
273  {1014, 2028, 1},
274  {1018, 2032, 2},
275  {1020, 2036, 1},
276 
277  {1026, 2044, 4},
278  };
279  assert(0==routine_hipcClientEachMbr(0,30, l, sizeof(l)/sizeof(l[0])));
280  }
281  return;
282 }
283 
284 /* Start of hipc_client static initialization */
285 const size_t Invmock_indp_member_idxs_ary[] = { 3 };
286 
288  = {
289  {0xff, "m0"},
292  {HIPC_MBR_ARRAY, "a2", 0, 1, Invmock_indp_member_idxs_ary, 0xff},
293 };
294 
296  {4, "base", Invmock_indp_member_base},
297 };
298 
299 const struct HIPC_cl_indp Invmock_indp = {
300  NULL, 0, 3, 1, Invmock_indp_struct
301 };
302 
303 unsigned char Invmock_cmdp_base_offset[] = { 0, 1, 4, 8 };
304 unsigned char Invmock_cmdp_base_size[] = { 1,1*3, 2, 3 };
305 unsigned char Invmock_smdp_base_offset[] = { 0, 1, 4, 8 };
306 unsigned char Invmock_smdp_base_size[] = { 1, 2,1*3, 3 };
307 unsigned char Invmock_lstructsizes[] = { 12 };
308 unsigned char Invmock_rstructsizes[] = { 12 };
309 
312 };
315 };
317  { '\0', Invmock_lstructsizes, Invmock_cmdp_struct };
319  { '\0', Invmock_rstructsizes, Invmock_smdp_struct };
321  { 0, &Invmock_indp, &Invmock_cmdp, &Invmock_smdp };
322 /* End of struct HIPC_client static initialization */
323 
324 static void test_hipcClientEachMbr_err(void)
325 {
326  struct HIPC_client cl;
327  struct HIPC_cl_indp_mbr mbr;
328  unsigned char *scur_p = (void *) 1000;
329  unsigned char *ccur_p = (void *) 2000;
330  size_t offset;
331  size_t size;
332 
333  mbr.type = HIPC_MBR_STRUCT;
334  mbr.struno = 0;
335 
336  offset = 0;
337  size = 1;
338  assert(HIPC_SUCCESS == hipcClientInit(&cl, &invmock));
339  assert(HIPC_ERR_INTERNAL_ERROR ==
340  hipcClientEachMbr(&cl, &mbr,
341  scur_p + offset,
342  scur_p + offset + size,
343  scur_p, ccur_p, 0, 0, loggerAdd));
344  hipcClientTerminate(&cl);
345 
346  offset = 1;
347  size = 1;
348  assert(HIPC_SUCCESS == hipcClientInit(&cl, &invmock));
349  assert(HIPC_ERR_INTERNAL_ERROR ==
350  hipcClientEachMbr(&cl, &mbr,
351  scur_p + offset,
352  scur_p + offset + size,
353  scur_p, ccur_p, 0, 0, loggerAdd));
354  hipcClientTerminate(&cl);
355 
356  offset = 4;
357  size = 1;
358  assert(HIPC_SUCCESS == hipcClientInit(&cl, &invmock));
359  assert(HIPC_ERR_INTERNAL_ERROR ==
360  hipcClientEachMbr(&cl, &mbr,
361  scur_p + offset,
362  scur_p + offset + size,
363  scur_p, ccur_p, 0, 0, loggerAdd));
364  hipcClientTerminate(&cl);
365 
366  /* Error in an element of a2 */
367  offset = 8;
368  size = 3;
369  assert(HIPC_SUCCESS == hipcClientInit(&cl, &invmock));
370  assert(HIPC_ERR_INTERNAL_ERROR ==
371  hipcClientEachMbr(&cl, &mbr,
372  scur_p + offset,
373  scur_p + offset + size,
374  scur_p, ccur_p, 0, 0, loggerAdd));
375  hipcClientTerminate(&cl);
376 
377  return;
378 }
379 
380 static void test_hipcClientPack(void)
381 {
382  unsigned char simg[IMG_SIZE];
383  unsigned char cimg[IMG_SIZE];
384  struct HIPC_client cl;
385  unsigned int i;
386 
387  cl = mock;
388  cl.endian_convert = 0;
389 
390  memset(simg, 0x00, IMG_SIZE);
391  memset(cimg, 0xff, IMG_SIZE);
392  assert(HIPC_SUCCESS == hipcClientPack(&cl, 0, 0, 0, simg, cimg));
393  for (i = 0; i < IMG_SIZE; ++i) {
394  assert(0x00 == simg[i]);
395  assert(0xff == cimg[i]);
396  }
397 
398  memset(simg, 0x00, IMG_SIZE);
399  memset(cimg, 0xff, IMG_SIZE);
400  assert(HIPC_SUCCESS == hipcClientPack(&cl, 0, 0, 1, simg, cimg));
401  assert(0xff == simg[0]);
402  assert(0xff == cimg[0]);
403  for (i = 1; i < IMG_SIZE; ++i) {
404  assert(0x00 == simg[i]);
405  assert(0xff == cimg[i]);
406  }
407 
408  memset(simg, 0x00, IMG_SIZE);
409  memset(cimg, 0x00, IMG_SIZE);
410  cimg[4] = 0xff;
411  assert(HIPC_SUCCESS == hipcClientPack(&cl, 1, 2, 1, simg, cimg));
412  for (i = 0; i < IMG_SIZE; ++i) {
413  if (2 == i) {
414  assert(0xff == simg[i]);
415  } else {
416  assert(0x00 == simg[i]);
417  }
418  if (4 == i) {
419  assert(0xff == cimg[i]);
420  } else {
421  assert(0x00 == cimg[i]);
422  }
423  }
424 
425  memset(simg, 0x00, IMG_SIZE);
426  memset(cimg, 0x00, IMG_SIZE);
427  cimg[44] = 0x01;
428  cimg[45] = 0x02;
429  cimg[46] = 0x03;
430  cimg[47] = 0x04;
431  assert(HIPC_SUCCESS == hipcClientPack(&cl, 2, 26, 4, simg, cimg));
432  assert(0x01 == simg[26]);
433  assert(0x02 == simg[27]);
434  assert(0x03 == simg[28]);
435  assert(0x04 == simg[29]);
436  assert(0x01 == cimg[44]);
437  assert(0x02 == cimg[45]);
438  assert(0x03 == cimg[46]);
439  assert(0x04 == cimg[47]);
440  for (i = 0; i < IMG_SIZE; ++i) {
441  if (26 <= i && 30 > i) {
442  assert(0x00 == cimg[i]);
443  } else if (44 <= i && 48 > i) {
444  assert(0x00 == simg[i]);
445  } else {
446  assert(0x00 == simg[i]);
447  assert(0x00 == cimg[i]);
448  }
449  }
450 
451  memset(simg, 0x00, IMG_SIZE);
452  memset(cimg, 0x00, IMG_SIZE);
453  cimg[44] = 0x01;
454  cimg[45] = 0x02;
455  cimg[46] = 0x03;
456  cimg[47] = 0x04;
457  cl.endian_convert = 1;
458  assert(HIPC_SUCCESS == hipcClientPack(&cl, 2, 26, 4, simg, cimg));
459  assert(0x04 == simg[26]);
460  assert(0x03 == simg[27]);
461  assert(0x02 == simg[28]);
462  assert(0x01 == simg[29]);
463  assert(0x01 == cimg[44]);
464  assert(0x02 == cimg[45]);
465  assert(0x03 == cimg[46]);
466  assert(0x04 == cimg[47]);
467  for (i = 0; i < IMG_SIZE; ++i) {
468  if (26 <= i && 30 > i) {
469  assert(0x00 == cimg[i]);
470  } else if (44 <= i && 48 > i) {
471  assert(0x00 == simg[i]);
472  } else {
473  assert(0x00 == simg[i]);
474  assert(0x00 == cimg[i]);
475  }
476  }
477 
478  return;
479 }
480 
482 {
483  unsigned char iary[3][IMG_SIZE];
484  unsigned char simg[IMG_SIZE];
485  unsigned char cimg[IMG_SIZE];
486  unsigned char *simg_pp[3];
487  unsigned char *cimg_pp[3] = { NULL, NULL, NULL };
488  struct HIPC_client cl;
489  unsigned int i;
490  unsigned int j;
491 
492  for (i = 0; i < 3; ++i) {
493  simg_pp[i] = iary[i];
494  }
495  cl = mock;
496  cl.endian_convert = 0;
497  cl.simg_pp = simg_pp;
498  cl.cimg_pp = cimg_pp;
499 
500  for (j = 0; j < 3; ++j) {
501  memset(iary[j], 0x00, IMG_SIZE);
502  }
503  memset(cimg, 0xff, IMG_SIZE);
504  assert(HIPC_SUCCESS == hipcClientPack(&cl, 0, 0, 1, NULL, cimg));
505  assert(0xff == cimg[0]);
506  assert(0xff == iary[0][0]);
507  assert(0x00 == iary[1][0]);
508  assert(0x00 == iary[2][0]);
509  for (i = 1; i < IMG_SIZE; ++i) {
510  for (j = 0; j < 3; ++j) {
511  assert(0x00 == iary[j][i]);
512  }
513  assert(0xff == cimg[i]);
514  }
515 
516  for (j = 0; j < 3; ++j) {
517  memset(iary[j], 0x00, IMG_SIZE);
518  }
519  assert(HIPC_SUCCESS == hipcClientPack(&cl, 0, 0, 1, NULL, NULL));
520  for (i = 0; i < IMG_SIZE; ++i) {
521  for (j = 0; j < 3; ++j) {
522  assert(0x00 == iary[j][i]);
523  }
524  }
525 
526  for (j = 0; j < 3; ++j) {
527  memset(iary[j], 0x00, IMG_SIZE);
528  }
529  memset(cimg, 0xff, IMG_SIZE);
530  hipcClientSetCimg(&cl, 0, &cimg);
531  assert(HIPC_SUCCESS == hipcClientPack(&cl, 0, 0, 1, NULL, NULL));
532  assert(0xff == cimg[0]);
533  assert(0xff == iary[0][0]);
534  assert(0x00 == iary[1][0]);
535  assert(0x00 == iary[2][0]);
536  for (i = 1; i < IMG_SIZE; ++i) {
537  for (j = 0; j < 3; ++j) {
538  assert(0x00 == iary[j][i]);
539  }
540  assert(0xff == cimg[i]);
541  }
542 
543  for (j = 0; j < 3; ++j) {
544  memset(iary[j], 0x00, IMG_SIZE);
545  }
546  memset(simg, 0x00, IMG_SIZE);
547  memset(cimg, 0xff, IMG_SIZE);
548  assert(HIPC_SUCCESS == hipcClientPack(&cl, 0, 0, 1, simg, NULL));
549  assert(0xff == simg[0]);
550  for (i = 1; i < IMG_SIZE; ++i) {
551  assert(0x00 == simg[i]);
552  }
553  for (i = 0; i < IMG_SIZE; ++i) {
554  assert(0xff == cimg[i]);
555  for (j = 0; j < 3; ++j) {
556  assert(0x00 == iary[j][i]);
557  }
558  }
559 
561  hipcClientPack(&cl, 255, 255, 255, NULL, cimg));
562 
563  return;
564 }
565 
566 static void test_hipcClientUnpack(void)
567 {
568  unsigned char simg[IMG_SIZE];
569  unsigned char cimg[IMG_SIZE];
570  struct HIPC_client cl;
571  unsigned int i;
572 
573  cl = mock;
574  cl.endian_convert = 0;
575 
576  memset(simg, 0x00, IMG_SIZE);
577  memset(cimg, 0xff, IMG_SIZE);
578  assert(HIPC_SUCCESS == hipcClientUnpack(&cl, 0, 0, 0, simg, cimg));
579  for (i = 0; i < IMG_SIZE; ++i) {
580  assert(0x00 == simg[i]);
581  assert(0xff == cimg[i]);
582  }
583 
584  memset(simg, 0x00, IMG_SIZE);
585  memset(cimg, 0xff, IMG_SIZE);
586  assert(HIPC_SUCCESS == hipcClientUnpack(&cl, 0, 0, 1, simg, cimg));
587  assert(0x00 == simg[0]);
588  assert(0x00 == cimg[0]);
589  for (i = 1; i < IMG_SIZE; ++i) {
590  assert(0x00 == simg[i]);
591  assert(0xff == cimg[i]);
592  }
593 
594  memset(simg, 0x00, IMG_SIZE);
595  memset(cimg, 0x00, IMG_SIZE);
596  simg[2] = 0xff;
597  assert(HIPC_SUCCESS == hipcClientUnpack(&cl, 1, 2, 1, simg, cimg));
598  for (i = 0; i < IMG_SIZE; ++i) {
599  if (2 == i) {
600  assert(0xff == simg[i]);
601  } else {
602  assert(0x00 == simg[i]);
603  }
604  if (4 == i) {
605  assert(0xff == cimg[i]);
606  } else {
607  assert(0x00 == cimg[i]);
608  }
609  }
610 
611  memset(simg, 0x00, IMG_SIZE);
612  memset(cimg, 0x00, IMG_SIZE);
613  simg[26] = 0x01;
614  simg[27] = 0x02;
615  simg[28] = 0x03;
616  simg[29] = 0x04;
617  assert(HIPC_SUCCESS == hipcClientUnpack(&cl, 2, 26, 4, simg, cimg));
618  assert(0x01 == simg[26]);
619  assert(0x02 == simg[27]);
620  assert(0x03 == simg[28]);
621  assert(0x04 == simg[29]);
622  assert(0x01 == cimg[44]);
623  assert(0x02 == cimg[45]);
624  assert(0x03 == cimg[46]);
625  assert(0x04 == cimg[47]);
626  for (i = 0; i < IMG_SIZE; ++i) {
627  if (26 <= i && 30 > i) {
628  assert(0x00 == cimg[i]);
629  } else if (44 <= i && 48 > i) {
630  assert(0x00 == simg[i]);
631  } else {
632  assert(0x00 == simg[i]);
633  assert(0x00 == cimg[i]);
634  }
635  }
636 
637  memset(simg, 0x00, IMG_SIZE);
638  memset(cimg, 0x00, IMG_SIZE);
639  simg[26] = 0x01;
640  simg[27] = 0x02;
641  simg[28] = 0x03;
642  simg[29] = 0x04;
643  cl.endian_convert = 1;
644  assert(HIPC_SUCCESS == hipcClientUnpack(&cl, 2, 26, 4, simg, cimg));
645  assert(0x01 == simg[26]);
646  assert(0x02 == simg[27]);
647  assert(0x03 == simg[28]);
648  assert(0x04 == simg[29]);
649  assert(0x04 == cimg[44]);
650  assert(0x03 == cimg[45]);
651  assert(0x02 == cimg[46]);
652  assert(0x01 == cimg[47]);
653  for (i = 0; i < IMG_SIZE; ++i) {
654  if (26 <= i && 30 > i) {
655  assert(0x00 == cimg[i]);
656  } else if (44 <= i && 48 > i) {
657  assert(0x00 == simg[i]);
658  } else {
659  assert(0x00 == simg[i]);
660  assert(0x00 == cimg[i]);
661  }
662  }
663 
665  hipcClientUnpack(&cl, 255, 255, 255, simg, cimg));
666 
667  return;
668 }
669 
671 {
672  unsigned char iary[3][IMG_SIZE];
673  unsigned char simg[IMG_SIZE];
674  unsigned char cimg[IMG_SIZE];
675  unsigned char *simg_pp[3];
676  unsigned char *cimg_pp[3] = { NULL, NULL, NULL };
677  struct HIPC_client cl;
678  unsigned int i;
679  unsigned int j;
680 
681  for (i = 0; i < 3; ++i) {
682  simg_pp[i] = iary[i];
683  }
684  cl = mock;
685  cl.endian_convert = 0;
686  cl.simg_pp = simg_pp;
687  cl.cimg_pp = cimg_pp;
688 
689  for (j = 0; j < 3; ++j) {
690  memset(iary[j], 0x00, IMG_SIZE);
691  }
692  memset(cimg, 0xff, IMG_SIZE);
693  assert(HIPC_SUCCESS == hipcClientUnpack(&cl, 0, 0, 1, NULL, cimg));
694  assert(0x00 == cimg[0]);
695  assert(0x00 == iary[0][0]);
696  assert(0x00 == iary[1][0]);
697  assert(0x00 == iary[2][0]);
698  for (i = 1; i < IMG_SIZE; ++i) {
699  for (j = 0; j < 3; ++j) {
700  assert(0x00 == iary[j][i]);
701  }
702  assert(0xff == cimg[i]);
703  }
704 
705  memset(cimg, 0xff, IMG_SIZE);
706  assert(HIPC_SUCCESS == hipcClientUnpack(&cl, 0, 0, 1, NULL, NULL));
707  for (i = 0; i < IMG_SIZE; ++i) {
708  assert(0xff == cimg[i]);
709  }
710 
711  for (j = 0; j < 3; ++j) {
712  memset(iary[j], 0x00, IMG_SIZE);
713  }
714  memset(cimg, 0xff, IMG_SIZE);
715  hipcClientSetCimg(&cl, 0, &cimg);
716  assert(HIPC_SUCCESS == hipcClientUnpack(&cl, 0, 0, 1, NULL, NULL));
717  assert(0x00 == cimg[0]);
718  assert(0x00 == iary[0][0]);
719  assert(0x00 == iary[1][0]);
720  assert(0x00 == iary[2][0]);
721  for (i = 1; i < IMG_SIZE; ++i) {
722  for (j = 0; j < 3; ++j) {
723  assert(0x00 == iary[j][i]);
724  }
725  assert(0xff == cimg[i]);
726  }
727 
728  for (j = 0; j < 3; ++j) {
729  memset(iary[j], 0x00, IMG_SIZE);
730  }
731  memset(simg, 0xff, IMG_SIZE);
732  memset(cimg, 0x00, IMG_SIZE);
733  assert(HIPC_SUCCESS == hipcClientUnpack(&cl, 0, 0, 1, simg, NULL));
734  assert(0xff == cimg[0]);
735  for (i = 1; i < IMG_SIZE; ++i) {
736  assert(0x00 == cimg[i]);
737  }
738  for (i = 0; i < IMG_SIZE; ++i) {
739  assert(0xff == simg[i]);
740  for (j = 0; j < 3; ++j) {
741  assert(0x00 == iary[j][i]);
742  }
743  }
744 
745  return;
746 }
747 
749 {
750  struct HIPC_client cl;
751  const char *str;
752 
753  cl = mock;
755  str = hipcClientGetErrDtlStr(&cl);
756  assert(0 == strcmp("The member size in server is not the same "
757  "as the size in client; member name: m0", str));
758 
759  cl.smdp_p->struct_p[1].size_p[0] = cl.cmdp_p->struct_p[1].size_p[0];
760  cl.smdp_p->struct_p[2].size_p[1] = cl.cmdp_p->struct_p[2].size_p[1];
761  assert(HIPC_SUCCESS == hipcClientCheckMbrSize(&cl));
762 
763  cl.smdp_p->struct_p[2].size_p[2] =
764  2 * cl.cmdp_p->struct_p[2].size_p[2];
765  assert(HIPC_SUCCESS == hipcClientCheckMbrSize(&cl));
766 
767  cl.smdp_p->struct_p[2].size_p[3] =
768  2 * cl.cmdp_p->struct_p[2].size_p[3];
770  str = hipcClientGetErrDtlStr(&cl);
771  assert(0 == strcmp("The member size in server is not the same "
772  "as the size in client; member name: ary", str));
773 
774  return;
775 }
776 
777 int main(int argc, char *argv[])
778 {
779  if (2 != argc) {
780  fprintf(stderr, "Usage: %s test_id\n", argv[0]);
781  exit(EXIT_FAILURE);
782  }
783 
784  switch (argv[1][0]) {
785  case 'a':
786  test_logger();
787  break;
788  case 'b':
790  break;
791  case 'c':
793  break;
794  case 'd':
797  break;
798  case 'e':
801  break;
802  case 'f':
804  break;
805  default:
806  fprintf(stderr, "Invalid test_id: %s \n", argv[1]);
807  exit(EXIT_FAILURE);
808  }
809 
810  return 0;
811 }
const struct HIPC_cl_indp_mbr Mock_indp_member_base[]
unsigned char Mock_smdp_base_offset[]
unsigned char Mock_cmdp_s0_size[]
const size_t Invmock_indp_member_idxs_ary[]
Machine-dependent information of a structure used in a client.
Definition: client.h:55
static void test_hipcClientUnpack(void)
size_t scur_p
Machine-independent information of a member of a structure used in a client.
Definition: client.h:18
const struct HIPC_cl_indp Invmock_indp
unsigned char Mock_cmdp_s0_offset[]
struct HIPC_cl_dp Mock_cmdp
Machine-independent information of a client.
Definition: client.h:44
enum HIPC_errno hipcClientPack(struct HIPC_client *const cl_p, const unsigned char struno, const size_t offset, const size_t size, void *simg, void *cimg)
Packs a range of contents of cimg into simg.
Definition: client.c:962
unsigned char Mock_cmdp_s1_offset[]
static void test_hipcClientCheckMbrSize(void)
static void test_hipcClientUnpack_NULLarg(void)
struct HIPC_cl_dp * cmdp_p
Client Machine DePendent data.
Definition: client.h:77
static void test_hipcClientPack_NULLarg(void)
size_t ccur_p
struct HIPC_cl_dp_stru Invmock_smdp_struct[]
enum HIPC_errno hipcClientEachMbr(struct HIPC_client *const cl_p, struct HIPC_cl_indp_mbr const *const mbr_p, unsigned char *const begin, unsigned char *const end, unsigned char *const scur_p, unsigned char *const ccur_p, const size_t ssize, const size_t csize, void(*fnc_p)(void *const ccur_p, void *const scur_p, const size_t n))
Calls the function specified by fnc_p with each member between begin and end.
Definition: client.c:756
static void test_logger(void)
unsigned char Invmock_rstructsizes[]
const struct HIPC_cl_indp_mbr Mock_indp_member_s0[]
unsigned char Invmock_smdp_base_offset[]
static void test_hipcClientPack(void)
void hipcClientTerminate(struct HIPC_client *const cl_p)
Terminates a HIPC client with releasing the memory space that the client has.
Definition: client.c:438
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
unsigned int nl
int endian_convert
Definition: client.h:75
struct HIPC_cl_dp_stru Mock_smdp_struct[]
unsigned char struno
Definition: client.h:23
enum HIPC_errno hipcClientCheckMbrSize(struct HIPC_client *const cl_p)
Checks whether sizes of members in structures in a server are the same as sizes in a client...
Definition: client.c:458
Machine-independent information of a structure used in a client.
Definition: client.h:35
const struct HIPC_cl_indp_mbr Invmock_indp_member_base[]
static int loggerCmp(const struct log l[], const unsigned int nl)
unsigned char Mock_smdp_base_size[]
static int routine_hipcClientEachMbr(const size_t offset, const size_t size, const struct log l[], const unsigned int nl)
unsigned char Mock_lstructsizes[]
struct HIPC_cl_dp Invmock_cmdp
static void test_hipcClientEachMbr_err(void)
const struct HIPC_cl_indp_mbr Mock_indp_member_s1[]
struct HIPC_client invmock
static void loggerAdd(void *const scur_p, void *const ccur_p, const size_t n)
static void loggerInit()
unsigned char Invmock_smdp_base_size[]
const struct HIPC_cl_indp_stru Invmock_indp_struct[]
const struct HIPC_cl_indp Mock_indp
enum HIPC_member_type type
Definition: client.h:19
unsigned char Mock_smdp_s0_size[]
static void test_hipcClientEachMbr(void)
struct HIPC_cl_dp_stru Invmock_cmdp_struct[]
unsigned char Invmock_lstructsizes[]
struct HIPC_cl_dp Mock_smdp
unsigned char Invmock_cmdp_base_size[]
void hipcClientSetCimg(struct HIPC_client *const cl_p, const unsigned char struno, void *cimg_p)
Sets a client-side image that is a structure instance of a structure.
Definition: client.c:260
unsigned char Mock_smdp_s1_offset[]
enum HIPC_errno hipcClientInit(struct HIPC_client *const cl_p, struct HIPC_client const *const clbase_p)
Initializes a HIPC client with allocating memory space if necessary.
Definition: client.c:339
size_t n
struct HIPC_client mock
unsigned char ** simg_pp
Server-side images of structures.
Definition: client.h:79
unsigned char Mock_smdp_s1_size[]
const size_t Mock_indp_member_idxs_ary[]
unsigned char Mock_rstructsizes[]
struct @6 lgr
struct HIPC_cl_dp_stru Mock_cmdp_struct[]
unsigned char Mock_cmdp_s1_size[]
Machine-dependent information of a client.
Definition: client.h:63
unsigned char Mock_smdp_s0_offset[]
struct HIPC_cl_dp_stru * struct_p
Definition: client.h:66
struct HIPC_cl_dp * smdp_p
Server Machine DePendent data.
Definition: client.h:78
unsigned char Mock_cmdp_base_size[]
enum HIPC_errno hipcClientUnpack(struct HIPC_client *const cl_p, const unsigned char struno, const size_t offset, const size_t size, void *simg, void *cimg)
Unpacks a range of contents of simg into cimg.
Definition: client.c:908
int main(int argc, char *argv[])
struct log l[256]
#define IMG_SIZE
unsigned char Mock_cmdp_base_offset[]
unsigned char * size_p
Definition: client.h:57
unsigned char ** cimg_pp
Client-side images of structures.
Definition: client.h:80
const struct HIPC_cl_indp_stru Mock_indp_struct[]
unsigned char Invmock_cmdp_base_offset[]
const size_t Mock_indp_member_idxs_as[]
struct HIPC_cl_dp Invmock_smdp