/* * Copyright (c) 2004-2005 The Trustees of Indiana University. * All rights reserved. * Copyright (c) 2004-2005 The Trustees of the University of Tennessee. * 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$ * * Additional copyrights may follow * * $HEADER$ */ #include "orte_config.h" #include "../src/include/orte_constants.h" #include "../src/include/orte_types.h" #include "../../src/dps/dps.h" #include "../../src/dps/dps_types.h" #include #include #include #ifdef HAVE_SYS_PARAM_H #include #endif #ifdef HAVE_NETINET_IN_H #include #endif #include "include/constants.h" #include "support.h" #include "../src/runtime/runtime.h" #include "../src/util/proc_info.h" #include "../src/util/sys_info.h" #include "util/malloc.h" #include "util/output.h" #include "../src/mca/base/base.h" #include "../src/dps/dps.h" #include "../src/mca/ns/ns.h" #include "../src/mca/ns/base/base.h" #include "../src/mca/gpr/base/base.h" #include "../src/mca/rmgr/base/base.h" #include "../src/mca/soh/base/base.h" #define NUM_ITERS 3 #define NUM_ELEMS 10 static bool test1(void); /* verify different buffer inits */ static bool test2(void); /* verify int16 */ static bool test2_1(void); /* verify int */ static bool test3(void); /* verify int32 */ static bool test3_1(void); /* verify int64 */ static bool test4(void); /* verify string */ static bool test5(void); /* verify name */ static bool test6(void); /* verify BOOL */ static bool test7(void); /* verify OBJECT */ static bool test8(void); /* verify composite (multiple types and element counts) */ static bool test9(void); /* verify GPR_KEYVAL */ static bool test10(void); /* verify GPR_VALUE */ static bool test11(void); /* verify size_t */ static bool test12(void); /* verify APP_CONTEXT */ static bool test13(void); /* verify ORTE_GPR_SUBSCRIPTION */ static bool test14(void); /* verify ORTE_GPR_NOTIFY_DATA */ static bool test15(void); /* verify pid_t */ FILE *test_out; int main (int argc, char* argv[]) { int ret; test_init("orte_dps"); test_out = stderr; /* Open up the output streams */ if (!ompi_output_init()) { return OMPI_ERROR; } /* * If threads are supported - assume that we are using threads - * and reset otherwise. */ ompi_set_using_threads(OMPI_HAVE_THREAD_SUPPORT); /* For malloc debugging */ ompi_malloc_init(); /* Ensure the system_info structure is instantiated and initialized */ if (ORTE_SUCCESS != (ret = orte_sys_info())) { return ret; } /* Ensure the process info structure is instantiated and initialized */ if (ORTE_SUCCESS != (ret = orte_proc_info())) { return ret; } orte_process_info.seed = true; orte_process_info.my_name = (orte_process_name_t*)malloc(sizeof(orte_process_name_t)); orte_process_info.my_name->cellid = 0; orte_process_info.my_name->jobid = 0; orte_process_info.my_name->vpid = 0; /* startup the MCA */ if (OMPI_SUCCESS == mca_base_open()) { fprintf(test_out, "MCA started\n"); } else { fprintf(test_out, "MCA could not start\n"); exit (1); } /* open the dps */ if (ORTE_SUCCESS == orte_dps_open()) { fprintf(test_out, "DPS started\n"); } else { fprintf(test_out, "DPS could not start\n"); exit (1); } /* open the name services */ if (ORTE_SUCCESS == orte_ns_base_open()) { fprintf(test_out, "NS started\n"); } else { fprintf(test_out, "NS could not start\n"); exit (1); } /* open the registry */ if (ORTE_SUCCESS == orte_gpr_base_open()) { fprintf(test_out, "GPR started\n"); } else { fprintf(test_out, "GPR could not start\n"); exit (1); } /* open the resource manager */ if (ORTE_SUCCESS == orte_rmgr_base_open()) { fprintf(test_out, "RMGR started\n"); } else { fprintf(test_out, "RMGR could not start\n"); exit (1); } /* open the soh */ if (ORTE_SUCCESS == orte_soh_base_open()) { fprintf(test_out, "SOH started\n"); } else { fprintf(test_out, "SOH could not start\n"); exit (1); } /* run the tests */ fprintf(test_out, "executing test1\n"); if (test1()) { test_success(); } else { test_failure("orte_dps test1 failed"); } fprintf(test_out, "executing test2\n"); if (test2()) { test_success(); } else { test_failure("orte_dps test2 failed"); } fprintf(test_out, "executing test2_1\n"); if (test2_1()) { test_success(); } else { test_failure("orte_dps test2_1 failed"); } fprintf(test_out, "executing test3\n"); if (test3()) { test_success(); } else { test_failure("orte_dps test3 failed"); } fprintf(test_out, "executing test3_1\n"); if (test3_1()) { test_success(); } else { test_failure("orte_dps test3_1 failed"); } fprintf(test_out, "executing test4\n"); if (test4()) { test_success(); } else { test_failure("orte_dps test4 failed"); } fprintf(test_out, "executing test5\n"); if (test5()) { test_success(); } else { test_failure("orte_dps test5 failed"); } fprintf(test_out, "executing test6\n"); if (test6()) { test_success(); } else { test_failure("orte_dps test6 failed"); } fprintf(test_out, "executing test7\n"); if (test7()) { test_success(); } else { test_failure("orte_dps test7 failed"); } fprintf(test_out, "executing test8\n"); if (test8()) { test_success(); } else { test_failure("orte_dps test8 failed"); } fprintf(test_out, "executing test9\n"); if (test9()) { test_success(); } else { test_failure("orte_dps test9 failed"); } fprintf(test_out, "executing test10\n"); if (test10()) { test_success(); } else { test_failure("orte_dps test10 failed"); } fprintf(test_out, "executing test11\n"); if (test11()) { test_success(); } else { test_failure("orte_dps test11 failed"); } fprintf(test_out, "executing test12\n"); if (test12()) { test_success(); } else { test_failure("orte_dps test12 failed"); } fprintf(test_out, "executing test13\n"); if (test13()) { test_success(); } else { test_failure("orte_dps test13 failed"); } fprintf(test_out, "executing test14\n"); if (test14()) { test_success(); } else { test_failure("orte_dps test14 failed"); } fprintf(test_out, "executing test15\n"); if (test15()) { test_success(); } else { test_failure("orte_dps test15 failed"); } ret = test_finalize(); fclose(test_out); return ret; } static bool test1(void) /* verify different buffer inits */ { orte_buffer_t *bufA; bufA = OBJ_NEW(orte_buffer_t); if (NULL == bufA) { test_comment("orte_buffer failed init in OBJ_NEW"); fprintf(test_out, "OBJ_NEW failed\n"); return false; } OBJ_RELEASE(bufA); if (NULL != bufA) { test_comment("OBJ_RELEASE did not NULL the buffer pointer"); fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer"); return false; } return (true); } /* * OMPI_INT16 pack/unpack */ static bool test2(void) { orte_buffer_t *bufA; int rc; int32_t i; int16_t src[NUM_ELEMS]; int16_t dst[NUM_ELEMS]; for(i=0; ikey), "%d", i); src[i]->type = ((i % 2) == 0) ? ORTE_INT16 : ORTE_INT32; if (ORTE_INT16 == src[i]->type) src[i]->value.i16 = i; else src[i]->value.i32 = i; } bufA = OBJ_NEW(orte_buffer_t); if (NULL == bufA) { test_comment("orte_buffer failed init in OBJ_NEW"); fprintf(test_out, "OBJ_NEW failed\n"); return false; } for (i=0;ikey, dst[j]->key) || src[j]->type != dst[j]->type) { test_comment ("test9: invalid results type/key mismatch from unpack"); return(false); } if (ORTE_INT16 == src[j]->type) { if (src[j]->value.i16 != dst[j]->value.i16) { test_comment ("test9: invalid results i16 value mismatch from unpack"); return(false); } } else if (ORTE_INT32 == src[j]->type) { if (src[j]->value.i32 != dst[j]->value.i32) { test_comment ("test9: invalid results i32 mismatch from unpack"); return(false); } } } } OBJ_RELEASE(bufA); if (NULL != bufA) { test_comment("OBJ_RELEASE did not NULL the buffer pointer"); fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer"); return false; } return (true); } /* ORTE_GPR_VALUE */ static bool test10(void) { orte_buffer_t *bufA; int rc; size_t i, j, k; orte_gpr_value_t *src[NUM_ELEMS]; orte_gpr_value_t *dst[NUM_ELEMS]; for(i=0; isegment = strdup("test-segment"); src[i]->num_tokens = (i % 10) + 1; /* ensure there is always at least one */ src[i]->tokens = (char**)malloc(src[i]->num_tokens * sizeof(char*)); for (j=0; j < src[i]->num_tokens; j++) { src[i]->tokens[j] = strdup("test-token"); } src[i]->cnt = (i % 20) + 1; src[i]->keyvals = (orte_gpr_keyval_t**)malloc(src[i]->cnt * sizeof(orte_gpr_keyval_t*)); for (j=0; j < src[i]->cnt; j++) { src[i]->keyvals[j] = OBJ_NEW(orte_gpr_keyval_t); asprintf(&((src[i]->keyvals[j])->key), "%lu", (unsigned long) j); (src[i]->keyvals[j])->type = ((j % 2) == 0) ? ORTE_INT16 : ORTE_INT32; if (ORTE_INT16 == (src[i]->keyvals[j])->type) (src[i]->keyvals[j])->value.i16 = j; else (src[i]->keyvals[j])->value.i32 = j; } } bufA = OBJ_NEW(orte_buffer_t); if (NULL == bufA) { test_comment("orte_buffer failed init in OBJ_NEW"); fprintf(test_out, "OBJ_NEW failed\n"); return false; } for (i=0;isegment, dst[j]->segment) || src[j]->num_tokens != dst[j]->num_tokens || src[j]->cnt != dst[j]->cnt) { test_comment ("test10: invalid results from unpack"); return(false); } for (k=0; knum_tokens; k++) { if (0 != strcmp(src[j]->tokens[k], dst[j]->tokens[k])) { test_comment ("test10: invalid results (tokens) from unpack"); return(false); } } for (k=0; k < src[j]->cnt; k++) { if (0 != strcmp((src[j]->keyvals[k])->key, (dst[j]->keyvals[k])->key)) { test_comment ("test10: invalid results (keyvalues) from unpack"); return(false); } if ((src[j]->keyvals[k])->type != (dst[j]->keyvals[k])->type) { test_comment ("test10: invalid results (keyvalue types) from unpack"); return(false); } if (ORTE_INT16 == (src[j]->keyvals[k])->type && (src[j]->keyvals[k])->value.i16 != (dst[j]->keyvals[k])->value.i16) { test_comment ("test10: invalid results (keyvalues.16) from unpack"); return(false); } else if (ORTE_INT32 == (src[j]->keyvals[k])->type && (src[j]->keyvals[k])->value.i32 != (dst[j]->keyvals[k])->value.i32) { test_comment ("test10: invalid results (keyvalues.32) from unpack"); return(false); } } } } OBJ_RELEASE(bufA); if (NULL != bufA) { test_comment("OBJ_RELEASE did not NULL the buffer pointer"); fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer"); return false; } return (true); } /* size_t */ static bool test11(void) { orte_buffer_t *bufA; int rc; size_t i; size_t src[NUM_ELEMS]; size_t dst[NUM_ELEMS]; for(i=0; iidx = i; src[i]->app = strdup("test-application-name"); src[i]->num_procs = i; /* test between 0 and NUM_ELEMS-1 proc counts */ /* test arg counts of 1 to NUM_ELEMS+1 */ src[i]->argc = i+1; if (src[i]->argc) { /* if to allow testing of argv count of zero */ src[i]->argv = (char**)malloc(src[i]->argc * sizeof(char*)); for (n=0; n < src[i]->argc; n++) { src[i]->argv[n] = strdup("test-argv"); } } /* test env counts of 1 to NUM_ELEMS+1 */ src[i]->num_env = i+1; if (src[i]->num_env) { /* if to allow testing of num_env count of zero */ src[i]->env = (char**)malloc(src[i]->num_env * sizeof(char*)); for (j=0; j < src[i]->num_env; j++) { src[i]->env[j] = strdup("test-env"); } } src[i]->cwd = strdup ("test-cwd"); /* test imap data for map count = num_procs */ src[i]->num_map = i+1; if (src[i]->num_map) { /* if to allow testing of map count of zero */ src[i]->map_data = (orte_app_context_map_t**)malloc(src[i]->num_map * sizeof(orte_app_context_map_t *)); /* map data type */ for (j=0; j < src[i]->num_map; j++) { src[i]->map_data[j] = OBJ_NEW(orte_app_context_map_t); /* assume we create with new rather than malloc? */ src[i]->map_data[j]->map_type = (uint8_t) j; src[i]->map_data[j]->map_data = strdup("test-map-data"); } } } /* source data set, now create buffer and pack source data */ bufA = OBJ_NEW(orte_buffer_t); if (NULL == bufA) { test_comment("orte_buffer failed init in OBJ_NEW"); fprintf(test_out, "OBJ_NEW failed\n"); return false; } /* fprintf(test_out,"New buffer ready\n"); */ /* fflush(test_out); */ /* orte_dps_dump_buffer_simple (bufA, 0); */ for (i=0;iidx != dst[j]->idx || 0 != strcmp(src[j]->app, dst[j]->app) || src[j]->num_procs != dst[j]->num_procs || src[j]->argc != dst[j]->argc || src[j]->num_env != dst[j]->num_env || 0 != strcmp(src[j]->cwd, dst[j]->cwd) || src[j]->num_map != dst[j]->num_map ) { test_comment ("test12: invalid results from unpack"); return(false); } /* now compare each of the size/cnt depedant values */ for (n=0; nargc; n++) { if (0 != strcmp(src[j]->argv[n], dst[j]->argv[n])) { test_comment ("test12: invalid results (argv) from unpack"); return(false); } } for (k=0; knum_env; k++) { if (0 != strcmp(src[j]->env[k], dst[j]->env[k])) { test_comment ("test12: invalid results (envs) from unpack"); return(false); } } for (k=0; k< src[j]->num_map; k++) { if ((src[j]->map_data[k])->map_type != (dst[j]->map_data[k])->map_type) { test_comment ("test12: invalid results (map_data types) from unpack"); return(false); } if (0 != strcmp((src[j]->map_data[k])->map_data, (dst[j]->map_data[k])->map_data)) { test_comment ("test12: invalid results (map_data data) from unpack"); return(false); } } } } OBJ_RELEASE(bufA); if (NULL != bufA) { test_comment("OBJ_RELEASE did not NULL the buffer pointer"); fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer"); return false; } return (true); } /* ORTE_GPR_SUBSCRIPTION */ static bool test13(void) { orte_buffer_t *bufA; int rc; size_t i, j, k; orte_gpr_subscription_t *src[NUM_ELEMS]; orte_gpr_subscription_t *dst[NUM_ELEMS]; for(i=0; iaddr_mode = (uint16_t) i; src[i]->segment = strdup("test-segment-name"); /* test token counts of 0! to NUM_ELEMS */ src[i]->num_tokens = i; if (src[i]->num_tokens) { /* if to allow testing of token count of zero */ src[i]->tokens = (char**)malloc(src[i]->num_tokens * sizeof(char*)); for (j=0; j < src[i]->num_tokens; j++) { src[i]->tokens[j] = strdup("test-token"); } } /* test key counts of 0 to NUM_ELEMS */ src[i]->num_keys = i; if (src[i]->num_keys) { /* if to allow testing of num_keys count of zero */ src[i]->keys = (char**)malloc(src[i]->num_keys * sizeof(char*)); for (j=0; j < src[i]->num_keys; j++) { src[i]->keys[j] = strdup("test-key"); } } /* skip the pointers for cb_func and user_tag */ } /* source data set, now create buffer and pack source data */ bufA = OBJ_NEW(orte_buffer_t); if (NULL == bufA) { test_comment("orte_buffer failed init in OBJ_NEW"); fprintf(test_out, "OBJ_NEW failed\n"); return false; } for (i=0;iaddr_mode != dst[j]->addr_mode || 0 != strcmp(src[j]->segment, dst[j]->segment) || src[j]->num_tokens != dst[j]->num_tokens || src[j]->num_keys != dst[j]->num_keys ) { test_comment ("test13: invalid results from unpack"); return(false); } /* now compare each of the size/cnt depedant values */ for (k=0; knum_tokens; k++) { if (0 != strcmp(src[j]->tokens[k], dst[j]->tokens[k])) { test_comment ("test13: invalid results (tokens) from unpack"); return(false); } } for (k=0; k< src[j]->num_keys; k++) { if (0 != strcmp(src[j]->keys[k], dst[j]->keys[k])) { test_comment ("test13: invalid results (keys) from unpack"); return(false); } } } } OBJ_RELEASE(bufA); if (NULL != bufA) { test_comment("OBJ_RELEASE did not NULL the buffer pointer"); fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer"); return false; } return (true); } /* ORTE_GPR_NOTIFY_DATA */ static bool test14(void) { orte_buffer_t *bufA; int rc; size_t i, j, k, l; orte_gpr_notify_data_t *src[NUM_ELEMS]; orte_gpr_notify_data_t *dst[NUM_ELEMS]; for(i=0; icb_num = i; src[i]->addr_mode = (orte_gpr_addr_mode_t) i; src[i]->segment = strdup("test-segment-name"); /* test value counts of 0 to NUM_ELEMS-1 */ src[i]->cnt = i; /* value count */ if (0 < src[i]->cnt) { /* if to allow testing of GPR value count of zero */ src[i]->values = (orte_gpr_value_t**)malloc(src[i]->cnt * sizeof(orte_gpr_value_t*)); for (j=0; j < src[i]->cnt; j++) { src[i]->values[j] = OBJ_NEW(orte_gpr_value_t); src[i]->values[j]->addr_mode = (orte_gpr_addr_mode_t) i+j+1; src[i]->values[j]->segment = strdup("test-gpr-notify-value-segment-name"); /* ek segment name again! */ /* tokens */ src[i]->values[j]->num_tokens = j; /* test tokens within gpr values within notify message between 0-NUM_ELEMS-1 */ if (src[i]->values[j]->num_tokens) { /* if to allow testing of num_tokens count of zero */ src[i]->values[j]->tokens = (char**)malloc(src[i]->values[j]->num_tokens * sizeof(char*)); for (k=0; k < src[i]->values[j]->num_tokens; k++) { src[i]->values[j]->tokens[k] = strdup("test-grp-notify-value-token"); } /* for each token */ } /* if tokens */ /* keyval pairs (field name is 'cnt' same as used for value count so be carefull) */ src[i]->values[j]->cnt = j; /* test keyval pairs within gpr values within notify message between 0-NUM_ELEMS-1 */ if (src[i]->values[j]->cnt) { /* if to allow testing of keyval pair count of zero */ src[i]->values[j]->keyvals = (orte_gpr_keyval_t**)malloc(src[i]->values[j]->cnt * sizeof(orte_gpr_keyval_t*)); for (k=0; k < src[i]->values[j]->cnt; k++) { src[i]->values[j]->keyvals[k] = OBJ_NEW (orte_gpr_keyval_t); src[i]->values[j]->keyvals[k]->key = strdup("test-grp-notify-value-key"); src[i]->values[j]->keyvals[k]->type = ORTE_INT32; /* make it simplier */ src[i]->values[j]->keyvals[k]->value.i32 = (uint32_t) (i*100)+(j*10)+k; /* something variable */ } /* for each keyval pair */ } /* if keyvals */ } /* for each value */ } } /* source data set, now create buffer and pack source data */ bufA = OBJ_NEW(orte_buffer_t); if (NULL == bufA) { test_comment("orte_buffer failed init in OBJ_NEW"); fprintf(test_out, "OBJ_NEW failed\n"); return false; } for (i=0;icb_num != dst[j]->cb_num || src[j]->addr_mode != dst[j]->addr_mode || 0 != strcmp(src[j]->segment, dst[j]->segment) || src[j]->cnt != dst[j]->cnt ) { test_comment ("test14: invalid results from unpack"); return(false); } /* now compare each value of the cnt depedant values */ for (k=0; kcnt; k++) { if (src[j]->values[k]->addr_mode != dst[j]->values[k]->addr_mode) { test_comment ("test14: invalid results (values-addr-mode) from unpack"); return(false); } if (0 != strcmp(src[j]->values[k]->segment, dst[j]->values[k]->segment)) { test_comment ("test14: invalid results (values-segment) from unpack"); return(false); } if (src[j]->values[k]->num_tokens != dst[j]->values[k]->num_tokens) { test_comment ("test14: invalid results (values-num_tokens) from unpack"); return(false); } for (l=0; lvalues[k]->num_tokens; l++) { if (0 != strcmp(src[j]->values[k]->tokens[l], dst[j]->values[k]->tokens[l])) { test_comment ("test14: invalid results (values-tokens) from unpack"); return(false); } } /* for each token inside each grp value */ if (src[j]->values[k]->cnt != dst[j]->values[k]->cnt) { test_comment ("test14: invalid results (values-cnt (of keyval pairs)) from unpack"); return(false); } for (l=0; l< src[j]->values[k]->cnt; l++) { if (0 != strcmp(src[j]->values[k]->keyvals[l]->key, dst[j]->values[k]->keyvals[l]->key)) { test_comment ("test14: invalid results (values-keyvals-key) from unpack"); return(false); } if (src[j]->values[k]->keyvals[l]->type != dst[j]->values[k]->keyvals[l]->type) { test_comment ("test14: invalid results (values-keyvals-type) from unpack"); return(false); } if (src[j]->values[k]->keyvals[l]->value.i32 != dst[j]->values[k]->keyvals[l]->value.i32) { test_comment ("test14: invalid results (values-keyvals-value.i32) from unpack"); return(false); } }/* for each keyvalpair inside each grp value */ } /* for each grp value */ } /* for each ELEMENT */ } OBJ_RELEASE(bufA); if (NULL != bufA) { test_comment("OBJ_RELEASE did not NULL the buffer pointer"); fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer"); return false; } return (true); } /* * pid_t pack/unpack */ static bool test15(void) { orte_buffer_t *bufA; int rc; size_t i; pid_t src[NUM_ELEMS]; pid_t dst[NUM_ELEMS]; for(i=0; i