root/test/dss/dss_payload.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main
  2. test1

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2016      Research Organization for Information Science
  13  *                         and Technology (RIST). All rights reserved.
  14  * $COPYRIGHT$
  15  *
  16  * Additional copyrights may follow
  17  *
  18  * $HEADER$
  19  */
  20 
  21 #include "opal_config.h"
  22 #include "opal/constants.h"
  23 
  24 #include <stdio.h>
  25 #include <string.h>
  26 #include <stdlib.h>
  27 
  28 #include "opal/runtime/opal.h"
  29 #include "opal/dss/dss.h"
  30 
  31 #define NUM_ITERS 100
  32 #define NUM_ELEMS 1024
  33 
  34 static bool test1(void);        /* verify dss_copy_payload */
  35 
  36 static FILE *test_out;
  37 
  38 
  39 int main (int argc, char* argv[])
  40 {
  41     int ret = 0;
  42 
  43     opal_init(&argc, &argv);
  44 
  45     test_out = stderr;
  46 
  47     /* run the tests */
  48 
  49     fprintf(test_out, "executing test1\n");
  50     if (test1()) {
  51         fprintf(test_out, "Test1 succeeded\n");
  52     } else {
  53         fprintf(test_out, "Test1 failed\n");
  54         ret = 1;
  55     }
  56 
  57     opal_finalize();
  58 
  59     return ret;
  60 }
  61 
  62 static bool test1(void)        /* verify dss_copy_payload */
  63 {
  64     opal_buffer_t *bufA, *bufB;
  65     int rc;
  66     int32_t i;
  67     int16_t src[NUM_ELEMS];
  68     int16_t dst[NUM_ELEMS];
  69     int32_t src32[NUM_ELEMS];
  70     int32_t dst32[NUM_ELEMS];
  71 
  72     /* init src arrays */
  73     for (i=0; i < NUM_ELEMS; i++) {
  74         src[i] = i;
  75         src32[i] = 132 * i;
  76     }
  77 
  78     /* init A */
  79     bufA = OBJ_NEW(opal_buffer_t);
  80     if (NULL == bufA) {
  81         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
  82         return false;
  83     }
  84 
  85     bufA->type = OPAL_DSS_BUFFER_NON_DESC;
  86 
  87     /* pack something in A */
  88     for (i=0;i<NUM_ITERS;i++) {
  89         rc = opal_dss.pack(bufA, src, NUM_ELEMS, OPAL_INT16);
  90         if (OPAL_SUCCESS != rc) {
  91             fprintf(test_out, "opal_dss.pack failed with return code %d\n", rc);
  92             return(false);
  93         }
  94     }
  95 
  96     /* setup bufB */
  97     bufB = OBJ_NEW(opal_buffer_t);
  98     if (NULL == bufB) {
  99         fprintf(test_out, "orte_buffer failed init in OBJ_NEW\n");
 100         return false;
 101     }
 102 
 103     bufB->type = OPAL_DSS_BUFFER_NON_DESC;
 104 
 105     /* pack something in B */
 106     for (i=0;i<NUM_ITERS;i++) {
 107         rc = opal_dss.pack(bufB, src32, NUM_ELEMS, OPAL_INT32);
 108         if (OPAL_SUCCESS != rc) {
 109             fprintf(test_out, "opal_dss.pack failed with return code %d\n", rc);
 110             return(false);
 111         }
 112     }
 113 
 114     /* copy payload to bufB */
 115     if (OPAL_SUCCESS != (rc = opal_dss.copy_payload(bufB, bufA))) {
 116         fprintf(test_out, "opal_dss.copy_payload failed with return code %d\n", rc);
 117         return(false);
 118     }
 119 
 120     /* pack some more stuff in B */
 121     for (i=0;i<NUM_ITERS;i++) {
 122         rc = opal_dss.pack(bufB, src32, NUM_ELEMS, OPAL_INT32);
 123         if (OPAL_SUCCESS != rc) {
 124             fprintf(test_out, "opal_dss.pack failed with return code %d\n", rc);
 125             return(false);
 126         }
 127     }
 128 
 129     /* validate the results */
 130     for (i=0; i<NUM_ITERS; i++) {
 131         int j;
 132         int32_t count;
 133 
 134         for(j=0; j<NUM_ELEMS; j++)
 135             dst32[j] = -1;
 136 
 137         count = NUM_ELEMS;
 138         rc = opal_dss.unpack(bufB, dst32, &count, OPAL_INT32);
 139         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 140             fprintf(test_out, "opal_dss.unpack of dest buffer failed with return code %d\n", rc);
 141             return(false);
 142         }
 143 
 144         for(j=0; j<NUM_ELEMS; j++) {
 145             if(src32[j] != dst32[j]) {
 146                 fprintf(test_out, "test1: invalid results from unpack of dest buffer\n");
 147                 return(false);
 148             }
 149         }
 150     }
 151 
 152     for (i=0; i<NUM_ITERS; i++) {
 153         int j;
 154         int32_t count;
 155 
 156         for(j=0; j<NUM_ELEMS; j++)
 157             dst[j] = -1;
 158 
 159         count = NUM_ELEMS;
 160         rc = opal_dss.unpack(bufB, dst, &count, OPAL_INT16);
 161         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 162             fprintf(test_out, "opal_dss.unpack of dest buffer failed with return code %d\n", rc);
 163             return(false);
 164         }
 165 
 166         for(j=0; j<NUM_ELEMS; j++) {
 167             if(src[j] != dst[j]) {
 168                 fprintf(test_out, "test1: invalid results from unpack of dest buffer\n");
 169                 return(false);
 170             }
 171         }
 172     }
 173 
 174     for (i=0; i<NUM_ITERS; i++) {
 175         int j;
 176         int32_t count;
 177 
 178         for(j=0; j<NUM_ELEMS; j++)
 179             dst32[j] = -1;
 180 
 181         count = NUM_ELEMS;
 182         rc = opal_dss.unpack(bufB, dst32, &count, OPAL_INT32);
 183         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 184             fprintf(test_out, "opal_dss.unpack of dest buffer failed with return code %d\n", rc);
 185             return(false);
 186         }
 187 
 188         for(j=0; j<NUM_ELEMS; j++) {
 189             if(src32[j] != dst32[j]) {
 190                 fprintf(test_out, "test1: invalid results from unpack of dest buffer\n");
 191                 return(false);
 192             }
 193         }
 194     }
 195 
 196     /* check that A is still okay */
 197     for (i=0; i<NUM_ITERS; i++) {
 198         int j;
 199         int32_t count;
 200 
 201         for(j=0; j<NUM_ELEMS; j++)
 202             dst[j] = -1;
 203 
 204         count = NUM_ELEMS;
 205         rc = opal_dss.unpack(bufA, dst, &count, OPAL_INT16);
 206         if (OPAL_SUCCESS != rc || count != NUM_ELEMS) {
 207             fprintf(test_out, "opal_dss.unpack of src buffer failed with return code %d\n", rc);
 208             return(false);
 209         }
 210 
 211         for(j=0; j<NUM_ELEMS; j++) {
 212             if(src[j] != dst[j]) {
 213                 fprintf(test_out, "test1: invalid results from unpack of src buffer\n");
 214                 return(false);
 215             }
 216         }
 217     }
 218 
 219     OBJ_RELEASE(bufA);
 220     OBJ_RELEASE(bufB);
 221     if (NULL != bufA || NULL != bufB) {
 222         fprintf(test_out, "OBJ_RELEASE did not NULL the buffer pointer\n");
 223         return false;
 224     }
 225 
 226     return (true);
 227 }
 228 
 229 

/* [<][>][^][v][top][bottom][index][help] */