1
1
This commit was SVN r2198.
Этот коммит содержится в:
Laura Casswell 2004-08-18 14:12:33 +00:00
родитель 9c2eea86bb
Коммит 8ba268c8dd
2 изменённых файлов: 125 добавлений и 140 удалений

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

@ -101,20 +101,6 @@ ompi_session_dir_DEPENDENCIES = $(ompi_session_dir_LDADD)
ompi_pack_SOURCES = ompi_pack.c ompi_pack_SOURCES = ompi_pack.c
ompi_pack_LDADD = \ ompi_pack_LDADD = \
$(top_builddir)/src/util/sys_info.lo \
$(top_builddir)/src/class/ompi_object.lo \
$(top_builddir)/src/util/malloc.lo \
$(top_builddir)/src/util/output.lo \
$(top_builddir)/src/util/argv.lo \
$(top_builddir)/src/util/strncpy.lo \
$(top_builddir)/src/threads/mutex.lo \
$(top_builddir)/src/threads/mutex_pthread.lo \
$(top_builddir)/src/threads/mutex_spinlock.lo \
$(top_builddir)/src/threads/mutex_spinwait.lo \
$(top_builddir)/src/util/os_path.lo \
$(top_builddir)/src/util/os_create_dirpath.lo \
$(top_builddir)/src/util/proc_info.lo \
$(top_builddir)/src/util/session_dir.lo \
$(top_builddir)/src/libmpi.la \ $(top_builddir)/src/libmpi.la \
$(top_builddir)/test/support/libsupport.la $(top_builddir)/test/support/libsupport.la
ompi_pack_DEPENDENCIES = $(ompi_session_dir_LDADD) ompi_pack_DEPENDENCIES = $(ompi_session_dir_LDADD)

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

