root/test/dss/dss_buffer.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main
  2. test1
  3. test2
  4. test3
  5. test4
  6. test5
  7. test6
  8. test7
  9. test8
  10. test9
  11. test10
  12. test11
  13. test12

   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 (c) 2016      Research Organization for Information Science
  13  *                         and Technology (RIST). All rights reserved.
  14  * Copyright (c) 2018      Amazon.com, Inc. or its affiliates.  All Rights reserved.
  15  * $COPYRIGHT$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 
  22 #include "opal_config.h"
  23 #include "opal/constants.h"
  24 
  25 
  26 #include <stdio.h>
  27 #include <string.h>
  28 #include <stdlib.h>
  29 #ifdef HAVE_SYS_PARAM_H
  30 #include <sys/param.h>
  31 #endif
  32 #include <string.h>
  33 
  34 #include "opal/runtime/opal.h"
  35 #include "opal/dss/dss.h"
  36 #include "opal/util/printf.h"
  37 
  38 #define NUM_ITERS 100
  39 #define NUM_ELEMS 1024
  40 
  41 static bool test1(void);        /* verify different buffer inits */
  42 static bool test2(void);        /* verify int16 */
  43 static bool test3(void);      /* verify int */
  44 static bool test4(void);        /* verify int32 */
  45 static bool test5(void);      /* verify int64 */
  46 static bool test6(void);        /* verify string */
  47 static bool test7(void);        /* verify BOOL */
  48 static bool test8(void);        /* verify OBJECT */
  49 static bool test9(void);        /* verify composite (multiple types and element counts) */
  50 static bool test10(void);        /* verify KEYVAL */
  51 static bool test11(void);        /* verify int32_t */
  52 static bool test12(void);        /* verify pid_t */
  53 
  54 static FILE *test_out;
  55 
  56 
  57 int main (int argc, char* argv[])
  58 {
  59     int ret = 0;
  60 
  61     opal_init(&argc, &argv);
  62 
  63     test_out = stderr;
  64 
  65     /* run the tests */
  66 
  67     fprintf(test_out, "executing test1\n");
  68     if (test1()) {
  69         fprintf(test_out, "Test1 succeeded\n");
  70     } else {
  71       fprintf(test_out, "Test1 failed\n");
  72       ret = 1;
  73     }
  74 
  75     fprintf(test_out, "executing test2\n");
  76     if (test2()) {
  77         fprintf(test_out, "Test2 succeeded\n");
  78     } else {
  79       fprintf(test_out, "Test2 failed\n");
  80       ret = 2;
  81     }
  82 
  83     fprintf(test_out, "executing test3\n");
  84     if (test3()) {
  85         fprintf(test_out, "Test3 succeeded\n");
  86     } else {
  87       fprintf(test_out, "Test3 failed\n");
  88       ret = 3;
  89     }
  90 
  91     fprintf(test_out, "executing test4\n");
  92     if (test4()) {
  93         fprintf(test_out, "Test4 succeeded\n");
  94     } else {
  95       fprintf(test_out, "Test4 failed\n");
  96       ret = 4;
  97     }
  98 
  99     fprintf(test_out, "executing test5\n");
 100     if (test5()) {
 101         fprintf(test_out, "Test5 succeeded\n");
 102     } else {
 103       fprintf(test_out, "Test5 failed\n");
 104       ret = 5;
 105     }
 106 
 107     fprintf(test_out, "executing test6\n");
 108     if (test6()) {
 109         fprintf(test_out, "Test6 succeeded\n");
 110     } else {
 111       fprintf(test_out, "Test6 failed\n");
 112       ret = 6;
 113     }
 114 
 115     fprintf(test_out, "executing test7\n");
 116     if (test7()) {
 117         fprintf(test_out, "Test7 succeeded\n");
 118     } else {
 119       fprintf(test_out, "Test7 failed\n");
 120       ret = 7;
 121     }
 122 
 123     fprintf(test_out, "executing test8\n");
 124     if (test8()) {
 125         fprintf(test_out, "Test8 succeeded\n");
 126     } else {
 127       fprintf(test_out, "Test8 failed\n");
 128       ret = 8;
 129     }
 130 
 131     fprintf(test_out, "executing test9\n");
 132     if (test9()) {
 133         fprintf(test_out, "Test9 succeeded\n");
 134     } else {
 135       fprintf(test_out, "opal_dss test9 failed\n");
 136       ret = 9;
 137     }
 138 
 139     fprintf(test_out, "executing test10\n");
 140     if (test10()) {
 141         fprintf(test_out, "Test10 succeeded\n");
 142     } else {
 143       fprintf(test_out, "opal_dss test10 failed\n");
 144       ret = 10;
 145     }
 146 
 147     fprintf(test_out, "executing test11\n");
 148     if (test11()) {
 149         fprintf(test_out, "Test11 succeeded\n");
 150     } else {
 151       fprintf(test_out, "opal_dss test11 failed\n");
 152       ret = 11;
 153     }
 154 
 155     fprintf(test_out, "executing test12\n");
 156     if (test12()) {
 157         fprintf(test_out, "Test12 succeeded\n");
 158     } else {
 159       fprintf(test_out, "opal_dss test12 failed\n");
 160       ret = 12;
 161     }
 162 
 163     fclose(test_out);
 164 
 165     opal_finalize();
 166 
 167     return ret;
 168 }
 169 
 170 static bool test1(void)        /* verify different buffer inits */
 171 {
 172     opal_buffer_t *bufA;
 173 
 174     bufA = OBJ_NEW(opal_buffer_t);
 175     if (NULL == bufA) {
 176         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 177         return false;
 178     }
 179 
 180     OBJ_RELEASE(bufA);
 181     if (NULL != bufA) {
 182         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 183         return false;
 184     }
 185     return (true);
 186 }
 187 
 188 /*
 189  * OMPI_INT16 pack/unpack
 190  */
 191 static bool test2(void)
 192 {
 193     opal_buffer_t *bufA;
 194     int rc;
 195     int32_t i;
 196     int16_t src[NUM_ELEMS];
 197     int16_t dst[NUM_ELEMS];
 198 
 199     for(i=0; i<NUM_ELEMS; i++)
 200         src[i] = i;
 201 
 202     bufA = OBJ_NEW(opal_buffer_t);
 203     if (NULL == bufA) {
 204         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 205         return false;
 206     }
 207 
 208     bufA->type = OPAL_DSS_BUFFER_NON_DESC;
 209 
 210     for (i=0;i<NUM_ITERS;i++) {
 211         rc = opal_dss.pack(bufA, src, NUM_ELEMS, OPAL_INT16);
 212         if (OPAL_SUCCESS != rc) {
 213             fprintf(test_out, "opal_dss.pack failed with return code %d\n", rc);
 214             return(false);
 215         }
 216     }
 217 
 218     for (i=0; i<NUM_ITERS; i++) {
 219         int j;
 220         int32_t count;
 221 
 222         for(j=0; j<NUM_ELEMS; j++)
 223             dst[j] = -1;
 224 
 225         count = NUM_ELEMS;
 226         rc = opal_dss.unpack(bufA, dst, &count, OPAL_INT16);
 227         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 228             fprintf(test_out, "opal_dss.unpack failed with return code %d\n", rc);
 229             return(false);
 230         }
 231 
 232         for(j=0; j<NUM_ELEMS; j++) {
 233             if(src[j] != dst[j]) {
 234                 fprintf(test_out, "test2: invalid results from unpack\n");
 235                 return(false);
 236             }
 237         }
 238     }
 239 
 240     OBJ_RELEASE(bufA);
 241     if (NULL != bufA) {
 242         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 243         return false;
 244     }
 245 
 246     return (true);
 247 }
 248 
 249 /*
 250  * OMPI_INT pack/unpack
 251  */
 252 static bool test3(void)
 253 {
 254     opal_buffer_t *bufA;
 255     int rc;
 256     int32_t i;
 257     int src[NUM_ELEMS];
 258     int dst[NUM_ELEMS];
 259 
 260     for(i=0; i<NUM_ELEMS; i++)
 261         src[i] = i;
 262 
 263     bufA = OBJ_NEW(opal_buffer_t);
 264     if (NULL == bufA) {
 265         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 266         return false;
 267     }
 268 
 269     for (i=0;i<NUM_ITERS;i++) {
 270         rc = opal_dss.pack(bufA, src, NUM_ELEMS, OPAL_INT);
 271         if (OPAL_SUCCESS != rc) {
 272             fprintf(test_out, "opal_dss.pack failed with return code %d\n", rc);
 273             return(false);
 274         }
 275     }
 276 
 277     for (i=0; i<NUM_ITERS; i++) {
 278         int j;
 279         int32_t count;
 280 
 281         for(j=0; j<NUM_ELEMS; j++)
 282             dst[j] = -1;
 283 
 284         count = NUM_ELEMS;
 285         rc = opal_dss.unpack(bufA, dst, &count, OPAL_INT);
 286         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 287             fprintf(test_out, "opal_dss.unpack failed with return code %d\n", rc);
 288             return(false);
 289         }
 290 
 291         for(j=0; j<NUM_ELEMS; j++) {
 292             if(src[j] != dst[j]) {
 293                 fprintf(test_out, "test2: invalid results from unpack\n");
 294                 return(false);
 295             }
 296         }
 297     }
 298 
 299     OBJ_RELEASE(bufA);
 300     if (NULL != bufA) {
 301         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 302         return false;
 303     }
 304 
 305     return (true);
 306 }
 307 
 308 /*
 309  * OMPI_INT32 pack/unpack
 310  */
 311 static bool test4(void)
 312 {
 313     opal_buffer_t *bufA;
 314     int rc;
 315     int32_t i;
 316     int32_t src[NUM_ELEMS];
 317     int32_t dst[NUM_ELEMS];
 318 
 319     for(i=0; i<NUM_ELEMS; i++)
 320         src[i] = i;
 321 
 322     bufA = OBJ_NEW(opal_buffer_t);
 323     if (NULL == bufA) {
 324         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 325         return false;
 326     }
 327 
 328     for (i=0;i<NUM_ITERS;i++) {
 329         rc = opal_dss.pack(bufA, src, NUM_ELEMS, OPAL_INT32);
 330         if (OPAL_SUCCESS != rc) {
 331             fprintf(test_out, "opal_dss.pack failed with return code %d\n", rc);
 332             return(false);
 333         }
 334     }
 335 
 336     for (i=0; i<NUM_ITERS; i++) {
 337         int j;
 338         int32_t count = NUM_ELEMS;
 339 
 340         for(j=0; j<NUM_ELEMS; j++)
 341             dst[j] = -1;
 342 
 343         rc = opal_dss.unpack(bufA, dst, &count, OPAL_INT32);
 344         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 345             fprintf(test_out, "opal_dss.unpack failed with return code %d\n", rc);
 346             return(false);
 347         }
 348 
 349         for(j=0; j<NUM_ELEMS; j++) {
 350             if(src[j] != dst[j]) {
 351                 fprintf(test_out, "test2: invalid results from unpack\n");
 352                 return(false);
 353             }
 354         }
 355     }
 356 
 357     OBJ_RELEASE(bufA);
 358     if (NULL != bufA) {
 359         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 360         return false;
 361     }
 362 
 363     return (true);
 364 }
 365 
 366 /*
 367  * OPAL_INT64 pack/unpack
 368  */
 369 static bool test5(void)
 370 {
 371     opal_buffer_t *bufA;
 372     int rc;
 373     int32_t i;
 374     int64_t src[NUM_ELEMS];
 375     int64_t dst[NUM_ELEMS];
 376 
 377     for(i=0; i<NUM_ELEMS; i++)
 378         src[i] = 1000*i;
 379 
 380     bufA = OBJ_NEW(opal_buffer_t);
 381     if (NULL == bufA) {
 382         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 383         return false;
 384     }
 385 
 386     for (i=0;i<NUM_ITERS;i++) {
 387         rc = opal_dss.pack(bufA, src, NUM_ELEMS, OPAL_INT64);
 388         if (OPAL_SUCCESS != rc) {
 389             fprintf(test_out, "opal_dss.pack int64 failed with return code %d\n", rc);
 390             return(false);
 391         }
 392     }
 393 
 394     for (i=0; i<NUM_ITERS; i++) {
 395         int j;
 396         int32_t count = NUM_ELEMS;
 397 
 398         for(j=0; j<NUM_ELEMS; j++)
 399             dst[j] = -1;
 400 
 401         rc = opal_dss.unpack(bufA, dst, &count, OPAL_INT64);
 402         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 403             fprintf(test_out, "opal_dss.unpack int64 failed with return code %d\n", rc);
 404             return(false);
 405         }
 406 
 407         for(j=0; j<NUM_ELEMS; j++) {
 408             if(src[j] != dst[j]) {
 409                 fprintf(test_out, "test2: invalid results from unpack int64\n");
 410                 return(false);
 411             }
 412         }
 413     }
 414 
 415     OBJ_RELEASE(bufA);
 416     if (NULL != bufA) {
 417         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 418         return false;
 419     }
 420 
 421     return (true);
 422 }
 423 
 424 /*
 425  * OMPI_STRING pack/unpack
 426  */
 427 
 428 static bool test6(void)
 429 {
 430     opal_buffer_t *bufA;
 431     int rc;
 432     int32_t i;
 433     char* src[NUM_ELEMS];
 434     char* dst[NUM_ELEMS];
 435 
 436     for(i=0; i<NUM_ELEMS; i++) {
 437         opal_asprintf(&src[i], "%d", i);
 438     }
 439 
 440     bufA = OBJ_NEW(opal_buffer_t);
 441     if (NULL == bufA) {
 442         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 443         return false;
 444     }
 445 
 446     for (i=0;i<NUM_ITERS;i++) {
 447         rc = opal_dss.pack(bufA, src, NUM_ELEMS, OPAL_STRING);
 448         if (OPAL_SUCCESS != rc) {
 449             fprintf(test_out, "opal_dss.pack failed with return code %d\n", rc);
 450             return(false);
 451         }
 452     }
 453 
 454     for (i=0; i<NUM_ITERS; i++) {
 455         int j;
 456         int32_t count = NUM_ELEMS;
 457 
 458         for(j=0; j<NUM_ELEMS; j++)
 459             dst[j] = NULL;
 460 
 461         rc = opal_dss.unpack(bufA, dst, &count, OPAL_STRING);
 462         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 463             fprintf(test_out, "opal_dss.unpack failed with return code %d\n", rc);
 464             return(false);
 465         }
 466 
 467         for(j=0; j<NUM_ELEMS; j++) {
 468             if(strcmp(src[j],dst[j]) != 0) {
 469                 fprintf(test_out, "test4: invalid results from unpack\n");
 470                 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]));
 471                 return(false);
 472             }
 473         }
 474     }
 475 
 476     OBJ_RELEASE(bufA);
 477     if (NULL != bufA) {
 478         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 479         return false;
 480     }
 481 
 482     return (true);
 483 }
 484 
 485 
 486 /**
 487  * OMPI_BOOL pack/unpack
 488  */
 489 
 490 static bool test7(void)
 491 {
 492     opal_buffer_t *bufA;
 493     int rc;
 494     int32_t i;
 495     bool src[NUM_ELEMS];
 496     bool dst[NUM_ELEMS];
 497 
 498     for(i=0; i<NUM_ELEMS; i++)
 499         src[i] = ((i % 2) == 0) ? true : false;
 500 
 501     bufA = OBJ_NEW(opal_buffer_t);
 502     if (NULL == bufA) {
 503         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 504         return false;
 505     }
 506 
 507     for (i=0;i<NUM_ITERS;i++) {
 508         rc = opal_dss.pack(bufA, src, NUM_ELEMS, OPAL_BOOL);
 509         if (OPAL_SUCCESS != rc) {
 510             fprintf(test_out, "opal_dss.pack failed with return code %d\n", rc);
 511             return(false);
 512         }
 513     }
 514 
 515     for (i=0; i<NUM_ITERS; i++) {
 516         int j;
 517         int32_t count = NUM_ELEMS;
 518         memset(dst,-1,sizeof(dst));
 519 
 520         rc = opal_dss.unpack(bufA, dst, &count, OPAL_BOOL);
 521         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 522             fprintf(test_out, "opal_dss.unpack failed with return code %d\n", rc);
 523             return(false);
 524         }
 525 
 526         for(j=0; j<NUM_ELEMS; j++) {
 527             if(src[j] != dst[j]) {
 528                 fprintf(test_out, "test6: invalid results from unpack\n");
 529                 return(false);
 530             }
 531         }
 532     }
 533 
 534     OBJ_RELEASE(bufA);
 535     if (NULL != bufA) {
 536         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 537         return false;
 538     }
 539 
 540     return (true);
 541 }
 542 
 543 /**
 544  * OMPI_BYTE_OBJECT pack/unpack
 545  */
 546 
 547 static bool test8(void)
 548 {
 549 
 550     opal_buffer_t *bufA;
 551     int rc;
 552     int32_t i;
 553     opal_byte_object_t *src[NUM_ELEMS];
 554     opal_byte_object_t *dst[NUM_ELEMS];
 555 
 556     for(i=0; i<NUM_ELEMS; i++) {
 557         src[i] = (opal_byte_object_t*)malloc(sizeof(opal_byte_object_t));
 558         opal_asprintf((char**)&(src[i]->bytes), "%d", i);
 559         src[i]->size = strlen((char*)(src[i]->bytes)) + 1;
 560     }
 561 
 562     bufA = OBJ_NEW(opal_buffer_t);
 563     if (NULL == bufA) {
 564         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 565         return false;
 566     }
 567 
 568     for (i=0;i<NUM_ITERS;i++) {
 569         rc = opal_dss.pack(bufA, src, NUM_ELEMS, OPAL_BYTE_OBJECT);
 570         if (OPAL_SUCCESS != rc) {
 571             fprintf(test_out, "opal_dss.pack failed with return code %d\n", rc);
 572             return(false);
 573         }
 574     }
 575 
 576     for (i=0; i<NUM_ITERS; i++) {
 577         int j;
 578         int32_t count = NUM_ELEMS;
 579 
 580         rc = opal_dss.unpack(bufA, dst, &count, OPAL_BYTE_OBJECT);
 581         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 582             fprintf(test_out, "opal_dss.unpack failed with return code %d\n", rc);
 583             return(false);
 584         }
 585 
 586         for(j=0; j<NUM_ELEMS; j++) {
 587             if(src[j]->size != dst[j]->size ||
 588                memcmp(src[j]->bytes,dst[j]->bytes,src[j]->size) != 0) {
 589                 fprintf(test_out, "test7: invalid results from unpack\n");
 590                 fprintf(test_out, "test7: object element %d has incorrect unpacked value\n", j);
 591                 return(false);
 592             }
 593         }
 594     }
 595 
 596     /* cleanup */
 597     OBJ_RELEASE(bufA);
 598     if (NULL != bufA) {
 599         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 600         return false;
 601     }
 602 
 603     return (true);
 604 }
 605 
 606 /**
 607  * ompi everything composite multipack/unpack
 608  */
 609 
 610 static bool test9(void)
 611 {
 612 
 613     opal_buffer_t *bufA;
 614     int rc;
 615     int32_t i;
 616 
 617     /* pack and unpack in this order */
 618     /* each block now has an offset to make debugging easier.. first block=100, 200,... */
 619     opal_byte_object_t *srco[NUM_ELEMS];
 620     opal_byte_object_t *dsto[NUM_ELEMS];
 621     char* srcs[NUM_ELEMS];
 622     char* dsts[NUM_ELEMS];
 623     bool srcb[NUM_ELEMS];
 624     bool dstb[NUM_ELEMS];
 625     int32_t src32[NUM_ELEMS];
 626     int32_t dst32[NUM_ELEMS];
 627     int16_t src16[NUM_ELEMS];
 628     int16_t dst16[NUM_ELEMS];
 629 
 630     for(i=0; i<NUM_ELEMS; i++) {
 631         /* object offset 100 */
 632         srco[i] = (opal_byte_object_t*)malloc(sizeof(opal_byte_object_t));
 633         opal_asprintf((char**)&(srco[i]->bytes), "%d", i+100);
 634         srco[i]->size = strlen((char*)(srco[i]->bytes)) + 1;
 635 
 636         /* strings +200 */
 637         opal_asprintf(&srcs[i], "%d", i+200);
 638 
 639         /* bool */
 640         srcb[i] = ((i % 2) == 0) ? true : false;
 641 
 642         /* INT32 +300 */
 643         src32[i] = i+300;
 644 
 645         /* INT16 +400 */
 646         src16[i] = i+400;
 647     }
 648 
 649     bufA = OBJ_NEW(opal_buffer_t);
 650     if (NULL == bufA) {
 651         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 652         return false;
 653     }
 654 
 655     for (i=0;i<NUM_ITERS;i++) {
 656         /* object first */
 657         rc = opal_dss.pack(bufA, srco, NUM_ELEMS, OPAL_BYTE_OBJECT);
 658         if (OPAL_SUCCESS != rc) {
 659             fprintf(test_out, "opal_dss.pack on object failed with return code %d\n", rc);
 660             return(false);
 661         }
 662         /* STRING */
 663         rc = opal_dss.pack(bufA, srcs, NUM_ELEMS, OPAL_STRING);
 664         if (OPAL_SUCCESS != rc) {
 665             fprintf(test_out, "opal_dss.pack on string failed with return code %d\n", rc);
 666             return(false);
 667         }
 668         /* BOOL */
 669         rc = opal_dss.pack(bufA, srcb, NUM_ELEMS, OPAL_BOOL);
 670         if (OPAL_SUCCESS != rc) {
 671             fprintf(test_out, "opal_dss.pack on bool failed with return code %d\n", rc);
 672             return(false);
 673         }
 674         /* INT32 */
 675         rc = opal_dss.pack(bufA, src32, NUM_ELEMS, OPAL_INT32);
 676         if (OPAL_SUCCESS != rc) {
 677             fprintf(test_out, "opal_dss.pack on INT32 failed with return code %d\n", rc);
 678             return(false);
 679         }
 680         /* INT16 */
 681         rc = opal_dss.pack(bufA, src16, NUM_ELEMS, OPAL_INT16);
 682         if (OPAL_SUCCESS != rc) {
 683             fprintf(test_out, "opal_dss.pack on INT16 failed with return code %d\n", rc);
 684             return(false);
 685         }
 686     }
 687 
 688 /*  fprintf(test_out,"test8:packed buffer info for STRING with %d iterations %d elements each\n", NUM_ITERS, NUM_ELEMS); */
 689 
 690     for (i=0; i<NUM_ITERS; i++) {
 691         int j;
 692         int32_t count;
 693 
 694         /* string */
 695         for(j=0; j<NUM_ELEMS; j++) dsts[j] = NULL;
 696         /* bool */
 697         memset(dstb,-1,sizeof(dstb));
 698         /* int32 */
 699         for(j=0; j<NUM_ELEMS; j++) dst32[j] = -1;
 700         /* int16 */
 701         for(j=0; j<NUM_ELEMS; j++) dst16[j] = -1;
 702 
 703 
 704         /* object */
 705         count=NUM_ELEMS;
 706         rc = opal_dss.unpack(bufA, dsto, &count, OPAL_BYTE_OBJECT);
 707         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 708             fprintf(test_out, "opal_dss.unpack on object failed with return code %d\n", rc);
 709             return(false);
 710         }
 711 
 712         for(j=0; j<NUM_ELEMS; j++) {
 713             if(srco[j]->size != dsto[j]->size ||
 714                memcmp(srco[j]->bytes,dsto[j]->bytes,srco[j]->size) != 0) {
 715                 fprintf(test_out, "test8: object element %d has incorrect unpacked value\n", j);
 716                 return(false);
 717             }
 718         }
 719 
 720         /* string */
 721         count = NUM_ELEMS;
 722         rc = opal_dss.unpack(bufA, dsts, &count, OPAL_STRING);
 723         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 724             fprintf(test_out, "opal_dss.unpack on string failed with return code %d\n", rc);
 725             return(false);
 726         }
 727 
 728         for(j=0; j<NUM_ELEMS; j++) {
 729             if(strcmp(srcs[j],dsts[j]) != 0) {
 730                 fprintf(test_out, "test8: invalid results from unpack\n");
 731                 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]));
 732                 return(false);
 733             }
 734         }
 735 
 736         /* bool */
 737         count = NUM_ELEMS;
 738         rc = opal_dss.unpack(bufA, dstb, &count, OPAL_BOOL);
 739         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 740             fprintf(test_out, "opal_dss.unpack on bool failed with return code %d\n", rc);
 741             return(false);
 742         }
 743 
 744         for(j=0; j<NUM_ELEMS; j++) {
 745             if(srcb[j] != dstb[j]) {
 746                 fprintf(test_out, "test8: invalid results from unpack\n");
 747                 return(false);
 748             }
 749         }
 750 
 751         /* int32 */
 752         count = NUM_ELEMS;
 753         rc = opal_dss.unpack(bufA, dst32, &count, OPAL_INT32);
 754         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 755             fprintf(test_out, "opal_dss.unpack on int32 failed with return code %d\n", rc);
 756             return(false);
 757         }
 758 
 759         for(j=0; j<NUM_ELEMS; j++) {
 760             if(src32[j] != dst32[j]) {
 761                 fprintf(test_out, "test8: invalid results from unpack\n");
 762                 return(false);
 763             }
 764         }
 765 
 766         /* int16 */
 767         count = NUM_ELEMS;
 768         rc = opal_dss.unpack(bufA, dst16, &count, OPAL_INT16);
 769         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 770             fprintf(test_out, "opal_dss.unpack on int16 failed with return code %d\n", rc);
 771             return(false);
 772         }
 773 
 774         for(j=0; j<NUM_ELEMS; j++) {
 775             if(src16[j] != dst16[j]) {
 776                 fprintf(test_out, "test8: invalid results from unpack\n");
 777                 return(false);
 778             }
 779         }
 780 
 781 
 782     } /* per iteration */
 783 
 784     OBJ_RELEASE(bufA);
 785     if (NULL != bufA) {
 786         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 787         return false;
 788     }
 789 
 790     return (true);
 791 }
 792 
 793 /* OPAL_DATA_VALUE */
 794 static bool test10(void)
 795 {
 796     opal_buffer_t *bufA;
 797     int rc;
 798     int i;
 799     int16_t i16[NUM_ELEMS];
 800     opal_value_t *src[NUM_ELEMS];
 801     opal_value_t *dst[NUM_ELEMS];
 802 
 803     /* setup source array of data values */
 804     for(i=0; i<NUM_ELEMS; i++) {
 805         i16[i] = (int16_t)i;
 806         src[i] = OBJ_NEW(opal_value_t);
 807         src[i]->type = ((i % 2) == 0) ? OPAL_INT16 : OPAL_STRING;
 808         if (OPAL_INT16 == src[i]->type)
 809             src[i]->data.uint16 = i16[i];
 810         else
 811             src[i]->data.string = strdup("truly-a-dumb-test");
 812     }
 813 
 814     bufA = OBJ_NEW(opal_buffer_t);
 815     if (NULL == bufA) {
 816         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 817         return false;
 818     }
 819 
 820     for (i=0;i<NUM_ITERS;i++) {
 821         rc = opal_dss.pack(bufA, src, NUM_ELEMS, OPAL_VALUE);
 822         if (OPAL_SUCCESS != rc) {
 823             fprintf(test_out, "opal_dss.pack failed with error code %d\n", rc);
 824             return(false);
 825         }
 826     }
 827 
 828     for (i=0; i<NUM_ITERS; i++) {
 829         int j;
 830         int32_t count = NUM_ELEMS;
 831         memset(dst,-1,sizeof(dst));
 832 
 833         rc = opal_dss.unpack(bufA, dst, &count, OPAL_VALUE);
 834         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 835             fprintf(test_out,
 836             "opal_dss.unpack (DATA_VALUE) failed on iteration %d with error code %d\n",
 837                                 i, rc);
 838             return(false);
 839         }
 840 
 841         for(j=0; j<NUM_ELEMS; j++) {
 842             if (src[j]->type != dst[j]->type) {
 843                 fprintf(test_out, "opal_dss.unpack (DATA_VALUE) invalid results type mismatch from unpack\n");
 844                 return(false);
 845             }
 846             if (0 != opal_dss.compare(src[j], dst[j], src[j]->type)) {
 847                 fprintf(test_out, "opal_dss.unpack (DATA_VALUE) invalid results value mismatch from unpack");
 848                 return(false);
 849             }
 850         }
 851     }
 852 
 853     OBJ_RELEASE(bufA);
 854     if (NULL != bufA) {
 855         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 856         return false;
 857     }
 858 
 859     return (true);
 860 }
 861 
 862 
 863 /* int32_t */
 864 static bool test11(void)
 865 {
 866     opal_buffer_t *bufA;
 867     int rc;
 868     int32_t i;
 869     int32_t src[NUM_ELEMS];
 870     int32_t dst[NUM_ELEMS];
 871 
 872     for(i=0; i<NUM_ELEMS; i++)
 873         src[i] = 1000*i;
 874 
 875     bufA = OBJ_NEW(opal_buffer_t);
 876     if (NULL == bufA) {
 877         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 878         fprintf(test_out, "OBJ_NEW failed\n");
 879         return false;
 880     }
 881 
 882     for (i=0;i<NUM_ITERS;i++) {
 883         rc = opal_dss.pack(bufA, src, NUM_ELEMS, OPAL_INT32);
 884         if (OPAL_SUCCESS != rc) {
 885             fprintf(test_out, "opal_dss.pack int32_t failed");
 886             fprintf(test_out, "orte_pack_int32_t failed with return code %d\n", rc);
 887             return(false);
 888         }
 889     }
 890 
 891     for (i=0; i<NUM_ITERS; i++) {
 892         int32_t j;
 893         int32_t count;
 894 
 895         count = NUM_ELEMS;
 896         rc = opal_dss.unpack(bufA, dst, &count, OPAL_INT32);
 897         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 898             fprintf(test_out, "opal_dss.unpack int32_t failed");
 899             fprintf(test_out, "orte_unpack_int32_t failed with return code %d\n", rc);
 900             return(false);
 901         }
 902 
 903         for(j=0; j<NUM_ELEMS; j++) {
 904             if(src[j] != dst[j]) {
 905                 fprintf(test_out, "test11: invalid results from unpack int32_t");
 906                 return(false);
 907             }
 908         }
 909     }
 910 
 911     OBJ_RELEASE(bufA);
 912     if (NULL != bufA) {
 913         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer");
 914         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer");
 915         return false;
 916     }
 917 
 918     return (true);
 919 }
 920 
 921 
 922 /*
 923  * pid_t pack/unpack
 924  */
 925 static bool test12(void)
 926 {
 927     opal_buffer_t *bufA;
 928     int rc;
 929     int32_t i;
 930     pid_t src[NUM_ELEMS];
 931     pid_t dst[NUM_ELEMS];
 932 
 933     for(i=0; i<NUM_ELEMS; i++)
 934         src[i] = (pid_t)i;
 935 
 936     bufA = OBJ_NEW(opal_buffer_t);
 937     if (NULL == bufA) {
 938         fprintf(test_out, "orte_buffer failed init in OBJ_NEW");
 939         fprintf(test_out, "OBJ_NEW failed\n");
 940         return false;
 941     }
 942 
 943     for (i=0;i<NUM_ITERS;i++) {
 944         rc = opal_dss.pack(bufA, src, NUM_ELEMS, OPAL_PID);
 945         if (OPAL_SUCCESS != rc) {
 946             fprintf(test_out, "opal_dss.pack failed");
 947             fprintf(test_out, "orte_pack pid_t failed with return code %d\n", rc);
 948             return(false);
 949         }
 950     }
 951 
 952     for (i=0; i<NUM_ITERS; i++) {
 953         int32_t j;
 954         int32_t count;
 955 
 956         count = NUM_ELEMS;
 957         rc = opal_dss.unpack(bufA, dst, &count, OPAL_PID);
 958         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 959             fprintf(test_out, "opal_dss.unpack failed");
 960             fprintf(test_out, "orte_pack pid_t failed with return code %d\n", rc);
 961             return(false);
 962         }
 963 
 964         for(j=0; j<NUM_ELEMS; j++) {
 965             if(src[j] != dst[j]) {
 966                 fprintf(test_out, "test2: invalid results from unpack");
 967                 return(false);
 968             }
 969         }
 970     }
 971 
 972     OBJ_RELEASE(bufA);
 973     if (NULL != bufA) {
 974         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 975         return false;
 976     }
 977 
 978     return (true);
 979 }

/* [<][>][^][v][top][bottom][index][help] */