nfs-ganesha 1.4

test2.c

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