From 959be36a9cdb90e382f829051b6800a252de2566 Mon Sep 17 00:00:00 2001 From: Graham Fagg Date: Thu, 12 Aug 2004 23:07:21 +0000 Subject: [PATCH] Added ompi_pack test and updated the Makefile.am to find it - the test suite put the test in a different memory layout than standalone and it did find a memory error straight away.... This commit was SVN r2097. --- test/util/Makefile.am | 22 ++++ test/util/ompi_pack.c | 228 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+) create mode 100644 test/util/ompi_pack.c diff --git a/test/util/Makefile.am b/test/util/Makefile.am index ee90e78df9..0ebbec7739 100644 --- a/test/util/Makefile.am +++ b/test/util/Makefile.am @@ -8,6 +8,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/test/support -DOMPI_ENABLE_DEBUG_OVERRIDE=1 noinst_PROGRAMS = \ ompi_numtostr \ + ompi_pack \ ompi_os_path \ ompi_sys_info \ ompi_os_create_dirpath \ @@ -97,3 +98,24 @@ ompi_session_dir_LDADD = \ $(top_builddir)/src/libmpi.la \ $(top_builddir)/test/support/libsupport.la ompi_session_dir_DEPENDENCIES = $(ompi_session_dir_LDADD) + +ompi_pack_SOURCES = ompi_pack.c +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)/test/support/libsupport.la +ompi_pack_DEPENDENCIES = $(ompi_session_dir_LDADD) + diff --git a/test/util/ompi_pack.c b/test/util/ompi_pack.c new file mode 100644 index 0000000000..6654de1d58 --- /dev/null +++ b/test/util/ompi_pack.c @@ -0,0 +1,228 @@ +/* + * $HEADER$ + */ + +#include +#include +#include +#include + +#include "ompi_config.h" +#include "util/sys_info.h" +#include "support.h" +#include "../src/util/pack.h" +#include "../src/include/constants.h" + +/* used for debugging */ +/* int dump_buf (ompi_buffer_t buf); */ + +ompi_buffer_t bufA; +ompi_buffer_t bufB; +ompi_buffer_t bufC; + + +static bool test1(void); /* verify different buffer inits */ +static bool test2(void); /* verify we can pack ok */ +static bool test3(void); /* verify we can pack expanding buf */ +static bool test4(void); /* verify pack a packed buffer */ +static bool test5(void); /* verify unpack */ +static bool test6(void); /* verity free */ + +int main () +{ + + test_init("ompi_pack"); + + if (test1()) { + test_success(); + } + else { + test_failure("ompi_pack test1 failed"); + } + + if (test2()) { + test_success(); + } + else { + test_failure("ompi_pack test2 failed"); + } + + if (test3()) { + test_success(); + } + else { + test_failure("ompi_pack test3 failed"); + } + + if (test4()) { + test_success(); + } + else { + test_failure("ompi_pack test4 failed"); + } + + if (test5()) { + test_success(); + } + else { + test_failure("ompi_pack test5 failed"); + } + + if (test6()) { + test_success(); + } + else { + test_failure("ompi_pack test6 failed"); + } + +/* if (testN()) { */ +/* test_success(); */ +/* } */ +/* else { */ +/* test_failure("ompi_pack testN failed"); */ +/* } */ + + + test_finalize(); + return (0); +} + +static bool test1(void) /* verify different buffer inits */ +{ + int rc; + + rc = ompi_buffer_init (&bufA, 0); + if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_init failed"); return(false);} + + rc = ompi_buffer_init (&bufB, 16); + if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_init failed"); return(false);} + + rc = ompi_buffer_init (&bufC, 1024); + if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_init failed"); return(false);} + + return (true); + + +} + +/* BufA should hold 1024 INT32s */ +static bool test2(void) /* verify we can pack ok */ +{ + int rc; + int i; + + for (i=0;i<1024;i++) { + rc = ompi_pack (bufA, &i, 1, OMPI_INT32); + if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);} + } + + return (true); +} + + +/* BufB was init with 16 bytes not 1024 sizeof(INT32)s */ +/* so it should expand and keep packing */ +static bool test3(void) /* verify we can pack expanding buf */ +{ + int rc; + int i; + int j; + + for (i=0;i<1024;i++) { + j = i * 2; /* so we can verify */ + rc = ompi_pack (bufB, &j, 1, OMPI_INT32); + if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);} + } + + return (true); +} + +static bool test4(void) /* verify pack a packed buffer */ +{ + int rc; + + rc = ompi_pack (bufC, bufA, 1, OMPI_PACKED); + if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);} + rc = ompi_pack (bufC, bufB, 1, OMPI_PACKED); + if (OMPI_ERROR==rc) { test_comment ("ompi_pack failed"); return(false);} + + return (true); +} + +static bool test5(void) /* verify unpack */ +{ + int rc; + int i, j; + int out; + + for (i=0;i<1024;i++) { + j = i; /* for bufA */ + rc = ompi_unpack (bufA, &out, 1, OMPI_INT32); + if (OMPI_ERROR==rc) { test_comment ("ompi_unpack failed"); return(false);} + + if (out!=j) { test_comment ("bufA packed != unpacked data"); return(false);} + } + + for (i=0;i<1024;i++) { + j = i*2; /* for bufB */ + rc = ompi_unpack (bufB, &out, 1, OMPI_INT32); + if (OMPI_ERROR==rc) { test_comment ("ompi_unpack failed"); return(false);} + + if (out!=j) { test_comment ("bufB packed != unpacked data"); return(false);} + } + + for (i=0;i<2048;i++) { + + if (i<1024) { j = i; /* bufAs data 1st half */ } + else { j = (i-1024)*2; /* bufBs data 2nd half */ } + + rc = ompi_unpack (bufC, &out, 1, OMPI_INT32); + if (OMPI_ERROR==rc) { test_comment ("ompi_unpack failed"); return(false);} + + if (out!=j) { + test_comment ("bufC packed != unpacked data"); + printf("iteration %d expected %d have %d\n", i, j, out); + return(false); + } + } + + + + + return (true); +} + +static bool test6(void) /* verity free */ +{ + int rc; + + rc = ompi_buffer_free (bufA); + if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_free failed"); return(false);} + rc = ompi_buffer_free (bufB); + if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_free failed"); return(false);} + rc = ompi_buffer_free (bufC); + if (OMPI_ERROR==rc) { test_comment ("ompi_buffer_free failed"); return(false);} + + return (true); +} + + +/* int dump_buf (ompi_buffer_t buf) */ +/* { */ +/* int rc, i, out; */ +/* */ +/* rc = 0; */ +/* i = 0; */ +/* while (1) { */ +/* rc = ompi_unpack (buf, &out, 1, OMPI_INT32); */ +/* if (rc==0) printf("%d[%d] ", i, out); */ +/* else { */ +/* printf("\n"); */ +/* break; */ +/* } */ +/* i++; */ +/* } */ +/* */ +/* return (i); */ +/* } */ +