@ -25,244 +25,243 @@ ompi_buffer_t bufC;
static bool test1(void); /* verify different buffer inits */ static bool test1(void); /* verify different buffer inits */
static bool test2(void); /* verify we can pack ok */ static bool test2(void); /* verify we can pack ok */
static bool test3(void); /* verify we can pack expanding buf */ static bool test3(void); /* verify we can pack expanding buf */
static bool test4(void); /* verify pack a packed buffer */ static bool test4(void); /* verify pack a packed buffer */
static bool test5(void); /* verify unpack */ static bool test5(void); /* verify unpack */
static bool test6(void); /* verify free */ static bool test6(void); /* verify free */
static bool test7(void); /* verify preallocated buffer init, pack and unpack */ static bool test7(void); /* verify preallocated buffer init, pack and unpack */
int main () int main (int argc, char* argv[])
{ {
test_init("ompi_pack"); test_init("ompi_pack");
if (test1()) { if (test1()) {
test_success(); test_success();
} }
else { else {
test_failure("ompi_pack test1 failed"); test_failure("ompi_pack test1 failed");
} }
if (test2()) { if (test2()) {
test_success(); test_success();
} }
else { else {
test_failure("ompi_pack test2 failed"); test_failure("ompi_pack test2 failed");
} }
if (test3()) { if (test3()) {
test_success(); test_success();
} }
else { else {
test_failure("ompi_pack test3 failed"); test_failure("ompi_pack test3 failed");
} }
if (test4()) { if (test4()) {
test_success(); test_success();
} }
else { else {
test_failure("ompi_pack test4 failed"); test_failure("ompi_pack test4 failed");
} }
if (test5()) { if (test5()) {
test_success(); test_success();
} }
else { else {
test_failure("ompi_pack test5 failed"); test_failure("ompi_pack test5 failed");
} }
if (test6()) { if (test6()) {
test_success(); test_success();
} }
else { else {
test_failure("ompi_pack test6 failed"); test_failure("ompi_pack test6 failed");
} }
if (test7()) { if (test7()) {
test_success(); test_success();
} }
else { else {
test_failure("ompi_pack test7 failed"); test_failure("ompi_pack test7 failed");
} }
/* if (testN()) { */ /* if (testN()) { */
/* test_success(); */ /* test_success(); */
/* } */ /* } */
/* else { */ /* else { */
/* test_failure("ompi_pack testN failed"); */ /* test_failure("ompi_pack testN failed"); */
/* } */ /* } */
test_finalize(); test_finalize();
return (0); return (0);
} }
static bool test1(void) /* verify different buffer inits */ static bool test1(void) /* verify different buffer inits */
{ {
int rc; int rc;
rc = ompi_buffer_init (&bufA, 0); rc = ompi_buffer_init (&bufA, 0);
if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_init failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_init failed"); return(false);}
rc = ompi_buffer_init (&bufB, 16); rc = ompi_buffer_init (&bufB, 16);
if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_init failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_init failed"); return(false);}
rc = ompi_buffer_init (&bufC, 1024); rc = ompi_buffer_init (&bufC, 1024);
if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_init failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_init failed"); return(false);}
return (true); return (true);
} }
/* BufA should hold 1024 INT32s */ /* BufA should hold 1024 INT32s */
static bool test2(void) /* verify we can pack ok */ static bool test2(void) /* verify we can pack ok */
{ {
int rc; int rc;
int i; int i;
for (i=0;i<1024;i++) { for (i=0;i<1024;i++) {
rc = ompi_pack (bufA, &i, 1, OMPI_INT32); rc = ompi_pack (bufA, &i, 1, OMPI_INT32);
if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);}
} }
return (true); return (true);
} }
/* BufB was init with 16 bytes not 1024 sizeof(INT32)s */ /* BufB was init with 16 bytes not 1024 sizeof(INT32)s */
/* so it should expand and keep packing */ /* so it should expand and keep packing */
static bool test3(void) /* verify we can pack expanding buf */ static bool test3(void) /* verify we can pack expanding buf */
{ {
int rc; int rc;
int i; int i;
int j; int j;
for (i=0;i<1024;i++) { for (i=0;i<1024;i++) {
j = i * 2; /* so we can verify */ j = i * 2; /* so we can verify */
rc = ompi_pack (bufB, &j, 1, OMPI_INT32); rc = ompi_pack (bufB, &j, 1, OMPI_INT32);
if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);}
} }
return (true); return (true);
} }
static bool test4(void) /* verify pack a packed buffer */ static bool test4(void) /* verify pack a packed buffer */
{ {
int rc; int rc;
rc = ompi_pack (bufC, bufA, 1, OMPI_PACKED); rc = ompi_pack (bufC, bufA, 1, OMPI_PACKED);
if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);}
rc = ompi_pack (bufC, bufB, 1, OMPI_PACKED); rc = ompi_pack (bufC, bufB, 1, OMPI_PACKED);
if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);}
return (true); return (true);
} }
static bool test5(void) /* verify unpack */ static bool test5(void) /* verify unpack */
{ {
int rc; int rc;
int i, j; int i, j;
int out; int out;
for (i=0;i<1024;i++) { for (i=0;i<1024;i++) {
j = i; /* for bufA */ j = i; /* for bufA */
rc = ompi_unpack (bufA, &out, 1, OMPI_INT32); rc = ompi_unpack (bufA, &out, 1, OMPI_INT32);
if (OMPI_ERROR==rc) { test_comment ("ompi_unpack failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_unpack failed"); return(false);}
if (out!=j) { test_comment ("bufA packed != unpacked data"); return(false);} if (out!=j) { test_comment ("bufA packed != unpacked data"); return(false);}
} }
for (i=0;i<1024;i++) { for (i=0;i<1024;i++) {
j = i*2; /* for bufB */ j = i*2; /* for bufB */
rc = ompi_unpack (bufB, &out, 1, OMPI_INT32); rc = ompi_unpack (bufB, &out, 1, OMPI_INT32);
if (OMPI_ERROR==rc) { test_comment ("ompi_unpack failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_unpack failed"); return(false);}
if (out!=j) { test_comment ("bufB packed != unpacked data"); return(false);} if (out!=j) { test_comment ("bufB packed != unpacked data"); return(false);}
} }
for (i=0;i<2048;i++) { for (i=0;i<2048;i++) {
if (i<1024) { j = i; /* bufAs data 1st half */ } if (i<1024) { j = i; /* bufAs data 1st half */ }
else { j = (i-1024)*2; /* bufBs data 2nd half */ } else { j = (i-1024)*2; /* bufBs data 2nd half */ }
rc = ompi_unpack (bufC, &out, 1, OMPI_INT32); rc = ompi_unpack (bufC, &out, 1, OMPI_INT32);
if (OMPI_ERROR==rc) { test_comment ("ompi_unpack failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_unpack failed"); return(false);}
if (out!=j) { if (out!=j) {
test_comment ("bufC packed != unpacked data"); test_comment ("bufC packed != unpacked data");
printf("iteration %d expected %d have %d\n", i, j, out); printf("iteration %d expected %d have %d\n", i, j, out);
return(false); return(false);
} }
} }
return (true); return (true);
} }
static bool test6(void) /* verify free */ static bool test6(void) /* verify free */
{ {
int rc; int rc;
rc = ompi_buffer_free (bufA); rc = ompi_buffer_free (bufA);
if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_free failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_free failed"); return(false);}
rc = ompi_buffer_free (bufB); rc = ompi_buffer_free (bufB);
if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_free failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_free failed"); return(false);}
rc = ompi_buffer_free (bufC); rc = ompi_buffer_free (bufC);
if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_free failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_free failed"); return(false);}
return (true); return (true);
} }
static bool test7(void) /* verify preallocated buffer init, pack and unpack */ static bool test7(void) /* verify preallocated buffer init, pack and unpack */
{ {
int rc; int rc;
int results[6]; int i, j, out;
int i, j, out; char *mybuf;
char *mybuf; int *p;
int *p;
/* we cannot use heap/static memory for a buffer as it cannot be realloced as needed for this test */ /* we cannot use heap/static memory for a buffer as it cannot be realloced as needed for this test */
mybuf = (char*) malloc (sizeof(int)*5); mybuf = (char*) malloc (sizeof(int)*5);
p = (int*) mybuf; p = (int*) mybuf;
for(i=0;i<5;i++) { for(i=0;i<5;i++) {
*p++ = htonl (i); /* the data must be in network byte order for this test to be valid */ *p++ = htonl (i); /* the data must be in network byte order for this test to be valid */
/* as the test is emulating prepacked data recvd from the network (OOB) */ /* as the test is emulating prepacked data recvd from the network (OOB) */
} }
rc = ompi_buffer_init_preallocated (&bufA, mybuf, sizeof(int)*5); rc = ompi_buffer_init_preallocated (&bufA, mybuf, sizeof(int)*5);
if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_init_preallocated failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_init_preallocated failed"); return(false);}
i = 5; i = 5;
rc = ompi_pack (bufA, &i, 1, OMPI_INT32); rc = ompi_pack (bufA, &i, 1, OMPI_INT32);
if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);}
/* ok, now check its contents */ /* ok, now check its contents */
for (i=0;i<6;i++) { for (i=0;i<6;i++) {
j = i; /* for bufA */ j = i; /* for bufA */
rc = ompi_unpack (bufA, &out, 1, OMPI_INT32); rc = ompi_unpack (bufA, &out, 1, OMPI_INT32);
if (OMPI_ERROR==rc) { test_comment ("ompi_unpack failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_unpack failed"); return(false);}
if (out!=j) { if (out!=j) {
test_comment ("bufA packed != unpacked data"); test_comment ("bufA packed != unpacked data");
printf("iteration %d expected %d have %d\n", i, j, out); printf("iteration %d expected %d have %d\n", i, j, out);
return(false); return(false);
} }
} }
/* I do not free mybuf as ompi_buffer_free() will */ /* I do not free mybuf as ompi_buffer_free() will */
rc = ompi_buffer_free (bufA); rc = ompi_buffer_free (bufA);
if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_free failed"); return(false);} if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_free failed"); return(false);}
return (true); return (true);
} }
/* int dump_buf (ompi_buffer_t buf) */ /* int dump_buf (ompi_buffer_t buf) */
@ -272,13 +271,13 @@ static bool test7(void) /* verify preallocated buffer init, pack and unpa
/* rc = 0; */ /* rc = 0; */
/* i = 0; */ /* i = 0; */
/* while (1) { */ /* while (1) { */
/* rc = ompi_unpack (buf, &out, 1, OMPI_INT32); */ /* rc = ompi_unpack (buf, &out, 1, OMPI_INT32); */
/* if (rc==0) printf("%d[%d] ", i, out); */ /* if (rc==0) printf("%d[%d] ", i, out); */
/* else { */ /* else { */
/* printf("\n"); */ /* printf("\n"); */
/* break; */ /* break; */
/* } */ /* } */
/* i++; */ /* i++; */
/* } */ /* } */
/* */ /* */
/* return (i); */ /* return (i); */