/* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. * Copyright (c) 2004-2005 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */ #include "opal_config.h" #include "opal/constants.h" #include #include #include #ifdef HAVE_SYS_PARAM_H #include #endif #include #include "opal/runtime/opal.h" #include "opal/dss/dss.h" #define NUM_ITERS 100 #define NUM_ELEMS 1024 static bool test1(void); /* verify different buffer inits */ static bool test2(void); /* verify int16 */ static bool test3(void); /* verify int */ static bool test4(void); /* verify int32 */ static bool test5(void); /* verify int64 */ static bool test6(void); /* verify string */ static bool test7(void); /* verify BOOL */ static bool test8(void); /* verify OBJECT */ static bool test9(void); /* verify composite (multiple types and element counts) */ static bool test10(void); /* verify KEYVAL */ static bool test11(void); /* verify int32_t */ static bool test12(void); /* verify pid_t */ static FILE *test_out; int main (int argc, char* argv[]) { int ret = 0; opal_init(&argc, &argv); test_out = stderr; /* run the tests */ fprintf(test_out, "executing test1\n"); if (test1()) { fprintf(test_out, "Test1 succeeded\n"); } else { fprintf(test_out, "Test1 failed\n"); ret = 1; } fprintf(test_out, "executing test2\n"); if (test2()) { fprintf(test_out, "Test2 succeeded\n"); } else { fprintf(test_out, "Test2 failed\n"); ret = 2; } fprintf(test_out, "executing test3\n"); if (test3()) { fprintf(test_out, "Test3 succeeded\n"); } else { fprintf(test_out, "Test3 failed\n"); ret = 3; } fprintf(test_out, "executing test4\n"); if (test4()) { fprintf(test_out, "Test4 succeeded\n"); } else { fprintf(test_out, "Test4 failed\n"); ret = 4; } fprintf(test_out, "executing test5\n"); if (test5()) { fprintf(test_out, "Test5 succeeded\n"); } else { fprintf(test_out, "Test5 failed\n"); ret = 5; } fprintf(test_out, "executing test6\n"); if (test6()) { fprintf(test_out, "Test6 succeeded\n"); } else { fprintf(test_out, "Test6 failed\n"); ret = 6; } fprintf(test_out, "executing test7\n"); if (test7()) { fprintf(test_out, "Test7 succeeded\n"); } else { fprintf(test_out, "Test7 failed\n"); ret = 7; } fprintf(test_out, "executing test8\n"); if (test8()) { fprintf(test_out, "Test8 succeeded\n"); } else { fprintf(test_out, "Test8 failed\n"); ret = 8; } fprintf(test_out, "executing test9\n"); if (test9()) { fprintf(test_out, "Test9 succeeded\n"); } else { fprintf(test_out, "opal_dss test9 failed\n"); ret = 9; } fprintf(test_out, "executing test10\n"); if (test10()) { fprintf(test_out, "Test10 succeeded\n"); } else { fprintf(test_out, "opal_dss test10 failed\n"); ret = 10; } fprintf(test_out, "executing test11\n"); if (test11()) { fprintf(test_out, "Test11 succeeded\n"); } else { fprintf(test_out, "opal_dss test11 failed\n"); ret = 11; } fprintf(test_out, "executing test12\n"); if (test12()) { fprintf(test_out, "Test12 succeeded\n"); } else { fprintf(test_out, "opal_dss test12 failed\n"); ret = 12; } fclose(test_out); opal_finalize(); return ret; } static bool test1(void) /* verify different buffer inits */ { opal_buffer_t *bufA; bufA = OBJ_NEW(opal_buffer_t); if (NULL == bufA) { fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n"); return false; } OBJ_RELEASE(bufA); if (NULL != bufA) { fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n"); return false; } return (true); } /* * OMPI_INT16 pack/unpack */ static bool test2(void) { opal_buffer_t *bufA; int rc; int32_t i; int16_t src[NUM_ELEMS]; int16_t dst[NUM_ELEMS]; for(i=0; itype = OPAL_DSS_BUFFER_NON_DESC; for (i=0;ibytes), "%d", i); src[i]->size = strlen((char*)(src[i]->bytes)) + 1; } bufA = OBJ_NEW(opal_buffer_t); if (NULL == bufA) { fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n"); return false; } for (i=0;isize != dst[j]->size || memcmp(src[j]->bytes,dst[j]->bytes,src[j]->size) != 0) { fprintf(test_out, "test7: invalid results from unpack\n"); fprintf(test_out, "test7: object element %d has incorrect unpacked value\n", j); return(false); } } } /* cleanup */ OBJ_RELEASE(bufA); if (NULL != bufA) { fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n"); return false; } return (true); } /** * ompi everything composite multipack/unpack */ static bool test9(void) { opal_buffer_t *bufA; int rc; int32_t i; /* pack and unpack in this order */ /* each block now has an offset to make debugging easier.. first block=100, 200,... */ opal_byte_object_t *srco[NUM_ELEMS]; opal_byte_object_t *dsto[NUM_ELEMS]; char* srcs[NUM_ELEMS]; char* dsts[NUM_ELEMS]; bool srcb[NUM_ELEMS]; bool dstb[NUM_ELEMS]; int32_t src32[NUM_ELEMS]; int32_t dst32[NUM_ELEMS]; int16_t src16[NUM_ELEMS]; int16_t dst16[NUM_ELEMS]; for(i=0; ibytes), "%d", i+100); srco[i]->size = strlen((char*)(srco[i]->bytes)) + 1; /* strings +200 */ asprintf(&srcs[i], "%d", i+200); /* bool */ srcb[i] = ((i % 2) == 0) ? true : false; /* INT32 +300 */ src32[i] = i+300; /* INT16 +400 */ src16[i] = i+400; } bufA = OBJ_NEW(opal_buffer_t); if (NULL == bufA) { fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n"); return false; } for (i=0;isize != dsto[j]->size || memcmp(srco[j]->bytes,dsto[j]->bytes,srco[j]->size) != 0) { fprintf(test_out, "test8: object element %d has incorrect unpacked value\n", j); return(false); } } /* string */ count = NUM_ELEMS; rc = opal_dss.unpack(bufA, dsts, &count, OPAL_STRING); if (OPAL_SUCCESS != rc || count != NUM_ELEMS) { fprintf(test_out, "opal_dss.unpack on string failed with return code %d\n", rc); return(false); } for(j=0; jtype = ((i % 2) == 0) ? OPAL_INT16 : OPAL_STRING; if (OPAL_INT16 == src[i]->type) src[i]->data.uint16 = i16[i]; else src[i]->data.string = strdup("truly-a-dumb-test"); } bufA = OBJ_NEW(opal_buffer_t); if (NULL == bufA) { fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n"); return false; } for (i=0;itype != dst[j]->type) { fprintf(test_out, "opal_dss.unpack (DATA_VALUE) invalid results type mismatch from unpack\n"); return(false); } if (0 != opal_dss.compare(src[j], dst[j], src[j]->type)) { fprintf(test_out, "opal_dss.unpack (DATA_VALUE) invalid results value mismatch from unpack"); return(false); } } } OBJ_RELEASE(bufA); if (NULL != bufA) { fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n"); return false; } return (true); } /* int32_t */ static bool test11(void) { opal_buffer_t *bufA; int rc; int32_t i; int32_t src[NUM_ELEMS]; int32_t dst[NUM_ELEMS]; for(i=0; i