Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief LCF commands supporting the test cases (enable write errors)
0003  *
0004  * @file t86_lcf.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 
0038 #include <ndrstandard.h>
0039 #include <ndebug.h>
0040 #include <nstdutil.h>
0041 #include <expluginbase.h>
0042 #include <sys_unix.h>
0043 #include <test.fd.h>
0044 #include <lcf.h>
0045 #include <sys_test.h>
0046 
0047 #include "atmi_int.h"
0048 /*---------------------------Externs------------------------------------*/
0049 /*---------------------------Macros-------------------------------------*/
0050 /*---------------------------Enums--------------------------------------*/
0051 /*---------------------------Typedefs-----------------------------------*/
0052 /*---------------------------Globals------------------------------------*/
0053 /*---------------------------Statics------------------------------------*/
0054 /*---------------------------Prototypes---------------------------------*/
0055 
0056 /**
0057  * Tmsrv crash (commit)
0058  */
0059 exprivate int custom_tcrash(ndrx_lcf_command_t *cmd, long *p_flags)
0060 {
0061     /* Assuming that init have finished... (sending to servers...) */
0062     G_atmi_env.test_tmsrv_commit_crash = atoi(cmd->arg_a);
0063     NDRX_LOG(log_error, "G_atmi_env.test_tmsrv_commit_crash=%d", 
0064             G_atmi_env.test_tmsrv_commit_crash);
0065 
0066     /* seems having some issues with ASAN */
0067     sleep(1);
0068     return 0;
0069 }
0070 
0071 /**
0072  * Queue write error setting
0073  */
0074 exprivate int custom_qwriterr(ndrx_lcf_command_t *cmd, long *p_flags)
0075 {
0076     /* Assuming that init have finished... (sending to servers...) */
0077     G_atmi_env.test_qdisk_write_fail = atoi(cmd->arg_a);
0078     NDRX_LOG(log_error, "G_atmi_env.test_qdisk_write_fail=%d", 
0079             G_atmi_env.test_qdisk_write_fail);
0080     /* seems having some issues with ASAN */
0081     sleep(1);
0082     return 0;
0083 }
0084 
0085 /**
0086  * Tmsrv write error
0087  */
0088 exprivate int custom_twriterr(ndrx_lcf_command_t *cmd, long *p_flags)
0089 {
0090     /* Assuming that init have finished... (sending to servers...) */
0091     G_atmi_env.test_tmsrv_write_fail = atoi(cmd->arg_a);
0092     NDRX_LOG(log_error, "G_atmi_env.test_tmsrv_write_fail=%d", 
0093             G_atmi_env.test_tmsrv_write_fail);
0094 
0095     /* seems having some issues with ASAN */
0096     sleep(1);
0097     return 0;
0098 }
0099 
0100 /**
0101  * Crash the app
0102  */
0103 exprivate void test_advertise_crash_exit(void)
0104 {
0105     NDRX_LOG(log_error, "TEST: Crash is happening");
0106     exit(1);
0107 }
0108 
0109 /**
0110  * Sleeping on startup...
0111  */
0112 exprivate void test_advertise_crash_sleep(void)
0113 {
0114     NDRX_LOG(log_error, "TEST: Seep 20 is happening");
0115     sleep(20);
0116 }
0117 
0118 /**
0119  * Advertise crashing mark
0120  */
0121 exprivate int custom_advcrash(ndrx_lcf_command_t *cmd, long *p_flags)
0122 {
0123 
0124     switch (atoi(cmd->arg_a))
0125     {
0126         case 1:
0127             G_atmi_env.test_advertise_crash = test_advertise_crash_exit;
0128             break;
0129         case 2:
0130             G_atmi_env.test_advertise_crash = test_advertise_crash_sleep;
0131             break;
0132     }
0133 
0134     /* seems having some issues with ASAN */
0135     sleep(1);
0136     return 0;
0137 }
0138 
0139 
0140 /**
0141  * Lock loss test cases with timeout flag
0142  */
0143 exprivate int custom_lockloss(ndrx_lcf_command_t *cmd, long *p_flags)
0144 {
0145     ndrx_G_systest_lockloss = atoi(cmd->arg_a);
0146     /* seems having some issues with ASAN */
0147     sleep(1);
0148     return 0;
0149 }
0150 
0151 /**
0152  * Initialize the plugin.
0153  * NOTE!!! This pluging is used by several other test cases.
0154  * @param provider_name plugin name/provider string
0155  * @param provider_name_bufsz provider string buffer size
0156  * @return FAIL (in case of error) or OR'ed function flags
0157  */
0158 expublic long ndrx_plugin_init(char *provider_name, int provider_name_bufsz)
0159 {
0160     int ret = EXSUCCEED;
0161     ndrx_lcf_reg_func_t cfunc;
0162     ndrx_lcf_reg_xadmin_t xfunc;
0163     
0164     /**************************************************************************/
0165     /* Queue write error command */
0166     /**************************************************************************/
0167     memset(&cfunc, 0, sizeof(cfunc));
0168     NDRX_STRCPY_SAFE(cfunc.cmdstr, "qwriterr");
0169     cfunc.command=1001;
0170     cfunc.version=NDRX_LCF_CCMD_VERSION;
0171     cfunc.pf_callback=custom_qwriterr;
0172     
0173     if (EXSUCCEED!=ndrx_lcf_func_add(&cfunc))
0174     {
0175         NDRX_LOG_EARLY(log_error, "TESTERROR: Failed to add func: %s", Nstrerror(Nerror));
0176         EXFAIL_OUT(ret);
0177     }
0178     
0179     memset(&xfunc, 0, sizeof(xfunc));
0180     NDRX_STRCPY_SAFE(xfunc.cmdstr, "qwriterr");
0181     xfunc.command=1001;
0182     xfunc.version = cfunc.version=NDRX_LCF_XCMD_VERSION;
0183     NDRX_STRCPY_SAFE(xfunc.helpstr, "Queue write error simulation");
0184     xfunc.dfltflags=(NDRX_LCF_FLAG_ARGA);
0185     xfunc.dfltslot=3;
0186     
0187     if (EXSUCCEED!=ndrx_lcf_xadmin_add(&xfunc))
0188     {
0189         NDRX_LOG_EARLY(log_error, "TESTERROR: Failed to add func: %s", Nstrerror(Nerror));
0190         EXFAIL_OUT(ret);
0191     }
0192     
0193     /**************************************************************************/
0194     /* tmsrv write error command */
0195     /**************************************************************************/
0196     memset(&cfunc, 0, sizeof(cfunc));
0197     NDRX_STRCPY_SAFE(cfunc.cmdstr, "twriterr");
0198     cfunc.command=1002;
0199     cfunc.version=NDRX_LCF_CCMD_VERSION;
0200     cfunc.pf_callback=custom_twriterr;
0201     
0202     if (EXSUCCEED!=ndrx_lcf_func_add(&cfunc))
0203     {
0204         NDRX_LOG_EARLY(log_error, "TESTERROR: Failed to add func: %s", Nstrerror(Nerror));
0205         EXFAIL_OUT(ret);
0206     }
0207     
0208     memset(&xfunc, 0, sizeof(xfunc));
0209     NDRX_STRCPY_SAFE(xfunc.cmdstr, "twriterr");
0210     xfunc.command=1002;
0211     xfunc.version = cfunc.version=NDRX_LCF_XCMD_VERSION;
0212     NDRX_STRCPY_SAFE(xfunc.helpstr, "Tmsrv write error simulation");
0213     xfunc.dfltflags=(NDRX_LCF_FLAG_ARGA);
0214     xfunc.dfltslot=4;
0215     
0216     if (EXSUCCEED!=ndrx_lcf_xadmin_add(&xfunc))
0217     {
0218         NDRX_LOG_EARLY(log_error, "TESTERROR: Failed to add func: %s", Nstrerror(Nerror));
0219         EXFAIL_OUT(ret);
0220     }
0221     
0222     /**************************************************************************/
0223     /* tmsrv commit crash ON*/
0224     /**************************************************************************/
0225     memset(&cfunc, 0, sizeof(cfunc));
0226     NDRX_STRCPY_SAFE(cfunc.cmdstr, "tcrash");
0227     cfunc.command=1003;
0228     cfunc.version=NDRX_LCF_CCMD_VERSION;
0229     cfunc.pf_callback=custom_tcrash;
0230     
0231     if (EXSUCCEED!=ndrx_lcf_func_add(&cfunc))
0232     {
0233         NDRX_LOG_EARLY(log_error, "TESTERROR: Failed to add func: %s", Nstrerror(Nerror));
0234         EXFAIL_OUT(ret);
0235     }
0236     
0237     memset(&xfunc, 0, sizeof(xfunc));
0238     NDRX_STRCPY_SAFE(xfunc.cmdstr, "tcrash");
0239     xfunc.command=1003;
0240     xfunc.version = cfunc.version=NDRX_LCF_XCMD_VERSION;
0241     NDRX_STRCPY_SAFE(xfunc.helpstr, "Tmsrv write error simulation");
0242     xfunc.dfltflags=(NDRX_LCF_FLAG_ARGA);
0243     xfunc.dfltslot=5;
0244     
0245     if (EXSUCCEED!=ndrx_lcf_xadmin_add(&xfunc))
0246     {
0247         NDRX_LOG_EARLY(log_error, "TESTERROR: Failed to add func: %s", Nstrerror(Nerror));
0248         EXFAIL_OUT(ret);
0249     }
0250     
0251     /**************************************************************************/
0252     /* xatmi advertise failure */
0253     /**************************************************************************/
0254     memset(&cfunc, 0, sizeof(cfunc));
0255     NDRX_STRCPY_SAFE(cfunc.cmdstr, "advcrash");
0256     cfunc.command=1004;
0257     cfunc.version=NDRX_LCF_CCMD_VERSION;
0258     cfunc.pf_callback=custom_advcrash;
0259     
0260     if (EXSUCCEED!=ndrx_lcf_func_add(&cfunc))
0261     {
0262         NDRX_LOG_EARLY(log_error, "TESTERROR: Failed to add func: %s", Nstrerror(Nerror));
0263         EXFAIL_OUT(ret);
0264     }
0265     
0266     memset(&xfunc, 0, sizeof(xfunc));
0267     NDRX_STRCPY_SAFE(xfunc.cmdstr, "advcrash");
0268     xfunc.command=1004;
0269     xfunc.version = cfunc.version=NDRX_LCF_XCMD_VERSION;
0270     NDRX_STRCPY_SAFE(xfunc.helpstr, "XATMI advertise error simulation");
0271     xfunc.dfltflags=(NDRX_LCF_FLAG_ARGA);
0272     xfunc.dfltslot=6;
0273     
0274     if (EXSUCCEED!=ndrx_lcf_xadmin_add(&xfunc))
0275     {
0276         NDRX_LOG_EARLY(log_error, "TESTERROR: Failed to add func: %s", Nstrerror(Nerror));
0277         EXFAIL_OUT(ret);
0278     }
0279 
0280     /**************************************************************************/
0281     /* Lock loss test scenario... */
0282     /**************************************************************************/
0283     memset(&cfunc, 0, sizeof(cfunc));
0284     NDRX_STRCPY_SAFE(cfunc.cmdstr, "lockloss");
0285     cfunc.command=1005;
0286     cfunc.version=NDRX_LCF_CCMD_VERSION;
0287     cfunc.pf_callback=custom_lockloss;
0288 
0289     if (EXSUCCEED!=ndrx_lcf_func_add(&cfunc))
0290     {
0291         NDRX_LOG_EARLY(log_error, "TESTERROR: Failed to add func: %s", Nstrerror(Nerror));
0292         EXFAIL_OUT(ret);
0293     }
0294 
0295     memset(&xfunc, 0, sizeof(xfunc));
0296     NDRX_STRCPY_SAFE(xfunc.cmdstr, "lockloss");
0297     xfunc.command=1005;
0298     xfunc.version = cfunc.version=NDRX_LCF_XCMD_VERSION;
0299     NDRX_STRCPY_SAFE(xfunc.helpstr, "XATMI advertise error simulation");
0300     xfunc.dfltflags=(NDRX_LCF_FLAG_ARGA);
0301     xfunc.dfltslot=6;
0302 
0303     if (EXSUCCEED!=ndrx_lcf_xadmin_add(&xfunc))
0304     {
0305         NDRX_LOG_EARLY(log_error, "TESTERROR: Failed to add func: %s", Nstrerror(Nerror));
0306         EXFAIL_OUT(ret);
0307     }
0308     
0309     
0310 out:
0311     /* No functions provided */
0312     return ret;
0313 }
0314 
0315 /* vim: set ts=4 sw=4 et smartindent: */