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 <unistd.h>
0039
0040 #include <atmi.h>
0041 #include <ubf.h>
0042 #include <ndebug.h>
0043 #include <test.fd.h>
0044 #include <ndrstandard.h>
0045
0046
0047 #define LOOP_NUM 10000
0048 #define THREADS_NUM 5
0049
0050
0051
0052
0053
0054
0055 exprivate int num1=2;
0056 exprivate int num2=1;
0057 exprivate int num3=0;
0058 exprivate int M_err = EXFALSE;
0059
0060
0061
0062
0063
0064
0065
0066 void* thmain(void* arg)
0067 {
0068
0069 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
0070 int i;
0071 int ret=EXSUCCEED;
0072
0073 CBadd(p_ub, T_DOUBLE_FLD, "5", 0, BFLD_STRING);
0074 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0075 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0076
0077
0078 for (i=0; i<LOOP_NUM; i++)
0079 {
0080 ret=tppost("EVX.TEST", (char*)p_ub, 0L, TPSIGRSTRT);
0081 NDRX_LOG(log_debug, "dispatched events: %d", ret);
0082
0083
0084 if (ret!=num1)
0085 {
0086 NDRX_LOG(log_error, "Applied event count is not %d (which is %d)",
0087 num1, ret);
0088 ret=EXFAIL;
0089 goto out;
0090 }
0091 else
0092 {
0093 NDRX_LOG(log_debug, "6 dispatches - OK");
0094 }
0095 }
0096
0097 out:
0098 if (EXFAIL==ret)
0099 {
0100 M_err=EXTRUE;
0101 }
0102
0103 tpterm();
0104 return NULL;
0105 }
0106
0107
0108
0109 int main(int argc, char** argv) {
0110
0111 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
0112 int i;
0113 int ret=EXSUCCEED;
0114 pthread_t th[THREADS_NUM];
0115
0116 CBadd(p_ub, T_DOUBLE_FLD, "5", 0, BFLD_STRING);
0117 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0118 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0119
0120 if (argc>1 && 'Y'==argv[1][0])
0121 {
0122
0123 num1*=3;
0124 num2*=3;
0125 }
0126
0127 for (i=0; i<THREADS_NUM; i++)
0128 {
0129 pthread_create(&th[i], NULL, thmain, NULL);
0130 }
0131
0132 for (i=0; i<THREADS_NUM; i++)
0133 {
0134 void* val;
0135 pthread_join(th[i], &val);
0136 }
0137
0138 if (M_err)
0139 {
0140 NDRX_LOG(log_error, "TESTERROR! some thread failed");
0141 EXFAIL_OUT(ret);
0142 }
0143
0144 ret=tppost("TEST2EV", (char*)p_ub, 0L, TPSIGRSTRT);
0145
0146
0147 if (num2!=ret)
0148 {
0149 NDRX_LOG(log_error, "TESTERROR: First post of TEST2EV did not return 3 (%d) ",
0150 ret);
0151 ret=EXFAIL;
0152 goto out;
0153 }
0154 sleep(10);
0155 ret=tppost("TEST2EV", (char*)p_ub, 0L, TPSIGRSTRT);
0156 if (num3!=ret)
0157 {
0158 NDRX_LOG(log_error, "TESTERROR: Second post of TEST2EV did not return 0 (%d) ",
0159 ret);
0160 ret=EXFAIL;
0161 goto out;
0162 }
0163
0164 out:
0165
0166
0167 if (ret>=0)
0168 {
0169 ret=EXSUCCEED;
0170 }
0171
0172 return ret;
0173 }
0174
0175