1 | /*
|
---|
2 | * $ZEL$
|
---|
3 | */
|
---|
4 |
|
---|
5 | #include "test_3100.h"
|
---|
6 |
|
---|
7 | int
|
---|
8 | check_rw_single(struct path* path, u_int32_t start, u_int32_t size)
|
---|
9 | {
|
---|
10 | u_int32_t *in, *out;
|
---|
11 | int i, res, first, count;
|
---|
12 |
|
---|
13 | in=calloc(size, 4);
|
---|
14 | out=calloc(size, 4);
|
---|
15 | if (!in || !out) {
|
---|
16 | printf("cannot allocate %d words for in- and output\n", size);
|
---|
17 | free(in); free(out);
|
---|
18 | return -1;
|
---|
19 | }
|
---|
20 |
|
---|
21 | for (i=0; i<size; i++) {
|
---|
22 | out[i]=random();
|
---|
23 | in[i]=~out[i];
|
---|
24 | }
|
---|
25 | if (lseek(path->p, start, SEEK_SET)!=start) {
|
---|
26 | printf("check_rw_single: lseek(%s, 0x%08x, SEEK_SET): %s\n",
|
---|
27 | path->name, start, strerror(errno));
|
---|
28 | return -1;
|
---|
29 | }
|
---|
30 | for (i=0; i<size; i++) {
|
---|
31 | res=write(path->p, out+i, 4);
|
---|
32 | if (res!=4) {
|
---|
33 | printf("write(%s, ..., 4): %s\n", path->name, strerror(errno));
|
---|
34 | return -1;
|
---|
35 | }
|
---|
36 | }
|
---|
37 | if (lseek(path->p, start, SEEK_SET)!=start) {
|
---|
38 | printf("check_rw_single: lseek(%s, 0x%08x, SEEK_SET): %s\n",
|
---|
39 | path->name, start, strerror(errno));
|
---|
40 | return -1;
|
---|
41 | }
|
---|
42 | for (i=0; i<size; i++) {
|
---|
43 | res=read(path->p, in+i, 4);
|
---|
44 | if (res!=4) {
|
---|
45 | printf("read(%s, ..., 4): %s\n", path->name, strerror(errno));
|
---|
46 | return -1;
|
---|
47 | }
|
---|
48 | }
|
---|
49 | first=1; count=0;
|
---|
50 | for (i=0; i<size; i++) {
|
---|
51 | if (in[i]!=out[i]) {
|
---|
52 | if (first) {
|
---|
53 | printf("%s: rw error:", path->name);
|
---|
54 | first=0;
|
---|
55 | }
|
---|
56 | printf("[%3d]: %08x --> %08x\n", i, out[i], in[i]);
|
---|
57 | count++;
|
---|
58 | }
|
---|
59 | }
|
---|
60 | return count?-1:0;
|
---|
61 | }
|
---|
62 |
|
---|