Whamcloud - gitweb
Landing b_hd_newconfig on HEAD
[fs/lustre-release.git] / lnet / tests / ut_cli.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4
5  #define UT_MSG_MODULE_NAME "utcli "
6  #include "ut.h"
7
8 int pkt_size = 300;
9 module_param(pkt_size,int,S_IRUGO);
10 int get=0;
11 module_param(get,int,S_IRUGO);
12 int put=0;
13 module_param(put,int,S_IRUGO);
14 int auto_unlink=1;
15 module_param(auto_unlink,int,S_IRUGO);
16 char* nid=0;
17 module_param(nid,charp,S_IRUGO);
18
19 static int __init utcli_init(void)
20 {
21         lnet_handle_md_t        mdh;
22         lnet_process_id_t       target;
23         lnet_process_id_t       mypid;
24         lnet_handle_eq_t        eqh;
25         lnet_md_t               md;
26         int                     rc,i;
27         char* buffer            = 0;
28         /*
29          * Put and get really control the same thing
30          */
31         if(put)get=0;
32         /* Default to get */
33         if(!put && !get)get=1;
34
35         PJK_UT_MSG("utcli_init %s\n",get==0?"PUT":"GET");
36         PJK_UT_MSG("pkt_size=%d\n",pkt_size);
37         PJK_UT_MSG("auto_unlink=%d\n",auto_unlink);
38         PJK_UT_MSG("nid=%s\n",nid);
39         if(nid == 0)
40         {
41                 CERROR("NID Must be specified\n");
42                 return -EINVAL;
43         }
44
45         PJK_UT_MSG("LIBCFS_ALLOC\n");
46         LIBCFS_ALLOC (buffer, pkt_size);
47         if (buffer == NULL)
48         {
49                 CERROR ("Unable to allocate out_buf (%d bytes)\n", pkt_size);
50                 return -ENOMEM;
51         }
52
53         PJK_UT_MSG("LNetNiInit()\n");
54         rc = LNetNIInit(0);
55         if (rc < 0)
56         {
57                 CERROR ("LNetNIInit: error %d\n", rc);
58                 goto exit0;
59         }
60
61
62         LNetGetId(0,&mypid);
63         PJK_UT_MSG("my.nid="LPX64"\n",mypid.nid);
64         PJK_UT_MSG("my.pid=0x%x\n",mypid.pid);
65
66
67         PJK_UT_MSG("LNetEQAlloc\n");
68         rc = LNetEQAlloc(
69                 64,      /* max number of envents why 64? */
70                 handler, /* handler callback */
71                 &eqh);   /* output handle */
72         if(rc != 0) {
73                 CERROR("LNetEQAlloc failed %d\n",rc);
74                 goto exit1;
75         }
76
77         md.start = buffer;
78         md.length = pkt_size;
79         md.threshold = auto_unlink ? (get ? 2 : 1) : 15;
80         md.max_size = 0;
81         md.options = 0;
82         if(get){
83                 md.options |= LNET_MD_OP_GET;
84         }else{
85                 md.options |= LNET_MD_OP_PUT;
86                 md.options |= LNET_MD_ACK_DISABLE;
87         }
88         md.user_ptr = 0;
89         md.eq_handle = eqh;
90
91         PJK_UT_MSG("LNetMDBind()\n");
92         if ((rc=LNetMDBind (
93                      md,
94                      LNET_UNLINK,
95                      &mdh)))               /* out handle */
96         {
97                 CERROR ("LNetMDBind error %d\n", rc);
98                 goto exit4;
99         }
100
101         target.pid = 0;
102         target.nid = libcfs_str2nid(nid);
103
104         PJK_UT_MSG("target.nid="LPX64"\n",target.nid);
105
106         for(i=0;i<1;i++)
107         {
108                 if(get){
109                         PJK_UT_MSG("LNetGet()\n");
110                         if((rc = LNetGet (
111                                     LNET_ID_ANY,
112                                     mdh,
113                                     target,       /* peer "address" */
114                                     UT_PORTAL,    /* portal */
115                                     i,            /* match bits */
116                                     0)))          /* header data */
117                         {
118                                 CERROR("LNetGet %d error %d\n",i, rc);
119                                 goto exit5;
120                         }
121                 }else{
122
123                         PJK_UT_MSG("LNetPut()\n");
124                         if((rc = LNetPut (
125                                     LNET_ID_ANY,
126                                     mdh,
127                                     LNET_ACK_REQ, /* we want ack */
128                                     target,       /* peer "address" */
129                                     UT_PORTAL,    /* portal */
130                                     i,            /* match bits */
131                                     0,            /* offset */
132                                     0)))          /* header data */
133                         {
134                                 CERROR("LNetPut %d error %d\n",i, rc);
135                                 goto exit5;
136                         }
137                 }
138         }
139
140
141         PJK_UT_MSG("------------Waiting for SEND_END()------------\n");
142         i=0;
143         while(i++ < 10 && seen == 0)
144                 cfs_pause(cfs_time_seconds(1));
145         if(seen == 0)
146                 PJK_UT_MSG("------------------TIMEDOUT--------------------\n");
147         else{
148                 int good;
149                 if(get){
150                         PJK_UT_MSG("------------Waiting for REPLY()------------\n");
151                         i=0;
152                         while(i++ < 10 && seen == 1)
153                                 cfs_pause(cfs_time_seconds(1));
154                         good = (seen != 1);
155                 }else{
156                         good = 1;
157                 }
158
159                 if(good)
160                         PJK_UT_MSG("------------------COMPLETE--------------------\n");
161                 else
162                         PJK_UT_MSG("------------------TIMEDOUT--------------------\n");
163         }
164
165
166
167         /*
168         PJK_UT_MSG("LNetEQWait()\n");
169         rc = LNetEQWait(eqh,&ev);
170         if(rc != 0)
171                 goto exit5;
172         */
173
174 exit5:
175         PJK_UT_MSG("LNetMDUnlink()\n");
176         LNetMDUnlink(mdh);
177
178         if(!seen_unlink){
179                 PJK_UT_MSG("------------Waiting for UNLINK ------------\n");
180                 i=0;
181                 while(i++ < 120 && seen_unlink == 0)
182                         cfs_pause(cfs_time_seconds(1));
183         }
184
185         cfs_pause(cfs_time_seconds(1));
186 exit4:
187         PJK_UT_MSG("LNetEQFree()\n");
188         LNetEQFree(eqh);
189 exit1:
190         PJK_UT_MSG("LNetNiFini()\n");
191         LNetNIFini();
192 exit0:
193         if(buffer)
194                 LIBCFS_FREE(buffer,pkt_size);
195
196         return -1;
197 } /* utcli_init() */
198
199
200 static void /*__exit*/ utcli_cleanup(void)
201 {
202         PJK_UT_MSG(">>>\n");
203         PJK_UT_MSG("<<<\n");
204 } /* utcli_cleanup() */
205
206
207 MODULE_AUTHOR("PJ Kirner (CFS)");
208 MODULE_DESCRIPTION("A simple LNET Unit Test module");
209 MODULE_LICENSE("GPL");
210
211 cfs_module(ut_cli, "1.0.0", utcli_init, utcli_cleanup);