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 #include <ubfutil.h>
0045
0046
0047 #define MAX_CALLS 10000
0048
0049
0050
0051
0052 int M_replies_got = 0;
0053 int M_notifs_got = 0;
0054 int M_calls_made = 0;
0055
0056
0057
0058
0059
0060
0061 void notification_callback (char *data, long len, long flags)
0062 {
0063 UBFH *p_ub = (UBFH *)data;
0064 NDRX_LOG(log_info, "Got notification...");
0065
0066 ndrx_debug_dump_UBF(log_error, "notification_callback", p_ub);
0067 M_notifs_got++;
0068 }
0069
0070
0071
0072
0073
0074 int handle_replies(UBFH **pp_ub, int num)
0075 {
0076 int ret = EXSUCCEED;
0077 long len;
0078 int cd;
0079 int i;
0080
0081
0082 if (0==num)
0083 {
0084 while (EXSUCCEED==tpgetrply(&cd, (char **)pp_ub, &len, TPGETANY | TPNOBLOCK)
0085 && 0!=cd)
0086 {
0087 ndrx_debug_dump_UBF(log_error, "Got reply", *pp_ub);
0088 M_replies_got++;
0089 }
0090 }
0091 else
0092 {
0093 for (i=0; i<num; i++)
0094 {
0095 if (EXSUCCEED!=tpgetrply(&cd, (char **)pp_ub, &len, TPGETANY))
0096 {
0097 NDRX_LOG(log_error, "TESTERROR! Failed to get rply!");
0098 EXFAIL_OUT(ret);
0099 }
0100 ndrx_debug_dump_UBF(log_error, "Got reply", *pp_ub);
0101 M_replies_got++;
0102 }
0103 }
0104
0105 out:
0106 return ret;
0107 }
0108
0109
0110
0111
0112 int main(int argc, char** argv)
0113 {
0114 int ret = EXSUCCEED;
0115 int i;
0116 char tmp[20];
0117 UBFH *p_ub = NULL;
0118 void (*prev_handler) (char *data, long len, long flags);
0119
0120 if (EXSUCCEED!=tpinit(NULL))
0121 {
0122 NDRX_LOG(log_error, "TESTERROR: Failed to init!!!!");
0123 EXFAIL_OUT(ret);
0124 }
0125
0126 if (NULL!=(prev_handler = tpsetunsol(notification_callback)))
0127 {
0128 NDRX_LOG(log_error, "TESTERRORR: Previous handler must be NULL!");
0129 EXFAIL_OUT(ret);
0130 }
0131
0132 if (notification_callback!= tpsetunsol(notification_callback))
0133 {
0134 NDRX_LOG(log_error, "TESTERRORR: Previous handler must be "
0135 "notification_callback()!");
0136 EXFAIL_OUT(ret);
0137 }
0138
0139
0140 if (NULL==(p_ub = (UBFH *)tpalloc("UBF", NULL, 1024)))
0141 {
0142 NDRX_LOG(log_error, "TESTERROR: Failed to allocate test buffer!");
0143 EXFAIL_OUT(ret);
0144 }
0145
0146
0147
0148
0149 for (i=1; i<MAX_CALLS+1; i++)
0150 {
0151
0152
0153
0154 snprintf(tmp, sizeof(tmp), "AA%02ld%08d", tpgetnodeid(), i);
0155
0156 restart:
0157 if (EXSUCCEED!=Bchg(p_ub, T_STRING_FLD, 0, tmp, 0L))
0158 {
0159 NDRX_LOG(log_error, "TESTERROR: Failed to set T_STRING_FLD to [%s]: %s",
0160 tmp, Bstrerror(Berror));
0161 EXFAIL_OUT(ret);
0162 }
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172 if (tpacall("SVC38_01", (char *)p_ub, 0L, TPNOBLOCK)<=0)
0173 {
0174 if (TPEBLOCK==tperrno || TPELIMIT==tperrno)
0175 {
0176 NDRX_LOG(log_error, "Additional handle_replies %d", tperrno);
0177 if (EXSUCCEED!=handle_replies(&p_ub, 0))
0178 {
0179 NDRX_LOG(log_error, "handle_replies() failed");
0180 EXFAIL_OUT(ret);
0181 }
0182
0183 goto restart;
0184 }
0185 else
0186 {
0187 NDRX_LOG(log_error, "TESTERROR: Failed to call [SVC38_01]: %s",
0188 tpstrerror(tperrno));
0189 EXFAIL_OUT(ret);
0190 }
0191 }
0192
0193 M_calls_made++;
0194
0195 restart2:
0196
0197
0198
0199 if (tpacall("SVC38_02", (char *)p_ub, 0L, TPNOBLOCK)<=0)
0200 {
0201
0202 if (TPELIMIT==tperrno || TPEBLOCK==tperrno)
0203 {
0204 NDRX_LOG(log_error, "Additional handle_replies %d", tperrno);
0205 if (EXSUCCEED!=handle_replies(&p_ub, 0))
0206 {
0207 NDRX_LOG(log_error, "handle_replies() failed");
0208 EXFAIL_OUT(ret);
0209 }
0210 goto restart2;
0211 }
0212 else
0213 {
0214 NDRX_LOG(log_error, "TESTERROR: Failed to call [SVC38_02]: %s",
0215 tpstrerror(tperrno));
0216 EXFAIL_OUT(ret);
0217 }
0218 }
0219 M_calls_made++;
0220 }
0221
0222 i=0;
0223 while (i<1000000 && (M_replies_got < M_calls_made || M_notifs_got < M_calls_made))
0224 {
0225
0226 NDRX_LOG(log_warn, "Waiting for replies...");
0227 usleep(1000);
0228 if (EXSUCCEED!=handle_replies(&p_ub, 0))
0229 {
0230 NDRX_LOG(log_error, "TESTERROR: handle_replies() failed");
0231 EXFAIL_OUT(ret);
0232 }
0233
0234 i++;
0235 }
0236
0237
0238 if (M_calls_made!=M_notifs_got)
0239 {
0240 NDRX_LOG(log_error, "TESTERROR: M_notifs_got = %d, expected: %d",
0241 M_notifs_got, M_calls_made);
0242 EXFAIL_OUT(ret);
0243 }
0244
0245
0246 if (M_calls_made!=M_replies_got)
0247 {
0248 NDRX_LOG(log_error, "TESTERROR: M_replies_got = %d, expected: %d",
0249 M_replies_got, M_calls_made);
0250 EXFAIL_OUT(ret);
0251 }
0252
0253 out:
0254
0255 if (NULL!=p_ub)
0256 {
0257 tpfree((char *)p_ub);
0258 }
0259
0260 return ret;
0261
0262 }
0263
0264
0265