1
1

Convert gpr_internal_fns to use the new support functions and

internally call function pointers instead of direct calls

This commit was SVN r5140.
Этот коммит содержится в:
Jeff Squyres 2005-04-01 22:18:24 +00:00
родитель 842a4e904e
Коммит 709a3e498e
2 изменённых файлов: 126 добавлений и 49 удалений

Просмотреть файл

@ -40,7 +40,6 @@ endif
gpr_internal_fns_SOURCES = gpr_internal_fns.c
gpr_internal_fns_LDADD = \
$(top_builddir)/src/libmpi.la \
$(replica) \
$(top_builddir)/test/support/libsupport.a
gpr_internal_fns_DEPENDENCIES = $(gpr_internal_fns_LDADD)

Просмотреть файл

@ -31,6 +31,7 @@
#include "include/orte_schema.h"
#include "support.h"
#include "components.h"
#include "class/orte_pointer_array.h"
#include "dps/dps.h"
@ -38,6 +39,7 @@
#include "util/proc_info.h"
#include "util/sys_info.h"
#include "mca/gpr/gpr.h"
#include "mca/gpr/base/base.h"
#include "mca/gpr/replica/api_layer/gpr_replica_api.h"
#include "mca/gpr/replica/functional_layer/gpr_replica_fn.h"
@ -49,6 +51,13 @@ static FILE *test_out=NULL;
static char *cmd_str="diff ./test_gpr_replica_out ./test_gpr_replica_out_std";
/*
* Local functions
*/
static void find(const char *name, test_component_handle_t *handle,
test_component_fn_t *ptr);
int main(int argc, char **argv)
{
int rc, num_names, num_found;
@ -59,6 +68,24 @@ int main(int argc, char **argv)
orte_gpr_replica_container_t *cptr=NULL;
orte_gpr_keyval_t *kptr=NULL;
orte_gpr_replica_itagval_t **ivals=NULL, *iptr;
bool allow, have;
int priority;
test_component_handle_t handle;
mca_gpr_base_component_t *gpr_component = NULL;
orte_gpr_base_module_t *gpr_module = NULL;
orte_gpr_replica_find_seg_fn_t find_seg_fn;
orte_gpr_replica_create_itag_fn_t create_itag_fn;
orte_gpr_replica_dict_lookup_fn_t dict_lookup_fn;
orte_gpr_replica_dict_reverse_lookup_fn_t dict_reverse_lookup_fn;
orte_gpr_replica_delete_itag_fn_t delete_itag_fn;
orte_gpr_replica_get_itag_list_fn_t get_itag_list_fn;
orte_gpr_replica_create_container_fn_t create_container_fn;
orte_gpr_replica_add_keyval_fn_t add_keyval_fn;
orte_gpr_replica_search_container_fn_t search_container_fn;
orte_gpr_replica_update_keyval_fn_t update_keyval_fn;
orte_gpr_replica_check_itag_list_fn_t check_itag_list_fn;
orte_gpr_replica_release_segment_fn_t release_segment_fn;
test_init("test_gpr_replica");
@ -77,12 +104,13 @@ int main(int argc, char **argv)
if (!ompi_output_init()) {
return OMPI_ERROR;
}
/*
* If threads are supported - assume that we are using threads - and reset otherwise.
* 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();
@ -115,48 +143,80 @@ int main(int argc, char **argv)
exit (1);
}
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 gpr replica component and initialize a module */
if (OMPI_SUCCESS !=
test_component_open("gpr", "replica", &handle,
(mca_base_component_t**) &gpr_component) ||
NULL == gpr_component) {
fprintf(test_out, "Could not open replica\n");
exit(1);
}
if (ORTE_SUCCESS == orte_gpr_base_select()) {
fprintf(test_out, "GPR replica selected\n");
} else {
fprintf(test_out, "GPR replica could not be selected\n");
exit (1);
gpr_module = gpr_component->gpr_init(&allow, &have, &priority);
if (NULL == gpr_module) {
fprintf(test_out, "replica component did not return a module\n");
exit(1);
}
if (ORTE_SUCCESS == orte_dps_open()) {
fprintf(test_out, "DPS started\n");
} else {
fprintf(test_out, "DPS could not start\n");
exit (1);
}
/* Find a bunch of function pointers */
fprintf(stderr, "finding relevant function pointers in component\n");
find("orte_gpr_replica_find_seg", &handle,
(test_component_fn_t*) &find_seg_fn);
find("orte_gpr_replica_create_itag", &handle,
(test_component_fn_t*) &create_itag_fn);
find("orte_gpr_replica_dict_lookup", &handle,
(test_component_fn_t*) &dict_lookup_fn);
find("orte_gpr_replica_dict_reverse_lookup", &handle,
(test_component_fn_t*) &dict_reverse_lookup_fn);
find("orte_gpr_replica_delete_itag", &handle,
(test_component_fn_t*) &delete_itag_fn);
find("orte_gpr_replica_get_itag_list", &handle,
(test_component_fn_t*) &get_itag_list_fn);
find("orte_gpr_replica_check_itag_list", &handle,
(test_component_fn_t*) &check_itag_list_fn);
find("orte_gpr_replica_create_container", &handle,
(test_component_fn_t*) &create_container_fn);
find("orte_gpr_replica_add_keyval", &handle,
(test_component_fn_t*) &add_keyval_fn);
find("orte_gpr_replica_search_container", &handle,
(test_component_fn_t*) &search_container_fn);
find("orte_gpr_replica_update_keyval", &handle,
(test_component_fn_t*) &update_keyval_fn);
find("orte_gpr_replica_release_segment", &handle,
(test_component_fn_t*) &release_segment_fn);
/* Now do the tests */
fprintf(stderr, "going to find seg\n");
if (ORTE_SUCCESS != (rc = orte_gpr_replica_find_seg(&seg, true, "test-segment"))) {
if (ORTE_SUCCESS != (rc = find_seg_fn(&seg, true, "test-segment"))) {
fprintf(test_out, "gpr_test: find_seg failed with error code %s\n",
ORTE_ERROR_NAME(rc));
test_failure("gpr_test: find_seg failed");
test_finalize();
return rc;
} else {
test_success();
fprintf(test_out, "gpr_test: find_seg passed\n");
}
fprintf(stderr, "creating tags\n");
for (i=0; i<10; i++) {
asprintf(&tmp, "test-tag-%d", i);
if (ORTE_SUCCESS != (rc = orte_gpr_replica_create_itag(&itag[i], seg, tmp))) {
if (ORTE_SUCCESS != (rc = create_itag_fn(&itag[i], seg, tmp))) {
fprintf(test_out, "gpr_test: create_itag failed with error code %s\n",
ORTE_ERROR_NAME(rc));
test_failure("gpr_test: create_itag failed");
test_finalize();
return rc;
} else {
test_success();
fprintf(test_out, "gpr_test: create_itag passed\n");
}
free(tmp);
@ -165,7 +225,7 @@ int main(int argc, char **argv)
fprintf(stderr, "lookup tags\n");
for (i=0; i<10; i++) {
asprintf(&tmp, "test-tag-%d", i);
if (ORTE_SUCCESS != (rc = orte_gpr_replica_dict_lookup(&itag2, seg, tmp)) ||
if (ORTE_SUCCESS != (rc = dict_lookup_fn(&itag2, seg, tmp)) ||
itag2 != itag[i]) {
fprintf(test_out, "gpr_test: lookup failed with error code %s\n",
ORTE_ERROR_NAME(rc));
@ -173,16 +233,16 @@ int main(int argc, char **argv)
test_finalize();
return rc;
} else {
test_success();
fprintf(test_out, "gpr_test: lookup passed\n");
}
free(tmp);
}
fprintf(stderr, "reverse lookup tags\n");
for (i=0; i<10; i++) {
asprintf(&tmp2, "test-tag-%d", i);
if (ORTE_SUCCESS != (rc = orte_gpr_replica_dict_reverse_lookup(&tmp, seg, itag[i])) ||
if (ORTE_SUCCESS != (rc = dict_reverse_lookup_fn(&tmp, seg, itag[i])) ||
0 != strcmp(tmp2, tmp)) {
fprintf(test_out, "gpr_test: reverse lookup failed with error code %s\n",
ORTE_ERROR_NAME(rc));
@ -190,17 +250,17 @@ int main(int argc, char **argv)
test_finalize();
return rc;
} else {
test_success();
fprintf(test_out, "gpr_test: reverse lookup passed\n");
}
free(tmp);
free(tmp2);
}
fprintf(stderr, "delete tags\n");
for (i=0; i<10; i++) {
asprintf(&tmp, "test-tag-%d", i);
if (ORTE_SUCCESS != (rc = orte_gpr_replica_delete_itag(seg, tmp))) {
if (ORTE_SUCCESS != (rc = delete_itag_fn(seg, tmp))) {
fprintf(test_out, "gpr_test: delete tag failed with error code %s\n",
ORTE_ERROR_NAME(rc));
test_failure("gpr_test: delete tag failed");
@ -218,7 +278,7 @@ int main(int argc, char **argv)
}
names[14] = NULL;
num_names = 0;
if (ORTE_SUCCESS != (rc = orte_gpr_replica_get_itag_list(&itaglist, seg,
if (ORTE_SUCCESS != (rc = get_itag_list_fn(&itaglist, seg,
names, &num_names))) {
fprintf(test_out, "gpr_test: get itag list failed with error code %s\n",
ORTE_ERROR_NAME(rc));
@ -234,9 +294,8 @@ int main(int argc, char **argv)
fprintf(test_out, "\tname %s itag %d\n", names[i], itaglist[i]);
}
fprintf(stderr, "creating container\n");
if (ORTE_SUCCESS != (rc = orte_gpr_replica_create_container(&cptr, seg,
if (ORTE_SUCCESS != (rc = create_container_fn(&cptr, seg,
3, itaglist))) {
fprintf(test_out, "gpr_test: create_container failed with error code %s\n",
ORTE_ERROR_NAME(rc));
@ -257,7 +316,7 @@ int main(int argc, char **argv)
kptr->key = strdup("stupid-value");
kptr->type = ORTE_INT16;
kptr->value.i16 = 21;
if (ORTE_SUCCESS != (rc = orte_gpr_replica_add_keyval(&iptr, seg, cptr, kptr))) {
if (ORTE_SUCCESS != (rc = add_keyval_fn(&iptr, seg, cptr, kptr))) {
fprintf(test_out, "gpr_test: add keyval failed with error code %s\n",
ORTE_ERROR_NAME(rc));
test_failure("gpr_test: add keyval failed");
@ -279,8 +338,8 @@ int main(int argc, char **argv)
kptr->key = strdup("stupid-value");
kptr->type = ORTE_STRING;
kptr->value.strptr = strdup("try-string-value");
orte_gpr_replica_create_itag(&itag2, seg, kptr->key);
if (ORTE_SUCCESS != (rc = orte_gpr_replica_search_container(&num_found, ORTE_GPR_REPLICA_OR,
create_itag_fn(&itag2, seg, kptr->key);
if (ORTE_SUCCESS != (rc = search_container_fn(&num_found, ORTE_GPR_REPLICA_OR,
&itag2, 1, cptr) ||
0 >= num_found)) {
fprintf(test_out, "gpr_test: search container for single entry failed - returned %s for itag %d\n",
@ -298,7 +357,7 @@ int main(int argc, char **argv)
kptr->key = strdup("stupid-value");
kptr->type = ORTE_STRING;
kptr->value.strptr = strdup("try-string-value");
if (ORTE_SUCCESS != (rc = orte_gpr_replica_update_keyval(seg, cptr, kptr))) {
if (ORTE_SUCCESS != (rc = update_keyval_fn(seg, cptr, kptr))) {
fprintf(test_out, "gpr_test: update single keyval failed with error code %s\n",
ORTE_ERROR_NAME(rc));
test_failure("gpr_test: update single keyval failed");
@ -322,14 +381,13 @@ int main(int argc, char **argv)
}
}
fprintf(stderr, "add multiple keyvals to a container\n");
for (i=0; i < 10; i++) {
kptr = OBJ_NEW(orte_gpr_keyval_t);
kptr->key = strdup("stupid-value");
kptr->type = ORTE_INT16;
kptr->value.i16 = i * 100;
if (ORTE_SUCCESS != (rc = orte_gpr_replica_add_keyval(&iptr, seg, cptr, kptr))) {
if (ORTE_SUCCESS != (rc = add_keyval_fn(&iptr, seg, cptr, kptr))) {
fprintf(test_out, "gpr_test: add keyval failed with error code %s\n",
ORTE_ERROR_NAME(rc));
test_failure("gpr_test: add keyval failed");
@ -342,25 +400,25 @@ int main(int argc, char **argv)
}
fprintf(stderr, "update multiple keyvals in a container\n");
if(ORTE_SUCCESS != orte_gpr_replica_find_seg(&seg, false, "test-segment")) {
if(ORTE_SUCCESS != find_seg_fn(&seg, false, "test-segment")) {
fprintf(test_out, "Failure in orte_gpr_replica_find_seg\n");
return -1;
}
orte_gpr.dump_all(0);
gpr_module->dump_all(0);
kptr = OBJ_NEW(orte_gpr_keyval_t);
kptr->key = strdup("stupid-value");
kptr->type = ORTE_INT32;
kptr->value.i32 = 123456;
if (ORTE_SUCCESS != (rc = orte_gpr_replica_create_itag(&itag2, seg, kptr->key))) {
if (ORTE_SUCCESS != (rc = create_itag_fn(&itag2, seg, kptr->key))) {
fprintf(test_out, "gpr_internal_fns: update multiple keyvals - failed to get itag with error %s\n",
ORTE_ERROR_NAME(rc));
test_failure("gpr_test: update multiple keyvals failed");
test_finalize();
return rc;
}
if (ORTE_SUCCESS != (rc = orte_gpr_replica_search_container(&num_found, ORTE_GPR_REPLICA_OR,
if (ORTE_SUCCESS != (rc = search_container_fn(&num_found, ORTE_GPR_REPLICA_OR,
&itag2, 1, cptr))) {
fprintf(test_out, "gpr_internal_fns: update multiple keyvals - failed to find itag with error %s\n",
ORTE_ERROR_NAME(rc));
@ -368,7 +426,7 @@ int main(int argc, char **argv)
test_finalize();
return rc;
}
if (ORTE_SUCCESS != (rc = orte_gpr_replica_update_keyval(seg, cptr, kptr))) {
if (ORTE_SUCCESS != (rc = update_keyval_fn(seg, cptr, kptr))) {
fprintf(test_out, "gpr_test: update multiple keyvals failed with error code %s\n",
ORTE_ERROR_NAME(rc));
test_failure("gpr_test: update multiple keyvals failed");
@ -379,48 +437,47 @@ int main(int argc, char **argv)
}
OBJ_RELEASE(kptr);
orte_gpr.dump_all(0);
gpr_module->dump_all(0);
fprintf(stderr, "check itag list\n");
if (orte_gpr_replica_check_itag_list(ORTE_GPR_REPLICA_XAND, 0, NULL, 15, itaglist)) {
if (check_itag_list_fn(ORTE_GPR_REPLICA_XAND, 0, NULL, 15, itaglist)) {
fprintf(test_out, "check_itag_list: trivial NULL case passed\n");
} else {
fprintf(test_out, "check_itag_list: trivial NULL case failed\n");
}
if (!orte_gpr_replica_check_itag_list(ORTE_GPR_REPLICA_XAND, 5, itaglist, 15, itaglist)) {
if (!check_itag_list_fn(ORTE_GPR_REPLICA_XAND, 5, itaglist, 15, itaglist)) {
fprintf(test_out, "check_itag_list: trivial mismatched xand case passed\n");
} else {
fprintf(test_out, "check_itag_list: trivial mismatched xand case failed\n");
}
if (!orte_gpr_replica_check_itag_list(ORTE_GPR_REPLICA_AND, 15, itaglist, 5, itaglist)) {
if (!check_itag_list_fn(ORTE_GPR_REPLICA_AND, 15, itaglist, 5, itaglist)) {
fprintf(test_out, "check_itag_list: trivial mismatched and case passed\n");
} else {
fprintf(test_out, "check_itag_list: trivial mismatched and case failed\n");
}
if (orte_gpr_replica_check_itag_list(ORTE_GPR_REPLICA_XAND, 10, itaglist, 10, itaglist)) {
if (check_itag_list_fn(ORTE_GPR_REPLICA_XAND, 10, itaglist, 10, itaglist)) {
fprintf(test_out, "check_itag_list: non-trivial xand case passed\n");
} else {
fprintf(test_out, "check_itag_list: non-trivial xand case failed\n");
}
if (orte_gpr_replica_check_itag_list(ORTE_GPR_REPLICA_AND, 5, itaglist, 10, itaglist)) {
if (check_itag_list_fn(ORTE_GPR_REPLICA_AND, 5, itaglist, 10, itaglist)) {
fprintf(test_out, "check_itag_list: non-trivial and case passed\n");
} else {
fprintf(test_out, "check_itag_list: non-trivial and case failed\n");
}
if (orte_gpr_replica_check_itag_list(ORTE_GPR_REPLICA_OR, 5, itaglist, 10, itaglist)) {
if (check_itag_list_fn(ORTE_GPR_REPLICA_OR, 5, itaglist, 10, itaglist)) {
fprintf(test_out, "check_itag_list: non-trivial or case passed\n");
} else {
fprintf(test_out, "check_itag_list: non-trivial or case failed\n");
}
if (orte_gpr_replica_check_itag_list(ORTE_GPR_REPLICA_XOR, 10, itaglist, 5, itaglist)) {
if (check_itag_list_fn(ORTE_GPR_REPLICA_XOR, 10, itaglist, 5, itaglist)) {
fprintf(test_out, "check_itag_list: non-trivial or case passed\n");
} else {
fprintf(test_out, "check_itag_list: non-trivial or case failed\n");
}
fprintf(stderr, "\nreleasing segment\n");
if (ORTE_SUCCESS != (rc = orte_gpr_replica_release_segment(&seg)) ||
if (ORTE_SUCCESS != (rc = release_segment_fn(&seg)) ||
NULL != seg) {
fprintf(test_out, "gpr_test: release segment failed with error code %s\n",
ORTE_ERROR_NAME(rc));
@ -439,8 +496,14 @@ int main(int argc, char **argv)
if (NULL != keys[i]) free(keys[i]);
}
free(itaglist);
/* finalize the gpr component */
if (NULL != gpr_component->gpr_finalize) {
gpr_component->gpr_finalize();
}
test_component_close(&handle);
orte_dps_close();
orte_gpr_base_close();
orte_sys_info_finalize();
orte_proc_info_finalize();
mca_base_close();
@ -461,3 +524,18 @@ int main(int argc, char **argv)
return 0;
}
static void find(const char *name, test_component_handle_t *handle,
test_component_fn_t *ptr)
{
test_component_sym_t sym;
if (OMPI_SUCCESS !=
test_component_find_symbol(name, handle, &sym)) {
fprintf(test_out, "Unable to find symbol: %s\n", name);
exit(1);
}
fprintf(test_out, "Found symbol: %s\n", name);
*ptr = sym.tcs_function;
}