nfs-ganesha 1.4
|
00001 /* 00002 * @(#)test7b.c 1.7 99/08/29 Connectathon Testsuite 00003 * 1.3 Lachman ONC Test Suite source 00004 * 00005 * Test link 00006 * 00007 * Uses the following important system calls against the server: 00008 * 00009 * chdir() 00010 * mkdir() (for initial directory creation if not -m) 00011 * creat() 00012 * stat() 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_parsing>\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(stdout, "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\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 #ifndef DOSorWIN32 00199 if(link(str, new) < 0) 00200 { 00201 oerrno = errno; 00202 error("can't link %s to %s", str, new); 00203 errno = oerrno; 00204 if(errno == EOPNOTSUPP) 00205 complete(); 00206 exit(1); 00207 } 00208 if(stat(new, &statb) < 0) 00209 { 00210 error("can't stat %s after link", new); 00211 exit(1); 00212 } 00213 if(statb.st_nlink != 2) 00214 { 00215 error("%s has %d links after link (expect 2)", new, statb.st_nlink); 00216 exit(1); 00217 } 00218 if(stat(str, &statb) < 0) 00219 { 00220 error("can't stat %s after link", str); 00221 exit(1); 00222 } 00223 if(statb.st_nlink != 2) 00224 { 00225 error("%s has %d links after link (expect 2)", str, statb.st_nlink); 00226 exit(1); 00227 } 00228 if(unlink(new) < 0) 00229 { 00230 error("can't unlink %s", new); 00231 exit(1); 00232 } 00233 if(stat(str, &statb) < 0) 00234 { 00235 error("can't stat %s after unlink %s", str, new); 00236 exit(1); 00237 } 00238 if(statb.st_nlink != 1) 00239 { 00240 error("%s has %d links after unlink (expect 1)", str, statb.st_nlink); 00241 exit(1); 00242 } 00243 #else /* DOSorWIN32 */ /* just rename back to orig name */ 00244 if(rename(str, new) < 0) 00245 { 00246 error("can't rename %s to %s", str, new); 00247 exit(1); 00248 } 00249 if(stat(new, &statb) < 0) 00250 { 00251 error("can't stat %s after rename %s", new, str); 00252 exit(1); 00253 } 00254 if(statb.st_nlink != 1) 00255 { 00256 error("%s has %d links after rename (expect 1)", new, statb.st_nlink); 00257 exit(1); 00258 } 00259 if(rename(new, str) < 0) 00260 { 00261 error("can't rename %s to %s", new, str); 00262 exit(1); 00263 } 00264 if(stat(str, &statb) < 0) 00265 { 00266 error("can't stat %s after rename %s", str, new); 00267 exit(1); 00268 } 00269 if(statb.st_nlink != 1) 00270 { 00271 error("%s has %d links after rename (expect 1)", str, statb.st_nlink); 00272 exit(1); 00273 } 00274 #endif /* DOSorWIN32 */ 00275 } 00276 } 00277 endtime(&time); 00278 00279 fprintf(stdout, "\t%d links on %d files", files * count, files); 00280 if(Tflag) 00281 { 00282 fprintf(stdout, " in %ld.%02ld seconds", 00283 (long)time.tv_sec, (long)time.tv_usec / 10000); 00284 } 00285 fprintf(stdout, "\n"); 00286 00287 /* Cleanup files left around */ 00288 rmdirtree(1, files, 0, fname, dname, &totfiles, &totdirs, 1); 00289 00290 if((log = fopen(log_file, "a")) == NULL) 00291 { 00292 printf("Enable to open the file '%s'\n", log_file); 00293 complete(); 00294 } 00295 fprintf(log, "b7b\t%d\t%d\t%ld.%02ld\n", files * count, files, (long)time.tv_sec, 00296 (long)time.tv_usec / 10000); 00297 fclose(log); 00298 00299 complete(); 00300 }