Added "put" function and completed unit test for it. Updated gpr.h to include mode "none" for empty flag.
This commit was SVN r2187.
Этот коммит содержится в:
родитель
c5ebf49f41
Коммит
b0ea8e0b06
@ -47,6 +47,9 @@
|
||||
|
||||
/** Define the mode bit-masks for registry operations.
|
||||
*/
|
||||
/** None
|
||||
*/
|
||||
#define OMPI_REGISTRY_NONE 0x0000
|
||||
/** Overwrite permission */
|
||||
#define OMPI_REGISTRY_OVERWRITE 0x0001
|
||||
/** AND tokens together for search results */
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "ompi_config.h"
|
||||
#include "include/constants.h"
|
||||
#include "util/output.h"
|
||||
#include "mca/gpr/base/base.h"
|
||||
#include "gpr_replica.h"
|
||||
#include "gpr_replica_internals.h"
|
||||
@ -69,19 +70,29 @@ int gpr_replica_put(ompi_registry_mode_t mode, char *segment,
|
||||
{
|
||||
ompi_list_t *keys;
|
||||
mca_gpr_keytable_t *keyptr;
|
||||
mca_gpr_keylist_t *new_keyptr;
|
||||
mca_gpr_registry_segment_t *seg;
|
||||
mca_gpr_registry_core_t *entry_ptr;
|
||||
ompi_registry_mode_t put_mode;
|
||||
int return_code;
|
||||
char **token;
|
||||
|
||||
|
||||
/* protect ourselves against errors */
|
||||
if (NULL == segment || NULL == object || 0 == size || NULL == tokens) {
|
||||
return OMPI_ERROR;
|
||||
}
|
||||
put_mode = mode & OMPI_REGISTRY_OVERWRITE; /* only overwrite permission mode flag allowed */
|
||||
|
||||
|
||||
token = tokens;
|
||||
|
||||
/* convert tokens to list of keys */
|
||||
keys = gpr_replica_get_key_list(segment, tokens);
|
||||
if (NULL == keys) {
|
||||
if (0 >= ompi_list_get_size(keys)) {
|
||||
return OMPI_ERROR;
|
||||
}
|
||||
|
||||
/* traverse the list to find undefined tokens - get new keys for them */
|
||||
for (keyptr = (mca_gpr_keytable_t*)ompi_list_get_first(keys);
|
||||
keyptr != (mca_gpr_keytable_t*)ompi_list_get_end(keys);
|
||||
@ -99,9 +110,44 @@ int gpr_replica_put(ompi_registry_mode_t mode, char *segment,
|
||||
}
|
||||
|
||||
/* see if specified entry already exists */
|
||||
for (entry_ptr = (mca_gpr_registry_core_t*)ompi_list_get_first(&seg->registry_entries);
|
||||
entry_ptr != (mca_gpr_registry_core_t*)ompi_list_get_end(&seg->registry_entries);
|
||||
entry_ptr = (mca_gpr_registry_core_t*)ompi_list_get_next(entry_ptr)) {
|
||||
if (gpr_replica_check_key_list(put_mode, keys, entry_ptr)) { /* found existing entry - overwrite if mode set, else error */
|
||||
if (put_mode) { /* overwrite enabled */
|
||||
free(entry_ptr->object);
|
||||
entry_ptr->object_size = size;
|
||||
entry_ptr->object = (ompi_registry_object_t*)malloc(size);
|
||||
memcpy(entry_ptr->object, object, size);
|
||||
return_code = OMPI_SUCCESS;
|
||||
goto CLEANUP;
|
||||
} else {
|
||||
return_code = OMPI_ERROR;
|
||||
goto CLEANUP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no existing entry - create new one */
|
||||
entry_ptr = OBJ_NEW(mca_gpr_registry_core_t);
|
||||
for (keyptr = (mca_gpr_keytable_t*)ompi_list_get_first(keys);
|
||||
keyptr != (mca_gpr_keytable_t*)ompi_list_get_end(keys);
|
||||
keyptr = (mca_gpr_keytable_t*)ompi_list_get_next(keyptr)) {
|
||||
new_keyptr = OBJ_NEW(mca_gpr_keylist_t);
|
||||
new_keyptr->key = keyptr->key;
|
||||
ompi_list_append(&entry_ptr->keys, &new_keyptr->item);
|
||||
}
|
||||
entry_ptr->object_size = size;
|
||||
entry_ptr->object = (ompi_registry_object_t*)malloc(size);
|
||||
memcpy(entry_ptr->object, object, size);
|
||||
ompi_list_append(&seg->registry_entries, &entry_ptr->item);
|
||||
|
||||
|
||||
CLEANUP:
|
||||
/* release list of keys */
|
||||
while (NULL != (keyptr = (mca_gpr_keytable_t*)ompi_list_remove_last(keys))) {
|
||||
OBJ_DESTRUCT(keyptr);
|
||||
}
|
||||
|
||||
return return_code;
|
||||
}
|
||||
@ -193,20 +239,12 @@ ompi_list_t* gpr_replica_get(ompi_registry_mode_t mode,
|
||||
reg = (mca_gpr_registry_core_t*)ompi_list_get_next(reg)) {
|
||||
|
||||
/* for each registry entry, check the key list */
|
||||
for (keyptr = (mca_gpr_keytable_t*)ompi_list_get_first(®->keys);
|
||||
keyptr != (mca_gpr_keytable_t*)ompi_list_get_end(®->keys);
|
||||
keyptr = (mca_gpr_keytable_t*)ompi_list_get_next(keyptr)) {
|
||||
if (gpr_replica_check_key_list(keys, keyptr->key)) { /* found the key on the list */
|
||||
if (OMPI_REGISTRY_OR == mode) { /* just needed to find one - add entry to list */
|
||||
ans = OBJ_NEW(ompi_registry_value_t);
|
||||
ans->object_size = reg->object_size;
|
||||
ans->object = (ompi_buffer_t*)malloc(ans->object_size);
|
||||
memcpy(ans->object, reg->object, ans->object_size);
|
||||
ompi_list_append(answer, &ans->item);
|
||||
}
|
||||
} else if (OMPI_REGISTRY_XAND == mode || OMPI_REGISTRY_XOR == mode) { /* key not on the list */
|
||||
break; /* don't include entry if mode was exclusive */
|
||||
}
|
||||
if (gpr_replica_check_key_list(mode, keys, reg)) { /* found the key(s) on the list */
|
||||
ans = OBJ_NEW(ompi_registry_value_t);
|
||||
ans->object_size = reg->object_size;
|
||||
ans->object = (ompi_buffer_t*)malloc(ans->object_size);
|
||||
memcpy(ans->object, reg->object, ans->object_size);
|
||||
ompi_list_append(answer, &ans->item);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,23 +115,20 @@ ompi_list_t *gpr_replica_get_key_list(char *segment, char **tokens)
|
||||
{
|
||||
ompi_list_t *keys;
|
||||
char **token;
|
||||
mca_gpr_keytable_t *keyptr, *dict_entry;
|
||||
|
||||
/* protect against errors */
|
||||
if (NULL == segment || NULL == tokens) {
|
||||
return NULL;
|
||||
}
|
||||
mca_gpr_keytable_t *keyptr;
|
||||
|
||||
token = tokens;
|
||||
keys = OBJ_NEW(ompi_list_t);
|
||||
|
||||
/* protect against errors */
|
||||
if (NULL == segment || NULL == tokens || NULL == *token) {
|
||||
return keys;
|
||||
}
|
||||
|
||||
while (NULL != *token) { /* traverse array of tokens until NULL */
|
||||
keyptr = OBJ_NEW(mca_gpr_keytable_t);
|
||||
if (NULL == (dict_entry = gpr_replica_find_dict_entry(segment, *token))) {
|
||||
keyptr->key = MCA_GPR_REPLICA_KEY_MAX; /* indicate unknown token */
|
||||
} else { /* found existing dictionary entry */
|
||||
keyptr->key = dict_entry->key;
|
||||
keyptr->token = strdup(dict_entry->token);
|
||||
}
|
||||
keyptr->token = strdup(*token);
|
||||
keyptr->key = gpr_replica_get_key(segment, *token);
|
||||
ompi_list_append(keys, &keyptr->item);
|
||||
token++;
|
||||
}
|
||||
@ -286,6 +283,7 @@ int gpr_replica_delete_key(char *segment, char *token)
|
||||
|
||||
int gpr_replica_empty_segment(mca_gpr_registry_segment_t *seg)
|
||||
{
|
||||
/* need to free memory from each entry - remove_last returns pointer to the entry */
|
||||
|
||||
/* empty the segment's registry */
|
||||
while (0 < ompi_list_get_size(&seg->registry_entries)) {
|
||||
@ -306,16 +304,24 @@ int gpr_replica_empty_segment(mca_gpr_registry_segment_t *seg)
|
||||
return OMPI_SUCCESS;
|
||||
}
|
||||
|
||||
bool gpr_replica_check_key_list(ompi_list_t *key_list, mca_gpr_replica_key_t key)
|
||||
bool gpr_replica_check_key_list(ompi_registry_mode_t mode, ompi_list_t *key_list, mca_gpr_registry_core_t *entry)
|
||||
{
|
||||
mca_gpr_keytable_t *keyptr;
|
||||
|
||||
for (keyptr = (mca_gpr_keytable_t*)ompi_list_get_first(&entry->keys);
|
||||
keyptr != (mca_gpr_keytable_t*)ompi_list_get_end(&entry->keys);
|
||||
keyptr = (mca_gpr_keytable_t*)ompi_list_get_next(keyptr)) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ompi_list_t *gpr_replica_test_internals(int level)
|
||||
{
|
||||
ompi_list_t *test_results;
|
||||
ompi_list_t *test_results, *keylist;
|
||||
ompi_registry_internal_test_results_t *result;
|
||||
char name[30], name2[30];
|
||||
char *name3[30];
|
||||
int i, j;
|
||||
mca_gpr_replica_key_t segkey, key;
|
||||
mca_gpr_registry_segment_t *seg;
|
||||
@ -398,7 +404,7 @@ ompi_list_t *gpr_replica_test_internals(int level)
|
||||
/* check ability to define key within a segment */
|
||||
success = true;
|
||||
result = OBJ_NEW(ompi_registry_internal_test_results_t);
|
||||
result->test = strdup("test-define-key");
|
||||
result->test = strdup("test-define-key-segment");
|
||||
for (i=0; i<5 && success; i++) {
|
||||
sprintf(name, "test-def-seg%d", i);
|
||||
for (j=0; j<10 && success; j++) {
|
||||
@ -416,6 +422,29 @@ ompi_list_t *gpr_replica_test_internals(int level)
|
||||
}
|
||||
ompi_list_append(test_results, &result->item);
|
||||
|
||||
|
||||
/* check ability to retrieve key within a segment */
|
||||
success = true;
|
||||
result = OBJ_NEW(ompi_registry_internal_test_results_t);
|
||||
result->test = strdup("test-get-key-segment");
|
||||
for (i=0; i<5 && success; i++) {
|
||||
sprintf(name, "test-def-seg%d", i);
|
||||
for (j=0; j<10 && success; j++) {
|
||||
sprintf(name2, "test-key%d", j);
|
||||
key = gpr_replica_get_key(name, name2);
|
||||
if (MCA_GPR_REPLICA_KEY_MAX == key) { /* got an error */
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
result->message = strdup("success");
|
||||
} else {
|
||||
result->message = strdup("failed");
|
||||
}
|
||||
ompi_list_append(test_results, &result->item);
|
||||
|
||||
|
||||
/* check ability to get dictionary entries */
|
||||
success = true;
|
||||
result = OBJ_NEW(ompi_registry_internal_test_results_t);
|
||||
@ -455,5 +484,31 @@ ompi_list_t *gpr_replica_test_internals(int level)
|
||||
}
|
||||
ompi_list_append(test_results, &result->item);
|
||||
}
|
||||
|
||||
|
||||
/* check ability to get key list */
|
||||
success = true;
|
||||
result = OBJ_NEW(ompi_registry_internal_test_results_t);
|
||||
result->test = strdup("test-get-keylist");
|
||||
for (i=0; i<5 && success; i++) {
|
||||
sprintf(name, "test-def-seg%d", i);
|
||||
for (j=0; j<10 && success; j++) {
|
||||
asprintf(&name3[j], "test-key%d", j);
|
||||
}
|
||||
name3[j] = NULL;
|
||||
keylist = gpr_replica_get_key_list(name, name3);
|
||||
if (0 >= ompi_list_get_size(keylist)) { /* error condition */
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
result->message = strdup("success");
|
||||
} else {
|
||||
result->message = strdup("failed");
|
||||
}
|
||||
ompi_list_append(test_results, &result->item);
|
||||
|
||||
/* check ability to empty segment */
|
||||
|
||||
return test_results;
|
||||
}
|
||||
|
@ -70,4 +70,4 @@ int gpr_replica_empty_segment(mca_gpr_registry_segment_t *seg);
|
||||
|
||||
ompi_list_t *gpr_replica_get_key_list(char *segment, char **tokens);
|
||||
|
||||
bool gpr_replica_check_key_list(ompi_list_t *key_list, mca_gpr_replica_key_t key);
|
||||
bool gpr_replica_check_key_list(ompi_registry_mode_t mode, ompi_list_t *key_list, mca_gpr_registry_core_t *entry);
|
||||
|
@ -35,10 +35,16 @@ int main(int argc, char **argv)
|
||||
ompi_list_t *test_list, *internal_tests;
|
||||
ompi_registry_index_value_t *ptr;
|
||||
ompi_registry_internal_test_results_t *ptri;
|
||||
ompi_registry_object_t *test_buffer;
|
||||
uint8_t *test_buf;
|
||||
ompi_registry_object_size_t input_size;
|
||||
ompi_registry_mode_t mode;
|
||||
bool multi, hidden;
|
||||
int i, j;
|
||||
bool success;
|
||||
char *tmp;
|
||||
int result; /* result from system call */
|
||||
char name[30], *name2[30];
|
||||
int result, put_test; /* result from system call */
|
||||
|
||||
test_init("test_gpr_replica");
|
||||
|
||||
@ -112,7 +118,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* check internals */
|
||||
internal_tests = ompi_registry.test_internals(1);
|
||||
if (0 == ompi_list_get_size(internal_tests)) { /* should have been something in dictionary */
|
||||
if (0 == ompi_list_get_size(internal_tests)) { /* should have been something in list */
|
||||
fprintf(test_out, "internal tests failed\n");
|
||||
test_failure("test_gpr_replica internal_tests failed\n");
|
||||
test_finalize();
|
||||
@ -128,6 +134,71 @@ int main(int argc, char **argv)
|
||||
test_success();
|
||||
}
|
||||
|
||||
/* test the put function */
|
||||
success = true;
|
||||
input_size = 10000;
|
||||
test_buffer = (ompi_registry_object_t*)malloc(input_size);
|
||||
test_buf = (uint8_t*)test_buffer;
|
||||
for (i=0; i<input_size; i++) {
|
||||
*test_buf = i % 256;
|
||||
test_buf++;
|
||||
}
|
||||
for (i=0; i<5 && success; i++) {
|
||||
sprintf(name, "test-def-seg%d", i);
|
||||
for (j=0; j<10 && success; j++) {
|
||||
asprintf(&name2[j], "test-key%d", j);
|
||||
}
|
||||
name2[j] = NULL;
|
||||
if (OMPI_SUCCESS != ompi_registry.put(OMPI_REGISTRY_NONE, name,
|
||||
name2, test_buffer, input_size)) {
|
||||
fprintf(test_out, "put test failed for segment %s\n", name);
|
||||
for (j=0; j<10; j++) {
|
||||
fprintf(test_out, "\t%s\n", name2[j]);
|
||||
}
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
fprintf(test_out, "put test: success\n");
|
||||
test_success();
|
||||
} else {
|
||||
fprintf(test_out, "put test failed\n");
|
||||
test_failure("test_gpr_replica put_test failed\n");
|
||||
test_finalize();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* test the put overwrite function */
|
||||
for (i=0; i<5 && success; i++) {
|
||||
sprintf(name, "test-def-seg%d", i);
|
||||
for (j=0; j<10 && success; j++) {
|
||||
asprintf(&name2[j], "test-key%d", j);
|
||||
}
|
||||
name2[j] = NULL;
|
||||
if (10 % i) {
|
||||
mode = OMPI_REGISTRY_OVERWRITE;
|
||||
} else {
|
||||
mode = OMPI_REGISTRY_NONE;
|
||||
}
|
||||
put_test = ompi_registry.put(mode, name, name2, test_buffer, input_size);
|
||||
if ((OMPI_REGISTRY_OVERWRITE == mode && OMPI_SUCCESS != put_test) ||
|
||||
(OMPI_REGISTRY_NONE == mode && OMPI_SUCCESS == put_test)) {
|
||||
fprintf(test_out, "put test failed for segment %s\n", name);
|
||||
for (j=0; j<10; j++) {
|
||||
fprintf(test_out, "\t%s\n", name2[j]);
|
||||
}
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
fprintf(test_out, "put overwrite test: success\n");
|
||||
test_success();
|
||||
} else {
|
||||
fprintf(test_out, "put overwrite test failed\n");
|
||||
test_failure("test_gpr_replica put_test failed\n");
|
||||
test_finalize();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* check the universe segment - should have a key value of "1" */
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user