|
||||
0001 /** 0002 * @brief Check shared memory directly, using system headers 0003 * 0004 * @file atmiclt34_2.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 <ndebug.h> 0041 #include <atmi.h> 0042 0043 0044 #include <ubf.h> 0045 #include <Exfields.h> 0046 #include <test.fd.h> 0047 #include <atmi_shm.h> 0048 /*---------------------------Externs------------------------------------*/ 0049 /*---------------------------Macros-------------------------------------*/ 0050 /*---------------------------Enums--------------------------------------*/ 0051 /*---------------------------Typedefs-----------------------------------*/ 0052 /*---------------------------Globals------------------------------------*/ 0053 /*---------------------------Statics------------------------------------*/ 0054 /*---------------------------Prototypes---------------------------------*/ 0055 0056 0057 /** 0058 * Initialise the application 0059 * @param argc argument count 0060 * @param argv argument values 0061 * @return SUCCEED/FAIL 0062 */ 0063 int init(int argc, char** argv) 0064 { 0065 int ret = EXSUCCEED; 0066 0067 TP_LOG(log_info, "Initialising..."); 0068 0069 if (EXSUCCEED!=tpinit(NULL)) 0070 { 0071 TP_LOG(log_error, "Failed to Initialise: %s", 0072 tpstrerror(tperrno)); 0073 ret = EXFAIL; 0074 goto out; 0075 } 0076 0077 out: 0078 return ret; 0079 } 0080 0081 /** 0082 * Terminate the application 0083 */ 0084 int uninit(int status) 0085 { 0086 int ret = EXSUCCEED; 0087 0088 TP_LOG(log_info, "Uninitialising..."); 0089 0090 ret = tpterm(); 0091 0092 return ret; 0093 } 0094 0095 /** 0096 * Load some keys with one free, the first one 0097 * @param mem memory to init 0098 * @param mark_free position to leave un-inited -> free 0099 * @param mark_was_used position to mark 0100 */ 0101 exprivate int init_one_free(int max_svcs, int mark_free) 0102 { 0103 int ret = EXSUCCEED; 0104 int i; 0105 char svcnm[MAXTIDENT+1]; 0106 0107 /* reset service memory... */ 0108 memset(G_svcinfo.mem, 0, G_svcinfo.size); 0109 0110 for (i=0; i<max_svcs; i++) 0111 { 0112 snprintf(svcnm, sizeof(svcnm), "SVC%d", i); 0113 /* lets install some service stuff there... */ 0114 if (EXSUCCEED!=ndrx_shm_install_svc(svcnm, 0, 1)) 0115 { 0116 NDRX_LOG(log_error, "Failed to install service [%s]! / prep", 0117 svcnm); 0118 EXFAIL_OUT(ret); 0119 } 0120 } 0121 0122 /* reset the cell.. */ 0123 NDRX_LOG(log_error, "Free pos: %d", mark_free); 0124 memset(G_svcinfo.mem+mark_free*(SHM_SVCINFO_SIZEOF), 0, SHM_SVCINFO_SIZEOF); 0125 0126 out: 0127 return ret; 0128 } 0129 0130 0131 0132 /** 0133 * This assumes that no other processes are looking into shared memory 0134 * This means that ndrxd must be in idle mode, with sanity checks disabled. 0135 * i.e. we run $ xadmin appconfig sanity 99999 0136 * before this test. 0137 * @return SUCCEED/FAIL 0138 */ 0139 int process (void) 0140 { 0141 int ret = EXSUCCEED; 0142 int i; 0143 char svcnm[MAXTIDENT+1]; 0144 int max_svcs; 0145 int run_max=10000; 0146 int last; 0147 /* let attach to shm... */ 0148 0149 /* service: 0150 * 0151 * expublic int _ndrx_shm_get_svc(char *svc, int *pos, int doing_install, int *p_install_cmd); 0152 * 0153 */ 0154 0155 0156 0157 /* fill with services */ 0158 max_svcs = G_max_svcs; 0159 0160 0161 for (i=max_svcs; i<run_max; i++) 0162 { 0163 if (EXSUCCEED!=init_one_free(max_svcs, 1)) 0164 { 0165 EXFAIL_OUT(ret); 0166 } 0167 0168 /* try to install now single position, we shall get one... */ 0169 snprintf(svcnm, sizeof(svcnm), "XXX%d", i); 0170 0171 /* lets install some service stuff there... */ 0172 if (EXSUCCEED!=ndrx_shm_install_svc(svcnm, 0, 1)) 0173 { 0174 NDRX_LOG(log_error, "Failed to install service [%s]! / test-one", 0175 svcnm); 0176 EXFAIL_OUT(ret); 0177 } 0178 0179 /* try to install again when full, should fail. */ 0180 snprintf(svcnm, sizeof(svcnm), "XXX%d", i+1); 0181 if (EXSUCCEED==ndrx_shm_install_svc(svcnm, 0, 1)) 0182 { 0183 NDRX_LOG(log_error, "Got succeed! but SHM is full on [%s]!", svcnm); 0184 EXFAIL_OUT(ret); 0185 } 0186 0187 /* remove from shm...and install again.. */ 0188 snprintf(svcnm, sizeof(svcnm), "XXX%d", i); 0189 ndrxd_shm_uninstall_svc(svcnm, &last, 1); 0190 0191 /* try to install again.. should succeed. */ 0192 if (EXSUCCEED!=ndrx_shm_install_svc(svcnm, 0, 1)) 0193 { 0194 NDRX_LOG(log_error, "Failed to install service [%s]! / test-one /2 ", 0195 svcnm); 0196 EXFAIL_OUT(ret); 0197 } 0198 0199 0200 } 0201 0202 out: 0203 0204 return ret; 0205 } 0206 0207 0208 /** 0209 * Main entry of th program 0210 * @param argc argument count 0211 * @param argv argument values 0212 * @return SUCCEED/FAIL 0213 */ 0214 int main(int argc, char** argv) 0215 { 0216 int ret = EXSUCCEED; 0217 0218 0219 if (EXSUCCEED!=init(argc, argv)) 0220 { 0221 TP_LOG(log_error, "Failed to Initialize!"); 0222 EXFAIL_OUT(ret); 0223 } 0224 0225 if (EXSUCCEED!=process()) 0226 { 0227 TP_LOG(log_error, "Process failed!"); 0228 EXFAIL_OUT(ret); 0229 } 0230 0231 out: 0232 uninit(ret); 0233 0234 return ret; 0235 } 0236 0237 /* vim: set ts=4 sw=4 et smartindent: */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |