nfs-ganesha 1.4

test8.c

Go to the documentation of this file.
00001 /*
00002  *      @(#)test8.c     1.7     2001/08/25 Connectathon Testsuite
00003  *      1.4 Lachman ONC Test Suite source
00004  *
00005  * Test symlink, readlink
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  *      symlink()
00013  *      readlink()
00014  *      lstat()
00015  *      unlink()
00016  */
00017 
00018 #if defined (DOS) || defined (WIN32)
00019 /* If Dos, Windows or Win32 */
00020 #define DOSorWIN32
00021 #endif
00022 
00023 #ifndef DOSorWIN32
00024 #include <sys/param.h>
00025 #include <unistd.h>
00026 #endif
00027 
00028 #include <sys/stat.h>
00029 #include <errno.h>
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <sys/types.h>
00034 #ifdef DOSorWIN32
00035 #include <time.h>
00036 #else
00037 #include <sys/time.h>
00038 #endif
00039 
00040 #include "tests.h"
00041 #include "Connectathon_config_parsing.h"
00042 
00043 static int Tflag = 0;           /* print timing */
00044 static int Fflag = 0;           /* test function only;  set count to 1, negate -t */
00045 static int Nflag = 0;           /* Suppress directory operations */
00046 
00047 static void usage()
00048 {
00049   fprintf(stdout, "usage: %s [-htfn] <config_file>\n", Myname);
00050   fprintf(stdout, "  Flags:  h    Help - print this usage info\n");
00051   fprintf(stdout, "          t    Print execution time statistics\n");
00052   fprintf(stdout, "          f    Test function only (negate -t)\n");
00053   fprintf(stdout, "          n    Suppress test directory create operations\n");
00054 }
00055 
00056 int main(int argc, char *argv[])
00057 {
00058   int files;                    /* number of files in each dir */
00059   int fi;
00060   int count;                    /* times to do each file */
00061   int ct;
00062   char *fname;
00063   char *sname;
00064   struct timeval time;
00065   char str[MAXPATHLEN];
00066   char new[MAXPATHLEN];
00067   char buf[MAXPATHLEN];
00068   int ret;
00069   struct stat statb;
00070   char *opts;
00071   int oerrno;
00072   struct testparam *param;
00073   struct btest *b;
00074   char *config_file;
00075   char *test_dir;
00076   char *log_file;
00077   FILE *log;
00078   int sname_len;
00079 
00080   umask(0);
00081   setbuf(stdout, NULL);
00082   Myname = *argv++;
00083   argc--;
00084   while(argc && **argv == '-')
00085     {
00086       for(opts = &argv[0][1]; *opts; opts++)
00087         {
00088           switch (*opts)
00089             {
00090             case 'h':          /* help */
00091               usage();
00092               exit(1);
00093               break;
00094 
00095             case 't':          /* time */
00096               Tflag++;
00097               break;
00098 
00099             case 'f':          /* funtionality */
00100               Fflag++;
00101               break;
00102 
00103             case 'n':          /* No Test Directory create */
00104               Nflag++;
00105               break;
00106 
00107             default:
00108               error("unknown option '%c'", *opts);
00109               usage();
00110               exit(1);
00111             }
00112         }
00113       argc--;
00114       argv++;
00115     }
00116 
00117   if(argc)
00118     {
00119       config_file = *argv;
00120       argc--;
00121       argv++;
00122     }
00123   else
00124     {
00125       fprintf(stderr, "Missing config_file");
00126       exit(1);
00127     }
00128 
00129   if(argc != 0)
00130     {
00131       fprintf(stderr, "too many parameters");
00132       usage();
00133       exit(1);
00134     }
00135 
00136   param = readin_config(config_file);
00137   if(param == NULL)
00138     {
00139       fprintf(stderr, "Nothing built\n");
00140       exit(1);
00141     }
00142 
00143   b = get_btest_args(param, EIGHT);
00144   if(b == NULL)
00145     {
00146       fprintf(stderr, "Missing basic test number 8 in the config file '%s'\n",
00147               config_file);
00148       free_testparam(param);
00149       exit(1);
00150     }
00151 
00152   if(b->files == -1)
00153     {
00154       fprintf(stderr,
00155               "Missing 'files' parameter in the config file '%s' for the basic test number 8\n",
00156               config_file);
00157       free_testparam(param);
00158       exit(1);
00159     }
00160   if(b->count == -1)
00161     {
00162       fprintf(stderr,
00163               "Missing 'count' parameter in the config file '%s' for the basic test number 8\n",
00164               config_file);
00165       free_testparam(param);
00166       exit(1);
00167     }
00168   count = b->count;
00169   files = b->files;
00170   fname = b->fname;
00171   sname = b->sname;
00172   test_dir = get_test_directory(param);
00173   log_file = get_log_file(param);
00174   sname_len = (int)strlen(sname);
00175 
00176   free_testparam(param);
00177 
00178 #ifndef S_IFLNK
00179   fprintf(stdout, "\
00180 %s: symlink and readlink not supported on this client\n", Myname);
00181 #else                           /* S_IFLNK */
00182   if(!Fflag)
00183     {
00184       Tflag = 0;
00185       count = 1;
00186     }
00187 
00188   if(!Nflag)
00189     testdir(test_dir);
00190   else
00191     mtestdir(test_dir);
00192 
00193   fprintf(stdout, "%s: symlink and readlink\n", Myname);
00194 
00195   starttime();
00196   for(ct = 0; ct < count; ct++)
00197     {
00198       for(fi = 0; fi < files; fi++)
00199         {
00200           sprintf(str, "%s%d", fname, fi);
00201           sprintf(new, "%s%d", sname, fi);
00202           if(symlink(new, str) < 0)
00203             {
00204               oerrno = errno;
00205               error("can't make symlink %s", str);
00206               errno = oerrno;
00207               if(errno == EOPNOTSUPP)
00208                 complete();
00209               else
00210                 exit(1);
00211             }
00212           if(lstat(str, &statb) < 0)
00213             {
00214               error("can't stat %s after symlink", str);
00215               exit(1);
00216             }
00217           if((statb.st_mode & S_IFMT) != S_IFLNK)
00218             {
00219               error("mode of %s not symlink");
00220               exit(1);
00221             }
00222           if((ret = readlink(str, buf, MAXPATHLEN)) != (int)strlen(new))
00223             {
00224               error("readlink %s ret %d, expect %d", str, ret, strlen(new));
00225               exit(1);
00226             }
00227           if(strncmp(new, buf, ret) != 0)
00228             {
00229               error("readlink %s returned bad linkname", str);
00230               exit(1);
00231             }
00232           if(unlink(str) < 0)
00233             {
00234               error("can't unlink %s", str);
00235               exit(1);
00236             }
00237         }
00238     }
00239   endtime(&time);
00240 
00241   fprintf(stdout, "\t%d symlinks and readlinks on %d files (size of symlink : %d)",
00242           files * count * 2, files, sname_len);
00243   if(Tflag)
00244     {
00245       fprintf(stdout, " in %ld.%02ld seconds",
00246               (long)time.tv_sec, (long)time.tv_usec / 10000);
00247     }
00248   fprintf(stdout, "\n");
00249 
00250   if((log = fopen(log_file, "a")) == NULL)
00251     {
00252       printf("Enable to open the file '%s'\n", log_file);
00253       complete();
00254     }
00255   fprintf(log, "b8\t%d\t%d\t%d\t%ld.%02ld\n", files * count * 2, files, sname_len,
00256           (long)time.tv_sec, (long)time.tv_usec / 10000);
00257   fclose(log);
00258 
00259 #endif                          /* S_IFLNK */
00260   complete();
00261 }