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 * Test for the LRU List layer 00025 * 00026 * $Header: /cea/home/cvs/cvs/SHERPA/BaseCvs/GANESHA/src/LRU/test_lru.c,v 1.9 2005/11/28 17:02:39 deniel Exp $ 00027 * 00028 * Revision 1.8 2005/10/05 14:03:29 deniel 00029 * DEBUG ifdef are now much cleaner 00030 * 00031 * Revision 1.7 2005/05/10 11:44:02 deniel 00032 * Datacache and metadatacache are noewqw bounded 00033 * 00034 * Revision 1.6 2004/12/08 15:47:18 deniel 00035 * Inclusion of systenm headers has been reviewed 00036 * 00037 * Revision 1.5 2004/10/19 08:41:09 deniel 00038 * Lots of memory leaks fixed 00039 * 00040 * Revision 1.4 2004/10/18 08:42:43 deniel 00041 * Modifying prototypes for LRU_new_entry 00042 * 00043 * Revision 1.3 2004/09/21 12:21:05 deniel 00044 * Differentiation des differents tests configurables 00045 * Premiere version clean 00046 * 00047 * Revision 1.2 2004/09/20 15:36:18 deniel 00048 * Premiere implementation, sans prealloc 00049 * 00050 * Revision 1.1 2004/09/01 14:52:24 deniel 00051 * Population de la branche LRU 00052 * 00053 * 00054 */ 00055 #ifdef HAVE_CONFIG_H 00056 #include "config.h" 00057 #endif 00058 00059 #include <stdio.h> 00060 #include <stdlib.h> 00061 #include <strings.h> 00062 #include <string.h> 00063 #include "LRU_List.h" 00064 #include "log.h" 00065 00066 #define PREALLOC 10000 00067 #define MAXTEST 10 00068 #define KEPT_ENTRY 5 00069 00070 int print_entry(LRU_data_t data, char *str) 00071 { 00072 return snprintf(str, LRU_DISPLAY_STRLEN, "%s", (char *)data.pdata); 00073 } /* print_entry */ 00074 00075 int clean_entry(LRU_entry_t * pentry, void *addparam) 00076 { 00077 return 0; 00078 } /* cleanentry */ 00079 00080 int main(int argc, char *argv[]) 00081 { 00082 SetDefaultLogging("TEST"); 00083 SetNamePgm("test_lru"); 00084 00085 LRU_list_t *plru; 00086 LRU_parameter_t param; 00087 LRU_entry_t *entry = NULL; 00088 LRU_entry_t *kept_entry = NULL; 00089 LRU_status_t status = 0; 00090 int i = 0; 00091 char strtab[MAXTEST][10]; 00092 00093 param.nb_entry_prealloc = PREALLOC; 00094 param.entry_to_str = print_entry; 00095 param.clean_entry = clean_entry; 00096 param.lp_name = "Test"; 00097 00098 if((plru = LRU_Init(param, &status)) == NULL) 00099 { 00100 LogTest("Test FAILED: Bad Init"); 00101 exit(1); 00102 } 00103 00104 for(i = 0; i < MAXTEST; i++) 00105 { 00106 LogTest("Added entry %d", i); 00107 sprintf(strtab[i], "%d", i); 00108 if((entry = LRU_new_entry(plru, &status)) == NULL) 00109 { 00110 00111 LogTest("Test FAILED: bad entry add, status = %d", status); 00112 exit(1); 00113 } 00114 00115 entry->buffdata.pdata = strtab[i]; 00116 entry->buffdata.len = strlen(strtab[i]); 00117 00118 if(i == KEPT_ENTRY) 00119 kept_entry = entry; 00120 } 00121 00122 /* printing the table */ 00123 LRU_Print(plru); 00124 00125 LRU_invalidate(plru, kept_entry); 00126 00127 if(isFullDebug(COMPONENT_LRU)) 00128 LRU_Print(plru); 00129 00130 if(LRU_gc_invalid(plru, NULL) != LRU_LIST_SUCCESS) 00131 { 00132 LogTest("Test FAILED: bad gc"); 00133 exit(1); 00134 } 00135 LRU_Print(plru); 00136 00137 /* Tous les tests sont ok */ 00138 LogTest("\n-----------------------------------------"); 00139 LogTest("Test succeeded: all tests pass successfully"); 00140 00141 exit(0); 00142 } /* main */