4 * This is a test application for msg handling that
6 * - serializes two contracts into msgb
7 * - put both msgb to message queue
8 * - revert previous steps
14 #include <semaphore.h>
17 int main(int argc, char** argv)
20 struct fwp_msgb *msgb;
28 printf("in=%d out=%d pending=%d \n",msgq.in,msgq.out,msgq.nr_pending);
30 /* prepare and enqueue the first message buffer */
31 msgb = fwp_msgb_alloc(sizeof(val_w1));
33 printf("Could not allocate msgb for message A\n");
36 printf("Message buffer for message A allocated\n");
38 memcpy(msgb->data, &val_w1, sizeof(val_w1));
39 printf("Enqueue message A. ");
40 if (!fwp_msgq_enqueue(&msgq, msgb))
47 printf("in=%d out=%d pending=%d \n",msgq.in,msgq.out,msgq.nr_pending);
48 /* prepare and enqueue the second message buffer */
49 msgb = fwp_msgb_alloc(sizeof(val_w2));
51 printf("Could not allocate msgb for message B\n");
54 printf("Message buffer for message B allocated\n");
56 memcpy(msgb->data, &val_w2, sizeof(val_w2));
57 printf("Enqueue message B. ");
58 if (!fwp_msgq_enqueue(&msgq, msgb))
65 printf("in=%d out=%d pending=%d \n",msgq.in,msgq.out,msgq.nr_pending);
67 /* dequeue the first message and compare with original contract*/
68 printf("Dequeue message A. ");
69 msgb = fwp_msgq_dequeue(&msgq);
76 printf("in=%d out=%d pending=%d \n",msgq.in,msgq.out,msgq.nr_pending);
78 memcpy(&val_r1, msgb->data, sizeof(val_w1));
81 if (val_w1 != val_r1) {
82 printf("Message A: W/R values do not match.\n");
85 printf("Message A: W/R values matches.\n");
88 /* dequeue the second message and compare with original contract*/
89 printf("Dequeue message B. ");
90 msgb = fwp_msgq_dequeue(&msgq);
97 printf("in=%d out=%d pending=%d \n",msgq.in,msgq.out,msgq.nr_pending);
99 memcpy(&val_r2, msgb->data, sizeof(val_w2));
102 if (val_w2 != val_r2) {
103 printf("Message B: W/R values do not match.\n");
106 printf("Message B: W/R values matches.\n");
108 msgb = fwp_msgq_dequeue(&msgq);
111 printf("Message should be empty but is is not\n");
115 printf("%s PASSED!\n", argv[0]);