nfs-ganesha 1.4
|
00001 /* 00002 * @(#)test5b.c 1.7 03/12/01 Connectathon Testsuite 00003 * 1.3 Lachman ONC Test Suite source 00004 * 00005 * Test read - will read a file of specified size, contents not looked at 00006 * 00007 * Uses the following important system calls against the server: 00008 * 00009 * chdir() 00010 * mkdir() (for initial directory creation if not -m) 00011 * open() 00012 * read() 00013 * unlink() 00014 */ 00015 00016 #if defined (DOS) || defined (WIN32) 00017 /* If Dos, Windows or Win32 */ 00018 #define DOSorWIN32 00019 #endif 00020 00021 #ifndef DOSorWIN32 00022 #include <sys/param.h> 00023 #include <unistd.h> 00024 #endif 00025 00026 #include <sys/stat.h> 00027 #include <stdio.h> 00028 #include <stdlib.h> 00029 #include <fcntl.h> 00030 #include <sys/types.h> 00031 #ifdef DOSorWIN32 00032 #include <time.h> 00033 #else 00034 #include <sys/time.h> 00035 #endif 00036 #ifdef MMAP 00037 #include <sys/mman.h> 00038 #endif 00039 00040 #include "tests.h" 00041 #include "Connectathon_config_parsing.h" 00042 00043 #ifndef MIN 00044 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 00045 #endif 00046 00047 #define BUFSZ 8192 00048 00049 static int Tflag = 0; /* print timing */ 00050 static int Fflag = 0; /* test function only; set count to 1, negate -t */ 00051 static int Nflag = 0; /* Suppress directory operations */ 00052 00053 static void usage() 00054 { 00055 fprintf(stdout, "usage: %s [-htfn] <config_file>\n", Myname); 00056 fprintf(stdout, " Flags: h Help - print this usage info\n"); 00057 fprintf(stdout, " t Print execution time statistics\n"); 00058 fprintf(stdout, " f Test function only (negate -t)\n"); 00059 fprintf(stdout, " n Suppress test directory create operations\n"); 00060 } 00061 00062 int main(int argc, char *argv[]) 00063 { 00064 int count; /* times to do each file */ 00065 int ct; 00066 off_t size; 00067 off_t si; 00068 int fd; 00069 off_t bytes = 0; 00070 int roflags; /* open read-only flags */ 00071 char *bigfile; 00072 struct timeval time; 00073 char *opts; 00074 char buf[BUFSZ]; 00075 double etime; 00076 #ifdef MMAP 00077 caddr_t maddr; 00078 #endif 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, FIVE); 00150 if(b == NULL) 00151 { 00152 fprintf(stderr, "Missing basic test number 5 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 5\n", 00162 config_file); 00163 free_testparam(param); 00164 exit(1); 00165 } 00166 if(b->size == -1) 00167 { 00168 fprintf(stderr, 00169 "Missing 'size' parameter in the config file '%s' for the basic test number 5\n", 00170 config_file); 00171 free_testparam(param); 00172 exit(1); 00173 } 00174 count = b->count; 00175 size = b->size; 00176 bigfile = b->bigfile; 00177 test_dir = get_test_directory(param); 00178 log_file = get_log_file(param); 00179 00180 free_testparam(param); 00181 00182 if(!Fflag) 00183 { 00184 Tflag = 0; 00185 count = 1; 00186 } 00187 00188 roflags = O_RDONLY; 00189 #ifdef DOSorWIN32 00190 roflags |= O_BINARY; 00191 #endif 00192 00193 fprintf(stdout, "%s: read\n", Myname); 00194 00195 mtestdir(test_dir); 00196 00197 starttime(); 00198 for(ct = 0; ct < count; ct++) 00199 { 00200 if((fd = open(bigfile, roflags)) < 0) 00201 { 00202 error("can't open '%s'", bigfile); 00203 exit(1); 00204 } 00205 #ifdef MMAP 00206 maddr = mmap((caddr_t) 0, (size_t) size, PROT_READ, MAP_PRIVATE, fd, (off_t) 0); 00207 if(maddr == MAP_FAILED) 00208 { 00209 error("can't mmap '%s'", bigfile); 00210 exit(1); 00211 } 00212 if(msync(maddr, (size_t) size, MS_INVALIDATE) < 0) 00213 { 00214 error("can't invalidate pages for '%s'", bigfile); 00215 exit(1); 00216 } 00217 if(munmap(maddr, (size_t) size) < 0) 00218 { 00219 error("can't munmap '%s'", bigfile); 00220 exit(1); 00221 } 00222 #endif 00223 for(si = size; si > 0; si -= bytes) 00224 { 00225 bytes = MIN(BUFSZ, si); 00226 if(read(fd, buf, bytes) != bytes) 00227 { 00228 error("'%s' read failed", bigfile); 00229 exit(1); 00230 } 00231 } 00232 close(fd); 00233 } 00234 endtime(&time); 00235 00236 fprintf(stdout, "\tread %ld byte file %d times", (long)size, count); 00237 00238 if(Tflag) 00239 { 00240 etime = (double)time.tv_sec + (double)time.tv_usec / 1000000.0; 00241 if(etime != 0.0) 00242 { 00243 fprintf(stdout, " in %ld.%02ld seconds (%ld bytes/sec)", 00244 (long)time.tv_sec, (long)time.tv_usec / 10000, 00245 (long)((double)size * ((double)count / etime))); 00246 } 00247 else 00248 { 00249 fprintf(stdout, " in %ld.%02ld seconds (> %ld bytes/sec)", 00250 (long)time.tv_sec, (long)time.tv_usec / 10000, (long)size * count); 00251 } 00252 } 00253 fprintf(stdout, "\n"); 00254 00255 if(unlink(bigfile) < 0) 00256 { 00257 error("can't unlink '%s'", bigfile); 00258 exit(1); 00259 } 00260 00261 if((log = fopen(log_file, "a")) == NULL) 00262 { 00263 printf("Enable to open the file '%s'\n", log_file); 00264 complete(); 00265 } 00266 #ifdef _TOTO 00267 if(etime != 0.0) 00268 { 00269 fprintf(log, "b5b\t%d\t%d\t%ld.%02ld\t%ld\n", (long)size, count, (long)time.tv_sec, 00270 (long)time.tv_usec / 10000, (long)((double)size * ((double)count / etime))); 00271 } 00272 else 00273 { 00274 fprintf(log, "b5b\t%d\t%d\t%ld.%02ld\t%ld\n", (long)size, count, (long)time.tv_sec, 00275 (long)time.tv_usec / 10000, (long)size * count); 00276 } 00277 #endif 00278 fclose(log); 00279 00280 complete(); 00281 }