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

1.1       root        1: /*     @(#)test5b.c    1.3 90/01/03 NFS Rev 2 Testsuite
                      2:  *     1.3 Lachman ONC Test Suite source
                      3:  *
                      4:  * Test read - will read a file of specified size, contents not looked at
                      5:  *
                      6:  * Uses the following important system calls against the server:
                      7:  *
                      8:  *     chdir()
                      9:  *     mkdir()         (for initial directory creation if not -m)
                     10:  *     open()
                     11:  *     read()
                     12:  *     unlink()
                     13:  */
                     14: 
                     15: #include <sys/param.h>
                     16: #ifndef major
                     17: #include <sys/types.h>
                     18: #endif
                     19: #ifdef SVR3
                     20: #include <sys/fs/nfs/time.h>
                     21: #else
                     22: #include <sys/time.h>
                     23: #endif
                     24: #include <sys/stat.h>
                     25: #include <stdio.h>
                     26: #include "tests.h"
                     27: 
                     28: #ifndef MIN
                     29: #define MIN(a, b)      ((a) < (b) ? (a) : (b))
                     30: #endif
                     31: 
                     32: #define        BUFSZ   8192
                     33: #define        DSIZE   1048576
                     34: 
                     35: int Tflag = 0;         /* print timing */
                     36: int Hflag = 0;         /* print help message */
                     37: int Fflag = 0;         /* test function only;  set count to 1, negate -t */
                     38: int Nflag = 0;         /* Suppress directory operations */
                     39: 
                     40: usage()
                     41: {
                     42:        fprintf(stdout, "usage: %s [-htfn] [size count fname]\n", Myname);
                     43:        fprintf(stdout, "  Flags:  h    Help - print this usage info\n");
                     44:        fprintf(stdout, "          t    Print execution time statistics\n");
                     45:        fprintf(stdout, "          f    Test function only (negate -t)\n");
                     46:        fprintf(stdout, "          n    Suppress test directory create operations\n");
                     47: }
                     48: 
                     49: main(argc, argv)
                     50:        int argc;
                     51:        char *argv[];
                     52: {
                     53:        int count = DCOUNT;     /* times to do each file */
                     54:        int ct;
                     55:        int size = DSIZE;
                     56:        int si;
                     57:        int i;
                     58:        int fd;
                     59:        int bytes;
                     60:        char *bigfile = "bigfile";
                     61:        struct timeval time;
                     62:        char str[MAXPATHLEN];
                     63:        struct stat statb;
                     64:        char *opts;
                     65:        char buf[BUFSZ];
                     66: 
                     67:        umask(0);
                     68:        setbuf(stdout, NULL);
                     69:        Myname = *argv++;
                     70:        argc--;
                     71:        while (argc && **argv == '-') {
                     72:                for (opts = &argv[0][1]; *opts; opts++) {
                     73:                        switch (*opts) {
                     74:                                case 'h':       /* help */
                     75:                                        usage();
                     76:                                        exit(1);
                     77: 
                     78:                                case 't':       /* time */
                     79:                                        Tflag++;
                     80:                                        break;
                     81:                                
                     82:                                case 'f':       /* funtionality */
                     83:                                        Fflag++;
                     84:                                        break;
                     85:                                
                     86:                                case 'n':       /* No Test Directory create */
                     87:                                        Nflag++;
                     88:                                        break;
                     89: 
                     90:                                default:
                     91:                                        error("unknown option '%c'", *opts);
                     92:                                        usage();
                     93:                                        exit(1);
                     94:                        }
                     95:                }
                     96:                argc--;
                     97:                argv++;
                     98:        }
                     99: 
                    100:        if (argc) {
                    101:                 size = getparm(*argv, 1, "size");
                    102:                if (size <= 0) {
                    103:                        usage();
                    104:                        exit(1);
                    105:                }
                    106:                argv++;
                    107:                argc--;
                    108:        }
                    109:        if (argc) {
                    110:                 count = getparm(*argv, 1, "count");
                    111:                if (count <= 0) {
                    112:                        usage();
                    113:                        exit(1);
                    114:                }
                    115:                argv++;
                    116:                argc--;
                    117:        }
                    118:        if (argc) {
                    119:                 bigfile = *argv;
                    120:                argv++;
                    121:                argc--;
                    122:        }
                    123:        if (argc) {
                    124:                usage();
                    125:                exit(1);
                    126:        }
                    127:        
                    128:        if (Fflag) {
                    129:                Tflag = 0;
                    130:                count = 1;
                    131:        }
                    132: 
                    133:        fprintf(stdout, "%s: read\n", Myname);
                    134: 
                    135:        mtestdir(NULL);
                    136: 
                    137:        if (Tflag) {
                    138:                starttime();
                    139:        }
                    140: 
                    141:        for (ct = 0; ct < count; ct++) {
                    142:                if ((fd = open(bigfile, 0)) < 0) {
                    143:                        error("can't open '%s'", bigfile);
                    144:                        exit(1);
                    145:                }
                    146:                for (si = size; si > 0; si -= bytes) {
                    147:                        bytes = MIN(BUFSZ, si);
                    148:                        if (read(fd, buf, bytes) != bytes) {
                    149:                                error("'%s' read failed", bigfile);
                    150:                                exit(1);
                    151:                        }
                    152:                }
                    153:                close(fd);
                    154:        }
                    155: 
                    156:        if (Tflag) {
                    157:                endtime(&time);
                    158:        }
                    159:        fprintf(stdout, "\tread %d byte file %d times", size, count);
                    160:        if (Tflag) {
                    161:                fprintf(stdout, " in %d.%-2d seconds (%d bytes/sec)",
                    162:                    time.tv_sec, time.tv_usec / 10000, size*count/time.tv_sec);
                    163:        }
                    164:        fprintf(stdout, "\n");
                    165: 
                    166:        if (unlink(bigfile) < 0) {
                    167:                error("can't unlink '%s'", bigfile);
                    168:                exit(1);
                    169:        }
                    170:        complete();
                    171: }

unix.superglobalmegacorp.com

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