diff --git a/src/mca/gpr/replica/gpr_replica_component.c b/src/mca/gpr/replica/gpr_replica_component.c index ba5d083032..bf7d01fcc6 100644 --- a/src/mca/gpr/replica/gpr_replica_component.c +++ b/src/mca/gpr/replica/gpr_replica_component.c @@ -606,7 +606,7 @@ int orte_gpr_replica_module_init(void) */ int orte_gpr_replica_finalize(void) { - int i; + int i, j; orte_gpr_replica_segment_t** seg; orte_gpr_replica_triggers_t** trig; orte_gpr_replica_callbacks_t* cb; @@ -618,7 +618,9 @@ int orte_gpr_replica_finalize(void) seg = (orte_gpr_replica_segment_t**)(orte_gpr_replica.segments)->addr; for (i=0; i < (orte_gpr_replica.segments)->size; i++) { if (NULL != seg[i]) { + j = i; OBJ_RELEASE(seg[i]); + orte_pointer_array_set_item(orte_gpr_replica.segments, j, NULL); } } OBJ_RELEASE(orte_gpr_replica.segments); @@ -626,7 +628,9 @@ int orte_gpr_replica_finalize(void) trig = (orte_gpr_replica_triggers_t**)(orte_gpr_replica.triggers)->addr; for (i=0; i < (orte_gpr_replica.triggers)->size; i++) { if (NULL != trig[i]) { + j = i; OBJ_RELEASE(trig[i]); + orte_pointer_array_set_item(orte_gpr_replica.triggers, j, NULL); } } OBJ_RELEASE(orte_gpr_replica.triggers); diff --git a/src/runtime/orte_finalize.c b/src/runtime/orte_finalize.c index b2ad1928ef..ef5d90e518 100644 --- a/src/runtime/orte_finalize.c +++ b/src/runtime/orte_finalize.c @@ -27,6 +27,7 @@ #include "mca/gpr/base/base.h" #include "mca/iof/base/base.h" #include "mca/rmgr/base/base.h" +#include "util/if.h" #include "util/malloc.h" #include "util/output.h" #include "util/session_dir.h" @@ -66,6 +67,9 @@ int orte_finalize(void) orte_proc_info_finalize(); orte_univ_info_finalize(); + /* cleanup the if data */ + ompi_iffinalize(); + /* finalize the mca */ mca_base_close(); diff --git a/src/util/if.c b/src/util/if.c index 3e83730989..a4035fd25f 100644 --- a/src/util/if.c +++ b/src/util/if.c @@ -255,6 +255,7 @@ static int ompi_ifinit(void) memcpy(intf_ptr, &intf, sizeof(intf)); ompi_list_append(&ompi_if_list, (ompi_list_item_t*)intf_ptr); } + free(ifconf.ifc_req); close(sd); #else /* WIN32 implementation begins */ @@ -361,6 +362,23 @@ static int ompi_ifinit(void) } +/* + * Finalize the list of configured interfaces to free malloc'd memory + */ + +int ompi_iffinalize(void) +{ +#ifndef WIN32 + ompi_if_t *intf_ptr; + + while (NULL != (intf_ptr = (ompi_if_t*)ompi_list_remove_first(&ompi_if_list))) { + OBJ_RELEASE(intf_ptr); + } +#endif + return OMPI_SUCCESS; +} + + /* * Look for interface by name and returns its address * as a dotted decimal formatted string. diff --git a/src/util/if.h b/src/util/if.h index 6b5a999a2a..574c92c941 100644 --- a/src/util/if.h +++ b/src/util/if.h @@ -111,6 +111,15 @@ OMPI_DECLSPEC int ompi_ifindextomask(int if_index, struct sockaddr*, int); */ OMPI_DECLSPEC bool ompi_ifislocal(char *hostname); +/** + * Finalize the functions to release malloc'd data + * + * @param none + * @return OMPI_SUCCESS if no problems encountered + * @return OMPI_ERROR if data could not be released + */ +OMPI_DECLSPEC int ompi_iffinalize(void); + #if defined(c_plusplus) || defined(__cplusplus) } #endif diff --git a/test/mca/gpr/Makefile.am b/test/mca/gpr/Makefile.am index 2e9e56d3f9..d9cffa8f1a 100644 --- a/test/mca/gpr/Makefile.am +++ b/test/mca/gpr/Makefile.am @@ -25,6 +25,7 @@ check_PROGRAMS = \ gpr_mem_leaks \ gpr_overwrite \ gpr_put_get \ + gpr_threads \ gpr_triggers TESTS = \ @@ -62,6 +63,13 @@ gpr_put_get_LDADD = \ $(top_builddir)/test/support/libsupport.a gpr_put_get_DEPENDENCIES = $(gpr_put_get_LDADD) +gpr_threads_SOURCES = gpr_threads.c +gpr_threads_LDADD = \ + $(top_builddir)/src/libmpi.la \ + $(replica) \ + $(top_builddir)/test/support/libsupport.a +gpr_threads_DEPENDENCIES = $(gpr_threads_LDADD) + gpr_triggers_SOURCES = gpr_triggers.c gpr_triggers_LDADD = \ $(top_builddir)/src/libmpi.la \ diff --git a/test/mca/gpr/gpr_overwrite.c b/test/mca/gpr/gpr_overwrite.c index 8d75663a1e..973b8ba285 100644 --- a/test/mca/gpr/gpr_overwrite.c +++ b/test/mca/gpr/gpr_overwrite.c @@ -254,6 +254,7 @@ int main(int argc, char **argv) mca_base_close(); ompi_malloc_finalize(); ompi_output_finalize(); + ompi_class_finalize(); fclose( test_out ); diff --git a/test/mca/gpr/gpr_threads.c b/test/mca/gpr/gpr_threads.c new file mode 100644 index 0000000000..845478277c --- /dev/null +++ b/test/mca/gpr/gpr_threads.c @@ -0,0 +1,119 @@ +/* + * 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 "include/orte_constants.h" +#include "include/orte_types.h" +#include "include/orte_schema.h" + +#include +#include + +#include "support.h" + +#include "threads/thread.h" +#include "util/proc_info.h" +#include "util/sys_info.h" +#include "mca/errmgr/errmgr.h" +#include "mca/ns/ns_types.h" +#include "mca/gpr/gpr.h" +#include "dps/dps.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" +#include "mca/gpr/replica/communications/gpr_replica_comm.h" +#include "mca/gpr/replica/transition_layer/gpr_replica_tl.h" + +/* output files needed by the test */ +static FILE *test_out=NULL; + +/* function for exercising the registry */ +void thread_fn(ompi_object_t *object); + +int main(int argc, char **argv) +{ + int i, rc, num_threads; + ompi_thread_t **threads; + + /* protect against sizeof mismatches */ + if (sizeof(i) > sizeof (void*)) { + fprintf(stderr, "cannot run this test on this machine\n"); + exit 77; + } + + test_init("test_gpr_threads"); + + if (getenv("TEST_WRITE_TO_FILE") != NULL) { + test_out = fopen( "test_gpr_threads", "w+" ); + } else { + test_out = stderr; + } + if( test_out == NULL ) { + test_failure("gpr_threads couldn't open test file failed"); + test_finalize(); + exit(1); + } + + if (1 < argc) { /* number of threads to run provided on cmd line */ + num_threads = strtol(argv[1], NULL, 0); + } else { /* default to 2 */ + num_threads = 2; + } + + /* setup the runtime environment */ + if (ORTE_SUCCESS != (rc = orte_init())) { + ORTE_ERROR_LOG(rc); + return rc; + } + + /* setup the threads */ + threads = (ompi_thread_t**)malloc(num_threads * sizeof(ompi_thread_t*)); + if (NULL == threads) { + ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); + return ORTE_ERR_OUT_OF_RESOURCE; + } + for (i=0; i < num_threads; i++) { + threads[i] = OBJ_NEW(ompi_thread_t); + if (NULL == threads[i]) { + ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); + return ORTE_ERR_OUT_OF_RESOURCE; + } + threads[i]->t_run = thread_fn; + threads[i]->t_arg = (void*)i; + } + + /* run the threads */ + for (i=0; i < num_threads; i++) { + if (OMPI_SUCCESS != (rc = ompi_thread_start(threads[i]))) { + ORTE_ERROR_LOG(rc); + exit rc; + } + } + + /* finalize things */ + orte_finalize(); + + fclose( test_out ); + + test_finalize(); + + return(0); +} + +void thread_fn(ompi_object_t *obj) +{ +} diff --git a/test/mca/rds/Makefile.am b/test/mca/rds/Makefile.am index a83002cdec..b1daf43025 100644 --- a/test/mca/rds/Makefile.am +++ b/test/mca/rds/Makefile.am @@ -19,13 +19,13 @@ include $(top_srcdir)/config/Makefile.options AM_CPPFLAGS = -I$(top_srcdir)/test/support -DOMPI_ENABLE_DEBUG_OVERRIDE=1 check_PROGRAMS = \ - test_rds_resfile + test_rds TESTS = \ $(check_PROGRAMS) -test_rds_resfile_SOURCES = test_rds_resfile.c -test_rds_resfile_LDADD = \ +test_rds_SOURCES = test_rds.c +test_rds_LDADD = \ $(top_builddir)/test/support/libsupport.a \ $(top_builddir)/src/libmpi.la -test_rds_resfile_DEPENDENCIES = $(test_rds_resfile_LDADD) +test_rds_DEPENDENCIES = $(test_rds_LDADD) diff --git a/test/mca/rds/test_rds.c b/test/mca/rds/test_rds.c new file mode 100644 index 0000000000..1f7f44c88f --- /dev/null +++ b/test/mca/rds/test_rds.c @@ -0,0 +1,82 @@ +/* + * unit test for RDS resource file parser + + -------------------------------------------------------------------------- + + Authors: Ralph H. Castain + + -------------------------------------------------------------------------- + +*/ + +#include "orte_config.h" +#include +#include + +#include "support.h" + +#include "include/orte_constants.h" + +#include "runtime/runtime.h" +#include "mca/rds/base/base.h" + +/* output files needed by the test */ +static FILE *test_out=NULL; + +static char *cmd_str="diff ./test_ns_replica_out ./test_ns_replica_out_std"; + + +int +main(int argc, char **argv) +{ + int rc; + + test_init("test_rds_fn"); + + if (getenv("TEST_WRITE_TO_FILE") != NULL) { + test_out = fopen( "test_rds_fn", "w+" ); + } else { + test_out = stderr; + } + if( test_out == NULL ) { + test_failure("rds_fn couldn't open test file failed"); + test_finalize(); + exit(1); + } + + /* startup the runtime */ + if (OMPI_SUCCESS == orte_init()) { + fprintf(test_out, "orte_init completed\n"); + } else { + fprintf(test_out, "orte_init failed\n"); + exit (1); + } + + /* run the query */ + if (ORTE_SUCCESS != (rc = orte_rds_base_query())) { + fprintf(test_out, "RDS query failed with code %s\n", + ORTE_ERROR_NAME(rc)); + test_failure("test_rds_fn rds_query failed"); + test_finalize(); + exit(1); + } else { + fprintf(test_out, "RDS query succeeded\n"); + test_success(); + } + + /* finalize */ + orte_finalize(); + + fclose( test_out ); +/* result = system( cmd_str ); + if( result == 0 ) { + test_success(); + } + else { + test_failure( "test_rds failed"); + } +*/ + test_finalize(); + + exit (0); +} diff --git a/test/mca/rds/test_rds_resfile.c b/test/mca/rds/test_rds_resfile.c deleted file mode 100644 index 44232b0a1e..0000000000 --- a/test/mca/rds/test_rds_resfile.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * unit test for RDS resource file parser - - -------------------------------------------------------------------------- - - Authors: Ralph H. Castain - - -------------------------------------------------------------------------- - -*/ - -#include "orte_config.h" -#include -#include - -int main(int argc, char **argv) -{ - printf("Test oob_test disabled. Does not compile.\n"); - return 77; -} - -#if 0 - -#include "support.h" - -#include "include/orte_constants.h" -#include "include/constants.h" -#include "include/orte_names.h" - -#include "../../../src/mca/rds/resfile/resfile.h" - -/* output files needed by the test */ -static FILE *test_out=NULL; - -static char *cmd_str="diff ./test_ns_replica_out ./test_ns_replica_out_std"; - - -int -main(int argc, char **argv) -{ - test_init("test_ns_replica"); - - test_out = fopen( "test_ns_replica_out", "w+" ); - if( test_out == NULL ) { - test_failure("test_ns_replica couldn't open test file failed"); - test_finalize(); - exit(1); - } - - /* 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 rds framework */ - if (ORTE_SUCCESS == orte_rds_open()) { - fprintf(test_out, "RDS opened\n"); - } else { - fprintf(test_out, "RDS could not open\n"); - exit (1); - } - - /* startup the rds */ - if (ORTE_SUCCESS != orte_rds_base_select(&multi, &hidden)) { - fprintf(test_out, "RDS could not start\n"); - test_failure("test_rds_resfile orte_rds_base_select failed"); - test_finalize(); - exit(1); - } else { - fprintf(test_out, "RDS started\n"); - test_success(); - } - - /* setup the environment for the resfile component */ - setenv("OMPI_MCA_RESOURCE_FILE", "../../../src/etc/lanl_resources.xml"); - - /* call the rds resfile component */ - if (ORTE_SUCCESS != (rc = orte_rds_resfile_query())) { - fprintf(test_out, "RDS Resfile query failed with code %s\n", - ORTE_ERROR_NAME(rc)); - test_failure("test_rds_resfile rds_resfile_query failed"); - test_finalize(); - exit(1); - } else { - fprintf(test_out, "RDS resfile_query succeeded\n"); - test_success(); - } - -} - -#endif