/* @(#)test5.c 1.5 90/01/03 NFS Rev 2 Testsuite
* 1.5 Lachman ONC Test Suite source
* Uses the following important system calls against the server:
* mkdir() (for initial directory creation if not -m)
#include <sys/fs/nfs/time.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int Tflag
= 0; /* print timing */
int Hflag
= 0; /* print help message */
int Fflag
= 0; /* test function only; set count to 1, negate -t */
int Nflag
= 0; /* Suppress directory operations */
int Sflag
= 0; /* use synchronous writes */
fprintf(stdout
, "usage: %s [-htfns] [size count fname]\n", Myname
);
fprintf(stdout
, "usage: %s [-htfn] [size count fname]\n", Myname
);
fprintf(stdout
, " Flags: h Help - print this usage info\n");
fprintf(stdout
, " t Print execution time statistics\n");
fprintf(stdout
, " f Test function only (negate -t)\n");
fprintf(stdout
, " n Suppress test directory create operations\n");
fprintf(stdout
, " s Use synchronous writes\n");
int count
= DCOUNT
; /* times to do each file */
char *bigfile
= "bigfile";
while (argc
&& **argv
== '-') {
for (opts
= &argv
[0][1]; *opts
; opts
++) {
case 'f': /* funtionality */
case 'n': /* No Test Directory create */
case 's': /* synchronous writes */
error("unknown option '%c'", *opts
);
size
= getparm(*argv
, 1, "size");
count
= getparm(*argv
, 1, "count");
oflags
= O_WRONLY
|O_SYNC
|O_CREAT
|O_TRUNC
;
oflags
= O_WRONLY
|O_CREAT
|O_TRUNC
;
fprintf(stdout
, "%s: read and write\n", Myname
);
for (i
=0; i
< BUFSZ
/ sizeof(int); i
++) {
for (ct
= 0; ct
< count
; ct
++) {
if ((fd
= open(bigfile
, oflags
, 0666)) < 0) {
if ((fd
= creat(bigfile
, 0666)) < 0) {
error("can't create '%s'", bigfile
);
if (fstat(fd
, &statb
) < 0) {
error("can't stat '%s'", bigfile
);
if (statb
.st_size
!= 0) {
error("'%s' has size %d, should be 0",
for (si
= size
; si
> 0; si
-= bytes
) {
if (write(fd
, buf
, bytes
) != bytes
) {
error("'%s' write failed", bigfile
);
if (stat(bigfile
, &statb
) < 0) {
error("can't stat '%s'", bigfile
);
if (statb
.st_size
!= size
) {
error("'%s' has size %d, should be %d",
bigfile
, statb
.st_size
, size
);
if ((fd
= open(bigfile
, 0)) < 0) {
error("can't open '%s'", bigfile
);
for (si
= size
; si
> 0; si
-= bytes
) {
if (read(fd
, buf
, bytes
) != bytes
) {
error("'%s' read failed", bigfile
);
for (i
= 0; i
< bytes
/ sizeof(int); i
++) {
if (((int *)buf
)[i
] != i
) {
error("bad data in '%s'", bigfile
);
fprintf(stdout
, "\twrote %d byte file %d times", size
, count
);
fprintf(stdout
, " in %d.%-2d seconds (%d bytes/sec)",
time
.tv_sec
, time
.tv_usec
/ 10000, size
*count
/time
.tv_sec
);
for (ct
= 0; ct
< count
; ct
++) {
if ((fd
= open(bigfile
, 0)) < 0) {
error("can't open '%s'", bigfile
);
for (si
= size
; si
> 0; si
-= bytes
) {
if (read(fd
, buf
, bytes
) != bytes
) {
error("'%s' read failed", bigfile
);
fprintf(stdout
, "\tread %d byte file %d times", size
, count
);
fprintf(stdout
, " in %d.%-2d seconds (%d bytes/sec)",
time
.tv_sec
, time
.tv_usec
/ 10000, size
*count
/time
.tv_sec
);
if (unlink(bigfile
) < 0) {
error("can't unlink '%s'", bigfile
);