Handle Boolean tags safely.
[tangerine.git] / test / rwverify.c
blobafecb0e113e9d33d4ad1d7ad90c0c6db4eca50b5
1 #include <exec/types.h>
2 #include <dos/dosextens.h>
3 #include <dos/bptr.h>
4 #include <proto/exec.h>
5 #include <proto/dos.h>
6 #include <stdio.h>
8 #define CHUNK 16
10 void hexdump(UBYTE *buf, int size) {
11 int i,j;
12 int count;
14 for (i = 0; i < size; i += CHUNK) {
15 printf("0x%06x ", i);
17 count = ((size-i) > CHUNK ? CHUNK : size-i);
19 for (j = 0; j < count; j++) {
20 if (j == CHUNK / 2) fputc(' ', stdout);
21 printf("%02x ", buf[i+j]);
24 for (j = count; j < CHUNK; j++) {
25 if (j == CHUNK / 2) fputc(' ', stdout);
26 fputs(" ", stdout);
29 fputc('\n', stdout);
33 int round1(char *filename) {
34 BPTR fh;
35 UBYTE buf[1024];
36 LONG bytes;
37 int i, n;
39 fputs("\nround 1: 1024 buffers of 1024 bytes each\n\n", stdout);
41 fh = Open(filename, MODE_NEWFILE);
42 if (fh == NULL) {
43 printf("couldn't open '%s' for write (%ld)\n", filename, IoErr());
44 return 1;
47 printf("opened '%s' for write\n", filename);
49 fputs("writing... ", stdout);
50 fflush(stdout);
52 for (n = 0; n < 1024; n++) {
53 for (i = 0; i < 1024; i++)
54 buf[i] = (i + n) & 0xff;
56 bytes = Write(fh, buf, 1024);
57 if (bytes < 0) {
58 printf("buffer %d: error (%ld)\n", n, IoErr());
59 Close(fh);
60 return 1;
63 if (bytes < 1024) {
64 printf("buffer %d: short write! error is %ld\n", n, IoErr());
65 Close(fh);
66 return 1;
70 fputs("1024 buffers written\n", stdout);
72 Close(fh);
74 fh = Open(filename, MODE_OLDFILE);
75 if (fh == NULL) {
76 printf("couldn't open '%s' for read (%ld)\n", filename, IoErr());
77 return 1;
80 printf("opened '%s' for read\n", filename);
82 fputs("reading... ", stdout);
83 fflush(stdout);
85 for (n = 0; n < 1024; n++) {
86 bytes = Read(fh, buf, 1024);
87 if (bytes < 0) {
88 printf("buffer %d: error (%ld)\n", n, IoErr());
89 Close(fh);
90 return 1;
92 if (bytes < 1024) {
93 printf("buffer %d: short read! error is %ld\n", n, IoErr());
94 Close(fh);
95 return 1;
98 for (i = 0; i < 1024; i++)
99 if (buf[i] != ((i + n) & 0xff)) {
100 printf("buffer %d: verify error!\n file pos %d, expected 0x%02x, got 0x%02x\n", n, n * 1024 + i, ((i + n) & 0xff), buf[i]);
101 printf("buffer dump (0x%02x bytes):\n", 1024);
102 hexdump(buf, 1024);
103 Close(fh);
104 return 1;
108 fputs("1024 buffers read and verified\n", stdout);
110 Close(fh);
112 DeleteFile(filename);
114 fputs("cleaned up\n", stdout);
116 return 0;
119 int round2(char *filename) {
120 BPTR fh;
121 UBYTE buf[1024];
122 LONG bytes;
123 int i, n;
125 fputs("\nround 2: 8192 buffers, increasing length from 0-1023 bytes\n\n", stdout);
127 fh = Open(filename, MODE_NEWFILE);
128 if (fh == NULL) {
129 printf("couldn't open '%s' for write (%ld)\n", filename, IoErr());
130 return 1;
133 printf("opened '%s' for write\n", filename);
135 fputs("writing... ", stdout);
136 fflush(stdout);
138 for (n = 0; n < 8192; n++) {
139 for (i = 0; i < (n & 1023); i++)
140 buf[i] = (i + n) & 0xff;
142 bytes = Write(fh, buf, (n & 1023));
143 if (bytes < 0) {
144 printf("buffer %d: error (%ld)\n", n, IoErr());
145 Close(fh);
146 return 1;
149 if (bytes < (n & 1023)) {
150 printf("buffer %d: short write! error is %ld\n", n, IoErr());
151 Close(fh);
152 return 1;
156 fputs("1024 buffers written\n", stdout);
158 Close(fh);
160 fh = Open(filename, MODE_OLDFILE);
161 if (fh == NULL) {
162 printf("couldn't open '%s' for read (%ld)\n", filename, IoErr());
163 return 1;
166 printf("opened '%s' for read\n", filename);
168 fputs("reading... ", stdout);
169 fflush(stdout);
171 for (n = 0; n < 8192; n++) {
172 bytes = Read(fh, buf, (n & 1023));
173 if (bytes < 0) {
174 printf("buffer %d: error (%ld)\n", n, IoErr());
175 Close(fh);
176 return 1;
178 if (bytes < (n & 1023)) {
179 printf("buffer %d: short read! error is %ld\n", n, IoErr());
180 Close(fh);
181 return 1;
184 for (i = 0; i < (n & 1023); i++)
185 if (buf[i] != ((i + n) & 0xff)) {
186 printf("buffer %d: verify error!\n file pos %d, expected 0x%02x, got 0x%02x\n", n, n * (n & 1023) + i, ((i + n) & 0xff), buf[i]);
187 printf("buffer dump (0x%02x bytes):\n", (n & 1023));
188 hexdump(buf, 1024);
189 Close(fh);
190 return 1;
194 fputs("8192 buffers read and verified\n", stdout);
196 Close(fh);
198 //DeleteFile(filename);
200 fputs("cleaned up\n", stdout);
202 return 0;
205 int main(int argc, char **argv) {
206 if (argc != 2) {
207 printf("usage: %s filename\n", argv[0]);
208 return 1;
211 if (round1(argv[1]) || round2(argv[1]))
212 return 1;
214 return 0;