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