nfs-ganesha 1.4
|
00001 /* 00002 * @(#)test7a.c 1.6 99/08/29 Connectathon Testsuite 00003 * 1.3 Lachman ONC Test Suite source 00004 * 00005 * Test rename 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 * rename() 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 #endif 00025 00026 #include <sys/types.h> 00027 #ifdef DOSorWIN32 00028 #include <time.h> 00029 #else 00030 #include <sys/time.h> 00031 #endif 00032 #include <sys/stat.h> 00033 #include <stdio.h> 00034 #include <stdlib.h> 00035 00036 #include "tests.h" 00037 #include "Connectathon_config_parsing.h" 00038 00039 static int Tflag = 0; /* print timing */ 00040 static int Fflag = 0; /* test function only; set count to 1, negate -t */ 00041 static int Nflag = 0; /* Suppress directory operations */ 00042 00043 static void usage() 00044 { 00045 fprintf(stdout, "usage: %s [-htfn] <config_file>\n", Myname); 00046 fprintf(stdout, " Flags: h Help - print this usage info\n"); 00047 fprintf(stdout, " t Print execution time statistics\n"); 00048 fprintf(stdout, " f Test function only (negate -t)\n"); 00049 fprintf(stdout, " n Suppress test directory create operations\n"); 00050 } 00051 00052 int main(int argc, char *argv[]) 00053 { 00054 int files; /* number of files in each dir */ 00055 int fi; 00056 int count; /* times to do each file */ 00057 int ct; 00058 int totfiles = 0; 00059 int totdirs = 0; 00060 char *fname; 00061 char *dname; 00062 char *nname; 00063 struct timeval time; 00064 char str[MAXPATHLEN]; 00065 char new[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': /* No Test Directory create */ 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, SEVEN); 00139 if(b == NULL) 00140 { 00141 fprintf(stderr, "Missing basic test number 7 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 7\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 7\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 nname = b->nname; 00168 test_dir = get_test_directory(param); 00169 log_file = get_log_file(param); 00170 00171 free_testparam(param); 00172 00173 if(!Fflag) 00174 { 00175 Tflag = 0; 00176 count = 1; 00177 } 00178 00179 fprintf(stdout, "%s: rename\n", Myname); 00180 00181 if(!Nflag) 00182 testdir(test_dir); 00183 else 00184 mtestdir(test_dir); 00185 00186 dirtree(1, files, 0, fname, dname, &totfiles, &totdirs); 00187 00188 starttime(); 00189 for(ct = 0; ct < count; ct++) 00190 { 00191 for(fi = 0; fi < files; fi++) 00192 { 00193 sprintf(str, "%s%d", fname, fi); 00194 sprintf(new, "%s%d", nname, fi); 00195 if(rename(str, new) < 0) 00196 { 00197 error("can't rename %s to %s", str, new); 00198 exit(1); 00199 } 00200 if(stat(str, &statb) == 0) 00201 { 00202 error("%s exists after rename", str); 00203 exit(1); 00204 } 00205 if(stat(new, &statb) < 0) 00206 { 00207 error("can't stat %s after rename", new); 00208 exit(1); 00209 } 00210 if(rename(new, str) < 0) 00211 { 00212 error("can't rename %s to %s", new, str); 00213 exit(1); 00214 } 00215 if(stat(new, &statb) == 0) 00216 { 00217 error("%s exists after rename", new); 00218 exit(1); 00219 } 00220 if(stat(str, &statb) < 0) 00221 { 00222 error("can't stat %s after rename", str); 00223 exit(1); 00224 } 00225 } 00226 } 00227 endtime(&time); 00228 00229 fprintf(stdout, "\t%d renames on %d files", files * count * 2, files); 00230 if(Tflag) 00231 { 00232 fprintf(stdout, " in %ld.%02ld seconds", 00233 (long)time.tv_sec, (long)time.tv_usec / 10000); 00234 } 00235 fprintf(stdout, "\n"); 00236 00237 /* Cleanup files left around */ 00238 rmdirtree(1, files, 0, fname, dname, &totfiles, &totdirs, 1); 00239 00240 if((log = fopen(log_file, "a")) == NULL) 00241 { 00242 printf("Enable to open the file '%s'\n", log_file); 00243 complete(); 00244 } 00245 fprintf(log, "b7a\t%d\t%d\t%ld.%02ld\n", files * count * 2, files, (long)time.tv_sec, 00246 (long)time.tv_usec / 10000); 00247 fclose(log); 00248 00249 complete(); 00250 }