nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 * 00004 * Copyright CEA/DAM/DIF (2008) 00005 * contributeur : Philippe DENIEL philippe.deniel@cea.fr 00006 * Thomas LEIBOVICI thomas.leibovici@cea.fr 00007 * 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 3 of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 * 00023 * --------------------------------------- 00024 * Configurable test for the LRU List layer 00025 * 00026 * $Header: /cea/home/cvs/cvs/SHERPA/BaseCvs/GANESHA/src/LRU/test_configurable_lru.c,v 1.7 2005/11/28 17:02:39 deniel Exp $ 00027 * 00028 * Revision 1.6 2005/05/10 11:44:02 deniel 00029 * Datacache and metadatacache are noewqw bounded 00030 * 00031 * Revision 1.5 2004/12/08 14:49:44 deniel 00032 * Lack of includes in test_configurable_hash.c and test_configurable_lru.c 00033 * 00034 * Revision 1.4 2004/10/19 08:41:09 deniel 00035 * Lots of memory leaks fixed 00036 * 00037 * Revision 1.3 2004/10/18 08:42:43 deniel 00038 * Modifying prototypes for LRU_new_entry 00039 * 00040 * Revision 1.2 2004/09/23 14:34:48 deniel 00041 * Mise en place du test configurable 00042 * 00043 * Revision 1.1 2004/09/21 13:18:40 deniel 00044 * test_configurable.c renomme en test_configurable_lru.c 00045 * 00046 * Revision 1.1 2004/09/01 14:52:24 deniel 00047 * Population de la branche LRU 00048 * 00049 * 00050 */ 00051 #ifdef HAVE_CONFIG_H 00052 #include "config.h" 00053 #endif 00054 00055 #include <stdio.h> 00056 #include <stdlib.h> 00057 #include <strings.h> 00058 #include <string.h> 00059 #include "LRU_List.h" 00060 #include "log.h" 00061 00062 #define LENBUF 256 00063 #define STRSIZE 10 00064 #define PREALLOC 1000000 00065 #define MAXTEST 1000000 00066 00067 LRU_entry_t *tabentry[MAXTEST]; 00068 00069 static int print_entry(LRU_data_t data, char *str) 00070 { 00071 return snprintf(str, LRU_DISPLAY_STRLEN, "%s, len=%llu", (char *)data.pdata, 00072 (unsigned long long)data.len); 00073 } /* print_entry */ 00074 00075 static int clean_entry(LRU_entry_t * pentry, void *addparam) 00076 { 00077 return 0; 00078 } /* cleanentry */ 00079 00080 int do_invalidate(LRU_list_t * plru, int key) 00081 { 00082 LRU_entry_t *pentry = NULL; 00083 00084 pentry = tabentry[key]; 00085 00086 return LRU_invalidate(plru, pentry); 00087 } 00088 00089 int do_new(LRU_list_t * plru, int key) 00090 { 00091 char *tmpkey = NULL; 00092 00093 LRU_entry_t *pentry = NULL; 00094 LRU_status_t status; 00095 00096 if((tmpkey = (char *)malloc(STRSIZE)) == NULL) 00097 return -1; 00098 00099 sprintf(tmpkey, "%d", key); 00100 00101 if((pentry = LRU_new_entry(plru, &status)) == NULL) 00102 { 00103 free(tmpkey); 00104 return status; 00105 } 00106 00107 pentry->buffdata.len = strlen(tmpkey); 00108 pentry->buffdata.pdata = tmpkey; 00109 00110 tabentry[key] = pentry; 00111 00112 return status; 00113 } 00114 00115 int do_gc(LRU_list_t * plru) 00116 { 00117 return LRU_gc_invalid(plru, NULL); 00118 } 00119 00120 int main(int argc, char *argv[]) 00121 { 00122 SetDefaultLogging("TEST"); 00123 SetNamePgm("test_configurable_lru"); 00124 00125 char buf[LENBUF]; 00126 int ok = 1; 00127 int hrc = 0; 00128 int rc = 0; 00129 int expected_rc; 00130 char c; 00131 char *p; 00132 int key; 00133 00134 LRU_status_t status = 0; 00135 LRU_list_t *plru; 00136 LRU_parameter_t param; 00137 00138 param.nb_entry_prealloc = PREALLOC; 00139 param.entry_to_str = print_entry; 00140 param.clean_entry = clean_entry; 00141 param.lp_name = "Test"; 00142 00143 if((plru = LRU_Init(param, &status)) == NULL) 00144 { 00145 LogTest("Test ECHOUE : Mauvaise init"); 00146 exit(1); 00147 } 00148 00149 /* 00150 * 00151 * La syntaxe d'un test est 00152 * 'i key rc' : invalide l'entree avec la clef key 00153 * 'n key rc' : cree une nouvelle entree avec la clef key 00154 * 'g key rc' : passage du garbage collector (key ne sert a rien) 00155 * 'p key rc' : imprime le LRU (key et rc ne servent a rien). 00156 * 00157 * Une ligne qui debute par '#' est un commentaire 00158 * Une ligne qui debute par un espace ou un tab est une ligne vide [meme si il y a des trucs derriere.. :-( ] 00159 * Une ligne vide (juste un CR) est une ligne vide (cette citation a recu le Premier Prix lors du Festival International 00160 * de la Tautologie de Langue Francaise (FITLF), a Poully le Marais, en Aout 2004) 00161 * 00162 */ 00163 00164 LogTest("============ Debut de l'interactif ================="); 00165 00166 while(ok) 00167 { 00168 /* Code interactif, pompe sur le test rbt de Jacques */ 00169 fputs("> ", stdout); 00170 if((p = fgets(buf, LENBUF, stdin)) == NULL) 00171 { 00172 LogTest("fin des commandes"); 00173 ok = 0; 00174 continue; 00175 } 00176 if((p = strchr(buf, '\n')) != NULL) 00177 *p = '\0'; 00178 00179 rc = sscanf(buf, "%c %d %d", &c, &key, &expected_rc); 00180 if(c == '#') 00181 { 00182 /* # indique un commentaire */ 00183 continue; 00184 } 00185 else if(c == ' ' || c == '\t' || rc == -1) 00186 { 00187 /* Cas d'une ligne vide */ 00188 if(rc > 1) 00189 LogTest("Erreur de syntaxe : mettre un diese au debut d'un commentaire"); 00190 00191 continue; 00192 } 00193 else 00194 { 00195 if(rc != 3) 00196 { 00197 LogTest("Erreur de syntaxe : sscanf retourne %d au lieu de 3", rc); 00198 continue; 00199 } 00200 LogTest("---> %c %d %d", c, key, expected_rc); 00201 } 00202 00203 switch (c) 00204 { 00205 case 'i': 00206 /* set overwrite */ 00207 LogTest("invalidate %d --> %d ?", key, expected_rc); 00208 00209 hrc = do_invalidate(plru, key); 00210 00211 if(hrc != expected_rc) 00212 LogTest(">>>> ERREUR: invalidate %d : %d != %d (expected)", 00213 key, hrc, expected_rc); 00214 else 00215 LogTest(">>>> OK invalidate %d", key); 00216 break; 00217 00218 case 'n': 00219 /* test */ 00220 LogTest("new %d --> %d ?", key, expected_rc); 00221 00222 hrc = do_new(plru, key); 00223 00224 if(hrc != expected_rc) 00225 LogTest(">>>> ERREUR: new %d : %d != %d (expected)", key, hrc, expected_rc); 00226 else 00227 LogTest(">>>> OK new %d", key); 00228 break; 00229 00230 case 'g': 00231 /* set no overwrite */ 00232 LogTest("gc %d --> %d ?", key, expected_rc); 00233 00234 hrc = do_gc(plru); 00235 00236 if(hrc != expected_rc) 00237 LogTest(">>>> ERREUR: gc %d: %d != %d (expected)", key, hrc, expected_rc); 00238 else 00239 LogTest(">>>> OK new %d", key); 00240 break; 00241 00242 case 'p': 00243 /* Print */ 00244 LRU_Print(plru); 00245 break; 00246 00247 default: 00248 /* syntaxe error */ 00249 LogTest("ordre '%c' non-reconnu", c); 00250 break; 00251 } 00252 } 00253 00254 LogTest("===================================================="); 00255 LogTest("Test reussi : tous les tests sont passes avec succes"); 00256 return 0; 00257 } /* main */