|
|
1.1 root 1: /* @(#)test5a.c 1.3 90/01/03 NFS Rev 2 Testsuite
2: * 1.3 Lachman ONC Test Suite source
3: *
4: * Test write - DOES NOT VERIFY WRITE CONTENTS
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: * write()
12: * stat()
13: * fstat()
14: */
15:
16: #include <sys/param.h>
17: #ifndef major
18: #include <sys/types.h>
19: #endif
20: #ifdef SVR3
21: #include <sys/fs/nfs/time.h>
22: #include <fcntl.h>
23: #else
24: #include <sys/time.h>
25: #endif
26: #include <sys/stat.h>
27: #include <stdio.h>
28: #include "tests.h"
29:
30: #ifndef MIN
31: #define MIN(a, b) ((a) < (b) ? (a) : (b))
32: #endif
33:
34: #define BUFSZ 8192
35: #define DSIZE 1048576
36:
37: int Tflag = 0; /* print timing */
38: int Hflag = 0; /* print help message */
39: int Fflag = 0; /* test function only; set count to 1, negate -t */
40: int Nflag = 0; /* Suppress directory operations */
41: #ifdef SVR3
42: int Sflag = 0; /* use synchronous writes */
43: #endif
44:
45: usage()
46: {
47: #ifdef SVR3
48: fprintf(stdout, "usage: %s [-htfns] [size count fname]\n", Myname);
49: #else
50: fprintf(stdout, "usage: %s [-htfn] [size count fname]\n", Myname);
51: #endif
52: fprintf(stdout, " Flags: h Help - print this usage info\n");
53: fprintf(stdout, " t Print execution time statistics\n");
54: fprintf(stdout, " f Test function only (negate -t)\n");
55: fprintf(stdout, " n Suppress test directory create operations\n");
56: #ifdef SVR3
57: fprintf(stdout, " s Use synchronous writes\n");
58: #endif
59: }
60:
61: main(argc, argv)
62: int argc;
63: char *argv[];
64: {
65: int count = DCOUNT; /* times to do each file */
66: int ct;
67: int size = DSIZE;
68: int si;
69: int i;
70: int fd;
71: int bytes;
72: #ifdef SVR3
73: int oflags;
74: #endif
75: char *bigfile = "bigfile";
76: struct timeval time;
77: char str[MAXPATHLEN];
78: struct stat statb;
79: char *opts;
80: char buf[BUFSZ];
81:
82: umask(0);
83: setbuf(stdout, NULL);
84: Myname = *argv++;
85: argc--;
86: while (argc && **argv == '-') {
87: for (opts = &argv[0][1]; *opts; opts++) {
88: switch (*opts) {
89: case 'h': /* help */
90: usage();
91: exit(1);
92:
93: case 't': /* time */
94: Tflag++;
95: break;
96:
97: case 'f': /* funtionality */
98: Fflag++;
99: break;
100:
101: case 'n': /* No Test Directory create */
102: Nflag++;
103: break;
104:
105: #ifdef SVR3
106: case 's': /* synchronous writes */
107: Sflag++;
108: break;
109: #endif
110:
111: default:
112: error("unknown option '%c'", *opts);
113: usage();
114: exit(1);
115: }
116: }
117: argc--;
118: argv++;
119: }
120:
121: if (argc) {
122: size = getparm(*argv, 1, "size");
123: if (size <= 0) {
124: usage();
125: exit(1);
126: }
127: argv++;
128: argc--;
129: }
130: if (argc) {
131: count = getparm(*argv, 1, "count");
132: if (count <= 0) {
133: usage();
134: exit(1);
135: }
136: argv++;
137: argc--;
138: }
139: if (argc) {
140: bigfile = *argv;
141: argv++;
142: argc--;
143: }
144: if (argc) {
145: usage();
146: exit(1);
147: }
148:
149: if (Fflag) {
150: Tflag = 0;
151: count = 1;
152: }
153:
154: #ifdef SVR3
155: if (Sflag) {
156: oflags = O_WRONLY|O_SYNC|O_CREAT|O_TRUNC;
157: } else {
158: oflags = O_WRONLY|O_CREAT|O_TRUNC;
159: }
160: #endif
161:
162: fprintf(stdout, "%s: write\n", Myname);
163:
164: if (!Nflag)
165: testdir(NULL);
166: else
167: mtestdir(NULL);
168:
169: /* Set up contents, however we won't verify. */
170: for (i=0; i < BUFSZ / sizeof(int); i++) {
171: ((int *)buf)[i] = i;
172: }
173:
174: if (Tflag) {
175: starttime();
176: }
177:
178: for (ct = 0; ct < count; ct++) {
179: #ifdef SVR3
180: if ((fd = open(bigfile, oflags, 0666)) < 0) {
181: #else
182: if ((fd = creat(bigfile, 0666)) < 0) {
183: #endif
184: error("can't create '%s'", bigfile);
185: exit(1);
186: }
187: if (fstat(fd, &statb) < 0) {
188: error("can't stat '%s'", bigfile);
189: exit(1);
190: }
191: if (statb.st_size != 0) {
192: error("'%s' has size %d, should be 0",
193: bigfile, statb.st_size);
194: exit(1);
195: }
196: for (si = size; si > 0; si -= bytes) {
197: bytes = MIN(BUFSZ, si);
198: if (write(fd, buf, bytes) != bytes) {
199: error("'%s' write failed", bigfile);
200: exit(1);
201: }
202: }
203: close(fd);
204: if (stat(bigfile, &statb) < 0) {
205: error("can't stat '%s'", bigfile);
206: exit(1);
207: }
208: if (statb.st_size != size) {
209: error("'%s' has size %d, should be %d",
210: bigfile, statb.st_size, size);
211: exit(1);
212: }
213: }
214:
215: if (Tflag) {
216: endtime(&time);
217: }
218:
219: fprintf(stdout, "\twrote %d byte file %d times", size, count);
220: if (Tflag) {
221: fprintf(stdout, " in %d.%-2d seconds (%d bytes/sec)",
222: time.tv_sec, time.tv_usec / 10000, size*count/time.tv_sec);
223: }
224: fprintf(stdout, "\n");
225:
226: complete();
227: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.