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
0040 #include <atmi.h>
0041 #include <ubf.h>
0042 #include <ndebug.h>
0043 #include <test.fd.h>
0044 #include <ndrstandard.h>
0045 #include <nstopwatch.h>
0046 #include <fcntl.h>
0047 #include <unistd.h>
0048 #include <nstdutil.h>
0049 #include <exassert.h>
0050 #include "test76.h"
0051
0052
0053
0054
0055
0056
0057 int M_term = EXFALSE;
0058 volatile int M_has_failure = EXFALSE;
0059
0060
0061
0062 void *run_case(void *x_void_ptr)
0063 {
0064 int ret = EXSUCCEED;
0065 long rsplen;
0066 char *svcnm = (char *)x_void_ptr;
0067 int tx_mode = EXFALSE;
0068 int fail_mode = EXFALSE;
0069 char res1[64];
0070 char res2[64];
0071 if (0==strncmp(svcnm, "TX", 2))
0072 {
0073 tx_mode=EXTRUE;
0074 }
0075
0076 if (0==strcmp(svcnm, "TXFAIL"))
0077 {
0078 fail_mode=EXTRUE;
0079 }
0080
0081 if (tx_mode)
0082 {
0083 NDRX_ASSERT_TP_OUT((EXSUCCEED==tpopen()), "Failed to tpopen()");
0084 }
0085
0086 while (!M_term)
0087 {
0088 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
0089
0090
0091 if (tx_mode)
0092 {
0093 NDRX_ASSERT_TP_OUT((EXSUCCEED==tpbegin(60, 0)), "Tran shall start OK");
0094 }
0095
0096 if (EXFAIL == tpcall(svcnm, (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0097 {
0098 NDRX_LOG(log_error, "%s failed: %s", svcnm, tpstrerror(tperrno));
0099 ret=EXFAIL;
0100 goto out;
0101 }
0102
0103
0104 NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_STRING_FLD, 0, res1, NULL)),
0105 "Res 1 missing");
0106 NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_STRING_FLD, 1, res2, NULL)),
0107 "Res 2 missing");
0108
0109
0110
0111 if (!tx_mode)
0112 {
0113 NDRX_ASSERT_VAL_OUT((0==strcmp(res1, "NOTX")), "Got [%s]", res1);
0114 NDRX_ASSERT_VAL_OUT((0==strcmp(res2, "NOTX")), "Got [%s]", res2);
0115 }
0116 else
0117 {
0118 NDRX_ASSERT_VAL_OUT((0==strcmp(res1, "INTX")), "Got [%s]", res1);
0119 NDRX_ASSERT_VAL_OUT((0==strcmp(res2, "INTX")), "Got [%s]", res2);
0120 }
0121
0122
0123 if (tx_mode)
0124 {
0125 if (fail_mode)
0126 {
0127
0128 NDRX_ASSERT_TP_OUT((EXFAIL==tpcommit(0)), "Commit shall fail");
0129 NDRX_ASSERT_TP_OUT((TPEABORT==tperrno), "Expected abort");
0130 }
0131 else
0132 {
0133
0134 NDRX_ASSERT_TP_OUT((EXSUCCEED==tpcommit(0)), "Commit shall be OK");
0135 }
0136 }
0137
0138 tpfree((char *)p_ub);
0139
0140 }
0141
0142 out:
0143
0144 if (tx_mode)
0145 {
0146 if (EXSUCCEED!=tpclose())
0147 {
0148 NDRX_LOG(log_error, "TESTERROR: tpclose() failed: %s",
0149 tpstrerror(tperrno));
0150 }
0151 }
0152
0153 tpterm();
0154
0155 fprintf(stderr, "Exit with %d\n", ret);
0156
0157 if (EXSUCCEED!=ret)
0158 {
0159 M_has_failure=EXTRUE;
0160 }
0161
0162 return NULL;
0163 }
0164
0165
0166
0167
0168
0169 int main(int argc, char** argv)
0170 {
0171 #define THREADS 3
0172 int ret=EXSUCCEED;
0173 pthread_t thrd[THREADS];
0174 int i;
0175 char *svcnms[] = {"TXOK", "TXFAIL", "NOTX"};
0176 ndrx_stopwatch_t w;
0177
0178
0179 for (i=0; i<THREADS; i++)
0180 {
0181 if(EXSUCCEED!=pthread_create(&thrd[i], NULL, run_case, svcnms[i]))
0182 {
0183 NDRX_LOG(log_error, "TESTERROR: Failed to create %s thread", svcnms[i]);
0184 EXFAIL_OUT(ret);
0185 }
0186 }
0187
0188 ndrx_stopwatch_reset(&w);
0189
0190
0191 while(!M_has_failure && ndrx_stopwatch_get_delta_sec(&w) < 180)
0192 {
0193 sleep(1);
0194 }
0195
0196
0197 M_term = EXTRUE;
0198
0199
0200
0201 for (i=0; i<THREADS; i++)
0202 {
0203 void *retptr;
0204 pthread_join(thrd[i], &retptr);
0205 }
0206
0207
0208
0209 if (M_has_failure)
0210 {
0211 NDRX_LOG(log_error, "TESTERROR! Failure is set");
0212 ret=EXFAIL;
0213 }
0214
0215 out:
0216 return ret;
0217 }
0218
0219