Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test the full Enduro/X multi-contexting.
0003  *
0004  * @file atmiclt16.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
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 /*---------------------------Externs------------------------------------*/
0055 /*---------------------------Macros-------------------------------------*/    
0056 /*---------------------------Enums--------------------------------------*/
0057 /*---------------------------Typedefs-----------------------------------*/
0058 /*---------------------------Globals------------------------------------*/
0059 /*---------------------------Statics------------------------------------*/
0060 /*---------------------------Prototypes---------------------------------*/
0061 
0062 TPCONTEXT_T M_ctx[2];
0063 
0064 /*
0065  * Thread function for doing ATMI tests...
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     /* disassoc current thread from context */
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     /* it must be NULL context afterwards */
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  * Do the test call to the server
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         /* get the first context */
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 /* vim: set ts=4 sw=4 et smartindent: */