[DAT/DAPL] DAT v2 extension tests
authorstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 15 Oct 2007 15:51:51 +0000 (15:51 +0000)
committerstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 15 Oct 2007 15:51:51 +0000 (15:51 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@860 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/dapl2/test/dtestx/SOURCES [new file with mode: 0644]
ulp/dapl2/test/dtestx/dtestx.c [new file with mode: 0644]
ulp/dapl2/test/dtestx/dtestx.rc [new file with mode: 0644]
ulp/dapl2/test/dtestx/makefile [new file with mode: 0644]

diff --git a/ulp/dapl2/test/dtestx/SOURCES b/ulp/dapl2/test/dtestx/SOURCES
new file mode 100644 (file)
index 0000000..a319339
--- /dev/null
@@ -0,0 +1,32 @@
+!if $(FREEBUILD)\r
+TARGETNAME=dtestx\r
+!else\r
+TARGETNAME=dtestxd\r
+!endif\r
+TARGETPATH=..\..\..\..\bin\user\obj$(BUILD_ALT_DIR)\r
+TARGETTYPE=PROGRAM\r
+UMTYPE=console\r
+USE_CRTDLL=1\r
+\r
+SOURCES=dtestx.rc      \\r
+               dtestx.c\r
+\r
+INCLUDES=.;..\..\dat\include;$(SDK_INC_PATH);\r
+\r
+RCOPTIONS=/I..\..\..\..\inc;\r
+\r
+# Set defines particular to the driver.\r
+# DAT_EXTENSIONS set by default\r
+#USER_C_FLAGS=$(USER_C_FLAGS) /DDAT_EXTENSIONS\r
+\r
+!if $(FREEBUILD)\r
+DATLIB=dat2.lib\r
+!else\r
+DATLIB=dat2d.lib\r
+!endif\r
+\r
+TARGETLIBS=$(TARGETPATH)\*\$(DATLIB) $(SDK_LIB_PATH)\ws2_32.lib\r
+\r
+# XXX do this ASAP - MSC_WARNING_LEVEL= /W3\r
+MSC_WARNING_LEVEL= /W1\r
+\r
diff --git a/ulp/dapl2/test/dtestx/dtestx.c b/ulp/dapl2/test/dtestx/dtestx.c
new file mode 100644 (file)
index 0000000..5fa26de
--- /dev/null
@@ -0,0 +1,906 @@
+/*\r
+ * Copyright (c) 2007 Intel Corporation.  All rights reserved.\r
+ *\r
+ * This software is available to you under a choice of one of two\r
+ * licenses.  You may choose to be licensed under the terms of the GNU\r
+ * General Public License (GPL) Version 2, available from the file\r
+ * COPYING in the main directory of this source tree, or the\r
+ * OpenIB.org BSD license below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ *\r
+ * $Id: $\r
+ */\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+#if defined(_WIN32) || defined(_WIN64)\r
+#include <windows.h>\r
+#include <winsock2.h>\r
+#include <ws2tcpip.h>\r
+#include <io.h>\r
+#include <process.h>\r
+\r
+#define getpid _getpid\r
+#define PRIx64 "%llx" \r
+#define DAPL_PROVIDER "ibnic0v2d"\r
+#else\r
+#include <netdb.h>\r
+#include <sys/socket.h>\r
+#include <netinet/in.h>\r
+#include <netinet/tcp.h>\r
+#include <arpa/inet.h>\r
+#include <endian.h>\r
+#include <byteswap.h>\r
+#define DAPL_PROVIDER "OpenIB-cma"\r
+#endif\r
+\r
+#include "dat/udat.h"\r
+#include "dat/dat_ib_extensions.h"\r
+\r
+int disconnect_ep(void);\r
+\r
+#define _OK(status, str) \\r
+{ \\r
+       const char  *maj_msg, *min_msg; \\r
+       if (status != DAT_SUCCESS) { \\r
+               dat_strerror(status, &maj_msg, &min_msg); \\r
+               fprintf(stderr, str " returned %s : %s\n", maj_msg, min_msg); \\r
+               exit(1); \\r
+       } \\r
+}\r
+\r
+#define _OK2(status, str) \\r
+{ \\r
+       const char  *maj_msg, *min_msg; \\r
+       if (status != DAT_SUCCESS) { \\r
+               dat_strerror(status, &maj_msg, &min_msg); \\r
+               fprintf(stderr, str " returned %s : %s\n", maj_msg, min_msg); \\r
+               exit(1); \\r
+       } \\r
+}\r
+\r
+#define DTO_TIMEOUT       (1000*1000*5)\r
+#define CONN_TIMEOUT      (1000*1000*10)\r
+#define SERVER_TIMEOUT    (1000*1000*120)\r
+#define SERVER_CONN_QUAL       31111\r
+#define BUF_SIZE               256\r
+#define BUF_SIZE_ATOMIC                8\r
+#define REG_MEM_COUNT          10\r
+#define SND_RDMA_BUF_INDEX     0\r
+#define RCV_RDMA_BUF_INDEX     1\r
+#define SEND_BUF_INDEX         2\r
+#define RECV_BUF_INDEX         3\r
+\r
+DAT_VADDR              *atomic_buf;\r
+DAT_LMR_HANDLE         lmr_atomic;\r
+DAT_LMR_CONTEXT                lmr_atomic_context;\r
+DAT_RMR_CONTEXT                rmr_atomic_context;\r
+DAT_VLEN               reg_atomic_size;\r
+DAT_VADDR              reg_atomic_addr;\r
+DAT_LMR_HANDLE         lmr[ REG_MEM_COUNT ];\r
+DAT_LMR_CONTEXT                lmr_context[ REG_MEM_COUNT ];\r
+DAT_RMR_TRIPLET                rmr[ REG_MEM_COUNT ];\r
+DAT_RMR_CONTEXT                rmr_context[ REG_MEM_COUNT ];\r
+DAT_VLEN               reg_size[ REG_MEM_COUNT ];\r
+DAT_VADDR              reg_addr[ REG_MEM_COUNT ];\r
+DAT_RMR_TRIPLET *      buf[ REG_MEM_COUNT ];\r
+DAT_EP_HANDLE          ep;\r
+DAT_EVD_HANDLE         async_evd = DAT_HANDLE_NULL;\r
+DAT_IA_HANDLE          ia = DAT_HANDLE_NULL;\r
+DAT_PZ_HANDLE          pz = DAT_HANDLE_NULL;\r
+DAT_EVD_HANDLE         cr_evd = DAT_HANDLE_NULL;\r
+DAT_EVD_HANDLE         con_evd = DAT_HANDLE_NULL;\r
+DAT_EVD_HANDLE         dto_evd = DAT_HANDLE_NULL;\r
+DAT_PSP_HANDLE         psp = DAT_HANDLE_NULL;\r
+DAT_CR_HANDLE          cr = DAT_HANDLE_NULL;\r
+int                    server;\r
+\r
+char *usage = "-s | hostname (default == -s)\n";\r
+\r
+#if defined(_WIN32) || defined(_WIN64)\r
+static void sleep(int secs)\r
+{\r
+       Sleep(secs*1000);\r
+}\r
+#define _WSACleanup() WSACleanup()\r
+#else\r
+#define        _WSACleanup()\r
+#endif\r
+\r
+void\r
+send_msg(\r
+       void *data,\r
+       DAT_COUNT size,\r
+       DAT_LMR_CONTEXT context,\r
+       DAT_DTO_COOKIE cookie,\r
+       DAT_COMPLETION_FLAGS flags)\r
+{\r
+       DAT_LMR_TRIPLET                 iov;\r
+       DAT_EVENT                       event;\r
+       DAT_COUNT                       nmore;\r
+       DAT_RETURN                      status;\r
+       DAT_DTO_COMPLETION_EVENT_DATA *dto_event = \r
+               &event.event_data.dto_completion_event_data;\r
+\r
+       iov.lmr_context     = context;\r
+       iov.virtual_address = (DAT_VADDR)data;\r
+       iov.segment_length  = (DAT_VLEN)size;\r
+\r
+       status = dat_ep_post_send(ep,\r
+                                  1,\r
+                                  &iov,\r
+                                  cookie,\r
+                                  flags);\r
+       _OK(status, "dat_ep_post_send");\r
+\r
+       if (! (flags & DAT_COMPLETION_SUPPRESS_FLAG)) {\r
+               status = dat_evd_wait(dto_evd, DTO_TIMEOUT, 1, &event, &nmore);\r
+               _OK(status, "dat_evd_wait after dat_ep_post_send");\r
+\r
+               if (event.event_number != DAT_DTO_COMPLETION_EVENT) {\r
+                       printf("unexpected event waiting for post_send "\r
+                               "completion - 0x%x\n", event.event_number);\r
+                       exit(1);\r
+               }\r
+\r
+               _OK(dto_event->status, "event status for post_send");\r
+       }\r
+}\r
+\r
+int\r
+connect_ep(char *hostname)\r
+{\r
+       DAT_SOCK_ADDR           remote_addr;\r
+       DAT_EP_ATTR             ep_attr;\r
+       DAT_RETURN              status;\r
+       DAT_REGION_DESCRIPTION  region;\r
+       DAT_EVENT               event;\r
+       DAT_COUNT               nmore;\r
+       DAT_LMR_TRIPLET         iov;\r
+       DAT_RMR_TRIPLET         r_iov;\r
+       DAT_DTO_COOKIE          cookie;\r
+       int                     i;\r
+       DAT_DTO_COMPLETION_EVENT_DATA *dto_event = \r
+               &event.event_data.dto_completion_event_data;\r
+\r
+       status = dat_ia_open(DAPL_PROVIDER, 8, &async_evd, &ia);\r
+       _OK(status, "dat_ia_open");\r
+\r
+       status = dat_pz_create(ia, &pz);\r
+       _OK(status, "dat_pz_create");\r
+\r
+       status = dat_evd_create(ia, 10, DAT_HANDLE_NULL, DAT_EVD_CR_FLAG,\r
+                               &cr_evd );\r
+       _OK(status, "dat_evd_create CR");\r
+       status = dat_evd_create(ia, 10, DAT_HANDLE_NULL,\r
+                               DAT_EVD_CONNECTION_FLAG, &con_evd );\r
+       _OK(status, "dat_evd_create CR");\r
+       status = dat_evd_create(ia, 10, DAT_HANDLE_NULL, DAT_EVD_DTO_FLAG,\r
+                               &dto_evd );\r
+       _OK(status, "dat_evd_create DTO");\r
+\r
+       memset(&ep_attr, 0, sizeof(ep_attr));\r
+       ep_attr.service_type                = DAT_SERVICE_TYPE_RC;\r
+       ep_attr.max_rdma_size               = 0x10000;\r
+       ep_attr.qos                         = 0;\r
+       ep_attr.recv_completion_flags       = 0;\r
+       ep_attr.max_recv_dtos               = 10;\r
+       ep_attr.max_request_dtos            = 10;\r
+       ep_attr.max_recv_iov                = 1;\r
+       ep_attr.max_request_iov             = 1;\r
+       ep_attr.max_rdma_read_in            = 4;\r
+       ep_attr.max_rdma_read_out           = 4;\r
+       ep_attr.request_completion_flags    = DAT_COMPLETION_DEFAULT_FLAG;\r
+       ep_attr.ep_transport_specific_count = 0;\r
+       ep_attr.ep_transport_specific       = NULL;\r
+       ep_attr.ep_provider_specific_count  = 0;\r
+       ep_attr.ep_provider_specific        = NULL;\r
+\r
+       status = dat_ep_create(ia, pz, dto_evd, dto_evd, con_evd, &ep_attr, &ep);\r
+       _OK(status, "dat_ep_create");\r
+\r
+       for (i = 0; i < REG_MEM_COUNT; i++) {\r
+               buf[ i ] = (DAT_RMR_TRIPLET*)malloc(BUF_SIZE);\r
+               region.for_va = buf[ i ];\r
+               status = dat_lmr_create(ia,\r
+                                       DAT_MEM_TYPE_VIRTUAL,\r
+                                       region,\r
+                                       BUF_SIZE,\r
+                                       pz,\r
+                                       DAT_MEM_PRIV_ALL_FLAG|DAT_IB_MEM_PRIV_REMOTE_ATOMIC,\r
+                                       DAT_VA_TYPE_VA,\r
+                                       &lmr[ i ],\r
+                                       &lmr_context[ i ],\r
+                                       &rmr_context[ i ],\r
+                                       &reg_size[ i ],\r
+                                       &reg_addr[ i ]);\r
+               _OK(status, "dat_lmr_create");\r
+       }\r
+\r
+       /* register atomic return buffer for original data */\r
+       atomic_buf = (DAT_UINT64*)malloc(BUF_SIZE);\r
+       region.for_va = atomic_buf;\r
+       status = dat_lmr_create(ia,\r
+                               DAT_MEM_TYPE_VIRTUAL,\r
+                               region,\r
+                               BUF_SIZE_ATOMIC,\r
+                               pz,\r
+                               DAT_MEM_PRIV_ALL_FLAG|DAT_IB_MEM_PRIV_REMOTE_ATOMIC,\r
+                               DAT_VA_TYPE_VA,\r
+                               &lmr_atomic,\r
+                               &lmr_atomic_context,\r
+                               &rmr_atomic_context,\r
+                               &reg_atomic_size,\r
+                               &reg_atomic_addr);\r
+       _OK(status, "dat_lmr_create atomic");\r
+       \r
+       for (i = RECV_BUF_INDEX; i < REG_MEM_COUNT; i++) {\r
+               cookie.as_64        = i;\r
+               iov.lmr_context     = lmr_context[ i ];\r
+               iov.virtual_address = (DAT_VADDR) buf[ i ];\r
+               iov.segment_length  = BUF_SIZE;\r
+\r
+               status = dat_ep_post_recv(ep,\r
+                                          1,\r
+                                          &iov,\r
+                                          cookie,\r
+                                          DAT_COMPLETION_DEFAULT_FLAG);\r
+               _OK(status, "dat_ep_post_recv");\r
+       }\r
+\r
+       /* setup receive buffer to initial string to be overwritten */\r
+       strcpy((char*)buf[ RCV_RDMA_BUF_INDEX ], "blah, blah, blah\n");\r
+\r
+       if (server) {\r
+\r
+               strcpy((char*)buf[ SND_RDMA_BUF_INDEX ], "server written data");\r
+\r
+               status = dat_psp_create(ia,\r
+                                       SERVER_CONN_QUAL,\r
+                                        cr_evd,\r
+                                        DAT_PSP_CONSUMER_FLAG,\r
+                                        &psp);\r
+               _OK(status, "dat_psp_create");\r
+\r
+               printf("Server waiting for connect request\n");\r
+               status = dat_evd_wait(cr_evd, SERVER_TIMEOUT, 1, &event, &nmore);\r
+               _OK(status, "listen dat_evd_wait");\r
+\r
+               if (event.event_number != DAT_CONNECTION_REQUEST_EVENT) {\r
+                       printf("unexpected event after dat_psp_create: 0x%x\n",\r
+                               event.event_number); \r
+                       exit(1);\r
+               }\r
+\r
+               if ((event.event_data.cr_arrival_event_data.conn_qual != SERVER_CONN_QUAL) ||\r
+                    (event.event_data.cr_arrival_event_data.sp_handle.psp_handle != psp)) {\r
+\r
+                       printf("wrong cr event data\n");\r
+                       exit(1);\r
+               }\r
+\r
+               cr = event.event_data.cr_arrival_event_data.cr_handle;\r
+               status = dat_cr_accept(cr, ep, 0, (DAT_PVOID)0);\r
+\r
+       } else {\r
+               struct addrinfo *target;\r
+               int                             rval;\r
+\r
+               if (getaddrinfo (hostname, NULL, NULL, &target) != 0) {\r
+                       printf("Error getting remote address.\n");\r
+                       exit(1);\r
+               }\r
+\r
+               rval = ((struct sockaddr_in *)target->ai_addr)->sin_addr.s_addr;\r
+               printf ("Server Name: %s \n", hostname);\r
+               printf ("Server Net Address: %d.%d.%d.%d\n",\r
+                   (rval >>  0) & 0xff,\r
+                   (rval >>  8) & 0xff,\r
+                   (rval >> 16) & 0xff,\r
+                   (rval >> 24) & 0xff);\r
+\r
+               remote_addr = *((DAT_IA_ADDRESS_PTR)target->ai_addr);\r
+\r
+               strcpy((char*)buf[ SND_RDMA_BUF_INDEX ], "client written data");\r
+\r
+               status = dat_ep_connect(ep,\r
+                                        &remote_addr,\r
+                                        SERVER_CONN_QUAL,\r
+                                        CONN_TIMEOUT,\r
+                                        0,\r
+                                        (DAT_PVOID)0,\r
+                                        0,\r
+                                        DAT_CONNECT_DEFAULT_FLAG );\r
+               _OK(status, "dat_psp_create");\r
+       }\r
+\r
+       printf("Client waiting for connect response\n");\r
+       status = dat_evd_wait(con_evd, CONN_TIMEOUT, 1, &event, &nmore);\r
+               _OK(status, "connect dat_evd_wait");\r
+\r
+       if (event.event_number != DAT_CONNECTION_EVENT_ESTABLISHED) {\r
+               printf("unexpected event after dat_ep_connect: 0x%x\n", event.event_number); \r
+               exit(1);\r
+       }\r
+\r
+       printf("Connected!\n");\r
+\r
+       /*\r
+        *  Setup our remote memory and tell the other side about it\r
+        */\r
+       printf("Sending RMR data to remote\n");\r
+       r_iov.rmr_context    = rmr_context[ RCV_RDMA_BUF_INDEX ];\r
+       r_iov.virtual_address = (DAT_VADDR) buf[ RCV_RDMA_BUF_INDEX ];\r
+       r_iov.segment_length = BUF_SIZE;\r
+\r
+       *buf[ SEND_BUF_INDEX ] = r_iov;\r
+\r
+       send_msg(       buf[ SEND_BUF_INDEX ],\r
+                       sizeof(DAT_RMR_TRIPLET),\r
+                       lmr_context[ SEND_BUF_INDEX ],\r
+                       cookie,\r
+                       DAT_COMPLETION_SUPPRESS_FLAG);\r
+\r
+       /*\r
+        *  Wait for their RMR\r
+        */\r
+       printf("Waiting for remote to send RMR data\n");\r
+       status = dat_evd_wait(dto_evd, DTO_TIMEOUT, 1, &event, &nmore);\r
+       _OK(status, "dat_evd_wait after dat_ep_post_send");\r
+\r
+       if (event.event_number != DAT_DTO_COMPLETION_EVENT) {\r
+               printf("unexpected event waiting for RMR context - 0x%x\n", \r
+                       event.event_number);\r
+               exit(1);\r
+       }\r
+\r
+       _OK(dto_event->status, "event status for post_send");\r
+       if ((dto_event->transfered_length != sizeof(DAT_RMR_TRIPLET)) ||\r
+            (dto_event->user_cookie.as_64 != RECV_BUF_INDEX)) {\r
+               printf("unexpected event data for receive: len=%d cookie=%d "\r
+                       "expected %d/%d\n",\r
+                       (int)dto_event->transfered_length,\r
+                       (int)dto_event->user_cookie.as_64,\r
+                       sizeof(DAT_RMR_TRIPLET), RECV_BUF_INDEX);\r
+               exit(1);\r
+       }\r
+\r
+       r_iov = *buf[ RECV_BUF_INDEX ];\r
+\r
+       printf("Received RMR from remote: r_iov: ctx=%x,va=%p,len=%d\n",\r
+               r_iov.rmr_context,\r
+               (void*)iov.virtual_address,\r
+               r_iov.segment_length);\r
+\r
+       return(0);\r
+}\r
+\r
+int\r
+disconnect_ep(void)\r
+{\r
+       DAT_RETURN      status;\r
+       int             i;\r
+       DAT_EVENT       event;\r
+       DAT_COUNT       nmore;\r
+\r
+       status = dat_ep_disconnect(ep, DAT_CLOSE_DEFAULT);\r
+       _OK2(status, "dat_ep_disconnect");\r
+\r
+       status = dat_evd_wait(con_evd, DAT_TIMEOUT_INFINITE, 1,\r
+                                       &event, &nmore);\r
+       _OK(status, "dat_evd_wait");\r
+       \r
+       if (server) {\r
+               status = dat_psp_free(psp);\r
+               _OK2(status, "dat_psp_free");\r
+       }\r
+\r
+       for (i = 0; i < REG_MEM_COUNT; i++) {\r
+               status = dat_lmr_free(lmr[ i ]);\r
+               _OK2(status, "dat_lmr_free");\r
+       }\r
+\r
+       if (lmr_atomic) {\r
+               status = dat_lmr_free(lmr_atomic);\r
+               _OK2(status, "dat_lmr_free_atomic");\r
+       }\r
+\r
+       status = dat_ep_free(ep);\r
+       _OK2(status, "dat_ep_free");\r
+\r
+       status = dat_evd_free(dto_evd);\r
+       _OK2(status, "dat_evd_free DTO");\r
+       status = dat_evd_free(con_evd);\r
+       _OK2(status, "dat_evd_free CON");\r
+       status = dat_evd_free(cr_evd);\r
+       _OK2(status, "dat_evd_free CR");\r
+\r
+       status = dat_pz_free(pz);\r
+       _OK2(status, "dat_pz_free");\r
+\r
+       status = dat_ia_close(ia, DAT_CLOSE_DEFAULT);\r
+       _OK2(status, "dat_ia_close");\r
+\r
+       return(0);\r
+}\r
+\r
+int\r
+do_immediate()\r
+{\r
+       DAT_REGION_DESCRIPTION  region;\r
+       DAT_EVENT               event;\r
+       DAT_COUNT               nmore;\r
+       DAT_LMR_TRIPLET         iov;\r
+       DAT_RMR_TRIPLET         r_iov;\r
+       DAT_DTO_COOKIE          cookie;\r
+       DAT_RMR_CONTEXT         their_context;\r
+       DAT_RETURN              status;\r
+       DAT_UINT32              immed_data;\r
+       DAT_UINT32              immed_data_recv;\r
+       DAT_DTO_COMPLETION_EVENT_DATA *dto_event = \r
+               &event.event_data.dto_completion_event_data;\r
+       DAT_IB_EXTENSION_EVENT_DATA *ext_event = \r
+               (DAT_IB_EXTENSION_EVENT_DATA *)&event.event_extension_data[0];\r
+\r
+       printf("\nDoing RDMA WRITE IMMEDIATE DATA\n");\r
+\r
+       if (server) {\r
+               immed_data = 0x1111;\r
+       } else {\r
+               immed_data = 0x7777;\r
+       }\r
+\r
+       cookie.as_64 = 0x5555;\r
+       \r
+       r_iov = *buf[ RECV_BUF_INDEX ];\r
+\r
+       iov.lmr_context     = lmr_context[ SND_RDMA_BUF_INDEX ];\r
+       iov.virtual_address = (DAT_VADDR) buf[ SND_RDMA_BUF_INDEX ];\r
+       iov.segment_length  = BUF_SIZE;\r
+\r
+       cookie.as_64 = 0x9999;\r
+       \r
+       status = dat_ib_post_rdma_write_immed(ep,               // ep_handle\r
+                                               1,              // num_segments\r
+                                               &iov,           // LMR\r
+                                               cookie,         // user_cookie\r
+                                               &r_iov,         // RMR\r
+                                               immed_data,\r
+                                               DAT_COMPLETION_DEFAULT_FLAG);\r
+       _OK(status, "dat_ib_post_rdma_write_immed");\r
+\r
+       /*\r
+        *  Collect first event, write completion or the inbound recv with immed\r
+        */\r
+       status = dat_evd_wait(dto_evd, DTO_TIMEOUT, 1, &event, &nmore);\r
+       _OK(status, "dat_evd_wait after dat_ib_post_rdma_write");\r
+       if (event.event_number != DAT_IB_DTO_EVENT)\r
+       {\r
+               printf("unexpected event #0x%x waiting for WR-IMMED #0x%x\n", \r
+                       event.event_number,DAT_IB_DTO_EVENT);\r
+               exit(1);\r
+       }\r
+       \r
+       if (nmore) printf("%s() nmore %d\n",__FUNCTION__,nmore);\r
+       _OK(dto_event->status, "DTO event status");\r
+       if (ext_event->type == DAT_IB_RDMA_WRITE_IMMED)\r
+       {\r
+         if ((dto_event->transfered_length != BUF_SIZE) ||\r
+            (dto_event->user_cookie.as_64 != 0x9999)) \r
+         {\r
+              printf("unexpected event data for rdma_write_immed: len=%d "\r
+                       "cookie=0x%x\n",\r
+                       (int)dto_event->transfered_length,\r
+                       (int)dto_event->user_cookie.as_64);\r
+             exit(1);\r
+         }\r
+       } \r
+       else if (ext_event->type == DAT_IB_RDMA_WRITE_IMMED_DATA)\r
+        {\r
+         if ((dto_event->transfered_length != BUF_SIZE) ||\r
+            (dto_event->user_cookie.as_64 != RECV_BUF_INDEX+1)) \r
+         {\r
+               printf("unexpected event data of immediate write: len=%d "\r
+                       "cookie=%d expected %d/%d\n",\r
+                       (int)dto_event->transfered_length,\r
+                       (int)dto_event->user_cookie.as_64,\r
+                       sizeof(int), RECV_BUF_INDEX+1);\r
+               exit(1);\r
+         }\r
+         \r
+         /* get immediate data from event */\r
+         immed_data_recv = ext_event->val.immed.data;\r
+       }\r
+       else\r
+       {\r
+               printf("unexpected extension type for event - 0x%x, 0x%x\n", \r
+                       event.event_number, ext_event->type);\r
+               exit(1);\r
+       }\r
+\r
+\r
+       /*\r
+        *  Collect second event, write completion or inbound recv with immed\r
+        */\r
+       status = dat_evd_wait(dto_evd, DTO_TIMEOUT, 1, &event, &nmore);\r
+       _OK(status, "dat_evd_wait after dat_ib_post_rdma_write");\r
+       if (event.event_number != DAT_IB_DTO_EVENT)\r
+       {\r
+               printf("unexpected event # waiting for WR-IMMED - 0x%x\n", \r
+                       event.event_number);\r
+               exit(1);\r
+       }\r
+       \r
+       _OK(dto_event->status, "event status");\r
+       if (ext_event->type == DAT_IB_RDMA_WRITE_IMMED)\r
+       {\r
+         if ((dto_event->transfered_length != BUF_SIZE) ||\r
+            (dto_event->user_cookie.as_64 != 0x9999)) \r
+         {\r
+              printf("unexpected event data for rdma_write_immed: len=%d "\r
+                       "cookie=0x%x\n",\r
+                       (int)dto_event->transfered_length,\r
+                       (int)dto_event->user_cookie.as_64);\r
+             exit(1);\r
+         }\r
+       } \r
+       else if (ext_event->type == DAT_IB_RDMA_WRITE_IMMED_DATA)\r
+        {\r
+         if ((dto_event->transfered_length != BUF_SIZE) ||\r
+            (dto_event->user_cookie.as_64 != RECV_BUF_INDEX+1)) \r
+         {\r
+               printf("unexpected event data of immediate write: len=%d "\r
+                       "cookie=%d expected %d/%d\n",\r
+                       (int)dto_event->transfered_length,\r
+                       (int)dto_event->user_cookie.as_64,\r
+                       sizeof(int), RECV_BUF_INDEX+1);\r
+               exit(1);\r
+         }\r
+         \r
+         /* get immediate data from event */\r
+         immed_data_recv = ext_event->val.immed.data;\r
+       }\r
+       else\r
+       {\r
+               printf("unexpected extension type for event - 0x%x, 0x%x\n", \r
+                       event.event_number, ext_event->type);\r
+               exit(1);\r
+       }\r
+               \r
+       if ((server) && (immed_data_recv != 0x7777))\r
+       {\r
+               printf("ERROR: Server: unexpected immed_data_recv 0x%x/0x%x\n", \r
+                       0x7777,  immed_data_recv);\r
+               exit(1);\r
+       } \r
+       else if ((!server) && (immed_data_recv != 0x1111))\r
+       {\r
+               printf("ERROR: Client: unexpected immed_data_recv 0x%x/0x%x\n", \r
+                       0x1111,  immed_data_recv);\r
+               exit(1);\r
+       }\r
+\r
+       if (server)\r
+               printf("Server received immed_data=0x%x\n", immed_data_recv);\r
+       else\r
+               printf("Client received immed_data=0x%x\n", immed_data_recv);\r
+       \r
+       printf("rdma buffer %p contains: %s\n", \r
+               buf[ RCV_RDMA_BUF_INDEX ], buf[ RCV_RDMA_BUF_INDEX ]);\r
+\r
+       printf("\n RDMA_WRITE_WITH_IMMEDIATE_DATA test - PASSED\n");\r
+       return (0);\r
+}\r
+\r
+int\r
+do_cmp_swap()\r
+{\r
+       DAT_DTO_COOKIE  cookie;\r
+       DAT_RETURN              status;\r
+       DAT_EVENT               event;\r
+       DAT_COUNT               nmore;\r
+       DAT_LMR_TRIPLET         l_iov;\r
+       DAT_RMR_TRIPLET         r_iov;\r
+       volatile DAT_UINT64     *target = (DAT_UINT64*)buf[ RCV_RDMA_BUF_INDEX ];\r
+       DAT_DTO_COMPLETION_EVENT_DATA *dto_event = \r
+               &event.event_data.dto_completion_event_data;\r
+       DAT_IB_EXTENSION_EVENT_DATA *ext_event = \r
+               (DAT_IB_EXTENSION_EVENT_DATA *)&event.event_extension_data[0];\r
+\r
+       printf("\nDoing CMP and SWAP\n");\r
+        \r
+       r_iov = *buf[ RECV_BUF_INDEX ];\r
+       \r
+       l_iov.lmr_context     = lmr_atomic_context;\r
+       l_iov.virtual_address = (DAT_UINT64)atomic_buf;\r
+       l_iov.segment_length  = BUF_SIZE_ATOMIC;\r
+\r
+       cookie.as_64 = 3333;\r
+\r
+       if (server) {\r
+               *target = 0x12345;\r
+               sleep(1);\r
+               /* server does not compare and should not swap */\r
+               printf("dtx svr - starting cmp_swap\n");\r
+               status = dat_ib_post_cmp_and_swap(      ep, \r
+                                                       (DAT_UINT64)0x654321, \r
+                                                       (DAT_UINT64)0x6789A, \r
+                                                       &l_iov,\r
+                                                       cookie, \r
+                                                       &r_iov, \r
+                                                       DAT_COMPLETION_DEFAULT_FLAG);\r
+               printf("dtx svr - done cmp_swap, chk status\n");\r
+       } else {\r
+               *target = 0x54321;\r
+               sleep(1); \r
+               printf("dtx cli - starting cmp_swap\n");\r
+               /* client does compare and should swap */\r
+               status = dat_ib_post_cmp_and_swap(      ep, \r
+                                                       (DAT_UINT64)0x12345, \r
+                                                       (DAT_UINT64)0x98765,\r
+                                                       &l_iov,\r
+                                                       cookie, \r
+                                                       &r_iov, \r
+                                                       DAT_COMPLETION_DEFAULT_FLAG);\r
+               printf("dtx cli - done cmp_swap, chk status\n");\r
+       }\r
+       _OK(status, "dat_ib_post_cmp_and_swap");\r
+       status = dat_evd_wait(dto_evd, DTO_TIMEOUT, 1, &event, &nmore);\r
+       _OK(status, "dat_evd_wait for compare and swap");\r
+       if (event.event_number != DAT_IB_DTO_EVENT) {\r
+           printf("unexpected event after post_cmp_and_swap: 0x%x\n", \r
+                   event.event_number); \r
+           exit(1);\r
+       }\r
+\r
+       _OK(dto_event->status, "event status for CMP and SWAP");\r
+       if (ext_event->type != DAT_IB_CMP_AND_SWAP) {\r
+           printf("unexpected event data of cmp and swap : type=%d cookie=%d "\r
+               "original 0x%llx\n",\r
+               (int)ext_event->type,\r
+               (int)dto_event->user_cookie.as_64,\r
+               *atomic_buf);\r
+           exit(1);\r
+       }\r
+\r
+       sleep(2); /* wait for other side to complete swap */\r
+\r
+       if (server) {\r
+           printf("Server got original data        = 0x%llx, expected "\r
+                       "0x54321\n", *atomic_buf);\r
+           printf("Client final result (on server) = 0x%llx, expected "\r
+                       "0x98765\n", *target);\r
+\r
+           if (*atomic_buf != 0x54321 || *target != 0x98765) {\r
+               printf("ERROR: Server CMP_SWAP\n");\r
+               exit(1);\r
+           }\r
+       } else {\r
+           printf("Client got original data        = 0x%llx, expected "\r
+                       "0x12345\n",*atomic_buf);\r
+           printf("Server final result (on client) = 0x%llx, expected "\r
+                       "0x54321\n", *target);\r
+\r
+           if (*atomic_buf != 0x12345 || *target != 0x54321) {\r
+               printf("ERROR: Client CMP_SWAP\n");\r
+               exit(1);\r
+           }\r
+       }\r
+       printf("\n CMP_SWAP test - PASSED\n");\r
+       return(0);\r
+}\r
+\r
+int\r
+do_fetch_add()\r
+{\r
+       DAT_DTO_COOKIE  cookie;\r
+       DAT_RETURN              status;\r
+       DAT_EVENT               event;\r
+       DAT_COUNT               nmore;\r
+       DAT_LMR_TRIPLET         l_iov;\r
+       DAT_RMR_TRIPLET         r_iov;\r
+       volatile DAT_UINT64     *target = (DAT_UINT64*)buf[ RCV_RDMA_BUF_INDEX ];\r
+       DAT_DTO_COMPLETION_EVENT_DATA *dto_event = \r
+               &event.event_data.dto_completion_event_data;\r
+       DAT_IB_EXTENSION_EVENT_DATA *ext_event = \r
+               (DAT_IB_EXTENSION_EVENT_DATA *)&event.event_extension_data[0];\r
+\r
+       printf("\nDoing FETCH and ADD\n");\r
+\r
+       r_iov = *buf[ RECV_BUF_INDEX ];\r
+       \r
+       l_iov.lmr_context     = lmr_atomic_context;\r
+       l_iov.virtual_address = (DAT_UINT64)atomic_buf;\r
+       l_iov.segment_length  = BUF_SIZE_ATOMIC;\r
+\r
+       cookie.as_64 = 0x7777;\r
+       if (server) {\r
+               /* Wait for client to finish cmp_swap */\r
+               while (*target != 0x98765)\r
+                       sleep(1);\r
+               *target = 0x10;\r
+               sleep(1);\r
+               status = dat_ib_post_fetch_and_add(     ep, \r
+                                                       (DAT_UINT64)0x100,\r
+                                                       &l_iov,\r
+                                                       cookie, \r
+                                                       &r_iov, \r
+                                                       DAT_COMPLETION_DEFAULT_FLAG);\r
+       } else {\r
+               /* Wait for server, no swap so nothing to check */\r
+               *target = 0x100;\r
+               sleep(1);\r
+               status = dat_ib_post_fetch_and_add(     ep, \r
+                                                       (DAT_UINT64)0x10, \r
+                                                       &l_iov,\r
+                                                       cookie, \r
+                                                       &r_iov, \r
+                                                       DAT_COMPLETION_DEFAULT_FLAG);\r
+       }\r
+       _OK(status, "dat_ib_post_fetch_and_add");\r
+       status = dat_evd_wait(dto_evd, DTO_TIMEOUT, 1, &event, &nmore);\r
+       _OK(status, "dat_evd_wait for fetch and add");\r
+       if (event.event_number != DAT_IB_DTO_EVENT) {\r
+               printf("unexpected event after post_fetch_and_add: 0x%x\n",\r
+                       event.event_number); \r
+               exit(1);\r
+       }\r
+\r
+       _OK(dto_event->status, "event status for FETCH and ADD");\r
+       if (ext_event->type != DAT_IB_FETCH_AND_ADD) {\r
+               printf("unexpected event data of fetch and add : type=%d "\r
+                       "cookie=%d original%d\n",\r
+                       (int)ext_event->type,\r
+                       (int)dto_event->user_cookie.as_64,\r
+                       (int)*atomic_buf);\r
+               exit(1);\r
+       }\r
+\r
+       if (server) {\r
+           printf("Client original data (on server) = 0x%llx, expected "\r
+                       "0x100\n", *atomic_buf);\r
+       } else {\r
+           printf("Server original data (on client) = 0x%llx, expected "\r
+                       "0x10\n", *atomic_buf);\r
+       }\r
+\r
+       sleep(1);       \r
+\r
+       if (server) {\r
+               status = dat_ib_post_fetch_and_add(ep, \r
+                                                  (DAT_UINT64)0x100, \r
+                                                  &l_iov,\r
+                                                  cookie, \r
+                                                  &r_iov, \r
+                                                  DAT_COMPLETION_DEFAULT_FLAG);\r
+       } else {\r
+               status = dat_ib_post_fetch_and_add(ep, \r
+                                                  (DAT_UINT64)0x10,\r
+                                                  &l_iov,\r
+                                                  cookie, \r
+                                                  &r_iov, \r
+                                                  DAT_COMPLETION_DEFAULT_FLAG);\r
+       }\r
+\r
+       status = dat_evd_wait(dto_evd, DTO_TIMEOUT, 1, &event, &nmore);\r
+       _OK(status, "dat_evd_wait for second fetch and add");\r
+       if (event.event_number != DAT_IB_DTO_EVENT) {\r
+               printf("unexpected event after second post_fetch_and_add: "\r
+                       "0x%x\n", event.event_number); \r
+               exit(1);\r
+       }\r
+\r
+       _OK(dto_event->status, "event status for second FETCH and ADD");\r
+       if (ext_event->type != DAT_IB_FETCH_AND_ADD) {\r
+               printf("unexpected event data of second fetch and add : "\r
+                       "type=%d cookie=%d original%p\n",\r
+                       (int)ext_event->type,\r
+                       (int)dto_event->user_cookie.as_64,\r
+                       atomic_buf);\r
+               exit(1);\r
+       }\r
+\r
+       sleep(1); /* wait for other side to complete fetch_add */\r
+\r
+       if (server) {\r
+           printf("Server got original data         = 0x%llx, expected "\r
+                       "0x200\n", *atomic_buf);\r
+           printf("Client final result (on server)  = 0x%llx, expected "\r
+                       "0x30\n", *target);\r
+\r
+           if (*atomic_buf != 0x200 || *target != 0x30) {\r
+               printf("ERROR: Server FETCH_ADD\n");\r
+               exit(1);\r
+           }\r
+       } else {\r
+           printf("Server side original data        = 0x%llx, expected "\r
+                       "0x20\n", *atomic_buf);\r
+           printf("Server final result (on client)  = 0x%llx, expected "\r
+                       "0x300\n", *target);\r
+\r
+           if (*atomic_buf != 0x20 || *target != 0x300) {\r
+               printf("ERROR: Server FETCH_ADD\n");\r
+               exit(1);\r
+           }\r
+       }\r
+       printf("\n FETCH_ADD test - PASSED\n");\r
+       return(0);\r
+}\r
+\r
+int\r
+main(int argc, char **argv)\r
+{\r
+       char *hostname;\r
+       int rc=0;\r
+\r
+       if (argc > 2) {\r
+               printf(usage);\r
+               exit(1);\r
+       }\r
+\r
+       if ((argc == 1) || strcmp(argv[ 1 ], "-s") == 0)\r
+       {\r
+               server = 1;\r
+       } else {\r
+               server = 0;\r
+               hostname = argv[ 1 ];\r
+       }\r
+\r
+#if defined(_WIN32) || defined(_WIN64)\r
+       {\r
+               WSADATA wsaData; \r
+               int i;\r
+\r
+               i = WSAStartup ( MAKEWORD(2,2), &wsaData );\r
+               if ( i != 0 ) {\r
+                       printf("%s WSAStartup(2.2) failed? (0x%x)\n",argv[0],i);\r
+                       fflush(stdout);\r
+                       exit(1);\r
+               }\r
+       }\r
+#endif\r
+\r
+       /*\r
+        * connect\r
+        */\r
+       if (connect_ep(hostname)) {\r
+               _WSACleanup();\r
+               exit(1);\r
+       }\r
+       if (do_immediate()) {\r
+               _WSACleanup();\r
+               exit(1);\r
+       }\r
+       if (do_cmp_swap()) {\r
+               _WSACleanup();\r
+               exit(1);\r
+       }\r
+       if (do_fetch_add()) {\r
+               _WSACleanup();\r
+               exit(1);\r
+       }\r
+       rc = disconnect_ep();\r
+       _WSACleanup();\r
+       return rc;\r
+}\r
diff --git a/ulp/dapl2/test/dtestx/dtestx.rc b/ulp/dapl2/test/dtestx/dtestx.rc
new file mode 100644 (file)
index 0000000..98659e0
--- /dev/null
@@ -0,0 +1,48 @@
+/*\r
+ * Copyright (c) 2007 Intel Corporation.  All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ *\r
+ * $Id$\r
+ */\r
+\r
+\r
+#include <oib_ver.h>\r
+\r
+#define VER_FILETYPE                   VFT_APP\r
+#define VER_FILESUBTYPE                        VFT2_UNKNOWN\r
+\r
+#if DBG\r
+#define VER_FILEDESCRIPTION_STR                "DAT/DAPL v2.0 extensions cli/svr test (Debug)"\r
+#define VER_INTERNALNAME_STR           "dtestxd.exe"\r
+#define VER_ORIGINALFILENAME_STR       "dtestxd.exe"\r
+#else\r
+#define VER_FILEDESCRIPTION_STR                "DAT/DAPL v2.0 Extensions cli/svr test"\r
+#define VER_INTERNALNAME_STR           "dtestx.exe"\r
+#define VER_ORIGINALFILENAME_STR       "dtestx.exe"\r
+#endif\r
+\r
+#include <common.ver>\r
diff --git a/ulp/dapl2/test/dtestx/makefile b/ulp/dapl2/test/dtestx/makefile
new file mode 100644 (file)
index 0000000..a0c0627
--- /dev/null
@@ -0,0 +1,7 @@
+#\r
+# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source\r
+# file to this component.  This file merely indirects to the real make file\r
+# that is shared by all the driver components of the OpenIB Windows project.\r
+#\r
+\r
+!INCLUDE ..\..\..\..\inc\openib.def\r