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

1.1     ! root        1: /*     @(#)test5.c     1.5 90/01/03 NFS Rev 2 Testsuite
        !             2:  *     1.5 Lachman ONC Test Suite source
        !             3:  *
        !             4:  * Test read and write
        !             5:  *
        !             6:  * Uses the following important system calls against the server:
        !             7:  *
        !             8:  *     chdir()
        !             9:  *     mkdir()         (for initial directory creation if not -m)
        !            10:  *     creat()
        !            11:  *     open()
        !            12:  *     read()
        !            13:  *     write()
        !            14:  *     stat()
        !            15:  *     fstat()
        !            16:  *     unlink()
        !            17:  */
        !            18: 
        !            19: #include <sys/param.h>
        !            20: #ifndef major
        !            21: #include <sys/types.h>
        !            22: #endif
        !            23: #ifdef SVR3
        !            24: #include <sys/fs/nfs/time.h>
        !            25: #include <fcntl.h>
        !            26: #else
        !            27: #include <sys/time.h>
        !            28: #endif
        !            29: #include <sys/stat.h>
        !            30: #include <stdio.h>
        !            31: #include "tests.h"
        !            32: 
        !            33: #ifndef MIN
        !            34: #define MIN(a, b)      ((a) < (b) ? (a) : (b))
        !            35: #endif
        !            36: 
        !            37: #define        BUFSZ   8192
        !            38: #define        DSIZE   1048576
        !            39: 
        !            40: int Tflag = 0;         /* print timing */
        !            41: int Hflag = 0;         /* print help message */
        !            42: int Fflag = 0;         /* test function only;  set count to 1, negate -t */
        !            43: int Nflag = 0;         /* Suppress directory operations */
        !            44: #ifdef SVR3
        !            45: int Sflag = 0;         /* use synchronous writes */
        !            46: #endif
        !            47: 
        !            48: usage()
        !            49: {
        !            50: #ifdef SVR3
        !            51:        fprintf(stdout, "usage: %s [-htfns] [size count fname]\n", Myname);
        !            52: #else
        !            53:        fprintf(stdout, "usage: %s [-htfn] [size count fname]\n", Myname);
        !            54: #endif
        !            55:        fprintf(stdout, "  Flags:  h    Help - print this usage info\n");
        !            56:        fprintf(stdout, "          t    Print execution time statistics\n");
        !            57:        fprintf(stdout, "          f    Test function only (negate -t)\n");
        !            58:        fprintf(stdout, "          n    Suppress test directory create operations\n");
        !            59: #ifdef SVR3
        !            60:        fprintf(stdout, "          s    Use synchronous writes\n");
        !            61: #endif
        !            62: }
        !            63: 
        !            64: main(argc, argv)
        !            65:        int argc;
        !            66:        char *argv[];
        !            67: {
        !            68:        int count = DCOUNT;     /* times to do each file */
        !            69:        int ct;
        !            70:        int size = DSIZE;
        !            71:        int si;
        !            72:        int i;
        !            73:        int fd;
        !            74:        int bytes;
        !            75: #ifdef SVR3
        !            76:        int oflags;
        !            77: #endif
        !            78:        char *bigfile = "bigfile";
        !            79:        struct timeval time;
        !            80:        char str[MAXPATHLEN];
        !            81:        struct stat statb;
        !            82:        char *opts;
        !            83:        char buf[BUFSZ];
        !            84: 
        !            85:        umask(0);
        !            86:        setbuf(stdout, NULL);
        !            87:        Myname = *argv++;
        !            88:        argc--;
        !            89:        while (argc && **argv == '-') {
        !            90:                for (opts = &argv[0][1]; *opts; opts++) {
        !            91:                        switch (*opts) {
        !            92:                                case 'h':       /* help */
        !            93:                                        usage();
        !            94:                                        exit(1);
        !            95: 
        !            96:                                case 't':       /* time */
        !            97:                                        Tflag++;
        !            98:                                        break;
        !            99:                                
        !           100:                                case 'f':       /* funtionality */
        !           101:                                        Fflag++;
        !           102:                                        break;
        !           103:                                
        !           104:                                case 'n':       /* No Test Directory create */
        !           105:                                        Nflag++;
        !           106:                                        break;
        !           107: 
        !           108: #ifdef SVR3
        !           109:                                case 's':       /* synchronous writes */
        !           110:                                        Sflag++;
        !           111:                                        break;
        !           112: #endif
        !           113: 
        !           114:                                default:
        !           115:                                        error("unknown option '%c'", *opts);
        !           116:                                        usage();
        !           117:                                        exit(1);
        !           118:                        }
        !           119:                }
        !           120:                argc--;
        !           121:                argv++;
        !           122:        }
        !           123: 
        !           124:        if (argc) {
        !           125:                 size = getparm(*argv, 1, "size");
        !           126:                if (size <= 0) {
        !           127:                        usage();
        !           128:                        exit(1);
        !           129:                }
        !           130:                argv++;
        !           131:                argc--;
        !           132:        }
        !           133:        if (argc) {
        !           134:                 count = getparm(*argv, 1, "count");
        !           135:                if (count <= 0) {
        !           136:                        usage();
        !           137:                        exit(1);
        !           138:                }
        !           139:                argv++;
        !           140:                argc--;
        !           141:        }
        !           142:        if (argc) {
        !           143:                 bigfile = *argv;
        !           144:                argv++;
        !           145:                argc--;
        !           146:        }
        !           147:        if (argc) {
        !           148:                usage();
        !           149:                exit(1);
        !           150:        }
        !           151:        
        !           152:        if (Fflag) {
        !           153:                Tflag = 0;
        !           154:                count = 1;
        !           155:        }
        !           156: 
        !           157: #ifdef SVR3
        !           158:        if (Sflag) {
        !           159:                oflags = O_WRONLY|O_SYNC|O_CREAT|O_TRUNC;
        !           160:        } else {
        !           161:                oflags = O_WRONLY|O_CREAT|O_TRUNC;
        !           162:        }
        !           163: #endif
        !           164: 
        !           165:        fprintf(stdout, "%s: read and write\n", Myname);
        !           166: 
        !           167:        if (!Nflag)
        !           168:                testdir(NULL);
        !           169:        else
        !           170:                mtestdir(NULL);
        !           171: 
        !           172:        for (i=0; i < BUFSZ / sizeof(int); i++) {
        !           173:                ((int *)buf)[i] = i;
        !           174:        }
        !           175: 
        !           176:        if (Tflag) {
        !           177:                starttime();
        !           178:        }
        !           179: 
        !           180:        for (ct = 0; ct < count; ct++) {
        !           181: #ifdef SVR3
        !           182:                if ((fd = open(bigfile, oflags, 0666)) < 0) {
        !           183: #else
        !           184:                if ((fd = creat(bigfile, 0666)) < 0) {
        !           185: #endif
        !           186:                        error("can't create '%s'", bigfile);
        !           187:                        exit(1);
        !           188:                }
        !           189:                if (fstat(fd, &statb) < 0) {
        !           190:                        error("can't stat '%s'", bigfile);
        !           191:                        exit(1);
        !           192:                }
        !           193:                if (statb.st_size != 0) {
        !           194:                        error("'%s' has size %d, should be 0",
        !           195:                            bigfile, statb.st_size);
        !           196:                        exit(1);
        !           197:                }
        !           198:                 for (si = size; si > 0; si -= bytes) {
        !           199:                        bytes = MIN(BUFSZ, si);
        !           200:                        if (write(fd, buf, bytes) != bytes) {
        !           201:                                error("'%s' write failed", bigfile);
        !           202:                                exit(1);
        !           203:                        }
        !           204:                }
        !           205:                close(fd);
        !           206:                if (stat(bigfile, &statb) < 0) {
        !           207:                        error("can't stat '%s'", bigfile);
        !           208:                        exit(1);
        !           209:                }
        !           210:                if (statb.st_size != size) {
        !           211:                        error("'%s' has size %d, should be %d",
        !           212:                            bigfile, statb.st_size, size);
        !           213:                        exit(1);
        !           214:                }
        !           215:        }
        !           216: 
        !           217:        if (Tflag) {
        !           218:                endtime(&time);
        !           219:        }
        !           220: 
        !           221:        if ((fd = open(bigfile, 0)) < 0) {
        !           222:                error("can't open '%s'", bigfile);
        !           223:                exit(1);
        !           224:        }
        !           225:        for (si = size; si > 0; si -= bytes) {
        !           226:                bytes = MIN(BUFSZ, si);
        !           227:                if (read(fd, buf, bytes) != bytes) {
        !           228:                        error("'%s' read failed", bigfile);
        !           229:                        exit(1);
        !           230:                }
        !           231:                for (i = 0; i < bytes / sizeof(int); i++) {
        !           232:                        if (((int *)buf)[i] != i) {
        !           233:                                error("bad data in '%s'", bigfile);
        !           234:                                exit(1);
        !           235:                        }
        !           236:                }
        !           237:        }
        !           238:        close(fd);
        !           239: 
        !           240:        fprintf(stdout, "\twrote %d byte file %d times", size, count);
        !           241:        if (Tflag) {
        !           242:                fprintf(stdout, " in %d.%-2d seconds (%d bytes/sec)",
        !           243:                    time.tv_sec, time.tv_usec / 10000, size*count/time.tv_sec);
        !           244:        }
        !           245:        fprintf(stdout, "\n");
        !           246:        if (Tflag) {
        !           247:                starttime();
        !           248:        }
        !           249: 
        !           250:        for (ct = 0; ct < count; ct++) {
        !           251:                if ((fd = open(bigfile, 0)) < 0) {
        !           252:                        error("can't open '%s'", bigfile);
        !           253:                        exit(1);
        !           254:                }
        !           255:                for (si = size; si > 0; si -= bytes) {
        !           256:                        bytes = MIN(BUFSZ, si);
        !           257:                        if (read(fd, buf, bytes) != bytes) {
        !           258:                                error("'%s' read failed", bigfile);
        !           259:                                exit(1);
        !           260:                        }
        !           261:                }
        !           262:                close(fd);
        !           263:        }
        !           264: 
        !           265:        if (Tflag) {
        !           266:                endtime(&time);
        !           267:        }
        !           268:        fprintf(stdout, "\tread %d byte file %d times", size, count);
        !           269:        if (Tflag) {
        !           270:                fprintf(stdout, " in %d.%-2d seconds (%d bytes/sec)",
        !           271:                    time.tv_sec, time.tv_usec / 10000, size*count/time.tv_sec);
        !           272:        }
        !           273:        fprintf(stdout, "\n");
        !           274: 
        !           275:        if (unlink(bigfile) < 0) {
        !           276:                error("can't unlink '%s'", bigfile);
        !           277:                exit(1);
        !           278:        }
        !           279:        complete();
        !           280: }

unix.superglobalmegacorp.com

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