Added hook to test internal subsystems. Expanded unit test to exploit. Fixed a few bugs.
This commit was SVN r2177.
Этот коммит содержится в:
родитель
11c9295d6c
Коммит
964ad6ae46
@ -99,6 +99,18 @@ typedef struct ompi_registry_index_value_t ompi_registry_index_value_t;
|
|||||||
|
|
||||||
OBJ_CLASS_DECLARATION(ompi_registry_index_value_t);
|
OBJ_CLASS_DECLARATION(ompi_registry_index_value_t);
|
||||||
|
|
||||||
|
/** Return value for test results on internal test
|
||||||
|
*/
|
||||||
|
struct ompi_registry_internal_test_results_t {
|
||||||
|
ompi_list_item_t item; /**< Allows this item to be placed on a list */
|
||||||
|
char *test;
|
||||||
|
char *message;
|
||||||
|
};
|
||||||
|
typedef struct ompi_registry_internal_test_results_t ompi_registry_internal_test_results_t;
|
||||||
|
|
||||||
|
OBJ_CLASS_DECLARATION(ompi_registry_internal_test_results_t);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Component functions that MUST be provided
|
* Component functions that MUST be provided
|
||||||
*/
|
*/
|
||||||
@ -120,6 +132,11 @@ typedef int (*mca_gpr_base_module_unsubscribe_fn_t)(ompi_process_name_t* subscri
|
|||||||
ompi_registry_mode_t mode,
|
ompi_registry_mode_t mode,
|
||||||
char *segment, char **tokens);
|
char *segment, char **tokens);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* test interface for internal functions - optional to provide
|
||||||
|
*/
|
||||||
|
typedef ompi_list_t* (*mca_gpr_base_module_test_internals_fn_t)(int level);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ver 1.0.0
|
* Ver 1.0.0
|
||||||
@ -133,6 +150,7 @@ struct mca_gpr_base_module_1_0_0_t {
|
|||||||
mca_gpr_base_module_unsubscribe_fn_t unsubscribe;
|
mca_gpr_base_module_unsubscribe_fn_t unsubscribe;
|
||||||
mca_gpr_base_module_delete_fn_t delete_object;
|
mca_gpr_base_module_delete_fn_t delete_object;
|
||||||
mca_gpr_base_module_index_fn_t index;
|
mca_gpr_base_module_index_fn_t index;
|
||||||
|
mca_gpr_base_module_test_internals_fn_t test_internals;
|
||||||
};
|
};
|
||||||
typedef struct mca_gpr_base_module_1_0_0_t mca_gpr_base_module_1_0_0_t;
|
typedef struct mca_gpr_base_module_1_0_0_t mca_gpr_base_module_1_0_0_t;
|
||||||
typedef mca_gpr_base_module_1_0_0_t mca_gpr_base_module_t;
|
typedef mca_gpr_base_module_1_0_0_t mca_gpr_base_module_t;
|
||||||
|
@ -79,3 +79,11 @@ ompi_list_t* gpr_proxy_get(ompi_registry_mode_t mode, char *segment, char **toke
|
|||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ompi_list_t* gpr_proxy_test_internals(int level)
|
||||||
|
{
|
||||||
|
ompi_list_t *test_results;
|
||||||
|
|
||||||
|
test_results = OBJ_NEW(ompi_list_t);
|
||||||
|
|
||||||
|
return test_results;
|
||||||
|
}
|
||||||
|
@ -81,5 +81,6 @@ int gpr_proxy_unsubscribe(ompi_process_name_t *caller, ompi_registry_mode_t mode
|
|||||||
ompi_list_t* gpr_proxy_get(ompi_registry_mode_t mode,
|
ompi_list_t* gpr_proxy_get(ompi_registry_mode_t mode,
|
||||||
char *segment, char **tokens);
|
char *segment, char **tokens);
|
||||||
|
|
||||||
|
ompi_list_t* gpr_proxy_test_internals(int level);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -53,7 +53,8 @@ static mca_gpr_base_module_t mca_gpr_proxy = {
|
|||||||
gpr_proxy_subscribe,
|
gpr_proxy_subscribe,
|
||||||
gpr_proxy_unsubscribe,
|
gpr_proxy_unsubscribe,
|
||||||
gpr_proxy_delete,
|
gpr_proxy_delete,
|
||||||
gpr_proxy_index
|
gpr_proxy_index,
|
||||||
|
gpr_proxy_test_internals
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -66,6 +67,31 @@ static bool initialized = false;
|
|||||||
*/
|
*/
|
||||||
ompi_process_name_t *mca_gpr_my_replica;
|
ompi_process_name_t *mca_gpr_my_replica;
|
||||||
|
|
||||||
|
/* constructor - used to initialize state of test results instance */
|
||||||
|
static void ompi_registry_internal_test_results_construct(ompi_registry_internal_test_results_t* results)
|
||||||
|
{
|
||||||
|
results->test = NULL;
|
||||||
|
results->message = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* destructor - used to free any resources held by instance */
|
||||||
|
static void ompi_registry_internal_test_results_destructor(ompi_registry_internal_test_results_t* results)
|
||||||
|
{
|
||||||
|
if (NULL != results->test) {
|
||||||
|
free(results->test);
|
||||||
|
}
|
||||||
|
if (NULL != results->message) {
|
||||||
|
free(results->message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* define instance of ompi_class_t */
|
||||||
|
OBJ_CLASS_INSTANCE(
|
||||||
|
ompi_registry_internal_test_results_t, /* type name */
|
||||||
|
ompi_list_item_t, /* parent "class" name */
|
||||||
|
ompi_registry_internal_test_results_construct, /* constructor */
|
||||||
|
ompi_registry_internal_test_results_destructor); /* destructor */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* don't really need this function - could just put NULL in the above structure
|
* don't really need this function - could just put NULL in the above structure
|
||||||
|
@ -183,5 +183,6 @@ int gpr_replica_unsubscribe(ompi_process_name_t *caller, ompi_registry_mode_t mo
|
|||||||
char *segment, char **tokens);
|
char *segment, char **tokens);
|
||||||
ompi_list_t* gpr_replica_get(ompi_registry_mode_t mode,
|
ompi_list_t* gpr_replica_get(ompi_registry_mode_t mode,
|
||||||
char *segment, char **tokens);
|
char *segment, char **tokens);
|
||||||
|
ompi_list_t* gpr_replica_test_internals(int level);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -55,7 +55,8 @@ static mca_gpr_base_module_t mca_gpr_replica = {
|
|||||||
gpr_replica_subscribe,
|
gpr_replica_subscribe,
|
||||||
gpr_replica_unsubscribe,
|
gpr_replica_unsubscribe,
|
||||||
gpr_replica_delete_object,
|
gpr_replica_delete_object,
|
||||||
gpr_replica_index
|
gpr_replica_index,
|
||||||
|
gpr_replica_test_internals
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -93,6 +94,32 @@ OBJ_CLASS_INSTANCE(
|
|||||||
mca_gpr_keytable_destructor); /* destructor */
|
mca_gpr_keytable_destructor); /* destructor */
|
||||||
|
|
||||||
|
|
||||||
|
/* constructor - used to initialize state of test results instance */
|
||||||
|
static void ompi_registry_internal_test_results_construct(ompi_registry_internal_test_results_t* results)
|
||||||
|
{
|
||||||
|
results->test = NULL;
|
||||||
|
results->message = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* destructor - used to free any resources held by instance */
|
||||||
|
static void ompi_registry_internal_test_results_destructor(ompi_registry_internal_test_results_t* results)
|
||||||
|
{
|
||||||
|
if (NULL != results->test) {
|
||||||
|
free(results->test);
|
||||||
|
}
|
||||||
|
if (NULL != results->message) {
|
||||||
|
free(results->message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* define instance of ompi_class_t */
|
||||||
|
OBJ_CLASS_INSTANCE(
|
||||||
|
ompi_registry_internal_test_results_t, /* type name */
|
||||||
|
ompi_list_item_t, /* parent "class" name */
|
||||||
|
ompi_registry_internal_test_results_construct, /* constructor */
|
||||||
|
ompi_registry_internal_test_results_destructor); /* destructor */
|
||||||
|
|
||||||
|
|
||||||
/* constructor - used to initialize state of keylist instance */
|
/* constructor - used to initialize state of keylist instance */
|
||||||
static void mca_gpr_keylist_construct(mca_gpr_keylist_t* keylist)
|
static void mca_gpr_keylist_construct(mca_gpr_keylist_t* keylist)
|
||||||
{
|
{
|
||||||
|
@ -40,14 +40,11 @@ mca_gpr_registry_segment_t *gpr_replica_find_seg(char *segment)
|
|||||||
ptr_seg != (mca_gpr_keytable_t*)ompi_list_get_end(&mca_gpr_replica_head.segment_dict);
|
ptr_seg != (mca_gpr_keytable_t*)ompi_list_get_end(&mca_gpr_replica_head.segment_dict);
|
||||||
ptr_seg = (mca_gpr_keytable_t*)ompi_list_get_next(ptr_seg)) {
|
ptr_seg = (mca_gpr_keytable_t*)ompi_list_get_next(ptr_seg)) {
|
||||||
if (0 == strcmp(segment, ptr_seg->token)) {
|
if (0 == strcmp(segment, ptr_seg->token)) {
|
||||||
fprintf(stderr, "findseg: found segment token %s key %d\n", ptr_seg->token, (int)ptr_seg->key);
|
|
||||||
/* search mca_gpr_replica_head to find segment */
|
/* search mca_gpr_replica_head to find segment */
|
||||||
for (seg=(mca_gpr_registry_segment_t*)ompi_list_get_first(&mca_gpr_replica_head.registry);
|
for (seg=(mca_gpr_registry_segment_t*)ompi_list_get_first(&mca_gpr_replica_head.registry);
|
||||||
seg != (mca_gpr_registry_segment_t*)ompi_list_get_end(&mca_gpr_replica_head.registry);
|
seg != (mca_gpr_registry_segment_t*)ompi_list_get_end(&mca_gpr_replica_head.registry);
|
||||||
seg = (mca_gpr_registry_segment_t*)ompi_list_get_next(seg)) {
|
seg = (mca_gpr_registry_segment_t*)ompi_list_get_next(seg)) {
|
||||||
fprintf(stderr, "findseg: checking seg\n");
|
|
||||||
if(seg->segment == ptr_seg->key) {
|
if(seg->segment == ptr_seg->key) {
|
||||||
fprintf(stderr, "findseg: found segment key %d\n", (int)seg->segment);
|
|
||||||
return(seg);
|
return(seg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,3 +310,59 @@ bool gpr_replica_check_key_list(ompi_list_t *key_list, mca_gpr_replica_key_t key
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ompi_list_t *gpr_replica_test_internals(int level)
|
||||||
|
{
|
||||||
|
ompi_list_t *test_results;
|
||||||
|
ompi_registry_internal_test_results_t *result;
|
||||||
|
char name[30];
|
||||||
|
int i;
|
||||||
|
mca_gpr_replica_key_t segkey;
|
||||||
|
mca_gpr_registry_segment_t *seg;
|
||||||
|
|
||||||
|
test_results = OBJ_NEW(ompi_list_t);
|
||||||
|
|
||||||
|
/* create several test segments */
|
||||||
|
for (i=0; i<5; i++) {
|
||||||
|
sprintf(name, "test-def-seg%d", i);
|
||||||
|
result = OBJ_NEW(ompi_registry_internal_test_results_t);
|
||||||
|
result->test = strdup(name);
|
||||||
|
if (OMPI_SUCCESS != gpr_replica_define_segment(name)) {
|
||||||
|
result->message = strdup("failed");
|
||||||
|
} else {
|
||||||
|
result->message = strdup("success");
|
||||||
|
}
|
||||||
|
ompi_list_append(test_results, &result->item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check ability to get key for a segment */
|
||||||
|
result = OBJ_NEW(ompi_registry_internal_test_results_t);
|
||||||
|
result->test = strdup("test-get-seg-key");
|
||||||
|
segkey = gpr_replica_get_key(name, NULL);
|
||||||
|
if (MCA_GPR_REPLICA_KEY_MAX == segkey) { /* couldn't find it */
|
||||||
|
asprintf(&result->message, "failed to find segment %s", name);
|
||||||
|
} else {
|
||||||
|
asprintf(&result->message, "success: %d", segkey);
|
||||||
|
}
|
||||||
|
ompi_list_append(test_results, &result->item);
|
||||||
|
|
||||||
|
/* check the ability to find a segment */
|
||||||
|
i = 2;
|
||||||
|
sprintf(name, "test-def-seg%d", i);
|
||||||
|
result = OBJ_NEW(ompi_registry_internal_test_results_t);
|
||||||
|
result->test = strdup("test-find-seg");
|
||||||
|
seg = gpr_replica_find_seg(name);
|
||||||
|
if (NULL == seg) {
|
||||||
|
asprintf(&result->message, "test failed with NULL returned: %s", name);
|
||||||
|
} else { /* locate key and check it */
|
||||||
|
segkey = gpr_replica_get_key(name, NULL);
|
||||||
|
if (segkey == seg->segment) {
|
||||||
|
result->message = strdup("success");
|
||||||
|
} else {
|
||||||
|
asprintf(&result->message, "test failed: key %d seg %d", segkey, seg->segment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ompi_list_append(test_results, &result->item);
|
||||||
|
|
||||||
|
return test_results;
|
||||||
|
}
|
||||||
|
@ -32,6 +32,9 @@ static char *cmd_str="diff ./test_gpr_replica_out ./test_gpr_replica_out_std";
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
mca_gpr_replica_key_t test_key, test_key2;
|
mca_gpr_replica_key_t test_key, test_key2;
|
||||||
|
ompi_list_t *test_list, *internal_tests;
|
||||||
|
ompi_registry_index_value_t *ptr;
|
||||||
|
ompi_registry_internal_test_results_t *ptri;
|
||||||
bool multi, hidden;
|
bool multi, hidden;
|
||||||
int i, j;
|
int i, j;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
@ -78,40 +81,65 @@ int main(int argc, char **argv)
|
|||||||
test_success();
|
test_success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* define a key */
|
/* try to define a segment */
|
||||||
test_key = gpr_replica_define_key("universe", NULL);
|
if (OMPI_SUCCESS != ompi_registry.define_segment("test-segment")) {
|
||||||
if (0 == test_key) {
|
fprintf(test_out, "GPR replica: could not define segment\n");
|
||||||
fprintf(test_out, "GPR replica: failed define key - %d\n", test_key);
|
test_failure("test_gpr_replica define_segment failed");
|
||||||
test_failure("test_gpr_replica define_key failed");
|
|
||||||
test_finalize();
|
test_finalize();
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
fprintf(test_out, "GPR replica: define_key succeeded - %d\n", test_key);
|
fprintf(test_out, "GPR test segment defined\n");
|
||||||
test_success();
|
test_success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get a key - check for correctness */
|
/* check index */
|
||||||
test_key2 = gpr_replica_get_key("universe", NULL);
|
test_list = ompi_registry.index(NULL);
|
||||||
if (test_key != test_key2) {
|
if (0 == ompi_list_get_size(test_list)) { /* should have been something in dictionary */
|
||||||
fprintf(test_out, "GPR replica: mismatched keys - %d %d\n", test_key, test_key2);
|
fprintf(test_out, "GPR replica: index function failed\n");
|
||||||
test_failure("test_gpr_replica get_key failed");
|
test_failure("test_gpr_replica index_global_dictionary failed\n");
|
||||||
test_finalize();
|
test_finalize();
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
fprintf(test_out, "GPR replica: get_key succeeded\n");
|
fprintf(test_out, "GPR index returned list\n");
|
||||||
|
for (ptr = (ompi_registry_index_value_t*)ompi_list_get_first(test_list);
|
||||||
|
ptr != (ompi_registry_index_value_t*)ompi_list_get_end(test_list);
|
||||||
|
ptr = (ompi_registry_index_value_t*)ompi_list_get_next(ptr)) {
|
||||||
|
fprintf(test_out, "\t%s\n", ptr->token);
|
||||||
|
}
|
||||||
test_success();
|
test_success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* check internals */
|
||||||
|
internal_tests = ompi_registry.test_internals(1);
|
||||||
|
if (0 == ompi_list_get_size(internal_tests)) { /* should have been something in dictionary */
|
||||||
|
fprintf(test_out, "internal tests failed\n");
|
||||||
|
test_failure("test_gpr_replica internal_tests failed\n");
|
||||||
|
test_finalize();
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
fprintf(test_out, "internal test results list\n");
|
||||||
|
for (ptri = (ompi_registry_internal_test_results_t*)ompi_list_get_first(internal_tests);
|
||||||
|
ptri != (ompi_registry_internal_test_results_t*)ompi_list_get_end(internal_tests);
|
||||||
|
ptri = (ompi_registry_internal_test_results_t*)ompi_list_get_next(ptri)) {
|
||||||
|
fprintf(test_out, "\t%s\n", ptri->test);
|
||||||
|
fprintf(test_out, "\t%s\n", ptri->message);
|
||||||
|
}
|
||||||
|
test_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* check the universe segment - should have a key value of "1" */
|
||||||
|
|
||||||
fclose( test_out );
|
fclose( test_out );
|
||||||
result = system( cmd_str );
|
/* result = system( cmd_str );
|
||||||
if( result == 0 ) {
|
if( result == 0 ) {
|
||||||
test_success();
|
test_success();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
test_failure( "test_ns_replica ompi_name_server get_proc_name_string, etc failed");
|
test_failure( "test_gpr_replica ompi_registry init, etc failed");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
test_finalize();
|
test_finalize();
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user