there was an #include directive missing
[openmpi-llc.git] / test / dss / dss_buffer.c
blob412aab039836d0ab7158831a0c10ebe4a5e2fa23
1 /*
2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * $COPYRIGHT$
14 * Additional copyrights may follow
16 * $HEADER$
19 #include "orte_config.h"
20 #include "orte/orte_constants.h"
21 #include "orte/orte_types.h"
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #ifdef HAVE_SYS_PARAM_H
28 #include <sys/param.h>
29 #endif
30 #ifdef HAVE_NETINET_IN_H
31 #include <netinet/in.h>
32 #endif
34 #include "opal/runtime/opal.h"
35 #include "orte/util/proc_info.h"
36 #include "orte/mca/errmgr/errmgr.h"
38 #include "orte/dss/dss.h"
40 #define NUM_ITERS 100
41 #define NUM_ELEMS 1024
43 static bool test1(void); /* verify different buffer inits */
44 static bool test2(void); /* verify int16 */
45 static bool test3(void); /* verify int */
46 static bool test4(void); /* verify int32 */
47 static bool test5(void); /* verify int64 */
48 static bool test6(void); /* verify string */
49 static bool test7(void); /* verify BOOL */
50 static bool test8(void); /* verify OBJECT */
51 static bool test9(void); /* verify composite (multiple types and element counts) */
52 static bool test10(void); /* verify KEYVAL */
53 static bool test11(void); /* verify size_t */
54 static bool test12(void); /* verify pid_t */
56 FILE *test_out;
59 int main (int argc, char* argv[])
61 int ret;
63 opal_init();
65 /* register handler for errnum -> string converstion */
66 opal_error_register("ORTE", ORTE_ERR_BASE, ORTE_ERR_MAX, orte_err2str);
68 test_out = stderr;
70 /* Ensure the process info structure is instantiated and initialized */
71 if (ORTE_SUCCESS != (ret = orte_proc_info())) {
72 return ret;
75 orte_process_info.seed = true;
76 orte_process_info.my_name = (orte_process_name_t*)malloc(sizeof(orte_process_name_t));
77 orte_process_info.my_name->cellid = 0;
78 orte_process_info.my_name->jobid = 0;
79 orte_process_info.my_name->vpid = 0;
82 /* open the dss */
83 if (ORTE_SUCCESS == orte_dss_open()) {
84 fprintf(test_out, "DSS started\n");
85 } else {
86 fprintf(test_out, "DSS could not start\n");
87 exit (1);
90 /* run the tests */
92 fprintf(test_out, "executing test1\n");
93 if (test1()) {
94 fprintf(test_out, "Test1 succeeded\n");
96 else {
97 fprintf(test_out, "Test1 failed\n");
100 fprintf(test_out, "executing test2\n");
101 if (test2()) {
102 fprintf(test_out, "Test2 succeeded\n");
104 else {
105 fprintf(test_out, "Test2 failed\n");
108 fprintf(test_out, "executing test3\n");
109 if (test3()) {
110 fprintf(test_out, "Test3 succeeded\n");
112 else {
113 fprintf(test_out, "Test3 failed\n");
116 fprintf(test_out, "executing test4\n");
117 if (test4()) {
118 fprintf(test_out, "Test4 succeeded\n");
120 else {
121 fprintf(test_out, "Test4 failed\n");
124 fprintf(test_out, "executing test5\n");
125 if (test5()) {
126 fprintf(test_out, "Test5 succeeded\n");
128 else {
129 fprintf(test_out, "Test5 failed\n");
132 fprintf(test_out, "executing test6\n");
133 if (test6()) {
134 fprintf(test_out, "Test6 succeeded\n");
136 else {
137 fprintf(test_out, "Test6 failed\n");
140 fprintf(test_out, "executing test7\n");
141 if (test7()) {
142 fprintf(test_out, "Test7 succeeded\n");
144 else {
145 fprintf(test_out, "Test7 failed\n");
148 fprintf(test_out, "executing test8\n");
149 if (test8()) {
150 fprintf(test_out, "Test8 succeeded\n");
152 else {
153 fprintf(test_out, "Test8 failed\n");
156 fprintf(test_out, "executing test9\n");
157 if (test9()) {
158 fprintf(test_out, "Test9 succeeded\n");
160 else {
161 fprintf(test_out, "orte_dss test9 failed\n");
164 fprintf(test_out, "executing test10\n");
165 if (test10()) {
166 fprintf(test_out, "Test10 succeeded\n");
168 else {
169 fprintf(test_out, "orte_dss test10 failed\n");
172 fprintf(test_out, "executing test11\n");
173 if (test11()) {
174 fprintf(test_out, "Test11 succeeded\n");
176 else {
177 fprintf(test_out, "orte_dss test11 failed\n");
180 fprintf(test_out, "executing test12\n");
181 if (test12()) {
182 fprintf(test_out, "Test12 succeeded\n");
184 else {
185 fprintf(test_out, "orte_dss test12 failed\n");
188 fclose(test_out);
190 orte_dss_close();
192 opal_finalize();
194 return(0);
197 static bool test1(void) /* verify different buffer inits */
199 orte_buffer_t *bufA;
201 bufA = OBJ_NEW(orte_buffer_t);
202 if (NULL == bufA) {
203 fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
204 return false;
207 OBJ_RELEASE(bufA);
208 if (NULL != bufA) {
209 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
210 return false;
212 return (true);
216 * OMPI_INT16 pack/unpack
218 static bool test2(void)
220 orte_buffer_t *bufA;
221 int rc;
222 int32_t i;
223 int16_t src[NUM_ELEMS];
224 int16_t dst[NUM_ELEMS];
226 for(i=0; i<NUM_ELEMS; i++)
227 src[i] = i;
229 bufA = OBJ_NEW(orte_buffer_t);
230 if (NULL == bufA) {
231 fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
232 return false;
235 for (i=0;i<NUM_ITERS;i++) {
236 rc = orte_dss.pack(bufA, src, NUM_ELEMS, ORTE_INT16);
237 if (ORTE_SUCCESS != rc) {
238 fprintf(test_out, "orte_dss.pack failed with return code %d\n", rc);
239 return(false);
243 for (i=0; i<NUM_ITERS; i++) {
244 int j;
245 size_t count;
247 for(j=0; j<NUM_ELEMS; j++)
248 dst[j] = -1;
250 count = NUM_ELEMS;
251 rc = orte_dss.unpack(bufA, dst, &count, ORTE_INT16);
252 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
253 fprintf(test_out, "orte_dss.unpack failed with return code %d\n", rc);
254 return(false);
257 for(j=0; j<NUM_ELEMS; j++) {
258 if(src[j] != dst[j]) {
259 fprintf(test_out, "test2: invalid results from unpack\n");
260 return(false);
265 OBJ_RELEASE(bufA);
266 if (NULL != bufA) {
267 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
268 return false;
271 return (true);
275 * OMPI_INT pack/unpack
277 static bool test3(void)
279 orte_buffer_t *bufA;
280 int rc;
281 int32_t i;
282 int src[NUM_ELEMS];
283 int dst[NUM_ELEMS];
285 for(i=0; i<NUM_ELEMS; i++)
286 src[i] = i;
288 bufA = OBJ_NEW(orte_buffer_t);
289 if (NULL == bufA) {
290 fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
291 return false;
294 for (i=0;i<NUM_ITERS;i++) {
295 rc = orte_dss.pack(bufA, src, NUM_ELEMS, ORTE_INT);
296 if (ORTE_SUCCESS != rc) {
297 fprintf(test_out, "orte_dss.pack failed with return code %d\n", rc);
298 return(false);
302 for (i=0; i<NUM_ITERS; i++) {
303 int j;
304 size_t count;
306 for(j=0; j<NUM_ELEMS; j++)
307 dst[j] = -1;
309 count = NUM_ELEMS;
310 rc = orte_dss.unpack(bufA, dst, &count, ORTE_INT);
311 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
312 fprintf(test_out, "orte_dss.unpack failed with return code %d\n", rc);
313 return(false);
316 for(j=0; j<NUM_ELEMS; j++) {
317 if(src[j] != dst[j]) {
318 fprintf(test_out, "test2: invalid results from unpack\n");
319 return(false);
324 OBJ_RELEASE(bufA);
325 if (NULL != bufA) {
326 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
327 return false;
330 return (true);
334 * OMPI_INT32 pack/unpack
336 static bool test4(void)
338 orte_buffer_t *bufA;
339 int rc;
340 int32_t i;
341 int32_t src[NUM_ELEMS];
342 int32_t dst[NUM_ELEMS];
344 for(i=0; i<NUM_ELEMS; i++)
345 src[i] = i;
347 bufA = OBJ_NEW(orte_buffer_t);
348 if (NULL == bufA) {
349 fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
350 return false;
353 for (i=0;i<NUM_ITERS;i++) {
354 rc = orte_dss.pack(bufA, src, NUM_ELEMS, ORTE_INT32);
355 if (ORTE_SUCCESS != rc) {
356 fprintf(test_out, "orte_dss.pack failed with return code %d\n", rc);
357 return(false);
361 for (i=0; i<NUM_ITERS; i++) {
362 int j;
363 size_t count = NUM_ELEMS;
365 for(j=0; j<NUM_ELEMS; j++)
366 dst[j] = -1;
368 rc = orte_dss.unpack(bufA, dst, &count, ORTE_INT32);
369 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
370 fprintf(test_out, "orte_dss.unpack failed with return code %d\n", rc);
371 return(false);
374 for(j=0; j<NUM_ELEMS; j++) {
375 if(src[j] != dst[j]) {
376 fprintf(test_out, "test2: invalid results from unpack\n");
377 return(false);
382 OBJ_RELEASE(bufA);
383 if (NULL != bufA) {
384 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
385 return false;
388 return (true);
392 * ORTE_INT64 pack/unpack
394 static bool test5(void)
396 orte_buffer_t *bufA;
397 int rc;
398 size_t i;
399 int64_t src[NUM_ELEMS];
400 int64_t dst[NUM_ELEMS];
402 for(i=0; i<NUM_ELEMS; i++)
403 src[i] = 1000*i;
405 bufA = OBJ_NEW(orte_buffer_t);
406 if (NULL == bufA) {
407 fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
408 return false;
411 for (i=0;i<NUM_ITERS;i++) {
412 rc = orte_dss.pack(bufA, src, NUM_ELEMS, ORTE_INT64);
413 if (ORTE_SUCCESS != rc) {
414 fprintf(test_out, "orte_dss.pack int64 failed with return code %d\n", rc);
415 return(false);
419 for (i=0; i<NUM_ITERS; i++) {
420 int j;
421 size_t count = NUM_ELEMS;
423 for(j=0; j<NUM_ELEMS; j++)
424 dst[j] = -1;
426 rc = orte_dss.unpack(bufA, dst, &count, ORTE_INT64);
427 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
428 fprintf(test_out, "orte_dss.unpack int64 failed with return code %d\n", rc);
429 return(false);
432 for(j=0; j<NUM_ELEMS; j++) {
433 if(src[j] != dst[j]) {
434 fprintf(test_out, "test2: invalid results from unpack int64\n");
435 return(false);
440 OBJ_RELEASE(bufA);
441 if (NULL != bufA) {
442 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
443 return false;
446 return (true);
450 * OMPI_STRING pack/unpack
453 static bool test6(void)
455 orte_buffer_t *bufA;
456 int rc;
457 int32_t i;
458 char* src[NUM_ELEMS];
459 char* dst[NUM_ELEMS];
461 for(i=0; i<NUM_ELEMS; i++) {
462 asprintf(&src[i], "%d", i);
465 bufA = OBJ_NEW(orte_buffer_t);
466 if (NULL == bufA) {
467 fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
468 return false;
471 for (i=0;i<NUM_ITERS;i++) {
472 rc = orte_dss.pack(bufA, src, NUM_ELEMS, ORTE_STRING);
473 if (ORTE_SUCCESS != rc) {
474 fprintf(test_out, "orte_dss.pack failed with return code %d\n", rc);
475 return(false);
479 for (i=0; i<NUM_ITERS; i++) {
480 int j;
481 size_t count = NUM_ELEMS;
483 for(j=0; j<NUM_ELEMS; j++)
484 dst[j] = NULL;
486 rc = orte_dss.unpack(bufA, dst, &count, ORTE_STRING);
487 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
488 fprintf(test_out, "orte_dss.unpack failed with return code %d\n", rc);
489 return(false);
492 for(j=0; j<NUM_ELEMS; j++) {
493 if(strcmp(src[j],dst[j]) != 0) {
494 fprintf(test_out, "test4: invalid results from unpack\n");
495 fprintf(test_out, "item %d src=[%s] len=%d dst=[%s] len=%d\n", j, src[j], (int)strlen(src[j]), dst[j], (int)strlen(dst[j]));
496 return(false);
501 OBJ_RELEASE(bufA);
502 if (NULL != bufA) {
503 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
504 return false;
507 return (true);
512 * OMPI_BOOL pack/unpack
515 static bool test7(void)
517 orte_buffer_t *bufA;
518 int rc;
519 int32_t i;
520 bool src[NUM_ELEMS];
521 bool dst[NUM_ELEMS];
523 for(i=0; i<NUM_ELEMS; i++)
524 src[i] = ((i % 2) == 0) ? true : false;
526 bufA = OBJ_NEW(orte_buffer_t);
527 if (NULL == bufA) {
528 fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
529 return false;
532 for (i=0;i<NUM_ITERS;i++) {
533 rc = orte_dss.pack(bufA, src, NUM_ELEMS, ORTE_BOOL);
534 if (ORTE_SUCCESS != rc) {
535 fprintf(test_out, "orte_dss.pack failed with return code %d\n", rc);
536 return(false);
540 for (i=0; i<NUM_ITERS; i++) {
541 int j;
542 size_t count = NUM_ELEMS;
543 memset(dst,-1,sizeof(dst));
545 rc = orte_dss.unpack(bufA, dst, &count, ORTE_BOOL);
546 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
547 fprintf(test_out, "orte_dss.unpack failed with return code %d\n", rc);
548 return(false);
551 for(j=0; j<NUM_ELEMS; j++) {
552 if(src[j] != dst[j]) {
553 fprintf(test_out, "test6: invalid results from unpack\n");
554 return(false);
559 OBJ_RELEASE(bufA);
560 if (NULL != bufA) {
561 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
562 return false;
565 return (true);
569 * OMPI_BYTE_OBJECT pack/unpack
572 static bool test8(void)
575 orte_buffer_t *bufA;
576 int rc;
577 int32_t i;
578 orte_byte_object_t *src[NUM_ELEMS];
579 orte_byte_object_t *dst[NUM_ELEMS];
581 for(i=0; i<NUM_ELEMS; i++) {
582 src[i] = (orte_byte_object_t*)malloc(sizeof(orte_byte_object_t));
583 asprintf((char**)&(src[i]->bytes), "%d", i);
584 src[i]->size = strlen((char*)(src[i]->bytes)) + 1;
587 bufA = OBJ_NEW(orte_buffer_t);
588 if (NULL == bufA) {
589 fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
590 return false;
593 for (i=0;i<NUM_ITERS;i++) {
594 rc = orte_dss.pack(bufA, src, NUM_ELEMS, ORTE_BYTE_OBJECT);
595 if (ORTE_SUCCESS != rc) {
596 fprintf(test_out, "orte_dss.pack failed with return code %d\n", rc);
597 return(false);
601 for (i=0; i<NUM_ITERS; i++) {
602 int j;
603 size_t count = NUM_ELEMS;
605 rc = orte_dss.unpack(bufA, dst, &count, ORTE_BYTE_OBJECT);
606 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
607 fprintf(test_out, "orte_dss.unpack failed with return code %d\n", rc);
608 return(false);
611 for(j=0; j<NUM_ELEMS; j++) {
612 if(src[j]->size != dst[j]->size ||
613 memcmp(src[j]->bytes,dst[j]->bytes,src[j]->size) != 0) {
614 fprintf(test_out, "test7: invalid results from unpack\n");
615 fprintf(test_out, "test7: object element %d has incorrect unpacked value\n", j);
616 return(false);
621 /* cleanup */
622 OBJ_RELEASE(bufA);
623 if (NULL != bufA) {
624 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
625 return false;
628 return (true);
632 * ompi everything composite multipack/unpack
635 static bool test9(void)
638 orte_buffer_t *bufA;
639 int rc;
640 int32_t i;
642 /* pack and unpack in this order */
643 /* each block now has an offset to make debugging easier.. first block=100, 200,... */
644 orte_byte_object_t *srco[NUM_ELEMS];
645 orte_byte_object_t *dsto[NUM_ELEMS];
646 char* srcs[NUM_ELEMS];
647 char* dsts[NUM_ELEMS];
648 bool srcb[NUM_ELEMS];
649 bool dstb[NUM_ELEMS];
650 int32_t src32[NUM_ELEMS];
651 int32_t dst32[NUM_ELEMS];
652 int16_t src16[NUM_ELEMS];
653 int16_t dst16[NUM_ELEMS];
655 for(i=0; i<NUM_ELEMS; i++) {
656 /* object offset 100 */
657 srco[i] = (orte_byte_object_t*)malloc(sizeof(orte_byte_object_t));
658 asprintf((char**)&(srco[i]->bytes), "%d", i+100);
659 srco[i]->size = strlen((char*)(srco[i]->bytes)) + 1;
661 /* strings +200 */
662 asprintf(&srcs[i], "%d", i+200);
664 /* bool */
665 srcb[i] = ((i % 2) == 0) ? true : false;
667 /* INT32 +300 */
668 src32[i] = i+300;
670 /* INT16 +400 */
671 src16[i] = i+400;
674 bufA = OBJ_NEW(orte_buffer_t);
675 if (NULL == bufA) {
676 fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
677 return false;
680 for (i=0;i<NUM_ITERS;i++) {
681 /* object first */
682 rc = orte_dss.pack(bufA, srco, NUM_ELEMS, ORTE_BYTE_OBJECT);
683 if (ORTE_SUCCESS != rc) {
684 fprintf(test_out, "orte_dss.pack on object failed with return code %d\n", rc);
685 return(false);
687 /* STRING */
688 rc = orte_dss.pack(bufA, srcs, NUM_ELEMS, ORTE_STRING);
689 if (ORTE_SUCCESS != rc) {
690 fprintf(test_out, "orte_dss.pack on string failed with return code %d\n", rc);
691 return(false);
693 /* BOOL */
694 rc = orte_dss.pack(bufA, srcb, NUM_ELEMS, ORTE_BOOL);
695 if (ORTE_SUCCESS != rc) {
696 fprintf(test_out, "orte_dss.pack on bool failed with return code %d\n", rc);
697 return(false);
699 /* INT32 */
700 rc = orte_dss.pack(bufA, src32, NUM_ELEMS, ORTE_INT32);
701 if (ORTE_SUCCESS != rc) {
702 fprintf(test_out, "orte_dss.pack on INT32 failed with return code %d\n", rc);
703 return(false);
705 /* INT16 */
706 rc = orte_dss.pack(bufA, src16, NUM_ELEMS, ORTE_INT16);
707 if (ORTE_SUCCESS != rc) {
708 fprintf(test_out, "orte_dss.pack on INT16 failed with return code %d\n", rc);
709 return(false);
713 /* fprintf(test_out,"test8:packed buffer info for STRING with %d iterations %d elements each\n", NUM_ITERS, NUM_ELEMS); */
715 for (i=0; i<NUM_ITERS; i++) {
716 int j;
717 size_t count;
719 /* string */
720 for(j=0; j<NUM_ELEMS; j++) dsts[j] = NULL;
721 /* bool */
722 memset(dstb,-1,sizeof(dstb));
723 /* int32 */
724 for(j=0; j<NUM_ELEMS; j++) dst32[j] = -1;
725 /* int16 */
726 for(j=0; j<NUM_ELEMS; j++) dst16[j] = -1;
729 /* object */
730 count=NUM_ELEMS;
731 rc = orte_dss.unpack(bufA, dsto, &count, ORTE_BYTE_OBJECT);
732 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
733 fprintf(test_out, "orte_dss.unpack on object failed with return code %d\n", rc);
734 return(false);
737 for(j=0; j<NUM_ELEMS; j++) {
738 if(srco[j]->size != dsto[j]->size ||
739 memcmp(srco[j]->bytes,dsto[j]->bytes,srco[j]->size) != 0) {
740 fprintf(test_out, "test8: object element %d has incorrect unpacked value\n", j);
741 return(false);
745 /* string */
746 count = NUM_ELEMS;
747 rc = orte_dss.unpack(bufA, dsts, &count, ORTE_STRING);
748 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
749 fprintf(test_out, "orte_dss.unpack on string failed with return code %d\n", rc);
750 return(false);
753 for(j=0; j<NUM_ELEMS; j++) {
754 if(strcmp(srcs[j],dsts[j]) != 0) {
755 fprintf(test_out, "test8: invalid results from unpack\n");
756 fprintf(test_out, "item %d src=[%s] len=%d dst=[%s] len=%d\n", j, srcs[j], (int)strlen(srcs[j]), dsts[j], (int)strlen(dsts[j]));
757 return(false);
761 /* bool */
762 count = NUM_ELEMS;
763 rc = orte_dss.unpack(bufA, dstb, &count, ORTE_BOOL);
764 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
765 fprintf(test_out, "orte_dss.unpack on bool failed with return code %d\n", rc);
766 return(false);
769 for(j=0; j<NUM_ELEMS; j++) {
770 if(srcb[j] != dstb[j]) {
771 fprintf(test_out, "test8: invalid results from unpack\n");
772 return(false);
776 /* int32 */
777 count = NUM_ELEMS;
778 rc = orte_dss.unpack(bufA, dst32, &count, ORTE_INT32);
779 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
780 fprintf(test_out, "orte_dss.unpack on int32 failed with return code %d\n", rc);
781 return(false);
784 for(j=0; j<NUM_ELEMS; j++) {
785 if(src32[j] != dst32[j]) {
786 fprintf(test_out, "test8: invalid results from unpack\n");
787 return(false);
791 /* int16 */
792 count = NUM_ELEMS;
793 rc = orte_dss.unpack(bufA, dst16, &count, ORTE_INT16);
794 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
795 fprintf(test_out, "orte_dss.unpack on int16 failed with return code %d\n", rc);
796 return(false);
799 for(j=0; j<NUM_ELEMS; j++) {
800 if(src16[j] != dst16[j]) {
801 fprintf(test_out, "test8: invalid results from unpack\n");
802 return(false);
807 } /* per iteration */
809 OBJ_RELEASE(bufA);
810 if (NULL != bufA) {
811 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
812 return false;
815 return (true);
818 /* ORTE_DATA_VALUE */
819 static bool test10(void)
821 orte_buffer_t *bufA;
822 int rc;
823 int i;
824 int16_t i16[NUM_ELEMS];
825 orte_data_value_t *src[NUM_ELEMS];
826 orte_data_value_t *dst[NUM_ELEMS];
828 /* setup source array of data values */
829 for(i=0; i<NUM_ELEMS; i++) {
830 i16[i] = (int16_t)i;
831 src[i] = OBJ_NEW(orte_data_value_t);
832 src[i]->type = ((i % 2) == 0) ? ORTE_INT16 : ORTE_STRING;
833 if (ORTE_INT16 == src[i]->type)
834 src[i]->data = &i16[i];
835 else
836 src[i]->data = strdup("truly-a-dumb-test");
839 bufA = OBJ_NEW(orte_buffer_t);
840 if (NULL == bufA) {
841 fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
842 return false;
845 for (i=0;i<NUM_ITERS;i++) {
846 rc = orte_dss.pack(bufA, src, NUM_ELEMS, ORTE_DATA_VALUE);
847 if (ORTE_SUCCESS != rc) {
848 fprintf(test_out, "orte_dss.pack failed with error code %d\n", rc);
849 return(false);
853 for (i=0; i<NUM_ITERS; i++) {
854 int j;
855 size_t count = NUM_ELEMS;
856 memset(dst,-1,sizeof(dst));
858 rc = orte_dss.unpack(bufA, dst, &count, ORTE_DATA_VALUE);
859 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
860 fprintf(test_out,
861 "orte_dss.unpack (DATA_VALUE) failed on iteration %d with error code %d\n",
862 i, rc);
863 return(false);
866 for(j=0; j<NUM_ELEMS; j++) {
867 if (src[j]->type != dst[j]->type) {
868 fprintf(test_out, "orte_dss.unpack (DATA_VALUE) invalid results type mismatch from unpack\n");
869 return(false);
871 if (0 != orte_dss.compare(src[j], dst[j], src[j]->type)) {
872 fprintf(test_out, "orte_dss.unpack (DATA_VALUE) invalid results value mismatch from unpack");
873 return(false);
878 OBJ_RELEASE(bufA);
879 if (NULL != bufA) {
880 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
881 return false;
884 return (true);
888 /* size_t */
889 static bool test11(void)
891 orte_buffer_t *bufA;
892 int rc;
893 size_t i;
894 size_t src[NUM_ELEMS];
895 size_t dst[NUM_ELEMS];
897 for(i=0; i<NUM_ELEMS; i++)
898 src[i] = 1000*i;
900 bufA = OBJ_NEW(orte_buffer_t);
901 if (NULL == bufA) {
902 fprintf(test_out, "orte_buffer failed init in OBJ_NEW");
903 fprintf(test_out, "OBJ_NEW failed\n");
904 return false;
907 for (i=0;i<NUM_ITERS;i++) {
908 rc = orte_dss.pack(bufA, src, NUM_ELEMS, ORTE_SIZE);
909 if (ORTE_SUCCESS != rc) {
910 fprintf(test_out, "orte_dss.pack size_t failed");
911 fprintf(test_out, "orte_pack_size_t failed with return code %d\n", rc);
912 return(false);
916 for (i=0; i<NUM_ITERS; i++) {
917 size_t j;
918 size_t count;
920 count = NUM_ELEMS;
921 rc = orte_dss.unpack(bufA, dst, &count, ORTE_SIZE);
922 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
923 fprintf(test_out, "orte_dss.unpack size_t failed");
924 fprintf(test_out, "orte_unpack_size_t failed with return code %d\n", rc);
925 return(false);
928 for(j=0; j<NUM_ELEMS; j++) {
929 if(src[j] != dst[j]) {
930 fprintf(test_out, "test2: invalid results from unpack size_t");
931 return(false);
936 OBJ_RELEASE(bufA);
937 if (NULL != bufA) {
938 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer");
939 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer");
940 return false;
943 return (true);
948 * pid_t pack/unpack
950 static bool test12(void)
952 orte_buffer_t *bufA;
953 int rc;
954 size_t i;
955 pid_t src[NUM_ELEMS];
956 pid_t dst[NUM_ELEMS];
958 for(i=0; i<NUM_ELEMS; i++)
959 src[i] = (pid_t)i;
961 bufA = OBJ_NEW(orte_buffer_t);
962 if (NULL == bufA) {
963 fprintf(test_out, "orte_buffer failed init in OBJ_NEW");
964 fprintf(test_out, "OBJ_NEW failed\n");
965 return false;
968 for (i=0;i<NUM_ITERS;i++) {
969 rc = orte_dss.pack(bufA, src, NUM_ELEMS, ORTE_PID);
970 if (ORTE_SUCCESS != rc) {
971 fprintf(test_out, "orte_dss.pack failed");
972 fprintf(test_out, "orte_pack pid_t failed with return code %d\n", rc);
973 return(false);
977 for (i=0; i<NUM_ITERS; i++) {
978 size_t j;
979 size_t count;
981 count = NUM_ELEMS;
982 rc = orte_dss.unpack(bufA, dst, &count, ORTE_PID);
983 if (ORTE_SUCCESS != rc || count != NUM_ELEMS) {
984 fprintf(test_out, "orte_dss.unpack failed");
985 fprintf(test_out, "orte_pack pid_t failed with return code %d\n", rc);
986 return(false);
989 for(j=0; j<NUM_ELEMS; j++) {
990 if(src[j] != dst[j]) {
991 fprintf(test_out, "test2: invalid results from unpack");
992 return(false);
997 OBJ_RELEASE(bufA);
998 if (NULL != bufA) {
999 fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
1000 return false;
1003 return (true);