nfs-ganesha 1.4

test1.c

Go to the documentation of this file.
00001 /*
00002  *      @(#)test1.c     1.5 99/08/29 Connectathon Testsuite
00003  *      1.4 Lachman ONC Test Suite source
00004  *
00005  * Test file and directory creation.
00006  * Builds a tree on the server.
00007  *
00008  * Uses the following important system calls against the server:
00009  *
00010  *      chdir()
00011  *      mkdir()         (if creating directories, level > 1)
00012  *      creat()
00013  */
00014 
00015 #if defined (DOS) || defined (WIN32)
00016 /* If Dos, Windows or Win32 */
00017 #define DOSorWIN32
00018 #endif
00019 
00020 #ifndef DOSorWIN32
00021 #include <sys/param.h>
00022 #endif
00023 
00024 #include <stdlib.h>
00025 #include <sys/types.h>
00026 #ifdef DOSorWIN32
00027 #include <time.h>
00028 #else
00029 #include <sys/time.h>
00030 #endif
00031 #include <sys/stat.h>
00032 #include <stdio.h>
00033 
00034 #include "tests.h"
00035 #include "Connectathon_config_parsing.h"
00036 
00037 static int Tflag = 0;           /* print timing */
00038 static int Sflag = 0;           /* don't print non-error messages */
00039 static int Fflag = 0;           /* test function only;  set count to 1, negate -t */
00040 static int Nflag = 0;           /* Suppress directory operations */
00041 
00042 static void usage()
00043 {
00044   fprintf(stdout, "usage: %s [-htfn] <config_file>\n", Myname);
00045   /* -s is a hidden option used by test2 */
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 totfiles = 0;
00056   int dirs;                     /* directories in each dir */
00057   int totdirs = 0;
00058   int levels;                   /* levels deep */
00059   char *fname;
00060   char *dname;
00061   struct timeval time;
00062   char *opts;
00063   struct testparam *param;
00064   struct btest *b;
00065   char *config_file;
00066   char *test_dir;
00067   char *log_file;
00068   FILE *log;
00069 
00070   setbuf(stdout, NULL);
00071   Myname = *argv++;
00072   argc--;
00073   while(argc && **argv == '-')
00074     {
00075       for(opts = &argv[0][1]; *opts; opts++)
00076         {
00077           switch (*opts)
00078             {
00079             case 'h':          /* help */
00080               usage();
00081               exit(1);
00082               break;
00083 
00084             case 's':          /* silent */
00085               Sflag++;
00086               break;
00087 
00088             case 't':          /* time */
00089               Tflag++;
00090               break;
00091 
00092             case 'f':          /* funtionality */
00093               Fflag++;
00094               break;
00095 
00096             case 'n':          /* No Test Directory create */
00097               Nflag++;
00098               break;
00099 
00100             default:
00101               error("unknown option '%c'", *opts);
00102               usage();
00103               exit(1);
00104             }
00105         }
00106       argc--;
00107       argv++;
00108     }
00109 
00110   if(argc)
00111     {
00112       config_file = *argv;
00113       argc--;
00114       argv++;
00115     }
00116   else
00117     {
00118       fprintf(stderr, "Missing config_file");
00119       exit(1);
00120     }
00121 
00122   if(argc != 0)
00123     {
00124       fprintf(stderr, "too many parameters");
00125       usage();
00126       exit(1);
00127     }
00128 
00129   param = readin_config(config_file);
00130   if(param == NULL)
00131     {
00132       fprintf(stderr, "Nothing built\n");
00133       exit(1);
00134     }
00135 
00136   b = get_btest_args(param, ONE);
00137   if(b == NULL)
00138     {
00139       fprintf(stderr, "Missing basic test number 1 in the config file '%s'\n",
00140               config_file);
00141       free_testparam(param);
00142       exit(1);
00143     }
00144 
00145   if(b->levels == -1)
00146     {
00147       fprintf(stderr,
00148               "Missing 'levels' parameter in the config file '%s' for the basic test number 1\n",
00149               config_file);
00150       free_testparam(param);
00151       exit(1);
00152     }
00153   if(b->files == -1)
00154     {
00155       fprintf(stderr,
00156               "Missing 'files' parameter in the config file '%s' for the basic test number 1\n",
00157               config_file);
00158       free_testparam(param);
00159       exit(1);
00160     }
00161   if(b->dirs == -1)
00162     {
00163       fprintf(stderr,
00164               "Missing 'dirs' parameter in the config file '%s' for the basic test number 1\n",
00165               config_file);
00166       free_testparam(param);
00167       exit(1);
00168     }
00169   levels = b->levels;
00170   files = b->files;
00171   dirs = b->dirs;
00172   fname = b->fname;
00173   dname = b->dname;
00174   test_dir = get_test_directory(param);
00175   log_file = get_log_file(param);
00176 
00177   free_testparam(param);
00178 
00179   if(!Fflag)
00180     {
00181       Tflag = 0;
00182       levels = 2;
00183       files = 2;
00184       dirs = 2;
00185     }
00186 
00187   if(!Sflag)
00188     {
00189       fprintf(stdout, "%s: File and directory creation test\n", Myname);
00190     }
00191 
00192   if(!Nflag)
00193     testdir(test_dir);
00194   else
00195     mtestdir(test_dir);
00196 
00197   starttime();
00198   dirtree(levels, files, dirs, fname, dname, &totfiles, &totdirs);
00199   endtime(&time);
00200 
00201   if(!Sflag)
00202     {
00203       fprintf(stdout,
00204               "\tcreated %d files %d directories %d levels deep",
00205               totfiles, totdirs, levels);
00206     }
00207   if(Tflag && !Sflag)
00208     {
00209       fprintf(stdout, " in %ld.%02ld seconds",
00210               (long)time.tv_sec, (long)time.tv_usec / 10000);
00211     }
00212   if(!Sflag)
00213     {
00214       fprintf(stdout, "\n");
00215     }
00216 
00217   if((log = fopen(log_file, "a")) == NULL)
00218     {
00219       printf("Enable to open the file '%s'\n", log_file);
00220       complete();
00221     }
00222   fprintf(log, "b1\t%d\t%d\t%d\t%ld.%02ld\n", totfiles, totdirs, levels,
00223           (long)time.tv_sec, (long)time.tv_usec / 10000);
00224   fclose(log);
00225 
00226   complete();
00227 }