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 <exassert.h>
0041 #include <atmi.h>
0042 #include <ubf.h>
0043 #include <ndebug.h>
0044 #include <test.fd.h>
0045 #include <ndrstandard.h>
0046 #include <nstopwatch.h>
0047 #include <fcntl.h>
0048 #include <unistd.h>
0049 #include <nstdutil.h>
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 int main(int argc, char** argv)
0062 {
0063 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 56000);
0064 long rsplen;
0065 int i;
0066 int ret=EXSUCCEED;
0067 TPQCTL qctl;
0068 short num;
0069 long len;
0070
0071 if (argc < 3 || 0==strcmp(argv[1], "deq") && argc < 4)
0072 {
0073 fprintf(stderr, "Usage: %s {enq <msg_no> | deq <msg_tot> <broken_txn_flag>}\n", argv[0]);
0074 exit(EXFAIL);
0075 }
0076
0077 NDRX_ASSERT_TP_OUT(EXSUCCEED==tpopen(), "Failed to topen()");
0078 NDRX_ASSERT_TP_OUT(EXSUCCEED==tpbegin(30, 0), "Failed to tpbegin()");
0079
0080 num = atoi(argv[2]);
0081
0082 if (0==strcmp(argv[1], "enq"))
0083 {
0084 if (EXSUCCEED!=Bchg(p_ub, T_SHORT_FLD, 0, (char *)&num, 0L))
0085 {
0086 fprintf(stderr, "Failed to set T_SHORT_FLD\n");
0087 EXFAIL_OUT(ret);
0088 }
0089
0090
0091 memset(&qctl, 0, sizeof(qctl));
0092
0093 if (EXSUCCEED!=tpenqueue("TESTSP", "Q1", &qctl, (char *)p_ub, 0, 0))
0094 {
0095 NDRX_LOG(log_error, "TESTERROR: tpenqueue() to `Q1' failed %s diag: %d:%s",
0096 tpstrerror(tperrno), qctl.diagnostic, qctl.diagmsg);
0097 EXFAIL_OUT(ret);
0098 EXFAIL_OUT(ret);
0099 }
0100
0101 NDRX_ASSERT_TP_OUT(EXSUCCEED==tpcommit(0), "Failed to tpcommit()");
0102
0103 }
0104 else if (0==strcmp(argv[1], "deq"))
0105 {
0106
0107 short messages[num];
0108 short val;
0109 int j;
0110 memset(messages, 0, sizeof(messages));
0111
0112
0113 memset(&qctl, 0, sizeof(qctl));
0114 while (EXSUCCEED==tpdequeue("TESTSP", "Q1", &qctl, (char **)&p_ub, &len, 0))
0115 {
0116 if (EXSUCCEED!=Bget(p_ub, T_SHORT_FLD, 0, (char *)&val, NULL))
0117 {
0118 NDRX_LOG(log_error, "TESTERROR: Failed to get T_SHORT_FLD: %s", Bstrerror(Berror));
0119 EXFAIL_OUT(ret);
0120 }
0121
0122 if (val<0 || val>=num)
0123 {
0124 NDRX_LOG(log_error, "TESTERROR: Message %d out of range in Q1", val);
0125 EXFAIL_OUT(ret);
0126 }
0127
0128 if (messages[val]!=0)
0129 {
0130 NDRX_LOG(log_error, "TESTERROR: Duplicate message %d in Q1", val);
0131 EXFAIL_OUT(ret);
0132 }
0133 NDRX_LOG(log_error, "GOT val=%hd", val);
0134 messages[val] = 1;
0135 memset(&qctl, 0, sizeof(qctl));
0136 }
0137
0138 if (TPEDIAGNOSTIC!=tperrno)
0139 {
0140 NDRX_LOG(log_error, "TESTRROR: Expected TPEDIAGNOSTIC, got %s", tpstrerror(tperrno));
0141 EXFAIL_OUT(ret);
0142 }
0143
0144 NDRX_LOG(log_error, "tpdequeue failed %s diag: %d:%s",
0145 tpstrerror(tperrno), qctl.diagnostic, qctl.diagmsg);
0146
0147 for (j=0; j<num; j++)
0148 {
0149 if (messages[j]!=1)
0150 {
0151 NDRX_LOG(log_error, "Message %d not found in Q", j);
0152 NDRX_ASSERT_TP_OUT(EXSUCCEED==tpabort(0), "Failed to tpcommit()");
0153 EXFAIL_OUT(ret);
0154 }
0155 }
0156
0157
0158 if ('Y'==argv[3][0])
0159 {
0160
0161 exit(0);
0162 }
0163
0164 NDRX_ASSERT_TP_OUT(EXSUCCEED==tpcommit(0), "Failed to tpcommit()");
0165 }
0166 else
0167 {
0168 NDRX_LOG(log_error, "Unknown command %s", argv[1]);
0169 exit(EXFAIL);
0170 }
0171
0172 out:
0173 tpterm();
0174 fprintf(stderr, "Exit with %d\n", ret);
0175
0176 return ret;
0177 }
0178
0179