2004-08-13 23:48:32 +04:00
|
|
|
|
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-08-13 23:48:32 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-10-20 05:03:09 +04:00
|
|
|
#include "ompi_config.h"
|
2004-08-17 03:07:10 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2004-08-13 23:48:32 +04:00
|
|
|
#include "support.h"
|
2004-08-17 03:07:10 +04:00
|
|
|
#include "mca/mpool/mpool.h"
|
|
|
|
|
|
|
|
static void *malloc_noalign(size_t size, size_t dummy) {
|
|
|
|
return malloc(size);
|
|
|
|
}
|
2004-08-13 23:48:32 +04:00
|
|
|
|
2004-08-30 05:25:03 +04:00
|
|
|
size_t offset;
|
|
|
|
static void *malloc_base_addr(void){
|
|
|
|
return (void *)offset;
|
|
|
|
}
|
|
|
|
|
2004-08-13 23:48:32 +04:00
|
|
|
#include "class/ompi_circular_buffer_fifo.h"
|
|
|
|
|
2004-08-17 03:07:10 +04:00
|
|
|
/* simple allocator for some simple tests */
|
|
|
|
mca_mpool_base_module_t pool = {
|
|
|
|
NULL, /* component structure */
|
2004-08-30 05:25:03 +04:00
|
|
|
malloc_base_addr, /* mca_mpool_base_module_address_fn_t */
|
2004-08-17 03:07:10 +04:00
|
|
|
malloc_noalign, /* mca_mpool_base_module_alloc_fn_t */
|
|
|
|
realloc, /* ca_mpool_base_module_realloc_fn_t */
|
|
|
|
free, /*mca_mpool_base_module_free_fn_t */
|
|
|
|
NULL, /* mca_mpool_base_module_register_fn_t */
|
|
|
|
NULL, /* mca_mpool_base_module_deregister_fn_t */
|
|
|
|
NULL /* mca_mpool_base_module_finalize_fn_t */
|
|
|
|
};
|
|
|
|
|
2004-08-13 23:48:32 +04:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
|
|
|
/* local variables */
|
2004-08-17 03:07:10 +04:00
|
|
|
ompi_cb_fifo_t fifo;
|
2004-08-19 02:52:02 +04:00
|
|
|
int i,size_of_fifo,lazy_free,return_status,error_cnt,loop_cnt;
|
2004-08-18 01:49:29 +04:00
|
|
|
void *ptr;
|
2004-08-25 00:18:29 +04:00
|
|
|
bool queue_empty;
|
2004-08-13 23:48:32 +04:00
|
|
|
|
2005-03-22 07:25:01 +03:00
|
|
|
#if 0
|
2004-08-13 23:48:32 +04:00
|
|
|
/* get queue size */
|
|
|
|
size_of_fifo=atoi(argv[1]);
|
2004-08-17 03:07:10 +04:00
|
|
|
lazy_free=atoi(argv[2]);
|
2004-08-19 02:52:02 +04:00
|
|
|
loop_cnt=atoi(argv[3]);
|
2004-08-30 05:25:03 +04:00
|
|
|
offset=atol(argv[4]);
|
2005-03-22 07:25:01 +03:00
|
|
|
#else
|
|
|
|
size_of_fifo = 5;
|
|
|
|
lazy_free = 1;
|
|
|
|
loop_cnt = 2;
|
|
|
|
offset = 2;
|
|
|
|
#endif
|
2004-08-13 23:48:32 +04:00
|
|
|
|
|
|
|
/* init result tracking */
|
|
|
|
test_init("ompi_circular_buffer_fifo");
|
|
|
|
|
2004-08-17 03:07:10 +04:00
|
|
|
/* init fifo */
|
|
|
|
return_status=ompi_cb_fifo_init(size_of_fifo,lazy_free,0,0,0,&fifo,
|
|
|
|
&pool);
|
2004-08-18 01:49:29 +04:00
|
|
|
/* check to see that retrun status is success */
|
|
|
|
if( OMPI_SUCCESS == return_status ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure(" ompi_cv_fifo_init \n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* populate fifo */
|
|
|
|
error_cnt=0;
|
|
|
|
for( i=0 ; i < ompi_cb_fifo_size(&fifo); i++ ) {
|
2004-08-30 05:25:03 +04:00
|
|
|
return_status=ompi_cb_fifo_write_to_head((void *)(i+5),&fifo,
|
|
|
|
(size_t)pool.mpool_base());
|
2004-08-18 01:49:29 +04:00
|
|
|
if( OMPI_CB_ERROR == return_status ) {
|
|
|
|
test_failure(" ompi_cb_fifo_write_to_head\n");
|
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( 0 == error_cnt ) {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try an over-fill the queue */
|
|
|
|
error_cnt=0;
|
|
|
|
for( i=0 ; i < 3 ; i++ ) {
|
2004-08-30 05:25:03 +04:00
|
|
|
return_status=ompi_cb_fifo_write_to_head((void *)i,&fifo,
|
|
|
|
(size_t)pool.mpool_base());
|
2004-08-18 01:49:29 +04:00
|
|
|
if( OMPI_CB_ERROR != return_status ) {
|
|
|
|
test_failure(" ompi_cb_fifo_write_to_head :: over-fill queue\n");
|
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( 0 == error_cnt ) {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pop items off the queue */
|
|
|
|
error_cnt=0;
|
|
|
|
for( i=0 ; i < ompi_cb_fifo_size(&fifo); i++ ) {
|
2004-08-30 05:25:03 +04:00
|
|
|
ptr=ompi_cb_fifo_read_from_tail(&fifo,0,&queue_empty,
|
|
|
|
(size_t)pool.mpool_base());
|
2004-08-18 01:49:29 +04:00
|
|
|
if( (void *)(i+5) != ptr ) {
|
|
|
|
test_failure(" ompi_cb_fifo_read_from_tail\n");
|
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( 0 == error_cnt ) {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free fifo */
|
|
|
|
return_status=ompi_cb_fifo_free(&fifo,&pool);
|
|
|
|
if( OMPI_SUCCESS == return_status ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure(" ompi_cv_fifo_init \n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init fifo - lazy_free greater than size ==> should return error*/
|
|
|
|
return_status=ompi_cb_fifo_init(size_of_fifo,size_of_fifo*2,0,0,0,&fifo,
|
|
|
|
&pool);
|
|
|
|
/* check to see that retrun status is success */
|
|
|
|
if( OMPI_SUCCESS != return_status ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure(" ompi_cv_fifo_init with lazy_free too large \n");
|
|
|
|
}
|
2004-08-17 03:07:10 +04:00
|
|
|
|
2004-08-18 01:49:29 +04:00
|
|
|
/* split the writting of data to the slot to a reserve, and then a
|
|
|
|
* write */
|
|
|
|
|
|
|
|
/* init fifo */
|
|
|
|
return_status=ompi_cb_fifo_init(size_of_fifo,lazy_free,0,0,0,&fifo,
|
|
|
|
&pool);
|
2004-08-17 03:07:10 +04:00
|
|
|
/* check to see that retrun status is success */
|
|
|
|
if( OMPI_SUCCESS == return_status ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure(" ompi_cv_fifo_init \n");
|
|
|
|
}
|
|
|
|
|
2004-08-18 01:49:29 +04:00
|
|
|
/* populate fifo */
|
|
|
|
error_cnt=0;
|
|
|
|
for( i=0 ; i < ompi_cb_fifo_size(&fifo); i++ ) {
|
2004-08-30 05:25:03 +04:00
|
|
|
return_status=ompi_cb_fifo_get_slot(&fifo,(size_t)pool.mpool_base());
|
2004-08-18 01:49:29 +04:00
|
|
|
if( OMPI_CB_ERROR == return_status ) {
|
|
|
|
test_failure(" ompi_cb_fifo_get_slot \n");
|
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( 0 == error_cnt ) {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try an over-fill the queue */
|
|
|
|
error_cnt=0;
|
|
|
|
for( i=0 ; i < 3 ; i++ ) {
|
2004-08-30 05:25:03 +04:00
|
|
|
return_status=ompi_cb_fifo_get_slot(&fifo,(size_t)pool.mpool_base());
|
2004-08-18 01:49:29 +04:00
|
|
|
if( OMPI_CB_ERROR != return_status ) {
|
|
|
|
test_failure(" ompi_cb_fifo_get_slot :: over-fill queue\n");
|
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( 0 == error_cnt ) {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write to slot - all slots previously reserved, so just use
|
|
|
|
* them now */
|
|
|
|
error_cnt=0;
|
|
|
|
for( i=0 ; i < ompi_cb_fifo_size(&fifo); i++ ) {
|
2004-08-30 05:25:03 +04:00
|
|
|
return_status=ompi_cb_fifo_write_to_slot(i,(void *)(i+5),&fifo,
|
|
|
|
(size_t)pool.mpool_base());
|
2004-08-18 01:49:29 +04:00
|
|
|
if( OMPI_CB_ERROR == return_status ) {
|
|
|
|
test_failure(" ompi_cb_fifo_write_to_slot \n");
|
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( 0 == error_cnt ) {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pop items off the queue */
|
|
|
|
error_cnt=0;
|
|
|
|
for( i=0 ; i < ompi_cb_fifo_size(&fifo); i++ ) {
|
2004-08-30 05:25:03 +04:00
|
|
|
ptr=ompi_cb_fifo_read_from_tail(&fifo,0,&queue_empty,
|
|
|
|
(size_t)pool.mpool_base());
|
2004-08-19 02:52:02 +04:00
|
|
|
if( (void *)(i+5) != ptr ) {
|
|
|
|
test_failure(" ompi_cb_fifo_read_from_tail\n");
|
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( 0 == error_cnt ) {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free fifo */
|
|
|
|
return_status=ompi_cb_fifo_free(&fifo,&pool);
|
|
|
|
if( OMPI_SUCCESS == return_status ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure(" ompi_cv_fifo_init \n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* go through the fifo multiple times */
|
|
|
|
|
|
|
|
/* init fifo */
|
|
|
|
return_status=ompi_cb_fifo_init(size_of_fifo,lazy_free,0,0,0,&fifo,
|
|
|
|
&pool);
|
|
|
|
/* check to see that retrun status is success */
|
|
|
|
if( OMPI_SUCCESS == return_status ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure(" ompi_cv_fifo_init \n");
|
|
|
|
}
|
|
|
|
|
|
|
|
error_cnt=0;
|
|
|
|
for( i=0 ; i < ompi_cb_fifo_size(&fifo)*loop_cnt ; i++ ) {
|
|
|
|
|
|
|
|
/* populate fifo */
|
2004-08-30 05:25:03 +04:00
|
|
|
return_status=ompi_cb_fifo_get_slot(&fifo,
|
|
|
|
(size_t)pool.mpool_base());
|
2004-08-19 02:52:02 +04:00
|
|
|
if( OMPI_CB_ERROR == return_status ) {
|
|
|
|
test_failure(" ompi_cb_fifo_get_slot \n");
|
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write to the slot */
|
|
|
|
return_status=ompi_cb_fifo_write_to_slot(i%(ompi_cb_fifo_size(&fifo)),
|
2004-08-30 05:25:03 +04:00
|
|
|
(void *)(i+5),&fifo, (size_t)pool.mpool_base());
|
2004-08-19 02:52:02 +04:00
|
|
|
if( OMPI_CB_ERROR == return_status ) {
|
|
|
|
test_failure(" ompi_cb_fifo_write_to_slot \n");
|
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pop items off the queue */
|
|
|
|
if( (i % ompi_cb_fifo_size(&fifo) ) ==
|
|
|
|
ompi_cb_fifo_size(&fifo)/2 ) {
|
|
|
|
/* force a flush */
|
2004-08-30 05:25:03 +04:00
|
|
|
ptr=ompi_cb_fifo_read_from_tail(&fifo,1,&queue_empty,
|
|
|
|
(size_t)pool.mpool_base());
|
2004-08-19 02:52:02 +04:00
|
|
|
} else {
|
2004-08-30 05:25:03 +04:00
|
|
|
ptr=ompi_cb_fifo_read_from_tail(&fifo,0,&queue_empty,
|
|
|
|
(size_t)pool.mpool_base());
|
2004-08-19 02:52:02 +04:00
|
|
|
}
|
2004-08-18 01:49:29 +04:00
|
|
|
if( (void *)(i+5) != ptr ) {
|
|
|
|
test_failure(" ompi_cb_fifo_read_from_tail\n");
|
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( 0 == error_cnt ) {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free fifo */
|
|
|
|
return_status=ompi_cb_fifo_free(&fifo,&pool);
|
|
|
|
if( OMPI_SUCCESS == return_status ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure(" ompi_cv_fifo_init \n");
|
|
|
|
}
|
2004-08-17 03:07:10 +04:00
|
|
|
|
2004-08-13 23:48:32 +04:00
|
|
|
/* finalize result tracking */
|
|
|
|
return test_finalize();
|
|
|
|
}
|