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

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

unix.superglobalmegacorp.com

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