HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
test_session.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 <mock.h>
7 #include <hipc/session.h>
8 
9 #define S HIPC_SUCCESS
10 #define R 0
11 #define W 1
12 
13 static enum HIPC_errno mockReadMsg(void *arg, hipc_msg msg)
14 {
15  struct MockIO *mio_p = arg;
16  enum HIPC_errno retval;
17 
18  retval = mockIORead(mio_p, msg, HIPC_MSGHDR_SIZE);
19  if (HIPC_SUCCESS != retval) {
20  return retval;
21  }
22  if (0 < hipcMsgBdySize(msg)) {
23  retval = mockIORead(mio_p, &msg[HIPC_MSGHDR_SIZE],
24  hipcMsgBdySize(msg));
25  if (HIPC_SUCCESS != retval) {
26  return retval;
27  }
28  }
29 
30  return HIPC_SUCCESS;
31 }
32 
33 static enum HIPC_errno mockWriteMsg(void *arg, const hipc_msg msg)
34 {
35  struct MockIO *mio_p = arg;
36 
37  return mockIOWrite(mio_p, msg, hipcMsgTotalSize(msg));
38 }
39 
40 static void openDefaultSession(hipc_session * const sess_p,
41  struct MockIO *mio_p)
42 {
43  struct MOCK1S1 mstru;
44  struct MockIOOp ops[] = {
46  0x43,0x49,0x44,0x5f,0x4d,0x4f,0x43,0x4b,0x31}},
47  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,108,0,1}},
48  {R, S, 1, {sizeof(mstru)}},
49  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,0,1,2}},
50  {R, S, 2, {offsetof(struct MOCK1S1,m1),offsetof(struct MOCK1S1,m2)}},
51  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,0,2,2}},
52  {R, S, 2, {sizeof(mstru.m1),sizeof(mstru.m2)}},
53  };
54  mockIOInit(mio_p, ops, sizeof(ops) / sizeof(ops[0]));
55  hipcOpen(sess_p, &HIPCUD_cfgmock1_CCFG, mockReadMsg, mio_p,
56  mockWriteMsg, mio_p);
57  HIPC_ERRCHECK(sess_p);
58  assert(1 == mockIOCheckCompletion(mio_p));
59 
60  return;
61 }
62 
63 static void closeDefaultSession(hipc_session * const sess_p,
64  struct MockIO *mio_p)
65 {
66  struct MockIOOp ops[] = {
67  {W, S, 4, {HIPC_MESSAGE_TYPE_BYE, HIPC_UNSTRU, 0, 0}},
68  {R, S, 4, {HIPC_MESSAGE_TYPE_QUIT, HIPC_UNSTRU, 0, 0}},
69  };
70  mockIOInit(mio_p, ops, sizeof(ops) / sizeof(ops[0]));
71  hipcClose(sess_p);
72  HIPC_ERRCHECK(sess_p);
73  assert(1 == mockIOCheckCompletion(mio_p));
74 
75  return;
76 }
77 
78 static void test_hipcSession(void)
79 {
80  hipc_session sess;
81  struct MockIO mio;
82  char val;
83  struct MOCK1S1 mstru;
84 
85  openDefaultSession(&sess, &mio);
86  {
87  struct MockIOOp ops[] = {
88  {W, S, 4, {HIPC_MESSAGE_TYPE_GET,HIPCUD_MOCK1S1,0,sizeof(mstru.m1)}},
89  {R, S, 4, {HIPC_MESSAGE_TYPE_SUCCESS,HIPCUD_MOCK1S1,0,sizeof(mstru.m1)}},
90  {R, S, 1, {5}},
91  };
92  assert(1 == sizeof(mstru.m1));
93  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
94  hipcGet(&sess, "MOCK1S1.m1", &val);
95  HIPC_ERRCHECK(&sess);
96  assert(5 == val);
97  assert(1 == mockIOCheckCompletion(&mio));
98  }
99  {
100  struct MockIOOp ops[] = {
101  {W, S, 5, {HIPC_MESSAGE_TYPE_PUT,HIPCUD_MOCK1S1,0,sizeof(mstru.m1), 7}},
103  };
104  assert(1 == sizeof(mstru.m1));
105  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
106  val = 7;
107  hipcPut(&sess, "MOCK1S1.m1", &val);
108  HIPC_ERRCHECK(&sess);
109  assert(1 == mockIOCheckCompletion(&mio));
110  }
111  closeDefaultSession(&sess, &mio);
112 
113  openDefaultSession(&sess, &mio); /* OPEN after CLOSE is OK. */
114  closeDefaultSession(&sess, &mio);
115  { /* CLOSE just after CLOSE is OK. */
116  mockIOInit(&mio, NULL, 0);
117  hipcClose(&sess);
118  HIPC_ERRCHECK(&sess);
119  assert(1 == mockIOCheckCompletion(&mio));
120  }
121 
122  assert(HIPC_ERR_INV_BASE_CLIENT ==
123  hipcOpen(&sess, NULL, mockReadMsg, &mio, mockWriteMsg, &mio));
124  assert(HIPC_ERR_SESS_STATE_MISMATCH == hipcGet(&sess, "MOCK1S1.m1", &val)); /* GET for a session that is not establised is NG. */
125  hipcClose(&sess);
126 
127  return;
128 }
129 
130 static enum HIPC_errno handler_MOCK2S1(struct HIPC_client *cl_p,
131  const hipc_msg msg, void *cimg,
132  void *arg)
133 {
134  struct MOCK2S1 *stru_p;
135  int *sum_p;
136 
137  assert(NULL != cimg);
138  assert(NULL != arg);
139  stru_p = cimg;
140  sum_p = arg;
141 
142  (*sum_p) += (stru_p->m1);
143 
144  return HIPC_SUCCESS;
145 }
146 
147 static enum HIPC_errno handler_msg(struct HIPC_client *cl_p,
148  const hipc_msg msg, void *cimg,
149  void *arg)
150 {
151  assert(NULL == cimg);
152  assert(NULL == arg);
153 
154  fprintf(stderr, "msg[4]: %d\n", msg[4]);
155  return msg[4];
156 }
157 
158 static void test_hipcSession_cast(void)
159 {
160  hipc_session sess;
161  struct MockIO mio;
162  char val;
163  struct MOCK2S1 m2s1;
164  struct MOCK2S2 m2s2;
165  int sum;
166 
167  assert(1 == sizeof(m2s1.m1));
168  assert(0 == offsetof(struct MOCK2S1, m1));
169  {
170  struct MockIOOp ops[] = {
172  0x43,0x49,0x44,0x5f,0x4d,0x4f,0x43,0x4b,0x32}},
173  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,108,0,2}},
174  {R, S, 2, {sizeof(struct MOCK2S1), sizeof(struct MOCK2S2)}},
175 
176  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,0,1,1}},
177  {R, S, 1, {offsetof(struct MOCK2S1,m1)}},
178  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,0,2,1}},
179  {R, S, 1, {sizeof(m2s1.m1)}},
180 
181  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,1,1,2}},
182  {R, S, 2, {offsetof(struct MOCK2S2,m1),offsetof(struct MOCK2S2,m2)}},
183  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,1,2,2}},
184  {R, S, 2, {sizeof(m2s2.m1),sizeof(m2s2.m2)}},
185  };
186  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
188  mockWriteMsg, &mio);
189  HIPC_ERRCHECK(&sess);
190  assert(1 == mockIOCheckCompletion(&mio));
191  }
192  {
193  struct MockIOOp ops[] = {
194  {W, S, 4, {HIPC_MESSAGE_TYPE_GET,HIPCUD_MOCK2S2,0,sizeof(m2s2.m1)}},
195  {R, S, 4, {HIPC_MESSAGE_TYPE_CAST,HIPCUD_MOCK2S1,0,sizeof(m2s1)}},
196  {R, S, sizeof(m2s1), {19}},
197  {R, S, 4, {HIPC_MESSAGE_TYPE_SUCCESS,HIPCUD_MOCK2S2,0,sizeof(m2s1.m1)}},
198  {R, S, 1, {5}},
199  };
200  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
201  sum = 0;
202  hipcGet(&sess, "MOCK2S2.m1", &val);
203  HIPC_ERRCHECK(&sess);
204  assert(0 == sum);
205  assert(5 == val);
206  assert(1 == mockIOCheckCompletion(&mio));
207  }
208  hipcSetHandler(&sess, "MOCK2S1", &m2s1, handler_MOCK2S1, &sum);
209  {
210  struct MockIOOp ops[] = {
211  {W, S, 4, {HIPC_MESSAGE_TYPE_GET,HIPCUD_MOCK2S2,0,sizeof(m2s2.m1)}},
212  {R, S, 4, {HIPC_MESSAGE_TYPE_CAST,HIPCUD_MOCK2S1,0,sizeof(m2s1)}},
213  {R, S, sizeof(m2s1), {19}},
214  {R, S, 4, {HIPC_MESSAGE_TYPE_SUCCESS,HIPCUD_MOCK2S2,0,sizeof(m2s1.m1)}},
215  {R, S, 1, {5}},
216  };
217  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
218  sum = 0;
219  hipcGet(&sess, "MOCK2S2.m1", &val);
220  HIPC_ERRCHECK(&sess);
221  assert(19 == sum);
222  assert(5 == val);
223  assert(1 == mockIOCheckCompletion(&mio));
224  }
225  {
226  struct MockIOOp ops[] = {
227  {W, S, 5, {HIPC_MESSAGE_TYPE_PUT,HIPCUD_MOCK2S2,0,sizeof(m2s2.m1), 7}},
228  {R, S, 4, {HIPC_MESSAGE_TYPE_CAST,HIPCUD_MOCK2S1,0,sizeof(m2s1)}},
229  {R, S, sizeof(m2s1), {1}},
230  {R, S, 4, {HIPC_MESSAGE_TYPE_CAST,HIPCUD_MOCK2S1,0,sizeof(m2s1)}},
231  {R, S, sizeof(m2s1), {2}},
232  {R, S, 4, {HIPC_MESSAGE_TYPE_CAST,HIPCUD_MOCK2S1,0,sizeof(m2s1)}},
233  {R, S, sizeof(m2s1), {3}},
235  };
236  assert(1 == sizeof(m2s2.m1));
237  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
238  val = 7;
239  sum = 0;
240  hipcPut(&sess, "MOCK2S2.m1", &val);
241  assert(6 == sum);
242  HIPC_ERRCHECK(&sess);
243  assert(1 == mockIOCheckCompletion(&mio));
244  }
245  hipcSetHandler(&sess, "MOCK2S1", NULL, handler_msg, NULL);
246  {
247  struct MockIOOp ops[] = {
248  {W, S, 4, {HIPC_MESSAGE_TYPE_GET,HIPCUD_MOCK2S2,0,sizeof(m2s2.m1)}},
249  {R, S, 4, {HIPC_MESSAGE_TYPE_CAST,HIPCUD_MOCK2S1,0,sizeof(m2s1)}},
250  {R, S, sizeof(m2s1), {HIPC_SUCCESS}},
251  {R, S, 4, {HIPC_MESSAGE_TYPE_SUCCESS,HIPCUD_MOCK2S2,0,sizeof(m2s1.m1)}},
252  {R, S, 1, {5}},
253  };
254  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
255  hipcGet(&sess, "MOCK2S2.m1", &val);
256  HIPC_ERRCHECK(&sess);
257  assert(5 == val);
258  assert(1 == mockIOCheckCompletion(&mio));
259  }
260  {
261  struct MockIOOp ops[] = {
262  {W, S, 4, {HIPC_MESSAGE_TYPE_BYE, HIPC_UNSTRU, 0, 0}},
263  {R, S, 4, {HIPC_MESSAGE_TYPE_QUIT, HIPC_UNSTRU, 0, 0}},
264  };
265  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
266  hipcClose(&sess);
267  HIPC_ERRCHECK(&sess);
268  assert(1 == mockIOCheckCompletion(&mio));
269  }
270 
271  openDefaultSession(&sess, &mio);
272  hipcSetHandler(&sess, "MOCK1S1", NULL, handler_msg, NULL);
273  { /* When a handler returns error */
274  struct MOCK1S1 m1s1;
275  struct MockIOOp ops[] = {
276  {W, S, 5, {HIPC_MESSAGE_TYPE_PUT,HIPCUD_MOCK1S1,0,sizeof(m1s1.m1), 7}},
277  {R, S, 4, {HIPC_MESSAGE_TYPE_CAST,HIPCUD_MOCK1S1,0,sizeof(m1s1)}},
278  {R, S, sizeof(m1s1), {HIPC_ERR_FOR_TESTING}},
279  };
280  assert(1 == sizeof(m1s1.m1));
281  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
282  val = 7;
283  assert(HIPC_ERR_FOR_TESTING == hipcPut(&sess, "MOCK1S1.m1", &val));
284  assert(1 == mockIOCheckCompletion(&mio));
285  }
286  closeDefaultSession(&sess, &mio);
287 
288  return;
289 }
290 
291 static void test_hipcOpen_err(void)
292 {
293  hipc_session sess;
294  struct MockIO mio;
295  struct MOCK1S1 mstru;
296 
297  assert(HIPC_ERR_INV_BASE_CLIENT ==
298  hipcOpen(&sess, NULL, mockReadMsg, &mio, mockWriteMsg, &mio));
299  hipcClose(&sess);
300 
301  {
302  struct MockIOOp ops[] = {
303  {W, HIPC_ERR_IO_WRITE, 13,
305  0x43, 0x49, 0x44, 0x5f, 0x4d, 0x4f, 0x43, 0x4b, 0x31}},
306  };
307  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
308  assert(HIPC_ERR_IO_WRITE ==
310  mockWriteMsg, &mio));
311  hipcClose(&sess);
312  assert(1 == mockIOCheckCompletion(&mio));
313  }
314 
315  {
316  struct MockIOOp ops[]= {
318  0x43,0x49,0x44,0x5f,0x4d,0x4f,0x43,0x4b,0x31}},
319  {R, HIPC_ERR_IO_READ, 4, {HIPC_MESSAGE_TYPE_SYS,108,0,1}},
320  };
321  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
322  assert(HIPC_ERR_IO_READ ==
324  mockWriteMsg, &mio));
325  hipcClose(&sess);
326  assert(1 == mockIOCheckCompletion(&mio));
327  }
328 
329  {
330  struct MockIOOp ops[] = {
332  0x43,0x49,0x44,0x5f,0x4d,0x4f,0x43,0x4b,0x31}},
334  };
335  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
336  assert(HIPC_ERR_S_BUF_SHTG ==
338  mockWriteMsg, &mio));
339  hipcClose(&sess);
340  assert(1 == mockIOCheckCompletion(&mio));
341  }
342 
343  {
344  struct MockIOOp ops[] = {
346  0x43,0x49,0x44,0x5f,0x4d,0x4f,0x43,0x4b,0x31}},
347  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,108,0,1}},
348  {R, S, 1, {sizeof(mstru)}},
350  };
351  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
354  mockWriteMsg, &mio));
355  hipcClose(&sess);
356  assert(1 == mockIOCheckCompletion(&mio));
357  }
358 
359  {
360  struct MockIOOp ops[] = {
362  0x43,0x49,0x44,0x5f,0x4d,0x4f,0x43,0x4b,0x31}},
363  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,108,0,1}},
364  {R, S, 1, {sizeof(mstru)}},
365  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,0,1,2}},
366  {R, S, 2, {offsetof(struct MOCK1S1,m1),offsetof(struct MOCK1S1,m2)}},
367  {R, S, 4, {HIPC_MESSAGE_TYPE_SYS,0,2,2}},
368  {R, S, 2, {sizeof(mstru.m1),sizeof(mstru.m2)+1}},
369  };
370  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
373  mockWriteMsg, &mio));
374  hipcClose(&sess);
375  assert(1 == mockIOCheckCompletion(&mio));
376  }
377 
378  return;
379 }
380 
381 static void test_hipcClose_err(void)
382 {
383  hipc_session sess;
384  struct MockIO mio;
385 
386  openDefaultSession(&sess, &mio);
387  {
388  struct MockIOOp ops[] = {
390  };
391  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
392  assert(HIPC_ERR_IO_WRITE == hipcClose(&sess));
393  assert(1 == mockIOCheckCompletion(&mio));
394  }
395 
396  openDefaultSession(&sess, &mio);
397  {
398  struct MockIOOp ops[]= {
399  {W, S, 4, {HIPC_MESSAGE_TYPE_BYE,HIPC_UNSTRU,0,0}},
401  };
402  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
403  assert(HIPC_ERR_IO_READ == hipcClose(&sess));
404  assert(1 == mockIOCheckCompletion(&mio));
405  }
406 
407  return;
408 }
409 
410 static void test_hipcGet_err(void)
411 {
412  hipc_session sess;
413  struct MockIO mio;
414  struct MOCK1S1 mstru;
415  char val;
416 
419  hipcGet(&sess, "MOCK1S1.m1", &val));
420 
421  openDefaultSession(&sess, &mio);
422  assert(HIPC_ERR_INV_ID_STR == hipcGet(&sess, "X", &val));
423  closeDefaultSession(&sess, &mio);
424 
425  openDefaultSession(&sess, &mio);
426  {
427  struct MockIOOp ops[] = {
428  {W, HIPC_ERR_IO_WRITE, 4, {HIPC_MESSAGE_TYPE_GET,HIPCUD_MOCK1S1,0,sizeof(mstru.m1)}},
429  };
430  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
431  assert(HIPC_ERR_IO_WRITE == hipcGet(&sess, "MOCK1S1.m1", &val));
432  assert(1 == mockIOCheckCompletion(&mio));
433  }
434  closeDefaultSession(&sess, &mio);
435 
436  openDefaultSession(&sess, &mio);
437  {
438  struct MockIOOp ops[]= {
439  {W, S, 4, {HIPC_MESSAGE_TYPE_GET,HIPCUD_MOCK1S1,0,sizeof(mstru.m1)}},
441  };
442  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
443  assert(HIPC_ERR_IO_READ == hipcGet(&sess, "MOCK1S1.m1", &val));
444  assert(1 == mockIOCheckCompletion(&mio));
445  }
446  closeDefaultSession(&sess, &mio);
447 
448  return;
449 }
450 
451 static void test_hipcPut_err(void)
452 {
453  hipc_session sess;
454  struct MockIO mio;
455  struct MOCK1S1 mstru;
456  char val;
457 
458  val = 7;
461  hipcPut(&sess, "MOCK1S1.m1", &val));
462 
463  openDefaultSession(&sess, &mio);
464  assert(HIPC_ERR_INV_ID_STR == hipcPut(&sess, "X", &val));
465  closeDefaultSession(&sess, &mio);
466 
467  openDefaultSession(&sess, &mio);
468  {
469  struct MockIOOp ops[]= {
470  {W, HIPC_ERR_IO_WRITE, 5, {HIPC_MESSAGE_TYPE_PUT,HIPCUD_MOCK1S1,0,sizeof(mstru.m1), 7}},
471  };
472  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
473  assert(HIPC_ERR_IO_WRITE == hipcPut(&sess, "MOCK1S1.m1", &val));
474  assert(1 == mockIOCheckCompletion(&mio));
475  }
476  closeDefaultSession(&sess, &mio);
477 
478  openDefaultSession(&sess, &mio);
479  {
480  struct MockIOOp ops[]= {
481  {W, S, 5, {HIPC_MESSAGE_TYPE_PUT,HIPCUD_MOCK1S1,0,sizeof(mstru.m1), 7}},
483  };
484  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
485  assert(HIPC_ERR_IO_READ == hipcPut(&sess, "MOCK1S1.m1", &val));
486  assert(1 == mockIOCheckCompletion(&mio));
487  }
488  closeDefaultSession(&sess, &mio);
489 
490  return;
491 }
492 
493 static void test_hipcSetHandler_err(void)
494 {
495  hipc_session sess;
496  struct MockIO mio;
497 
500  hipcSetHandler(&sess, "MOCK1S1.m1", NULL, NULL, NULL));
501 
502  openDefaultSession(&sess, &mio);
503  assert(HIPC_ERR_INV_ID_STR ==
504  hipcSetHandler(&sess, "X", NULL, NULL, NULL));
505  closeDefaultSession(&sess, &mio);
506 
507  return;
508 }
509 
510 static enum HIPC_errno handler_err(struct HIPC_client *cl_p,
511  const hipc_msg msg, void *cimg,
512  void *arg)
513 {
514  return hipcClientSetError(cl_p, HIPC_ERR_FOR_TESTING, "handler_err");
515 }
516 
517 static void test_hipcWaitReturn_err(void)
518 {
519  hipc_session sess;
520  struct MockIO mio;
521  struct MOCK1S1 m1s1;
522  hipc_msg msgR;
523 
525  assert(HIPC_ERR_SESS_STATE_MISMATCH == hipcWaitReturn(&sess, msgR));
526 
527  openDefaultSession(&sess, &mio);
528  {
529  struct MockIOOp ops[] = {
530  {R, S, 4, {HIPC_MESSAGE_TYPE_BYE, HIPC_UNSTRU, 0, 0}},
531  };
532  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
533  assert(HIPC_ERR_PROTOCOL_VIOLATION == hipcWaitReturn(&sess, msgR));
534  assert(1 == mockIOCheckCompletion(&mio));
535  }
536  closeDefaultSession(&sess, &mio);
537 
538  openDefaultSession(&sess, &mio);
539  {
540  struct MockIOOp ops[] = {
541  {R, S, 4, {HIPC_MESSAGE_TYPE_CAST, HIPC_UNSTRU, 0, 0}},
542  };
543  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
544  assert(HIPC_ERR_PROTOCOL_VIOLATION == hipcWaitReturn(&sess, msgR));
545  assert(1 == mockIOCheckCompletion(&mio));
546  }
547  closeDefaultSession(&sess, &mio);
548 
549  openDefaultSession(&sess, &mio);
550  hipcSetHandler(&sess, "MOCK1S1", NULL, handler_err, NULL);
551  {
552  struct MockIOOp ops[]= {
553  {R, S, 4, {HIPC_MESSAGE_TYPE_CAST,HIPCUD_MOCK1S1,0,sizeof(m1s1)}},
554  {R, S, sizeof(m1s1), },
555  };
556  mockIOInit(&mio, ops, sizeof(ops) / sizeof(ops[0]));
557  assert(HIPC_ERR_FOR_TESTING == hipcWaitReturn(&sess, msgR));
558  assert(0 ==
559  strcmp("handler_err", hipcClientGetErrDtlStr(&sess.cl)));
560  assert(1 == mockIOCheckCompletion(&mio));
561  }
562  closeDefaultSession(&sess, &mio);
563 
564  return;
565 }
566 
567 int main(int argc, char *argv[])
568 {
569  if (2 != argc) {
570  fprintf(stderr, "Usage: %s test_id\n", argv[0]);
571  exit(EXIT_FAILURE);
572  }
573 
574  switch (argv[1][0]) {
575  case 'a':
577  break;
578  case 'b':
580  break;
581  case 'c':
583  break;
584  case 'd':
586  break;
587  case 'e':
589  break;
590  case 'f':
592  break;
593  case 'g':
595  break;
596  case 'h':
598  break;
599  default:
600  fprintf(stderr, "Invalid test_id: %s \n", argv[1]);
601  exit(EXIT_FAILURE);
602  }
603 
604  return 0;
605 }
int m2
Definition: cfgmock2.h:6
unsigned char hipc_msg[HIPC_MSG_ALLOCSIZE]
Definition: msg.h:8
static void test_hipcSession_cast(void)
Definition: test_session.c:158
enum HIPC_errno hipcGet(hipc_session *const sess_p, char const *const str, void *const cimg)
Gets data specified by str from a HIPC server.
Definition: session.c:312
size_t hipcMsgTotalSize(const hipc_msg msg)
Returns total size of a HIPC message, which is the header size plus the body size.
Definition: msg.c:9
#define W
Definition: test_session.c:11
static void test_hipcClose_err(void)
Definition: test_session.c:381
char m1
Definition: cfgmock1.h:2
int m2
Definition: cfgmock1.h:3
enum HIPC_errno hipcPut(hipc_session *const sess_p, char const *const str, void *const cimg)
Puts data specified by str from a HIPC server.
Definition: session.c:361
enum HIPC_errno hipcOpen(hipc_session *const sess_p, struct HIPC_client const *const clbase_p, enum HIPC_errno(*rfnc_p)(void *, hipc_msg), void *rarg, enum HIPC_errno(*wfnc_p)(void *, const hipc_msg), void *warg)
Open a session to a HIPC server.
Definition: session.c:217
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
static void closeDefaultSession(hipc_session *const sess_p, struct MockIO *mio_p)
Definition: test_session.c:63
static enum HIPC_errno mockReadMsg(void *arg, hipc_msg msg)
Definition: test_session.c:13
HIPC_errno
Definition: hipc.h:4
static enum HIPC_errno handler_err(struct HIPC_client *cl_p, const hipc_msg msg, void *cimg, void *arg)
Definition: test_session.c:510
int mockIOCheckCompletion(struct MockIO *mio_p)
Definition: mockio.c:19
const struct HIPC_client HIPCUD_cfgmock1_CCFG
Definition: cfgmock1_ccfg.c:50
char m1
Definition: cfgmock2.h:2
#define R
Definition: test_session.c:10
enum HIPC_errno hipcClientSetError(struct HIPC_client *const cl_p, enum HIPC_errno hipc_errno, char const *const str)
Sets an error to a client with error detail.
Definition: client.c:240
unsigned char hipcMsgBdySize(const hipc_msg msg)
Returns body size of a HIPC message.
Definition: msg.c:20
void mockIOInit(struct MockIO *mio_p, const struct MockIOOp *ops, const unsigned int nops)
Definition: mockio.c:8
enum HIPC_session_state state
Definition: session.h:16
enum HIPC_errno hipcWaitReturn(hipc_session *const sess_p, hipc_msg msgR)
Waits a return message from a HIPC server.
Definition: session.c:98
enum HIPC_errno mockIOWrite(struct MockIO *mio_p, const void *buf, const size_t size)
Definition: mockio.c:63
struct HIPC_client cl
Definition: session.h:15
enum HIPC_errno hipcClose(hipc_session *const sess_p)
Closes a session.
Definition: session.c:276
enum HIPC_errno hipcSetHandler(hipc_session *const sess_p, char const *const str, void *const cimg, enum HIPC_errno(*hndlr_p)(struct HIPC_client *, const hipc_msg, void *, void *), void *const arg)
Set a handler to a structure type.
Definition: session.c:174
Definition: mockio.h:19
static void openDefaultSession(hipc_session *const sess_p, struct MockIO *mio_p)
Definition: test_session.c:40
enum HIPC_errno mockIORead(struct MockIO *mio_p, void *buf, const size_t size)
Definition: mockio.c:30
static enum HIPC_errno mockWriteMsg(void *arg, const hipc_msg msg)
Definition: test_session.c:33
static void test_hipcOpen_err(void)
Definition: test_session.c:291
const struct HIPC_client HIPCUD_cfgmock2_CCFG
Definition: cfgmock2_ccfg.c:64
static enum HIPC_errno handler_msg(struct HIPC_client *cl_p, const hipc_msg msg, void *cimg, void *arg)
Definition: test_session.c:147
#define HIPC_ERRCHECK(sess_p)
Checks whether an error has occurred.
Definition: session.h:72
static void test_hipcSession(void)
Definition: test_session.c:78
#define S
Definition: test_session.c:9
static void test_hipcWaitReturn_err(void)
Definition: test_session.c:517
static void test_hipcGet_err(void)
Definition: test_session.c:410
static void test_hipcPut_err(void)
Definition: test_session.c:451
static enum HIPC_errno handler_MOCK2S1(struct HIPC_client *cl_p, const hipc_msg msg, void *cimg, void *arg)
Definition: test_session.c:130
#define HIPC_UNSTRU
Definition: hipc.h:44
char m1
Definition: cfgmock2.h:5
int main(int argc, char *argv[])
Definition: test_session.c:567
static void test_hipcSetHandler_err(void)
Definition: test_session.c:493