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