1 /* $NetBSD: 9994_f.c,v 1.2 2002/08/09 10:04:37 soren Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by IWAMOTO Toshihiro <iwamoto@sat.t.u-tokyo.ac.jp> and Konrad E. Schroder
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Regression test based on test program submutted with NetBSD PR #9994.
35 * Two files are opened, one in the current directory and another in a
36 * control directory (in another filesystem). Random read, write, and
37 * truncate operations are performed on both files.
39 * An error return indicates that an operation failed on one of the files
40 * (control *or* test, either one).
42 * A zero return indicates success; the two files should be identical.
43 * (This program does not test to make sure that they are identical.)
50 #include <sys/types.h>
53 #define CONTROL_ERROR 1
56 int main(int argc
, char **argv
)
58 int bsize
, quiet
, usepid
;
60 char prop
[] = "/\b-\b\\\b|\b";
61 int testfd
, controlfd
;
65 const char *prog
= getprogname();
74 while ((c
= getopt(argc
, argv
, "b:c:n:pqs:")) != -1) {
92 rseed
= strtoul(optarg
, NULL
, 0);
95 errx(1, "usage: %s [-b bsize] [-c control-dir] [-n count] [-pq] [-s randseed]", prog
);
101 hoge
= (char *)malloc(bsize
);
102 buf
= (char *)malloc(bsize
);
104 for(i
= 0; i
< bsize
; i
++)
105 hoge
[i
] = random() & 0xff;
107 /* Set up test and control file descriptors */
110 sprintf(buf
, "test.%d", getpid());
112 sprintf(buf
, "test");
114 testfd
= open(buf
, O_RDWR
| O_CREAT
, 0644);
121 sprintf(buf
, "%s/control.%d", ctldir
, getpid());
123 sprintf(buf
, "%s/control", ctldir
);
125 controlfd
= open(buf
, O_RDWR
| O_CREAT
, 0644);
131 for(i
= 0, p
= 0; i
< n
; i
++) {
135 write(1, prop
+ 2 * p
, 2);
139 k
= random() & 0x3fffff;
141 if (lseek(testfd
, k
, SEEK_SET
) < 0) {
145 if (lseek(controlfd
, k
, SEEK_SET
) < 0) {
153 if (read(testfd
, buf
, bsize
) < 0) {
157 if (read(controlfd
, buf
, bsize
) < 0) {
163 if (write(testfd
, hoge
, bsize
) < 0) {
167 if (write(controlfd
, hoge
, bsize
) < 0) {
173 if (ftruncate(testfd
, k
) < 0) {
177 if (ftruncate(controlfd
, k
) < 0) {
183 j
= random() % (100 * 1000);