0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038
0039 #include <atmi.h>
0040 #include <ubf.h>
0041 #include <ndebug.h>
0042 #include <test.fd.h>
0043 #include <ndrstandard.h>
0044
0045 #include "exassert.h"
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 int main(int argc, char** argv) {
0058
0059 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 4048);
0060 long rsplen;
0061 int i;
0062 int ret=EXSUCCEED;
0063 double d;
0064 double dv = 55.66;
0065 int cd;
0066 long revent;
0067 int received = 0;
0068 char tmp[126];
0069 long len;
0070
0071
0072 if (argc < 2)
0073 {
0074 fprintf(stderr, "Usage: %s normal|timeout\n", argv[0]);
0075 exit(EXFAIL);
0076 }
0077 else if (0==strcmp(argv[1], "normal"))
0078 {
0079
0080 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
0081 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0082 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0083
0084 if (EXFAIL==(cd=tpconnect("CONVSV", (char *)p_ub, 0L, TPRECVONLY)))
0085 {
0086 NDRX_LOG(log_error, "TESTSV connect failed!: %s",
0087 tpstrerror(tperrno));
0088 ret=EXFAIL;
0089 goto out;
0090 }
0091
0092
0093 NDRX_LOG(log_debug, "About to tprecv!");
0094
0095 while (EXSUCCEED==tprecv(cd, (char **)&p_ub, &len, 0L, &revent))
0096 {
0097 received++;
0098 NDRX_LOG(log_debug, "MSG RECEIVED OK!");
0099 }
0100
0101
0102
0103 if (TPEEVENT==tperrno)
0104 {
0105 received++;
0106 snprintf(tmp, sizeof(tmp), "CLT: %d", received);
0107
0108 Bprint(p_ub);
0109 Badd(p_ub, T_STRING_FLD, tmp, 0L);
0110 if (TPEV_SENDONLY==revent)
0111 {
0112 int i=0;
0113
0114 for (i=0; i<100 && EXSUCCEED==ret; i++)
0115 {
0116 ret=tpsend(cd, (char *)p_ub, 0L, 0L, &revent);
0117 }
0118 }
0119 }
0120
0121
0122 if (EXFAIL==tpsend(cd, NULL, 0L, TPRECVONLY, &revent))
0123 {
0124 NDRX_LOG(log_debug, "Failed to give server control!!");
0125 ret=EXFAIL;
0126 goto out;
0127 }
0128
0129 NDRX_LOG(log_debug, "Get response from tprecv!");
0130 Bfprint(p_ub, stderr);
0131
0132
0133 ret=tprecv(cd, (char **)&p_ub, &len, 0L, &revent);
0134 NDRX_LOG(log_error, "tprecv failed with revent=%ld tperrno=%d", revent, tperrno);
0135
0136 if (EXFAIL==ret && TPEEVENT==tperrno && TPEV_SVCSUCC==revent)
0137 {
0138 NDRX_LOG(log_error, "Service finished with TPEV_SVCSUCC!");
0139 ret=EXSUCCEED;
0140 }
0141
0142
0143 ret=tprecv(cd, (char **)&p_ub, &len, 0L, &revent);
0144
0145 if (EXSUCCEED==ret)
0146 {
0147 NDRX_LOG(log_error, "TESTERROR ! Error shall be generated when "
0148 "fetching from closed connection!");
0149 EXFAIL_OUT(ret);
0150 }
0151 else
0152 {
0153 ret = EXSUCCEED;
0154 }
0155
0156 if (tperrno!=TPEINVAL)
0157 {
0158 NDRX_LOG(log_error, "TESTERROR ! Expected err %d got %d!",
0159 TPEINVAL, tperrno);
0160 EXFAIL_OUT(ret);
0161 }
0162
0163 }
0164 else if (0==strcmp(argv[1], "timeout"))
0165 {
0166
0167
0168
0169
0170
0171 if (EXFAIL!=(cd=tpconnect("TOUTSV", (char *)p_ub, 0L, TPRECVONLY)))
0172 {
0173 NDRX_LOG(log_error, "TOUTSV not failed!");
0174 ret=EXFAIL;
0175 goto out;
0176 }
0177
0178 if (tperrno!=TPETIME)
0179 {
0180 NDRX_LOG(log_error, "TESTERROR ! Expected err %d got %d!",
0181 TPETIME, tperrno);
0182 EXFAIL_OUT(ret);
0183 }
0184 }
0185 else if (0==strcmp(argv[1], "noblk"))
0186 {
0187 if (EXFAIL==(cd=tpconnect("NOBLK", (char *)p_ub, 0L, TPRECVONLY)))
0188 {
0189 NDRX_LOG(log_error, "NOBLK failed: %s", tpstrerror(tperrno));
0190 ret=EXFAIL;
0191 goto out;
0192 }
0193
0194 NDRX_ASSERT_TP_OUT( (EXFAIL==tprecv(cd, (char **)&p_ub, &len, TPNOBLOCK, &revent)
0195 && TPEBLOCK==tperrno), "Invalid blocking condition");
0196
0197 #ifdef EX_USE_EPOLL
0198
0199 sleep(15);
0200 #endif
0201
0202
0203 while (EXSUCCEED==tprecv(cd, (char **)&p_ub, &len, 0, &revent));
0204
0205 NDRX_ASSERT_TP_OUT((TPEEVENT==tperrno && TPEV_SVCSUCC==revent),
0206 "Invalid term event %ld", revent);
0207 }
0208 else if (0==strcmp(argv[1], "echoloop"))
0209 {
0210
0211 for (i=0; i<100000; i++)
0212 {
0213 if (EXFAIL==(cd=tpconnect("ECHO", (char *)p_ub, 0L, TPRECVONLY)))
0214 {
0215 NDRX_LOG(log_error, "ECHO failed: %s", tpstrerror(tperrno));
0216 ret=EXFAIL;
0217 goto out;
0218 }
0219
0220 while (EXSUCCEED==tprecv(cd, (char **)&p_ub, &len, 0L, &revent))
0221 {
0222 NDRX_LOG(log_error, "ECHO no msg expected");
0223 ret=EXFAIL;
0224 goto out;
0225 }
0226
0227 NDRX_ASSERT_TP_OUT((TPEEVENT==tperrno && TPEV_SVCSUCC==revent),
0228 "Invalid term event %ld", revent);
0229
0230 tpterm();
0231 }
0232 }
0233 else
0234 {
0235 NDRX_LOG(log_error, "TESTERROR: invalid test case [%s]", argv[1]);
0236 ret=EXFAIL;
0237 goto out;
0238 }
0239
0240 out:
0241
0242 if (EXSUCCEED!=tpterm())
0243 {
0244 NDRX_LOG(log_error, "tpterm failed with: %s", tpstrerror(tperrno));
0245 }
0246
0247 return ret;
0248 }
0249
0250