diff --git a/test/asm/atomic_math.c b/test/asm/atomic_math.c index aadd555b49..57157e463b 100644 --- a/test/asm/atomic_math.c +++ b/test/asm/atomic_math.c @@ -33,10 +33,16 @@ int64_t val64 = 0; #endif int valint = 0; +typedef union { + int value; + void *ptr; +} ip_union_t; + static void* atomic_math_test(void* arg) { - int count = (int) (unsigned long) arg; + ip_union_t *ip = (ip_union_t*) arg; + int count = ip->value; int i; for (i = 0 ; i < count ; ++i) { @@ -57,12 +63,22 @@ atomic_math_test_th(int count, int thr_count) #if OMPI_HAVE_POSIX_THREADS pthread_t *th; int tid, ret = 0; + ip_union_t ip; th = (pthread_t *) malloc(thr_count * sizeof(pthread_t)); - if (!th) { perror("malloc"); exit(EXIT_FAILURE); } + if (!th) { + perror("malloc"); + exit(EXIT_FAILURE); + } + /* Ok to use a single instance of ip_union_t from the stack here + because a) we're passing the same count to all threads, and b) + we're waiting for all the threads to finish before leaving this + function, so there's no race condition of the instance + disappearing before the threads start. */ + ip.value = count; for (tid = 0; tid < thr_count; tid++) { - if (pthread_create(&th[tid], NULL, atomic_math_test, (void*) count) != 0) { + if (pthread_create(&th[tid], NULL, atomic_math_test, (void*) &ip) != 0) { perror("pthread_create"); exit(EXIT_FAILURE); } @@ -81,8 +97,10 @@ atomic_math_test_th(int count, int thr_count) return ret; #else + ip_union_t ip; + ip.value = count; if (thr_count == 1) { - atomic_math_test((void*) count); + atomic_math_test((void*) &ip); } else { return 77; } @@ -114,8 +132,10 @@ main(int argc, char *argv[]) } #if OMPI_HAVE_ATOMIC_MATH_64 if (val64 != TEST_REPS * num_threads * 6) { + /* Safe to case to (int) here because we know it's going to be + a small value */ printf("ompi_atomic_add32 failed. Expected %d, got %d.\n", - TEST_REPS * num_threads * 6, val64); + TEST_REPS * num_threads * 6, (int) val64); ret = 1; } #else diff --git a/test/dps/dps_test.c b/test/dps/dps_test.c index d77cdbcc31..6ca8f35e01 100644 --- a/test/dps/dps_test.c +++ b/test/dps/dps_test.c @@ -1162,7 +1162,8 @@ static bool test10(void) 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), "%d", j); + 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; @@ -1399,7 +1400,7 @@ static bool test12(void) rc = orte_dps.unpack(bufA, dst, &count, ORTE_APP_CONTEXT); if (ORTE_SUCCESS != rc || count != NUM_ELEMS) { test_comment ("orte_dps.unpack failed"); - fprintf(test_out, "orte_unpack_value failed with return code %d (count=%d)\n", rc, count); + fprintf(test_out, "orte_unpack_value failed with return code %d (count=%lu)\n", rc, (unsigned long) count); return(false); } @@ -1521,7 +1522,7 @@ static bool test13(void) rc = orte_dps.unpack(bufA, dst, &count, ORTE_GPR_SUBSCRIPTION); if (ORTE_SUCCESS != rc || count != NUM_ELEMS) { test_comment ("orte_dps.unpack failed"); - fprintf(test_out, "orte_unpack_value (ORTE_GPR_SUBSCRIPTION) failed with return code %d (count=%d)\n", rc, count); + fprintf(test_out, "orte_unpack_value (ORTE_GPR_SUBSCRIPTION) failed with return code %d (count=%lu)\n", rc, (unsigned long) count); return(false); } @@ -1643,7 +1644,7 @@ static bool test14(void) rc = orte_dps.unpack(bufA, dst, &count, ORTE_GPR_NOTIFY_DATA); if (ORTE_SUCCESS != rc || count != NUM_ELEMS) { test_comment ("orte_dps.unpack failed"); - fprintf(test_out, "orte_unpack_value (ORTE_GPR_NOTIFY_DATA) failed with return code %d (count=%d)\n", rc, count); + fprintf(test_out, "orte_unpack_value (ORTE_GPR_NOTIFY_DATA) failed with return code %d (count=%lu)\n", rc, (unsigned long) count); return(false); } diff --git a/test/mca/gpr/gpr_internal_fns.c b/test/mca/gpr/gpr_internal_fns.c index 2954707475..2c0d6071a2 100644 --- a/test/mca/gpr/gpr_internal_fns.c +++ b/test/mca/gpr/gpr_internal_fns.c @@ -257,7 +257,7 @@ int main(int argc, char **argv) fprintf(stderr, "creating tags\n"); for (i=0; i<10; i++) { - asprintf(&tmp, "test-tag-%d", i); + asprintf(&tmp, "test-tag-%lu", (unsigned long) i); 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)); @@ -273,7 +273,7 @@ int main(int argc, char **argv) fprintf(stderr, "lookup tags\n"); for (i=0; i<10; i++) { - asprintf(&tmp, "test-tag-%d", i); + asprintf(&tmp, "test-tag-%lu", (unsigned long) i); 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", @@ -290,7 +290,7 @@ int main(int argc, char **argv) fprintf(stderr, "reverse lookup tags\n"); for (i=0; i<10; i++) { - asprintf(&tmp2, "test-tag-%d", i); + asprintf(&tmp2, "test-tag-%lu", (unsigned long) 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", @@ -308,7 +308,7 @@ int main(int argc, char **argv) fprintf(stderr, "delete tags\n"); for (i=0; i<10; i++) { - asprintf(&tmp, "test-tag-%d", i); + asprintf(&tmp, "test-tag-%lu", (unsigned long) i); 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)); @@ -323,7 +323,7 @@ int main(int argc, char **argv) fprintf(stderr, "get itag list\n"); for (i=0; i < 14; i++) { - asprintf(&names[i], "dummy%d", i); + asprintf(&names[i], "dummy%lu", (unsigned long) i); } names[14] = NULL; num_names = 0; @@ -338,9 +338,11 @@ int main(int argc, char **argv) fprintf(test_out, "gpr_test: get itag list passed\n"); } - fprintf(test_out, "number of names found %d\n", num_names); + fprintf(test_out, "number of names found %lu\n", + (unsigned long) num_names); for (i=0; i < num_names; i++) { - fprintf(test_out, "\tname %s itag %d\n", names[i], itaglist[i]); + fprintf(test_out, "\tname %s itag %lu\n", names[i], + (unsigned long) itaglist[i]); } fprintf(stderr, "creating container\n"); @@ -359,7 +361,8 @@ int main(int argc, char **argv) fprintf(test_out, "itags for container\n"); for (i=0; i < cptr->num_itags; i++) { - fprintf(test_out, "\tindex %d itag %d\n", i, cptr->itags[i]); + fprintf(test_out, "\tindex %lu itag %lu\n", (unsigned long) i, + (unsigned long) cptr->itags[i]); } fprintf(stderr, "add keyval\n"); @@ -380,8 +383,8 @@ int main(int argc, char **argv) ivals = (orte_gpr_replica_itagval_t**)((cptr->itagvals)->addr); if (NULL != ivals[0]) { - fprintf(stderr, "ival[0] %d %d %d\n", ivals[0]->itag, - ivals[0]->type, ivals[0]->value.i16); + fprintf(stderr, "ival[0] %lu %d %d\n", (unsigned long) ivals[0]->itag, + ivals[0]->type, (int) ivals[0]->value.i16); } fprintf(stderr, "search container for single entry\n"); @@ -393,8 +396,8 @@ int main(int argc, char **argv) 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", - ORTE_ERROR_NAME(rc), itag2); + fprintf(test_out, "gpr_test: search container for single entry failed - returned %s for itag %lu\n", + ORTE_ERROR_NAME(rc), (unsigned long) itag2); test_failure("gpr_test: search container for single entry failed"); test_finalize(); return -1; @@ -423,11 +426,13 @@ int main(int argc, char **argv) for (i=0; i < (cptr->itagvals)->size; i++) { if (NULL != ivals[i]) { if (ivals[i]->type == ORTE_INT16) { - fprintf(stderr, "ival[%d] %d %d %d\n", i, ivals[i]->itag, - ivals[i]->type, ivals[i]->value.i16); + fprintf(stderr, "ival[%lu] %lu %d %d\n", (unsigned long) i, + (unsigned long) ivals[i]->itag, + ivals[i]->type, (int) ivals[i]->value.i16); } else if (ivals[i]->type == ORTE_STRING) { - fprintf(stderr, "ival[%d] %d %d %s\n", i, ivals[i]->itag, - ivals[i]->type, ivals[i]->value.strptr); + fprintf(stderr, "ival[%lu] %lu %d %s\n", (unsigned long) i, + (unsigned long) ivals[i]->itag, + ivals[i]->type, ivals[i]->value.strptr); } } } diff --git a/test/mca/gpr/gpr_mem_leaks.c b/test/mca/gpr/gpr_mem_leaks.c index 473d29dc5f..f7310f1e9a 100644 --- a/test/mca/gpr/gpr_mem_leaks.c +++ b/test/mca/gpr/gpr_mem_leaks.c @@ -185,12 +185,13 @@ int main(int argc, char **argv) val->num_tokens = 14; val->tokens = (char**)malloc(val->num_tokens * sizeof(char*)); for (i=0; i < 14; i++) { - asprintf(&(val->tokens[i]), "dummy%d", i); + asprintf(&(val->tokens[i]), "dummy%lu", (unsigned long) i); } val->keyvals = (orte_gpr_keyval_t**)malloc(20*sizeof(orte_gpr_keyval_t*)); for (i=0; i<20; i++) { val->keyvals[i] = OBJ_NEW(orte_gpr_keyval_t); - asprintf(&((val->keyvals[i])->key), "stupid-test-%d", i); + asprintf(&((val->keyvals[i])->key), "stupid-test-%lu", + (unsigned long) i); (val->keyvals[i])->type = ORTE_UINT32; (val->keyvals[i])->value.ui32 = (uint32_t)i; } @@ -242,7 +243,7 @@ int main(int argc, char **argv) val->num_tokens = 5; val->tokens = (char**)malloc(val->num_tokens * sizeof(char*)); for (i=0; i < 5; i++) { - asprintf(&(val->tokens[i]), "multi-dum-dum-%d", i); + asprintf(&(val->tokens[i]), "multi-dum-dum-%lu", (unsigned long) i); } val->keyvals = (orte_gpr_keyval_t**)malloc(sizeof(orte_gpr_keyval_t*)); val->keyvals[0] = OBJ_NEW(orte_gpr_keyval_t); @@ -250,7 +251,7 @@ int main(int argc, char **argv) (val->keyvals[0])->type = ORTE_STRING; (val->keyvals[0])->value.strptr = strdup("try-string-value"); for (i = 0; i < 10; i++) { - fprintf(stderr, "\tputting copy %d\n", i); + fprintf(stderr, "\tputting copy %lu\n", (unsigned long) i); if (ORTE_SUCCESS != (rc = gpr_module->put(1, &val))) { fprintf(test_out, "gpr_test: put multiple copies of one keyval in a container failed with error code %s\n", ORTE_ERROR_NAME(rc)); diff --git a/test/mca/gpr/gpr_overwrite.c b/test/mca/gpr/gpr_overwrite.c index b1dc5dbea1..db1c7f8ed0 100644 --- a/test/mca/gpr/gpr_overwrite.c +++ b/test/mca/gpr/gpr_overwrite.c @@ -322,8 +322,9 @@ int test_overwrite(ompi_list_t* nodes) { ompi_list_item_t* item; orte_gpr_value_t **values; - int rc, num_values, i, j; + int rc; test_node_t* node; + size_t i, j, num_values; num_values = ompi_list_get_size(nodes); if (0 >= num_values) { diff --git a/test/mca/gpr/gpr_put_get.c b/test/mca/gpr/gpr_put_get.c index 4db738c118..d9354fe551 100644 --- a/test/mca/gpr/gpr_put_get.c +++ b/test/mca/gpr/gpr_put_get.c @@ -195,7 +195,7 @@ int main(int argc, char **argv) val->num_tokens = 14; val->tokens = (char**)malloc(val->num_tokens * sizeof(char*)); for (i=0; i < 14; i++) { - asprintf(&(val->tokens[i]), "dummy%d", i); + asprintf(&(val->tokens[i]), "dummy%lu", (unsigned long) i); } val->keyvals = (orte_gpr_keyval_t**)malloc(sizeof(orte_gpr_keyval_t*)); val->keyvals[0] = OBJ_NEW(orte_gpr_keyval_t); @@ -221,12 +221,13 @@ int main(int argc, char **argv) val->num_tokens = 14; val->tokens = (char**)malloc(val->num_tokens * sizeof(char*)); for (i=0; i < 14; i++) { - asprintf(&(val->tokens[i]), "dummy%d", i); + asprintf(&(val->tokens[i]), "dummy%lu", (unsigned long) i); } val->keyvals = (orte_gpr_keyval_t**)malloc(20*sizeof(orte_gpr_keyval_t*)); for (i=0; i<20; i++) { val->keyvals[i] = OBJ_NEW(orte_gpr_keyval_t); - asprintf(&((val->keyvals[i])->key), "stupid-test-%d", i); + asprintf(&((val->keyvals[i])->key), "stupid-test-%lu", + (unsigned long) i); (val->keyvals[i])->type = ORTE_UINT32; (val->keyvals[i])->value.ui32 = (uint32_t)i; } @@ -248,13 +249,14 @@ int main(int argc, char **argv) val->num_tokens = 10; val->tokens = (char**)malloc(val->num_tokens * sizeof(char*)); for (i=0; i < val->num_tokens; i++) { - asprintf(&(val->tokens[i]), "dummy%d", i); + asprintf(&(val->tokens[i]), "dummy%lu", (unsigned long) i); } val->cnt = 20; val->keyvals = (orte_gpr_keyval_t**)malloc(val->cnt * sizeof(orte_gpr_keyval_t*)); for (i=0; icnt; i++) { val->keyvals[i] = OBJ_NEW(orte_gpr_keyval_t); - asprintf(&((val->keyvals[i])->key), "stupid-test-%d", i); + asprintf(&((val->keyvals[i])->key), "stupid-test-%lu", + (unsigned long) i); (val->keyvals[i])->type = ORTE_UINT32; (val->keyvals[i])->value.ui32 = (uint32_t)i; } @@ -301,11 +303,12 @@ int main(int argc, char **argv) fprintf(stderr, "get results:\n"); for (j=0; j < cnt; j++) { - fprintf(stderr, "value %d: cnt %d\t segment %s num_tokens %d\n", j, - values[j]->cnt, - values[j]->segment, values[j]->num_tokens); + fprintf(stderr, "value %lu: cnt %lu\t segment %s num_tokens %lu\n", + (unsigned long) j, (unsigned long) values[j]->cnt, + values[j]->segment, (unsigned long) values[j]->num_tokens); for (i=0; i < values[j]->num_tokens; i++) { - fprintf(stderr, "token: %d %s\n", i, values[j]->tokens[i]); + fprintf(stderr, "token: %lu %s\n", (unsigned long) i, + values[j]->tokens[i]); } kvals = values[j]->keyvals; for (i=0; i < values[j]->cnt; i++) { @@ -338,11 +341,12 @@ int main(int argc, char **argv) fprintf(stderr, "get results:\n"); for (j=0; j < cnt; j++) { - fprintf(stderr, "value %d: cnt %d\t segment %s num_tokens %d\n", j, - values[j]->cnt, - values[j]->segment, values[j]->num_tokens); + fprintf(stderr, "value %lu: cnt %lu\t segment %s num_tokens %lu\n", + (unsigned long) j, (unsigned long) values[j]->cnt, + values[j]->segment, (unsigned long) values[j]->num_tokens); for (i=0; i < values[j]->num_tokens; i++) { - fprintf(stderr, "token: %d %s\n", i, values[j]->tokens[i]); + fprintf(stderr, "token: %lu %s\n", (unsigned long) i, + values[j]->tokens[i]); } kvals = values[j]->keyvals; for (i=0; i < values[j]->cnt; i++) { @@ -360,7 +364,7 @@ int main(int argc, char **argv) val->num_tokens = 5; val->tokens = (char**)malloc(val->num_tokens * sizeof(char*)); for (i=0; i < 5; i++) { - asprintf(&(val->tokens[i]), "multi-dum-dum-%d", i); + asprintf(&(val->tokens[i]), "multi-dum-dum-%lu", (unsigned long) i); } val->keyvals = (orte_gpr_keyval_t**)malloc(sizeof(orte_gpr_keyval_t*)); val->keyvals[0] = OBJ_NEW(orte_gpr_keyval_t); @@ -368,7 +372,7 @@ int main(int argc, char **argv) (val->keyvals[0])->type = ORTE_STRING; (val->keyvals[0])->value.strptr = strdup("try-string-value"); for (i = 0; i < 10; i++) { - fprintf(stderr, "\tputting copy %d\n", i); + fprintf(stderr, "\tputting copy %lu\n", (unsigned long) i); if (ORTE_SUCCESS != (rc = gpr_module->put(1, &val))) { fprintf(test_out, "gpr_test: put multiple copies of one keyval in a container failed with error code %s\n", ORTE_ERROR_NAME(rc)); diff --git a/test/mca/ns/ns_replica.c b/test/mca/ns/ns_replica.c index d0db61a080..1b59184163 100644 --- a/test/mca/ns/ns_replica.c +++ b/test/mca/ns/ns_replica.c @@ -136,7 +136,7 @@ int main(int argc, char **argv) test_finalize(); exit(1); } else { - fprintf(test_out, "cellid created: %d\n", cell); + fprintf(test_out, "cellid created: %lu\n", (unsigned long) cell); test_success(); } @@ -148,7 +148,7 @@ int main(int argc, char **argv) test_finalize(); exit(1); } else { - fprintf(test_out, "jobid created: %d\n", job); + fprintf(test_out, "jobid created: %lu\n", (unsigned long) job); test_success(); } @@ -161,7 +161,8 @@ int main(int argc, char **argv) test_finalize(); exit(1); } else { - fprintf(test_out, "range reserved: %d\n", vpid); + fprintf(test_out, "range reserved: %lu\n", + (unsigned long) vpid); test_success(); } @@ -239,8 +240,9 @@ int main(int argc, char **argv) test_finalize(); exit(1); } - fprintf(test_out, "(%d) ints cell %0X(%ld) job %0X(%ld) vpid %0x(%ld)\n\n", - i, cell, (long int)cell, job, (long int)job, vpid, (long int)vpid); + fprintf(test_out, "(%d) ints cell %lu job %lu vpid %lu\n\n", + i, (unsigned long) cell, (unsigned long) job, + (unsigned long) vpid); free(test_name); } }