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 <unistd.h> /* Symbolic Constants */
0041 #include <sys/types.h> /* Primitive System Data Types */
0042 #include <errno.h> /* Errors */
0043 #include <stdio.h> /* Input/Output */
0044 #include <stdlib.h> /* General Utilities */
0045 #include <pthread.h> /* POSIX Threads */
0046
0047 #include <atmi.h>
0048 #include <ubf.h>
0049 #include <ndebug.h>
0050 #include <test.fd.h>
0051 #include <ndrstandard.h>
0052 #include <nstopwatch.h>
0053 #include <nstdutil.h>
0054
0055
0056
0057
0058
0059
0060
0061
0062 TPCONTEXT_T M_ctx[2];
0063
0064
0065
0066
0067 void do_thread_work ( void *ptr )
0068 {
0069 UBFH *p_ub;
0070 long slot = (long)ptr;
0071 long rsplen;
0072 int ret=EXSUCCEED;
0073 TPCONTEXT_T test_ctx;
0074
0075 if (EXSUCCEED!=tpsetctxt(M_ctx[slot], 0))
0076 {
0077 NDRX_LOG(log_error, "TESTERROR: failed to tpsetctxt(): %s", tpstrerror(tperrno));
0078 EXFAIL_OUT(ret);
0079 }
0080
0081 if (NULL==(p_ub = (UBFH *)tpalloc("UBF", NULL, 9216)))
0082 {
0083 NDRX_LOG(log_error, "TESTERROR: failed to tpalloc(): %s", tpstrerror(tperrno));
0084 EXFAIL_OUT(ret);
0085 }
0086
0087 if (EXFAIL == tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0088 {
0089 NDRX_LOG(log_error, "TESTERROR: TESTSV failed: %s", tpstrerror(tperrno));
0090 EXFAIL_OUT(ret);
0091 }
0092
0093 out:
0094
0095 if (NULL!=p_ub)
0096 {
0097 tpfree((char *)p_ub);
0098 }
0099
0100
0101 if (TPMULTICONTEXTS!=tpgetctxt(&M_ctx[slot], 0))
0102 {
0103 NDRX_LOG(log_error, "TESTERROR: failed to tpgetctxt(): %s", tpstrerror(tperrno));
0104 EXFAIL_OUT(ret);
0105 }
0106
0107
0108 if (TPNULLCONTEXT!=(ret=tpgetctxt(&test_ctx, 0)))
0109 {
0110 NDRX_LOG(log_error, "TESTERROR: tpgetctxt() must be in NULLCONTEXT, "
0111 "but got: %d", ret);
0112 EXFAIL_OUT(ret);
0113 }
0114
0115 return;
0116 }
0117
0118
0119
0120
0121 int main(int argc, char** argv)
0122 {
0123 int i;
0124 pthread_t thread1;
0125 int ret = EXSUCCEED;
0126
0127 for (i =0; i< 2; i++)
0128 {
0129 if (EXSUCCEED!=tpinit(NULL))
0130 {
0131 NDRX_LOG(log_error, "TESTERROR: tpinit fail: %s", tpstrerror(tperrno));
0132 EXFAIL_OUT(ret);
0133 }
0134
0135
0136 if (TPMULTICONTEXTS!=tpgetctxt(&M_ctx[i], 0))
0137 {
0138 NDRX_LOG(log_error, "TESTERROR: tpgetctxt fail: %s", tpstrerror(tperrno));
0139 EXFAIL_OUT(ret);
0140 }
0141 }
0142
0143 for (i=0; i<1000; i++)
0144 {
0145 int slot = i%2;
0146 pthread_create (&thread1, NULL, (void *) &do_thread_work, (void *)((long)slot));
0147 pthread_join(thread1, NULL);
0148 }
0149
0150
0151 out:
0152 return ret;
0153 }
0154
0155