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 #include <math.h>
0039 #include <unistd.h>
0040
0041 #include <atmi.h>
0042 #include <atmi_int.h>
0043 #include <ubf.h>
0044 #include <ndebug.h>
0045 #include <test.fd.h>
0046 #include <ndrstandard.h>
0047 #include <nstopwatch.h>
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 int main(int argc, char** argv) {
0060
0061 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 9216);
0062 long rsplen;
0063 int i=0;
0064 int ret=EXSUCCEED;
0065
0066 if (EXSUCCEED!=tpopen())
0067 {
0068 NDRX_LOG(log_error, "TESTERROR: tpopen() fail: %d:[%s]",
0069 tperrno, tpstrerror(tperrno));
0070 ret=EXFAIL;
0071 goto out;
0072 }
0073
0074
0075 NDRX_LOG(log_debug, "Testing normal tx processing - commit() ...");
0076
0077 for (i=0; i<100; i++)
0078 {
0079
0080 if (EXSUCCEED!=tpbegin(5, 0))
0081 {
0082 NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]",
0083 tperrno, tpstrerror(tperrno));
0084 ret=EXFAIL;
0085 goto out;
0086 }
0087
0088 ret=tpacall("RUNTX", (char *)p_ub, 0, TPNOREPLY);
0089
0090 if (EXSUCCEED==ret)
0091 {
0092 NDRX_LOG(log_error, "TESTERROR: tpacall+TPNOREPLY must fail");
0093 ret=EXFAIL;
0094 goto out;
0095 }
0096
0097 if (tperrno!=TPEINVAL)
0098 {
0099 NDRX_LOG(log_error, "TESTERROR: tpacall+TPNOREPLY: expected TPEINVAL got %d:%s",
0100 tperrno, tpstrerror(tperrno));
0101 ret=EXFAIL;
0102 goto out;
0103 }
0104
0105
0106 ret=tpacallex("RUNTX", (char *)p_ub, 0, TPNOREPLY, NULL, 0, 0, 0, 0, 0, 0);
0107
0108 if (EXSUCCEED==ret)
0109 {
0110 NDRX_LOG(log_error, "TESTERROR: tpacallex+TPNOREPLY must fail");
0111 ret=EXFAIL;
0112 goto out;
0113 }
0114
0115 if (tperrno!=TPEINVAL)
0116 {
0117 NDRX_LOG(log_error, "TESTERROR: tpacallex+TPNOREPLY: expected TPEINVAL got %d:%s",
0118 tperrno, tpstrerror(tperrno));
0119 ret=EXFAIL;
0120 goto out;
0121 }
0122
0123 ret = EXSUCCEED;
0124
0125
0126
0127 ret=tpacall("NOTRANFAIL", (char *)p_ub, 0, TPNOREPLY|TPNOTRAN);
0128 if (EXSUCCEED!=ret)
0129 {
0130 NDRX_LOG(log_error, "TESTERROR: tpacall+TPNOREPLY|TPNOTRAN must "
0131 "not fail, but got: %s", tpstrerror(tperrno));
0132 ret=EXFAIL;
0133 goto out;
0134 }
0135
0136 ret=tpacallex("NOTRANFAIL", (char *)p_ub, 0, TPNOREPLY|TPNOTRAN,
0137 NULL, 0, 0, 0, 0, 0, 0);
0138 if (EXSUCCEED!=ret)
0139 {
0140 NDRX_LOG(log_error, "TESTERROR: tpacall+TPNOREPLY|TPNOTRAN must "
0141 "not fail, but got: %s", tpstrerror(tperrno));
0142 ret=EXFAIL;
0143 goto out;
0144 }
0145
0146
0147
0148 Bchg(p_ub, T_STRING_FLD, 0, "TEST HELLO WORLD COMMIT", 0L);
0149
0150
0151 if (EXFAIL == (ret=tpcall("RUNTX", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0)))
0152 {
0153 NDRX_LOG(log_error, "TX3SVC failed: %s", tpstrerror(tperrno));
0154 ret=EXFAIL;
0155 goto out;
0156 }
0157
0158 if (EXSUCCEED!=(ret=tpcommit(0)))
0159 {
0160 NDRX_LOG(log_error, "TESTERROR: tpcommit()==%d fail: %d:[%s]",
0161 ret, tperrno, tpstrerror(tperrno));
0162 ret=EXFAIL;
0163 goto out;
0164 }
0165 }
0166
0167
0168 NDRX_LOG(log_debug, "Testing normal tx processing - abort() ...");
0169
0170 for (i=0; i<100; i++)
0171 {
0172 if (EXSUCCEED!=tpbegin(5, 0))
0173 {
0174 NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]",
0175 tperrno, tpstrerror(tperrno));
0176 ret=EXFAIL;
0177 goto out;
0178 }
0179
0180 Bchg(p_ub, T_STRING_FLD, 0, "TEST HELLO WORLD ABORT", 0L);
0181
0182
0183 if (EXFAIL == (ret=tpcall("RUNTX", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0)))
0184 {
0185 NDRX_LOG(log_error, "TX3SVC failed: %s", tpstrerror(tperrno));
0186 ret=EXFAIL;
0187 goto out;
0188 }
0189
0190 if (EXSUCCEED!=(ret=tpabort(0)))
0191 {
0192 NDRX_LOG(log_error, "TESTERROR: tpabort()==%d fail: %d:[%s]",
0193 ret, tperrno, tpstrerror(tperrno));
0194 ret=EXFAIL;
0195 goto out;
0196 }
0197 }
0198
0199
0200 NDRX_LOG(log_debug, "Service returns fail");
0201
0202 for (i=0; i<100; i++)
0203 {
0204 if (EXSUCCEED!=tpbegin(5, 0))
0205 {
0206 NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]",
0207 tperrno, tpstrerror(tperrno));
0208 ret=EXFAIL;
0209 goto out;
0210 }
0211
0212 Bchg(p_ub, T_STRING_FLD, 0, "TEST HELLO WORLD SVCFAIL", 0L);
0213
0214
0215 if (EXFAIL != (ret=tpcall("RUNTXFAIL", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0)))
0216 {
0217 NDRX_LOG(log_error, "RUNTXFAIL should return fail!");
0218 }
0219
0220 ret=tpcommit(0);
0221
0222 if (EXSUCCEED==ret || tperrno!=TPEABORT)
0223 {
0224 NDRX_LOG(log_error, "TESTERROR: abort()==%d fail: %d:[%s] - must be TPEABORT!",
0225 ret, tperrno, tpstrerror(tperrno));
0226 ret=EXFAIL;
0227 goto out;
0228 }
0229
0230 ret = EXSUCCEED;
0231 }
0232
0233 NDRX_LOG(log_debug, "Transaction time-out (by tmsrv)");
0234
0235 for (i=0; i<5; i++)
0236 {
0237 if (EXSUCCEED!=tpbegin(5, 0))
0238 {
0239 NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]",
0240 tperrno, tpstrerror(tperrno));
0241 ret=EXFAIL;
0242 goto out;
0243 }
0244
0245 Bchg(p_ub, T_STRING_FLD, 0, "TEST HELLO WORLD TOUT", 0L);
0246
0247
0248 if (EXFAIL == (ret=tpcall("RUNTX", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0)))
0249 {
0250 NDRX_LOG(log_error, "TESTERROR: RUNTX should not return fail!");
0251 }
0252
0253 sleep(10);
0254
0255 ret=tpcommit(0);
0256
0257 if (EXSUCCEED==ret || tperrno!=TPEABORT)
0258 {
0259 NDRX_LOG(log_error, "TESTERROR: tpcommit()==%d fail: %d:[%s] - must be TPEABORT!",
0260 ret, tperrno, tpstrerror(tperrno));
0261 ret=EXFAIL;
0262 goto out;
0263 }
0264
0265 ret = EXSUCCEED;
0266 }
0267
0268
0269 NDRX_LOG(log_debug, "Call service, but not in tran mode - transaction must not be aborted!");
0270
0271 for (i=0; i<100; i++)
0272 {
0273 if (EXSUCCEED!=tpbegin(5, 0))
0274 {
0275 NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]",
0276 tperrno, tpstrerror(tperrno));
0277 ret=EXFAIL;
0278 goto out;
0279 }
0280
0281 Bchg(p_ub, T_STRING_FLD, 0, "TEST HELLO WORLD SVCFAIL", 0L);
0282
0283
0284 if (EXFAIL != (ret=tpcall("NOTRANFAIL", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,TPNOTRAN)))
0285 {
0286 NDRX_LOG(log_error, "TESTERROR: NOTRANFAIL should return fail!");
0287 }
0288
0289 ret=tpcommit(0);
0290
0291 if (EXSUCCEED!=ret)
0292 {
0293 NDRX_LOG(log_error, "TESTERROR: tpcommit()==%d fail: %d:[%s] - must be SUCCEED!",
0294 ret, tperrno, tpstrerror(tperrno));
0295 ret=EXFAIL;
0296 goto out;
0297 }
0298
0299 ret = EXSUCCEED;
0300 }
0301
0302
0303 NDRX_LOG(log_debug, "Done...");
0304
0305
0306 if (EXSUCCEED!=tpclose())
0307 {
0308 NDRX_LOG(log_error, "TESTERROR: tpclose() fail: %d:[%s]",
0309 tperrno, tpstrerror(tperrno));
0310 ret=EXFAIL;
0311 goto out;
0312 }
0313
0314 out:
0315 if (EXSUCCEED!=ret)
0316 {
0317
0318 if (EXSUCCEED!=tpabort(0))
0319 {
0320 NDRX_LOG(log_error, "TESTERROR: tpabort() fail: %d:[%s]",
0321 tperrno, tpstrerror(tperrno));
0322 }
0323 tpclose();
0324 }
0325
0326 tpterm();
0327
0328 NDRX_LOG(log_error, "Exiting with %d", ret);
0329
0330 return ret;
0331 }
0332
0333