Annotation of 43BSDReno/sys/nfs/TEST/unix-tests/basic/test2.c, revision 1.1.1.1

1.1       root        1: /*     @(#)test2.c     1.4 90/01/03 NFS Rev 2 Testsuite
                      2:  *     1.3 Lachman ONC Test Suite source
                      3:  *
                      4:  * Test file and directory removal.
                      5:  * Builds a tree on the server.
                      6:  *
                      7:  * Uses the following important system calls against the server:
                      8:  *
                      9:  *     chdir()
                     10:  *     rmdir()         (if removing directories, level > 1)
                     11:  *     unlink()
                     12:  */
                     13: 
                     14: #include <sys/param.h>
                     15: #ifndef major
                     16: #include <sys/types.h>
                     17: #endif
                     18: #ifdef SVR3
                     19: #include <sys/fs/nfs/time.h>
                     20: #else
                     21: #include <sys/time.h>
                     22: #endif
                     23: #include <sys/stat.h>
                     24: #include <stdio.h>
                     25: #include "tests.h"
                     26: 
                     27: int Tflag = 0;         /* print timing */
                     28: int Hflag = 0;         /* print help message */
                     29: int Fflag = 0;         /* test function only;  set count to 1, negate -t */
                     30: int Nflag = 0;         /* Suppress directory operations */
                     31: 
                     32: usage()
                     33: {
                     34:        fprintf(stdout, "usage: %s [-htfn] [levels files dirs fname dname]\n",
                     35:            Myname);
                     36:        fprintf(stdout, "  Flags:  h    Help - print this usage info\n");
                     37:        fprintf(stdout, "          t    Print execution time statistics\n");
                     38:        fprintf(stdout, "          f    Test function only (negate -t)\n");
                     39:        fprintf(stdout, "          n    Suppress test directory create operations\n");
                     40: }
                     41: 
                     42: main(argc, argv)
                     43:        int argc;
                     44:        char *argv[];
                     45: {
                     46:        int files = DFILS;      /* number of files in each dir */
                     47:        int totfiles = 0;
                     48:        int dirs = DDIRS;       /* directories in each dir */
                     49:        int totdirs = 0;
                     50:        int levels = DLEVS;     /* levels deep */
                     51:        char *fname = FNAME;
                     52:        char *dname = DNAME;
                     53:        struct timeval time;
                     54:        char command[MAXPATHLEN];
                     55:        struct stat statb;
                     56:        char *opts;
                     57:        char str[256];
                     58: 
                     59:        setbuf(stdout, NULL);
                     60:        Myname = *argv++;
                     61:        argc--;
                     62:        while (argc && **argv == '-') {
                     63:                for (opts = &argv[0][1]; *opts; opts++) {
                     64:                        switch (*opts) {
                     65:                                case 'h':       /* help */
                     66:                                        usage();
                     67:                                        exit(1);
                     68: 
                     69:                                case 't':       /* time */
                     70:                                        Tflag++;
                     71:                                        break;
                     72: 
                     73:                                case 'f':       /* funtionality */
                     74:                                        Fflag++;
                     75:                                        break;
                     76: 
                     77:                                case 'n':       /* No Test Directory create */
                     78:                                        Nflag++;
                     79:                                        break;
                     80: 
                     81:                                default:
                     82:                                        error("unknown option '%c'", *opts);
                     83:                                        usage();
                     84:                                        exit(1);
                     85:                        }
                     86:                }
                     87:                argc--;
                     88:                argv++;
                     89:        }
                     90: 
                     91:        if (argc) {
                     92:                levels = getparm(*argv, 1, "levels");
                     93:                argv++;
                     94:                argc--;
                     95:        }
                     96:        if (argc) {
                     97:                files = getparm(*argv, 0, "files");
                     98:                argv++;
                     99:                argc--;
                    100:        }
                    101:        if (argc) {
                    102:                dirs = getparm(*argv, 0, "dirs");
                    103:                if (dirs == 0 && levels != 1) {
                    104:                        error("Illegal dirs parameter, must be at least 1");
                    105:                        exit(1);
                    106:                }
                    107:                argv++;
                    108:                argc--;
                    109:        }
                    110:        if (argc) {
                    111:                fname = *argv;
                    112:                argc--;
                    113:                argv++;
                    114:        }
                    115:        if (argc) {
                    116:                dname = *argv;
                    117:                argc--;
                    118:                argv++;
                    119:        }
                    120:        if (argc != 0) {
                    121:                error("too many parameters");
                    122:                usage();
                    123:                exit(1);
                    124:        }
                    125: 
                    126:        if (Fflag) {
                    127:                Tflag = 0;
                    128:                levels = 2;
                    129:                files = 2;
                    130:                dirs = 2;
                    131:        }
                    132: 
                    133:        fprintf(stdout, "%s: File and directory removal test\n", Myname);
                    134: 
                    135:        if (mtestdir(NULL)) {
                    136:                sprintf(str, "test1 -s %s %d %d %d %s %s",
                    137:                        Nflag ? "-n" : "",
                    138:                        levels, files, dirs, fname, dname);
                    139:                if (system(str) != 0) {
                    140:                        error("can't make directroy tree to remove");
                    141:                        exit(1);
                    142:                }
                    143:                if (mtestdir(NULL)) {
                    144:                        error("still can't go to test directory");
                    145:                        exit(1);
                    146:                }
                    147:        }
                    148: 
                    149:        if (Tflag) {
                    150:                starttime();
                    151:        }
                    152:        rmdirtree(levels, files, dirs, fname, dname, &totfiles, &totdirs, 0);
                    153:        if (Tflag) {
                    154:                endtime(&time);
                    155:        }
                    156:        fprintf(stdout,
                    157:            "\tremoved %d files %d directories %d levels deep",
                    158:            totfiles, totdirs, levels);
                    159:        if (Tflag) {
                    160:                fprintf(stdout, " in %d.%-2d seconds",
                    161:                    time.tv_sec, time.tv_usec / 10000);
                    162:        }
                    163:        fprintf(stdout, "\n");
                    164:        complete();
                    165: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.