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