nfs-ganesha 1.4
|
00001 /* 00002 * @(#)test7.c 1.7 99/08/29 Connectathon Testsuite 00003 * 1.4 Lachman ONC Test Suite source 00004 * 00005 * Test rename, link 00006 * 00007 * Uses the following important system calls against the server: 00008 * 00009 * chdir() 00010 * creat() 00011 * stat() 00012 * rename() 00013 * link() 00014 * unlink() 00015 */ 00016 00017 #if defined (DOS) || defined (WIN32) 00018 /* If Dos, Windows or Win32 */ 00019 #define DOSorWIN32 00020 #endif 00021 00022 #ifndef DOSorWIN32 00023 #include <sys/param.h> 00024 #include <unistd.h> 00025 #endif 00026 00027 #include <sys/stat.h> 00028 #include <errno.h> 00029 #include <stdio.h> 00030 #include <stdlib.h> 00031 #ifdef DOSorWIN32 00032 #include <time.h> 00033 #else 00034 #include <sys/time.h> 00035 #endif 00036 #include <sys/types.h> 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 [-htfn] <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 char *nname; 00065 struct timeval time; 00066 char str[MAXPATHLEN]; 00067 char new[MAXPATHLEN]; 00068 struct stat statb; 00069 char *opts; 00070 int oerrno; 00071 struct testparam *param; 00072 struct btest *b; 00073 char *config_file; 00074 char *test_dir; 00075 char *log_file; 00076 FILE *log; 00077 00078 umask(0); 00079 setbuf(stdout, NULL); 00080 Myname = *argv++; 00081 argc--; 00082 while(argc && **argv == '-') 00083 { 00084 for(opts = &argv[0][1]; *opts; opts++) 00085 { 00086 switch (*opts) 00087 { 00088 case 'h': /* help */ 00089 usage(); 00090 exit(1); 00091 break; 00092 00093 case 't': /* time */ 00094 Tflag++; 00095 break; 00096 00097 case 'f': /* funtionality */ 00098 Fflag++; 00099 break; 00100 00101 case 'n': /* No Test Directory create */ 00102 Nflag++; 00103 break; 00104 00105 default: 00106 error("unknown option '%c'", *opts); 00107 usage(); 00108 exit(1); 00109 } 00110 } 00111 argc--; 00112 argv++; 00113 } 00114 00115 if(argc) 00116 { 00117 config_file = *argv; 00118 argc--; 00119 argv++; 00120 } 00121 else 00122 { 00123 fprintf(stderr, "Missing config_file"); 00124 exit(1); 00125 } 00126 00127 if(argc != 0) 00128 { 00129 fprintf(stderr, "too many parameters"); 00130 usage(); 00131 exit(1); 00132 } 00133 00134 param = readin_config(config_file); 00135 if(param == NULL) 00136 { 00137 fprintf(stderr, "Nothing built\n"); 00138 exit(1); 00139 } 00140 00141 b = get_btest_args(param, SEVEN); 00142 if(b == NULL) 00143 { 00144 fprintf(stderr, "Missing basic test number 7 in the config file '%s'\n", 00145 config_file); 00146 free_testparam(param); 00147 exit(1); 00148 } 00149 00150 if(b->files == -1) 00151 { 00152 fprintf(stderr, 00153 "Missing 'files' parameter in the config file '%s' for the basic test number 7\n", 00154 config_file); 00155 free_testparam(param); 00156 exit(1); 00157 } 00158 if(b->count == -1) 00159 { 00160 fprintf(stderr, 00161 "Missing 'count' parameter in the config file '%s' for the basic test number 7\n", 00162 config_file); 00163 free_testparam(param); 00164 exit(1); 00165 } 00166 count = b->count; 00167 files = b->files; 00168 fname = b->fname; 00169 dname = b->dname; 00170 nname = b->nname; 00171 test_dir = get_test_directory(param); 00172 log_file = get_log_file(param); 00173 00174 free_testparam(param); 00175 00176 if(!Fflag) 00177 { 00178 Tflag = 0; 00179 count = 1; 00180 } 00181 00182 fprintf(stdout, "%s: link and rename\n", Myname); 00183 00184 if(!Nflag) 00185 testdir(test_dir); 00186 else 00187 mtestdir(test_dir); 00188 00189 dirtree(1, files, 0, fname, dname, &totfiles, &totdirs); 00190 00191 starttime(); 00192 for(ct = 0; ct < count; ct++) 00193 { 00194 for(fi = 0; fi < files; fi++) 00195 { 00196 sprintf(str, "%s%d", fname, fi); 00197 sprintf(new, "%s%d", nname, fi); 00198 if(rename(str, new) < 0) 00199 { 00200 error("can't rename %s to %s", str, new); 00201 exit(1); 00202 } 00203 if(stat(str, &statb) == 0) 00204 { 00205 error("%s exists after rename to %s", str, new); 00206 exit(1); 00207 } 00208 if(stat(new, &statb) < 0) 00209 { 00210 error("can't stat %s after rename from %s", new, str); 00211 exit(1); 00212 } 00213 if(statb.st_nlink != 1) 00214 { 00215 error("%s has %d links after rename (expect 1)", new, statb.st_nlink); 00216 exit(1); 00217 } 00218 #ifndef DOSorWIN32 00219 if(link(new, str) < 0) 00220 { 00221 oerrno = errno; 00222 error("can't link %s to %s", new, str); 00223 errno = oerrno; 00224 if(errno == EOPNOTSUPP) 00225 complete(); 00226 exit(1); 00227 } 00228 if(stat(new, &statb) < 0) 00229 { 00230 error("can't stat %s after link", new); 00231 exit(1); 00232 } 00233 if(statb.st_nlink != 2) 00234 { 00235 error("%s has %d links after link (expect 2)", new, statb.st_nlink); 00236 exit(1); 00237 } 00238 if(stat(str, &statb) < 0) 00239 { 00240 error("can't stat %s after link", str); 00241 exit(1); 00242 } 00243 if(statb.st_nlink != 2) 00244 { 00245 error("%s has %d links after link (expect 2)", str, statb.st_nlink); 00246 exit(1); 00247 } 00248 if(unlink(new) < 0) 00249 { 00250 error("can't unlink %s", new); 00251 exit(1); 00252 } 00253 if(stat(str, &statb) < 0) 00254 { 00255 error("can't stat %s after unlink %s", str, new); 00256 exit(1); 00257 } 00258 if(statb.st_nlink != 1) 00259 { 00260 error("%s has %d links after unlink (expect 1)", str, statb.st_nlink); 00261 exit(1); 00262 } 00263 #else /* DOSorWIN32 */ 00264 /* just rename back to orig name */ 00265 if(rename(new, str) < 0) 00266 { 00267 error("can't rename %s to %s", new, str); 00268 exit(1); 00269 } 00270 if(stat(str, &statb) < 0) 00271 { 00272 error("can't find %s after rename", str); 00273 exit(1); 00274 } 00275 if(stat(new, &statb) == 0) 00276 { 00277 error("still found %s after rename", new); 00278 exit(1); 00279 } 00280 #endif /* DOSorWIN32 */ 00281 } 00282 } 00283 00284 endtime(&time); 00285 fprintf(stdout, "\t%d renames and links on %d files", files * count * 2, files); 00286 if(Tflag) 00287 { 00288 fprintf(stdout, " in %ld.%02ld seconds", 00289 (long)time.tv_sec, (long)time.tv_usec / 10000); 00290 } 00291 fprintf(stdout, "\n"); 00292 00293 /* Cleanup files left around */ 00294 rmdirtree(1, files, 0, fname, dname, &totfiles, &totdirs, 1); 00295 00296 if((log = fopen(log_file, "a")) == NULL) 00297 { 00298 printf("Enable to open the file '%s'\n", log_file); 00299 complete(); 00300 } 00301 fprintf(log, "b7\t%d\t%d\t%ld.%02ld\n", files * count * 2, files, (long)time.tv_sec, 00302 (long)time.tv_usec / 10000); 00303 fclose(log); 00304 00305 complete(); 00306 }