|
| 1 | +/* -*- Mode: C; c-basic-offset:4 ; -*- */ |
| 2 | +/* |
| 3 | + * Copyright (c) 2014-2017 Research Organization for Information Science |
| 4 | + * and Technology (RIST). All rights reserved. |
| 5 | + * $COPYRIGHT$ |
| 6 | + * |
| 7 | + * Additional copyrights may follow |
| 8 | + * |
| 9 | + * $HEADER$ |
| 10 | + */ |
| 11 | + |
| 12 | +#include "opal_config.h" |
| 13 | +#include "opal/runtime/opal.h" |
| 14 | +#include "opal/datatype/opal_datatype.h" |
| 15 | +#include "opal/datatype/opal_datatype_internal.h" |
| 16 | +#include "opal/datatype/opal_convertor.h" |
| 17 | +#include "opal/datatype/opal_datatype_prototypes.h" |
| 18 | +#include "opal/util/arch.h" |
| 19 | +#include <time.h> |
| 20 | +#include <stdlib.h> |
| 21 | +#ifdef HAVE_SYS_TIME_H |
| 22 | +#include <sys/time.h> |
| 23 | +#endif |
| 24 | +#include <stdio.h> |
| 25 | +#include <string.h> |
| 26 | + |
| 27 | +/* Compile with: |
| 28 | +gcc -DHAVE_CONFIG_H -I. -I../../include -I../.. -I../../include -I../../../ompi-trunk/opal -I../../../ompi-trunk/orte -g opal_datatype_test.c -o opal_datatype_test |
| 29 | +*/ |
| 30 | + |
| 31 | +uint32_t remote_arch = 0xffffffff; |
| 32 | + |
| 33 | +/** |
| 34 | + * Main function. Call several tests and print-out the results. It try to stress the convertor |
| 35 | + * using difficult data-type constructions as well as strange segment sizes for the conversion. |
| 36 | + * Usually, it is able to detect most of the data-type and convertor problems. Any modifications |
| 37 | + * on the data-type engine should first pass all the tests from this file, before going into other |
| 38 | + * tests. |
| 39 | + */ |
| 40 | +int main( int argc, char* argv[] ) |
| 41 | +{ |
| 42 | +#if OPAL_ENABLE_HETEROGENEOUS_SUPPORT |
| 43 | + opal_datatype_init(); |
| 44 | + |
| 45 | + /** |
| 46 | + * By default simulate homogeneous architectures. |
| 47 | + */ |
| 48 | + remote_arch = opal_local_arch ^ OPAL_ARCH_ISBIGENDIAN; |
| 49 | + |
| 50 | + opal_convertor_t * pConv; |
| 51 | + int sbuf[2], rbuf[2]; |
| 52 | + size_t max_data; |
| 53 | + struct iovec a; |
| 54 | + uint32_t iov_count; |
| 55 | + |
| 56 | + sbuf[0] = 0x01000000; sbuf[1] = 0x02000000; |
| 57 | + |
| 58 | + printf( "\n\n#\n * TEST UNPACKING 1 int out of 1\n#\n\n" ); |
| 59 | + |
| 60 | + pConv = opal_convertor_create( remote_arch, 0 ); |
| 61 | + rbuf[0] = -1; rbuf[1] = -1; |
| 62 | + if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( pConv, &opal_datatype_int4, 1, rbuf ) ) { |
| 63 | + printf( "Cannot attach the datatype to a convertor\n" ); |
| 64 | + return OPAL_ERROR; |
| 65 | + } |
| 66 | + |
| 67 | + a.iov_base = sbuf; |
| 68 | + a.iov_len = 4; |
| 69 | + iov_count = 1; |
| 70 | + max_data = 4; |
| 71 | + opal_unpack_general( pConv, &a, &iov_count, &max_data ); |
| 72 | + |
| 73 | + assert(1 == rbuf[0]); |
| 74 | + assert(-1 == rbuf[1]); |
| 75 | + OBJ_RELEASE(pConv); |
| 76 | + |
| 77 | + printf( "\n\n#\n * TEST UNPACKING 1 int out of 2\n#\n\n" ); |
| 78 | + pConv = opal_convertor_create( remote_arch, 0 ); |
| 79 | + rbuf[0] = -1; rbuf[1] = -1; |
| 80 | + if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( pConv, &opal_datatype_int4, 2, rbuf ) ) { |
| 81 | + printf( "Cannot attach the datatype to a convertor\n" ); |
| 82 | + return OPAL_ERROR; |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | + a.iov_base = sbuf; |
| 87 | + a.iov_len = 4; |
| 88 | + iov_count = 1; |
| 89 | + max_data = 4; |
| 90 | + opal_unpack_general( pConv, &a, &iov_count, &max_data ); |
| 91 | + |
| 92 | + assert(1 == rbuf[0]); |
| 93 | + assert(-1 == rbuf[1]); |
| 94 | + OBJ_RELEASE(pConv); |
| 95 | + |
| 96 | + /* clean-ups all data allocations */ |
| 97 | + opal_datatype_finalize(); |
| 98 | + opal_finalize(); |
| 99 | + return OPAL_SUCCESS; |
| 100 | +#else |
| 101 | + return 77; |
| 102 | +#endif |
| 103 | +} |
0 commit comments