nfs-ganesha 1.4
|
00001 /* 00002 * @(#)test4a.c 1.7 99/12/10 Connectathon Testsuite 00003 * 1.3 Lachman ONC Test Suite source 00004 * 00005 * Test getattr and lookup 00006 * 00007 * Creates the files in the test directory - does not create a directory 00008 * tree. 00009 * 00010 * Uses the following important system calls against the server: 00011 * 00012 * chdir() 00013 * mkdir() (for initial directory creation if not -m) 00014 * creat() 00015 * stat() 00016 */ 00017 00018 #if defined (DOS) || defined (WIN32) 00019 /* If Dos, Windows or Win32 */ 00020 #define DOSorWIN32 00021 #endif 00022 00023 #ifndef DOSorWIN32 00024 #include <sys/param.h> 00025 #endif 00026 00027 #include <sys/stat.h> 00028 #include <stdio.h> 00029 #include <stdlib.h> 00030 #include <sys/types.h> 00031 #ifdef DOSorWIN32 00032 #include <time.h> 00033 #else 00034 #include <sys/time.h> 00035 #endif 00036 00037 #include "tests.h" 00038 #include "Connectathon_config_parsing.h" 00039 00040 static int Tflag = 0; /* print timing */ 00041 static int Fflag = 0; /* test function only; set count to 1, negate -t */ 00042 static int Nflag = 0; /* Suppress directory operations */ 00043 00044 static void usage() 00045 { 00046 fprintf(stdout, "usage: %s [-htfn] <config_file>\n", Myname); 00047 fprintf(stdout, " Flags: h Help - print this usage info\n"); 00048 fprintf(stdout, " t Print execution time statistics\n"); 00049 fprintf(stdout, " f Test function only (negate -t)\n"); 00050 fprintf(stdout, " n Suppress test directory create operations\n"); 00051 } 00052 00053 int main(int argc, char *argv[]) 00054 { 00055 int files; /* number of files in each dir */ 00056 int fi; 00057 int count; /* times to do each file */ 00058 int ct; 00059 int totfiles = 0; 00060 int totdirs = 0; 00061 char *fname; 00062 char *dname; 00063 struct timeval time; 00064 char str[MAXPATHLEN]; 00065 struct stat statb; 00066 char *opts; 00067 struct testparam *param; 00068 struct btest *b; 00069 char *config_file; 00070 char *test_dir; 00071 char *log_file; 00072 FILE *log; 00073 00074 umask(0); 00075 setbuf(stdout, NULL); 00076 Myname = *argv++; 00077 argc--; 00078 while(argc && **argv == '-') 00079 { 00080 for(opts = &argv[0][1]; *opts; opts++) 00081 { 00082 switch (*opts) 00083 { 00084 case 'h': /* help */ 00085 usage(); 00086 exit(1); 00087 break; 00088 00089 case 't': /* time */ 00090 Tflag++; 00091 break; 00092 00093 case 'f': /* funtionality */ 00094 Fflag++; 00095 break; 00096 00097 case 'n': /* suppress initial directory */ 00098 Nflag++; 00099 break; 00100 00101 default: 00102 error("unknown option '%c'", *opts); 00103 usage(); 00104 exit(1); 00105 } 00106 } 00107 argc--; 00108 argv++; 00109 } 00110 00111 if(argc) 00112 { 00113 config_file = *argv; 00114 argc--; 00115 argv++; 00116 } 00117 else 00118 { 00119 fprintf(stderr, "Missing config_file"); 00120 exit(1); 00121 } 00122 00123 if(argc != 0) 00124 { 00125 fprintf(stderr, "too many parameters"); 00126 usage(); 00127 exit(1); 00128 } 00129 00130 param = readin_config(config_file); 00131 if(param == NULL) 00132 { 00133 fprintf(stderr, "Nothing built\n"); 00134 exit(1); 00135 } 00136 00137 b = get_btest_args(param, FOUR); 00138 if(b == NULL) 00139 { 00140 fprintf(stderr, "Missing basic test number 4 in the config file '%s'\n", 00141 config_file); 00142 free_testparam(param); 00143 exit(1); 00144 } 00145 00146 if(b->files == -1) 00147 { 00148 fprintf(stderr, 00149 "Missing 'files' parameter in the config file '%s' for the basic test number 4\n", 00150 config_file); 00151 free_testparam(param); 00152 exit(1); 00153 } 00154 if(b->count == -1) 00155 { 00156 fprintf(stderr, 00157 "Missing 'count' parameter in the config file '%s' for the basic test number 4\n", 00158 config_file); 00159 free_testparam(param); 00160 exit(1); 00161 } 00162 count = b->count; 00163 files = b->files; 00164 fname = b->fname; 00165 dname = b->dname; 00166 test_dir = get_test_directory(param); 00167 log_file = get_log_file(param); 00168 00169 free_testparam(param); 00170 00171 if(!Fflag) 00172 { 00173 Tflag = 0; 00174 count = 1; 00175 } 00176 00177 if(!Nflag) 00178 testdir(test_dir); 00179 else 00180 mtestdir(test_dir); 00181 00182 dirtree(1, files, 0, fname, dname, &totfiles, &totdirs); 00183 00184 fprintf(stdout, "%s: getattr and lookup\n", Myname); 00185 00186 starttime(); 00187 for(ct = 0; ct < count; ct++) 00188 { 00189 for(fi = 0; fi < files; fi++) 00190 { 00191 sprintf(str, "%s%d", fname, fi); 00192 if(stat(str, &statb) < 0) 00193 { 00194 error("can't stat %s", str); 00195 exit(1); 00196 } 00197 } 00198 } 00199 endtime(&time); 00200 00201 fprintf(stdout, "\t%d stats on %d files", files * count * 2, files); 00202 if(Tflag) 00203 { 00204 fprintf(stdout, " in %ld.%02ld seconds", 00205 (long)time.tv_sec, (long)time.tv_usec / 10000); 00206 } 00207 fprintf(stdout, "\n"); 00208 00209 if((log = fopen(log_file, "a")) == NULL) 00210 { 00211 printf("Enable to open the file '%s'\n", log_file); 00212 complete(); 00213 } 00214 fprintf(log, "b4a\t%d\t%d\t%ld.%02ld\n", files * count * 2, files, (long)time.tv_sec, 00215 (long)time.tv_usec / 10000); 00216 fclose(log); 00217 00218 /* XXX REMOVE DIRECTORY TREE? */ 00219 complete(); 00220 }