Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Ndrxd sanity scans / ulog entries - client
0003  *
0004  * @file atmiclt74.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 <atmi.h>
0041 #include <ubf.h>
0042 #include <ndebug.h>
0043 #include <test.fd.h>
0044 #include <ndrstandard.h>
0045 #include <nstopwatch.h>
0046 #include <fcntl.h>
0047 #include <unistd.h>
0048 #include <nstdutil.h>
0049 #include <signal.h>
0050 #include "test74.h"
0051 /*---------------------------Externs------------------------------------*/
0052 /*---------------------------Macros-------------------------------------*/
0053 /*---------------------------Enums--------------------------------------*/
0054 /*---------------------------Typedefs-----------------------------------*/
0055 /*---------------------------Globals------------------------------------*/
0056 /*---------------------------Statics------------------------------------*/
0057 /*---------------------------Prototypes---------------------------------*/
0058 
0059 /**
0060  * Run die...
0061  * @param ptr
0062  */
0063 exprivate void die_thread_fun(void *ptr)
0064 {
0065     tpinit(NULL);
0066     sleep(9999);
0067 }
0068 
0069 /**
0070  * Do the test call to the server
0071  */
0072 int main(int argc, char** argv)
0073 {
0074     int ret=EXSUCCEED;
0075     ndrx_stopwatch_t w;
0076     int i;
0077     int thread_die = EXFALSE;
0078     int main_thread_die = EXFALSE;
0079     struct sigaction sa;
0080     sa.sa_handler = SIG_IGN; /* handle signal by ignoring */
0081     sigemptyset(&sa.sa_mask);
0082     sa.sa_flags = 0;
0083     if (sigaction(SIGCHLD, &sa, 0) == -1) {
0084         perror(0);
0085         exit(1);
0086     }
0087     
0088     if (argc>1 && 0==strcmp(argv[1], "die"))
0089     {
0090         tpinit(NULL);
0091         /* Lets die */
0092         return -1;
0093     }
0094     
0095     if (argc>1 && 0==strcmp(argv[1], "thread_die"))
0096     {
0097         thread_die=EXTRUE;
0098     }
0099     
0100     if (argc>1 && 0==strcmp(argv[1], "main_die"))
0101     {
0102         main_thread_die=EXTRUE;
0103     }
0104     
0105     
0106     /* now try the test where  */
0107     
0108     /* run for some 2 minutes... */
0109     
0110     ndrx_stopwatch_reset(&w);
0111     
0112     while (ndrx_stopwatch_get_delta_sec(&w) < 120)
0113     {
0114         for (i=0; i<100; i++)
0115         {
0116             /* run some fork... */
0117             if (0==fork())
0118             {
0119                 if (thread_die || main_thread_die)
0120                 {
0121                     pthread_t thread1;
0122 
0123                    /* run thread which will die... 
0124                     * The main thread is OK, but thread dies, thus we need some ULOG.
0125                     * Sure thing this will have no guarantee, but we can inspect by
0126                     * our selves..
0127                     */
0128                     pthread_attr_t pthread_custom_attr;
0129                     pthread_attr_init(&pthread_custom_attr);
0130                     ndrx_platf_stack_set(&pthread_custom_attr);
0131 
0132 
0133                     /* create threads 1 and 2 */    
0134                     pthread_create (&thread1, &pthread_custom_attr, 
0135                             (void *) &die_thread_fun, NULL);
0136                 }
0137                 
0138                 tpinit(NULL);
0139                 usleep(700000);
0140                 
0141                 /* main thread unclean shutdown.. */
0142                 if (!main_thread_die)
0143                 {
0144                     tpterm();
0145                 }
0146                 
0147                 return 0;
0148             }
0149             usleep(900);
0150         }
0151         sleep(1);
0152     }
0153     
0154 out:
0155     
0156     fprintf(stderr, "Exit with %d\n", ret);
0157 
0158     return ret;
0159 }
0160 
0161 /* vim: set ts=4 sw=4 et smartindent: */