Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief System testing routines / entry points and tests
0003  *
0004  * @file sys_test.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 <stdint.h>
0037 #include <stdlib.h>
0038 #include <errno.h>
0039 
0040 #include <ndrstandard.h>
0041 #include <ndebug.h>
0042 #include <userlog.h>
0043 #include <sys_test.h>
0044 
0045 /*---------------------------Externs------------------------------------*/
0046 /*---------------------------Macros-------------------------------------*/
0047 /*---------------------------Enums--------------------------------------*/
0048 /*---------------------------Typedefs-----------------------------------*/
0049 /*---------------------------Globals------------------------------------*/
0050 expublic int ndrx_G_systest_enabled = EXFALSE;    /**< Is system tests enbld ?*/
0051 
0052 /* Test hook points: */
0053 expublic int ndrx_G_systest_lockloss = 0;    /**<  Is lock loss test in progress ? */
0054 
0055 /*---------------------------Statics------------------------------------*/
0056 
0057 exprivate char *M_modebuf = NULL;       /**< Mode buffer of system tests */
0058 
0059 /*---------------------------Prototypes---------------------------------*/
0060 
0061 /**
0062  * Prepare system tests keywords
0063  * @return EXSUCCEED/EXFAIL
0064  */
0065 expublic int ndrx_systest_init(void)
0066 {
0067     int ret = EXSUCCEED;
0068     char *param;
0069     int len;
0070     
0071     param = getenv(CONF_NDRX_TESTMODE);
0072     
0073     if (NULL!=param)
0074     {
0075         len = strlen(param)+3;/* +,,EOS*/
0076         
0077         M_modebuf = NDRX_MALLOC(len); 
0078         
0079         if (NULL==M_modebuf)
0080         {
0081             userlog("Failed to malloc %d bytes: %s", len, strerror(errno));
0082             EXFAIL_OUT(ret);
0083         }
0084         
0085         snprintf(M_modebuf, len, ",%s,", param);
0086         ndrx_str_strip(M_modebuf, " \t");
0087         ndrx_G_systest_enabled = EXTRUE;
0088         
0089         NDRX_LOG_EARLY(log_debug, "Test mode enabled: [%s]", M_modebuf);
0090     }
0091     else
0092     {
0093         NDRX_LOG_EARLY(log_debug, "sys_test off");
0094     }
0095     
0096 out:
0097     return ret;
0098 }
0099 
0100 /**
0101  * Test is particular test case enabled
0102  * @param mode test mode string
0103  * @return EXTRUE/EXFALSE
0104  */
0105 expublic int ndrx_systest_case(char *mode)
0106 {
0107     if (M_modebuf && 0!=strstr(M_modebuf, mode))
0108     {
0109         return EXTRUE;
0110     }
0111     
0112     return EXFALSE;
0113 }
0114 
0115 
0116 /* vim: set ts=4 sw=4 et smartindent: */