diff options
Diffstat (limited to 'firmware/test/fat')
-rw-r--r-- | firmware/test/fat/Makefile | 49 | ||||
-rw-r--r-- | firmware/test/fat/README | 32 | ||||
-rw-r--r-- | firmware/test/fat/ata-sim.c | 68 | ||||
-rw-r--r-- | firmware/test/fat/autoconf.h | 9 | ||||
-rw-r--r-- | firmware/test/fat/main.c | 724 | ||||
-rw-r--r-- | firmware/test/fat/test.sh | 146 | ||||
-rw-r--r-- | firmware/test/fat/test16.sh | 135 |
7 files changed, 0 insertions, 1163 deletions
diff --git a/firmware/test/fat/Makefile b/firmware/test/fat/Makefile deleted file mode 100644 index 38bce0bde1..0000000000 --- a/firmware/test/fat/Makefile +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | SECTOR_SIZE = 512 | ||
2 | FIRMWARE = ../.. | ||
3 | |||
4 | DRIVERS = ../../drivers | ||
5 | EXPORT = ../../export | ||
6 | |||
7 | BUILDDATE=$(shell date -u +'-DYEAR=%Y -DMONTH=%m -DDAY=%d') | ||
8 | INCLUDE = -I$(EXPORT) -I$(FIRMWARE)/include -I$(FIRMWARE)/target/hosted -I$(FIRMWARE)/target/hosted/sdl | ||
9 | DEFINES = -DTEST_FAT -DDEBUG -DDISK_WRITE -DHAVE_FAT16SUPPORT -D__PCTOOL__ | ||
10 | |||
11 | CFLAGS = -g -Wall -std=gnu99 -Wno-pointer-sign $(DEFINES) $(BUILDDATE) -I. $(INCLUDE) -I$(FIRMWARE)/libc/include -DROCKBOX_DIR='".rockbox"' -DSECTOR_SIZE=$(SECTOR_SIZE) | ||
12 | SIMFLAGS = -g -Wall -std=gnu99 -Wno-pointer-sign $(DEFINES) -I. $(INCLUDE) -DSECTOR_SIZE=$(SECTOR_SIZE) | ||
13 | |||
14 | TARGET = fat | ||
15 | |||
16 | all: $(TARGET) | ||
17 | |||
18 | $(TARGET): fat.o ata-sim.o main.o disk.o dir.o file.o ctype.o unicode.o strlcpy.o | ||
19 | gcc -g -o fat $+ | ||
20 | |||
21 | fat.o: $(DRIVERS)/fat.c $(EXPORT)/fat.h $(EXPORT)/ata.h | ||
22 | $(CC) $(CFLAGS) -c $< -o $@ | ||
23 | |||
24 | ctype.o: $(FIRMWARE)/libc/ctype.c | ||
25 | $(CC) $(CFLAGS) -c $< -o $@ | ||
26 | |||
27 | disk.o: $(FIRMWARE)/common/disk.c | ||
28 | $(CC) $(CFLAGS) -c $< -o $@ | ||
29 | |||
30 | dir.o: $(FIRMWARE)/common/dir_uncached.c | ||
31 | $(CC) $(CFLAGS) -c $< -o $@ | ||
32 | |||
33 | file.o: $(FIRMWARE)/common/file.c | ||
34 | $(CC) $(CFLAGS) -c $< -o $@ | ||
35 | |||
36 | unicode.o: $(FIRMWARE)/common/unicode.c | ||
37 | $(CC) $(CFLAGS) -c $< -o $@ | ||
38 | |||
39 | strlcpy.o: $(FIRMWARE)/common/strlcpy.c | ||
40 | $(CC) $(CFLAGS) -c $< -o $@ | ||
41 | |||
42 | ata-sim.o: ata-sim.c $(EXPORT)/ata.h | ||
43 | $(CC) $(SIMFLAGS) -c $< -o $@ | ||
44 | |||
45 | main.o: main.c $(EXPORT)/ata.h | ||
46 | $(CC) $(SIMFLAGS) -c $< -o $@ | ||
47 | |||
48 | clean: | ||
49 | rm -f *.o $(TARGET) | ||
diff --git a/firmware/test/fat/README b/firmware/test/fat/README deleted file mode 100644 index 58ffe7ffa8..0000000000 --- a/firmware/test/fat/README +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | This code is for testing the Rockbox fat code on a dummy drive image file. | ||
2 | |||
3 | Dummy image | ||
4 | ----------- | ||
5 | Here's how to create a 1 gig dummy drive image in linux: | ||
6 | |||
7 | # dd if=/dev/hda of=disk.img bs=1M count=1024 | ||
8 | |||
9 | You can then format disk.img as a FAT32 partition: | ||
10 | |||
11 | # mkdosfs -F 32 disk.img | ||
12 | |||
13 | To mount the image, your linux kernel must include the loopback device: | ||
14 | |||
15 | # mount -o loop disk.img /mnt/image | ||
16 | |||
17 | Now copy some test data to the disk, umount it and start testing. | ||
18 | |||
19 | The test script mounts the disk image in order to initialize it will a number | ||
20 | of dummy files. Since users are no longer allowed to mount loopback devices, | ||
21 | you can either run the test script as root (not recommended) or add a line to | ||
22 | your fstab file: | ||
23 | |||
24 | /path/to/disk.img /mnt/dummy vfat loop,users,noauto 0 0 | ||
25 | |||
26 | |||
27 | Test code | ||
28 | --------- | ||
29 | The files in this dir build the 'fat' program. It will read 'disk.img' and | ||
30 | treat is as a real disk, thanks to the ata-sim.c module. | ||
31 | |||
32 | Modify the main.c source code to make it perform the tests you want. | ||
diff --git a/firmware/test/fat/ata-sim.c b/firmware/test/fat/ata-sim.c deleted file mode 100644 index 07b772f433..0000000000 --- a/firmware/test/fat/ata-sim.c +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include "debug.h" | ||
5 | |||
6 | static FILE* file; | ||
7 | |||
8 | void panicf( const char *fmt, ... ); | ||
9 | |||
10 | int storage_read_sectors(unsigned long start, int count, void* buf) | ||
11 | { | ||
12 | if ( count > 1 ) | ||
13 | DEBUGF("[Reading %d blocks: 0x%lx to 0x%lx]\n", | ||
14 | count, start, start+count-1); | ||
15 | else | ||
16 | DEBUGF("[Reading block 0x%lx]\n", start); | ||
17 | |||
18 | if(fseek(file,start*SECTOR_SIZE,SEEK_SET)) { | ||
19 | perror("fseek"); | ||
20 | return -1; | ||
21 | } | ||
22 | if(!fread(buf,SECTOR_SIZE,count,file)) { | ||
23 | DEBUGF("ata_write_sectors(0x%lx, 0x%x, %p)\n", start, count, buf ); | ||
24 | perror("fread"); | ||
25 | panicf("Disk error\n"); | ||
26 | } | ||
27 | return 0; | ||
28 | } | ||
29 | |||
30 | int storage_write_sectors(unsigned long start, int count, void* buf) | ||
31 | { | ||
32 | if ( count > 1 ) | ||
33 | DEBUGF("[Writing %d blocks: 0x%lx to 0x%lx]\n", | ||
34 | count, start, start+count-1); | ||
35 | else | ||
36 | DEBUGF("[Writing block 0x%lx]\n", start); | ||
37 | |||
38 | if (start == 0) | ||
39 | panicf("Writing on sector 0!\n"); | ||
40 | |||
41 | if(fseek(file,start*SECTOR_SIZE,SEEK_SET)) { | ||
42 | perror("fseek"); | ||
43 | return -1; | ||
44 | } | ||
45 | if(!fwrite(buf,SECTOR_SIZE,count,file)) { | ||
46 | DEBUGF("ata_write_sectors(0x%lx, 0x%x, %p)\n", start, count, buf ); | ||
47 | perror("fwrite"); | ||
48 | panicf("Disk error\n"); | ||
49 | } | ||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | int ata_init(void) | ||
54 | { | ||
55 | char* filename = "disk.img"; | ||
56 | /* check disk size */ | ||
57 | file=fopen(filename,"rb+"); | ||
58 | if(!file) { | ||
59 | fprintf(stderr, "read_disk() - Could not find \"%s\"\n",filename); | ||
60 | return -1; | ||
61 | } | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | void ata_exit(void) | ||
66 | { | ||
67 | fclose(file); | ||
68 | } | ||
diff --git a/firmware/test/fat/autoconf.h b/firmware/test/fat/autoconf.h deleted file mode 100644 index e5a91790af..0000000000 --- a/firmware/test/fat/autoconf.h +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | /* fake autoconf for fat testing */ | ||
2 | |||
3 | #ifndef __BUILD_AUTOCONF_H | ||
4 | #define __BUILD_AUTOCONF_H | ||
5 | |||
6 | /* assume little endian for now */ | ||
7 | #define ROCKBOX_LITTLE_ENDIAN 1 | ||
8 | |||
9 | #endif | ||
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c deleted file mode 100644 index e838682b0b..0000000000 --- a/firmware/test/fat/main.c +++ /dev/null | |||
@@ -1,724 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include <stdarg.h> | ||
5 | #include <time.h> | ||
6 | #include "fat.h" | ||
7 | #include "debug.h" | ||
8 | #include "disk.h" | ||
9 | #include "dir.h" | ||
10 | #include "file.h" | ||
11 | #include "ata.h" | ||
12 | #include "storage.h" | ||
13 | |||
14 | void dbg_dump_sector(int sec); | ||
15 | void dbg_dump_buffer(unsigned char *buf, int len, int offset); | ||
16 | void dbg_console(void); | ||
17 | |||
18 | void mutex_init(struct mutex* l) {} | ||
19 | void mutex_lock(struct mutex* l) {} | ||
20 | void mutex_unlock(struct mutex* l) {} | ||
21 | |||
22 | void panicf( char *fmt, ...) | ||
23 | { | ||
24 | va_list ap; | ||
25 | va_start( ap, fmt ); | ||
26 | fprintf(stderr,"***PANIC*** "); | ||
27 | vfprintf(stderr, fmt, ap ); | ||
28 | va_end( ap ); | ||
29 | exit(1); | ||
30 | } | ||
31 | |||
32 | void debugf(const char *fmt, ...) | ||
33 | { | ||
34 | va_list ap; | ||
35 | va_start( ap, fmt ); | ||
36 | fprintf(stderr,"DEBUGF: "); | ||
37 | vfprintf( stderr, fmt, ap ); | ||
38 | va_end( ap ); | ||
39 | } | ||
40 | |||
41 | void ldebugf(const char* file, int line, const char *fmt, ...) | ||
42 | { | ||
43 | va_list ap; | ||
44 | va_start( ap, fmt ); | ||
45 | fprintf( stderr, "%s:%d ", file, line ); | ||
46 | vfprintf( stderr, fmt, ap ); | ||
47 | va_end( ap ); | ||
48 | } | ||
49 | |||
50 | void dbg_dump_sector(int sec) | ||
51 | { | ||
52 | unsigned char buf[SECTOR_SIZE]; | ||
53 | |||
54 | storage_read_sectors(sec,1,buf); | ||
55 | DEBUGF("---< Sector %d >-----------------------------------------\n", sec); | ||
56 | dbg_dump_buffer(buf, SECTOR_SIZE, 0); | ||
57 | } | ||
58 | |||
59 | void dbg_dump_buffer(unsigned char *buf, int len, int offset) | ||
60 | { | ||
61 | int i, j; | ||
62 | unsigned char c; | ||
63 | unsigned char ascii[33]; | ||
64 | |||
65 | for(i = 0;i < len/16;i++) | ||
66 | { | ||
67 | DEBUGF("%03x: ", i*16 + offset); | ||
68 | for(j = 0;j < 16;j++) | ||
69 | { | ||
70 | c = buf[i*16+j]; | ||
71 | |||
72 | DEBUGF("%02x ", c); | ||
73 | if(c < 32 || c > 127) | ||
74 | { | ||
75 | ascii[j] = '.'; | ||
76 | } | ||
77 | else | ||
78 | { | ||
79 | ascii[j] = c; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | ascii[j] = 0; | ||
84 | DEBUGF("%s\n", ascii); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | void dbg_dir(char* currdir) | ||
89 | { | ||
90 | DIR* dir; | ||
91 | struct dirent* entry; | ||
92 | |||
93 | dir = opendir(currdir); | ||
94 | if (dir) | ||
95 | { | ||
96 | while ( (entry = readdir(dir)) ) { | ||
97 | DEBUGF("%15s %lx\n", entry->d_name, entry->startcluster); | ||
98 | } | ||
99 | closedir(dir); | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | DEBUGF( "Could not open dir %s\n", currdir); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | #define CHUNKSIZE 8 | ||
108 | #define BUFSIZE 8192 | ||
109 | |||
110 | int dbg_mkfile(char* name, int num) | ||
111 | { | ||
112 | char text[BUFSIZE+1]; | ||
113 | int i; | ||
114 | int fd; | ||
115 | int x=0; | ||
116 | bool stop = false; | ||
117 | |||
118 | fd = creat(name,O_WRONLY); | ||
119 | if (fd<0) { | ||
120 | DEBUGF("Failed creating file\n"); | ||
121 | return -1; | ||
122 | } | ||
123 | num *= 1024; | ||
124 | while ( num ) { | ||
125 | int rc; | ||
126 | int len = num > BUFSIZE ? BUFSIZE : num; | ||
127 | |||
128 | for (i=0; i<len/CHUNKSIZE; i++ ) | ||
129 | sprintf(text+i*CHUNKSIZE,"%c%06x,",name[1],x++); | ||
130 | |||
131 | rc = write(fd, text, len); | ||
132 | if ( rc < 0 ) { | ||
133 | DEBUGF("Failed writing data\n"); | ||
134 | return -1; | ||
135 | } | ||
136 | else | ||
137 | if ( rc == 0 ) { | ||
138 | DEBUGF("No space left\n"); | ||
139 | return -2; | ||
140 | } | ||
141 | else | ||
142 | DEBUGF("wrote %d bytes\n",rc); | ||
143 | |||
144 | num -= len; | ||
145 | |||
146 | if ( !num ) { | ||
147 | if ( stop ) | ||
148 | break; | ||
149 | |||
150 | /* add a random number of chunks to test byte-copy code */ | ||
151 | num = ((int) rand() % SECTOR_SIZE) & ~7; | ||
152 | LDEBUGF("Adding random size %d\n",num); | ||
153 | stop = true; | ||
154 | } | ||
155 | } | ||
156 | |||
157 | return close(fd); | ||
158 | } | ||
159 | |||
160 | |||
161 | int dbg_chkfile(char* name, int size) | ||
162 | { | ||
163 | char text[81920]; | ||
164 | int i; | ||
165 | int x=0; | ||
166 | int pos = 0; | ||
167 | int block=0; | ||
168 | int fd = open(name,O_RDONLY); | ||
169 | if (fd<0) { | ||
170 | DEBUGF("Failed opening file\n"); | ||
171 | return -1; | ||
172 | } | ||
173 | |||
174 | size = lseek(fd, 0, SEEK_END); | ||
175 | DEBUGF("File is %d bytes\n", size); | ||
176 | /* random start position */ | ||
177 | if ( size ) | ||
178 | pos = ((int)rand() % size) & ~7; | ||
179 | lseek(fd, pos, SEEK_SET); | ||
180 | x = pos / CHUNKSIZE; | ||
181 | |||
182 | LDEBUGF("Check base is %x (%d)\n",x,pos); | ||
183 | |||
184 | while (1) { | ||
185 | int rc = read(fd, text, sizeof text); | ||
186 | DEBUGF("read %d bytes\n",rc); | ||
187 | if (rc < 0) { | ||
188 | panicf("Failed reading data\n"); | ||
189 | } | ||
190 | else { | ||
191 | char tmp[CHUNKSIZE+1]; | ||
192 | if (!rc) | ||
193 | break; | ||
194 | for (i=0; i<rc/CHUNKSIZE; i++ ) { | ||
195 | sprintf(tmp,"%c%06x,",name[1],x++); | ||
196 | if (strncmp(text+i*CHUNKSIZE,tmp,CHUNKSIZE)) { | ||
197 | int idx = pos + block*sizeof(text) + i*CHUNKSIZE; | ||
198 | DEBUGF("Mismatch in byte 0x%x (byte 0x%x of sector 0x%x)." | ||
199 | "\nExpected %.8s found %.8s\n", | ||
200 | idx, idx % SECTOR_SIZE, idx / SECTOR_SIZE, | ||
201 | tmp, | ||
202 | text+i*CHUNKSIZE); | ||
203 | DEBUGF("i=%x, idx=%x\n",i,idx); | ||
204 | dbg_dump_buffer(text+i*CHUNKSIZE - 0x20, 0x40, idx - 0x20); | ||
205 | return -1; | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | block++; | ||
210 | } | ||
211 | |||
212 | return close(fd); | ||
213 | } | ||
214 | |||
215 | int dbg_wrtest(char* name) | ||
216 | { | ||
217 | char text[81920]; | ||
218 | int i; | ||
219 | int x=0; | ||
220 | int pos = 0; | ||
221 | int block=0; | ||
222 | int size, fd, rc; | ||
223 | char tmp[CHUNKSIZE+1]; | ||
224 | |||
225 | fd = open(name,O_RDWR); | ||
226 | if (fd<0) { | ||
227 | DEBUGF("Failed opening file\n"); | ||
228 | return -1; | ||
229 | } | ||
230 | |||
231 | size = lseek(fd, 0, SEEK_END); | ||
232 | DEBUGF("File is %d bytes\n", size); | ||
233 | /* random start position */ | ||
234 | if ( size ) | ||
235 | pos = ((int)rand() % size) & ~7; | ||
236 | rc = lseek(fd, pos, SEEK_SET); | ||
237 | if ( rc < 0 ) | ||
238 | panicf("Failed seeking\n"); | ||
239 | x = pos / CHUNKSIZE; | ||
240 | LDEBUGF("Check base is %x (%d)\n",x,pos); | ||
241 | |||
242 | sprintf(tmp,"%c%06x,",name[1],x++); | ||
243 | rc = write(fd, tmp, 8); | ||
244 | if ( rc < 0 ) | ||
245 | panicf("Failed writing data\n"); | ||
246 | |||
247 | if ( size ) | ||
248 | pos = ((int)rand() % size) & ~7; | ||
249 | rc = lseek(fd, pos, SEEK_SET); | ||
250 | if ( rc < 0 ) | ||
251 | panicf("Failed seeking\n"); | ||
252 | x = pos / CHUNKSIZE; | ||
253 | LDEBUGF("Check base 2 is %x (%d)\n",x,pos); | ||
254 | |||
255 | while (1) { | ||
256 | rc = read(fd, text, sizeof text); | ||
257 | DEBUGF("read %d bytes\n",rc); | ||
258 | if (rc < 0) { | ||
259 | panicf("Failed reading data\n"); | ||
260 | } | ||
261 | else { | ||
262 | if (!rc) | ||
263 | break; | ||
264 | for (i=0; i<rc/CHUNKSIZE; i++ ) { | ||
265 | sprintf(tmp,"%c%06x,",name[1],x++); | ||
266 | if (strncmp(text+i*CHUNKSIZE,tmp,CHUNKSIZE)) { | ||
267 | int idx = pos + block*sizeof(text) + i*CHUNKSIZE; | ||
268 | DEBUGF("Mismatch in byte 0x%x (byte 0x%x of sector 0x%x)." | ||
269 | "\nExpected %.8s found %.8s\n", | ||
270 | idx, idx % SECTOR_SIZE, idx / SECTOR_SIZE, | ||
271 | tmp, | ||
272 | text+i*CHUNKSIZE); | ||
273 | DEBUGF("i=%x, idx=%x\n",i,idx); | ||
274 | dbg_dump_buffer(text+i*CHUNKSIZE - 0x20, 0x40, idx - 0x20); | ||
275 | return -1; | ||
276 | } | ||
277 | } | ||
278 | } | ||
279 | block++; | ||
280 | } | ||
281 | |||
282 | return close(fd); | ||
283 | } | ||
284 | |||
285 | void dbg_type(char* name) | ||
286 | { | ||
287 | const int size = SECTOR_SIZE*5; | ||
288 | unsigned char buf[SECTOR_SIZE*5+1]; | ||
289 | int fd,rc; | ||
290 | |||
291 | fd = open(name,O_RDONLY); | ||
292 | if (fd<0) | ||
293 | return; | ||
294 | DEBUGF("Got file descriptor %d\n",fd); | ||
295 | |||
296 | while ( 1 ) { | ||
297 | rc = read(fd, buf, size); | ||
298 | if( rc > 0 ) | ||
299 | { | ||
300 | buf[size] = 0; | ||
301 | printf("%d: %.*s\n", rc, rc, buf); | ||
302 | } | ||
303 | else if ( rc == 0 ) { | ||
304 | DEBUGF("EOF\n"); | ||
305 | break; | ||
306 | } | ||
307 | else | ||
308 | { | ||
309 | DEBUGF("Failed reading file: %d\n",rc); | ||
310 | break; | ||
311 | } | ||
312 | } | ||
313 | close(fd); | ||
314 | } | ||
315 | |||
316 | int dbg_append(char* name) | ||
317 | { | ||
318 | int x=0; | ||
319 | int size, fd, rc; | ||
320 | char tmp[CHUNKSIZE+1]; | ||
321 | |||
322 | fd = open(name,O_RDONLY); | ||
323 | if (fd<0) { | ||
324 | DEBUGF("Failed opening file\n"); | ||
325 | return -1; | ||
326 | } | ||
327 | |||
328 | size = lseek(fd, 0, SEEK_END); | ||
329 | DEBUGF("File is %d bytes\n", size); | ||
330 | x = size / CHUNKSIZE; | ||
331 | LDEBUGF("Check base is %x (%d)\n",x,size); | ||
332 | |||
333 | if (close(fd) < 0) | ||
334 | return -1; | ||
335 | |||
336 | fd = open(name,O_RDWR|O_APPEND); | ||
337 | if (fd<0) { | ||
338 | DEBUGF("Failed opening file\n"); | ||
339 | return -1; | ||
340 | } | ||
341 | |||
342 | sprintf(tmp,"%c%06x,",name[1],x++); | ||
343 | rc = write(fd, tmp, 8); | ||
344 | if ( rc < 0 ) | ||
345 | panicf("Failed writing data\n"); | ||
346 | |||
347 | return close(fd); | ||
348 | } | ||
349 | |||
350 | int dbg_test(char* name) | ||
351 | { | ||
352 | int x=0; | ||
353 | int j; | ||
354 | int fd; | ||
355 | char text[BUFSIZE+1]; | ||
356 | |||
357 | for (j=0; j<5; j++) { | ||
358 | int num = 40960; | ||
359 | |||
360 | fd = open(name,O_WRONLY|O_CREAT|O_APPEND, 0666); | ||
361 | if (fd<0) { | ||
362 | DEBUGF("Failed opening file\n"); | ||
363 | return -1; | ||
364 | } | ||
365 | |||
366 | while ( num ) { | ||
367 | int rc, i; | ||
368 | int len = num > BUFSIZE ? BUFSIZE : num; | ||
369 | |||
370 | for (i=0; i<len/CHUNKSIZE; i++ ) | ||
371 | sprintf(text+i*CHUNKSIZE,"%c%06x,",name[1],x++); | ||
372 | |||
373 | rc = write(fd, text, len); | ||
374 | if ( rc < 0 ) { | ||
375 | DEBUGF("Failed writing data\n"); | ||
376 | return -1; | ||
377 | } | ||
378 | else | ||
379 | if ( rc == 0 ) { | ||
380 | DEBUGF("No space left\n"); | ||
381 | return -2; | ||
382 | } | ||
383 | else | ||
384 | DEBUGF("wrote %d bytes\n",rc); | ||
385 | |||
386 | num -= len; | ||
387 | } | ||
388 | |||
389 | if (close(fd) < 0) | ||
390 | return -1; | ||
391 | } | ||
392 | |||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | int dbg_dump(char* name, int offset) | ||
397 | { | ||
398 | char buf[SECTOR_SIZE]; | ||
399 | |||
400 | int rc; | ||
401 | int fd = open(name,O_RDONLY); | ||
402 | if (fd<0) { | ||
403 | DEBUGF("Failed opening file\n"); | ||
404 | return -1; | ||
405 | } | ||
406 | lseek(fd, offset, SEEK_SET); | ||
407 | rc = read(fd, buf, sizeof buf); | ||
408 | |||
409 | if ( rc < 0 ) | ||
410 | panicf("Error reading data\n"); | ||
411 | |||
412 | if (close(fd) < 0) | ||
413 | return -1; | ||
414 | |||
415 | dbg_dump_buffer(buf, rc, offset); | ||
416 | |||
417 | return 0; | ||
418 | } | ||
419 | |||
420 | void dbg_tail(char* name) | ||
421 | { | ||
422 | unsigned char buf[SECTOR_SIZE*5]; | ||
423 | int fd,rc; | ||
424 | |||
425 | fd = open(name,O_RDONLY); | ||
426 | if (fd<0) | ||
427 | return; | ||
428 | DEBUGF("Got file descriptor %d\n",fd); | ||
429 | |||
430 | rc = lseek(fd,-SECTOR_SIZE,SEEK_END); | ||
431 | if ( rc >= 0 ) { | ||
432 | rc = read(fd, buf, SECTOR_SIZE); | ||
433 | if( rc > 0 ) | ||
434 | { | ||
435 | buf[rc]=0; | ||
436 | printf("%d:\n%s\n", (int)strlen(buf), buf); | ||
437 | } | ||
438 | else if ( rc == 0 ) { | ||
439 | DEBUGF("EOF\n"); | ||
440 | } | ||
441 | else | ||
442 | { | ||
443 | DEBUGF("Failed reading file: %d\n",rc); | ||
444 | } | ||
445 | } | ||
446 | else { | ||
447 | perror("lseek"); | ||
448 | } | ||
449 | |||
450 | close(fd); | ||
451 | } | ||
452 | |||
453 | int dbg_head(char* name) | ||
454 | { | ||
455 | unsigned char buf[SECTOR_SIZE*5]; | ||
456 | int fd,rc; | ||
457 | |||
458 | fd = open(name,O_RDONLY); | ||
459 | if (fd<0) | ||
460 | return -1; | ||
461 | DEBUGF("Got file descriptor %d\n",fd); | ||
462 | |||
463 | rc = read(fd, buf, SECTOR_SIZE*3); | ||
464 | if( rc > 0 ) | ||
465 | { | ||
466 | buf[rc]=0; | ||
467 | printf("%d:\n%s\n", (int)strlen(buf), buf); | ||
468 | } | ||
469 | else if ( rc == 0 ) { | ||
470 | DEBUGF("EOF\n"); | ||
471 | } | ||
472 | else | ||
473 | { | ||
474 | DEBUGF("Failed reading file: %d\n",rc); | ||
475 | } | ||
476 | |||
477 | return close(fd); | ||
478 | } | ||
479 | |||
480 | int dbg_trunc(char* name, int size) | ||
481 | { | ||
482 | int fd,rc; | ||
483 | |||
484 | #if 1 | ||
485 | fd = open(name,O_RDWR); | ||
486 | if (fd<0) | ||
487 | return -1; | ||
488 | |||
489 | rc = ftruncate(fd, size); | ||
490 | if (rc<0) { | ||
491 | DEBUGF("ftruncate(%d) failed\n", size); | ||
492 | return -2; | ||
493 | } | ||
494 | |||
495 | #else | ||
496 | fd = open(name,O_RDWR|O_TRUNC); | ||
497 | if (fd<0) | ||
498 | return -1; | ||
499 | |||
500 | rc = lseek(fd, size, SEEK_SET); | ||
501 | if (fd<0) | ||
502 | return -2; | ||
503 | #endif | ||
504 | |||
505 | return close(fd); | ||
506 | } | ||
507 | |||
508 | int dbg_mkdir(char* name) | ||
509 | { | ||
510 | int fd; | ||
511 | |||
512 | fd = mkdir(name); | ||
513 | if (fd<0) { | ||
514 | DEBUGF("Failed creating directory\n"); | ||
515 | return -1; | ||
516 | } | ||
517 | return 0; | ||
518 | } | ||
519 | |||
520 | int dbg_cmd(int argc, char *argv[]) | ||
521 | { | ||
522 | char* cmd = NULL; | ||
523 | char* arg1 = NULL; | ||
524 | char* arg2 = NULL; | ||
525 | |||
526 | if (argc > 1) { | ||
527 | cmd = argv[1]; | ||
528 | if ( argc > 2 ) { | ||
529 | arg1 = argv[2]; | ||
530 | if ( argc > 3 ) { | ||
531 | arg2 = argv[3]; | ||
532 | } | ||
533 | } | ||
534 | } | ||
535 | else { | ||
536 | DEBUGF("usage: fat command [options]\n" | ||
537 | "commands:\n" | ||
538 | " dir <dir>\n" | ||
539 | " ds <sector> - display sector\n" | ||
540 | " type <file>\n" | ||
541 | " head <file>\n" | ||
542 | " tail <file>\n" | ||
543 | " mkfile <file> <size (KB)>\n" | ||
544 | " chkfile <file>\n" | ||
545 | " del <file>\n" | ||
546 | " rmdir <dir>\n" | ||
547 | " dump <file> <offset>\n" | ||
548 | " mkdir <dir>\n" | ||
549 | " trunc <file> <size>\n" | ||
550 | " wrtest <file>\n" | ||
551 | " append <file>\n" | ||
552 | " test <file>\n" | ||
553 | " ren <file> <newname>\n" | ||
554 | ); | ||
555 | return -1; | ||
556 | } | ||
557 | |||
558 | if (!strcasecmp(cmd, "dir")) | ||
559 | { | ||
560 | if ( arg1 ) | ||
561 | dbg_dir(arg1); | ||
562 | else | ||
563 | dbg_dir("/"); | ||
564 | } | ||
565 | |||
566 | if (!strcasecmp(cmd, "ds")) | ||
567 | { | ||
568 | if ( arg1 ) { | ||
569 | DEBUGF("secnum: %ld\n", strtol(arg1, NULL, 0)); | ||
570 | dbg_dump_sector(strtol(arg1, NULL, 0)); | ||
571 | } | ||
572 | } | ||
573 | |||
574 | if (!strcasecmp(cmd, "type")) | ||
575 | { | ||
576 | if (arg1) | ||
577 | dbg_type(arg1); | ||
578 | } | ||
579 | |||
580 | if (!strcasecmp(cmd, "head")) | ||
581 | { | ||
582 | if (arg1) | ||
583 | return dbg_head(arg1); | ||
584 | } | ||
585 | |||
586 | if (!strcasecmp(cmd, "tail")) | ||
587 | { | ||
588 | if (arg1) | ||
589 | dbg_tail(arg1); | ||
590 | } | ||
591 | |||
592 | if (!strcasecmp(cmd, "mkfile")) | ||
593 | { | ||
594 | if (arg1) { | ||
595 | if (arg2) | ||
596 | return dbg_mkfile(arg1,strtol(arg2, NULL, 0)); | ||
597 | else | ||
598 | return dbg_mkfile(arg1,1); | ||
599 | } | ||
600 | } | ||
601 | |||
602 | if (!strcasecmp(cmd, "chkfile")) | ||
603 | { | ||
604 | if (arg1) { | ||
605 | if (arg2) | ||
606 | return dbg_chkfile(arg1, strtol(arg2, NULL, 0)); | ||
607 | else | ||
608 | return dbg_chkfile(arg1, 0); | ||
609 | } | ||
610 | } | ||
611 | |||
612 | if (!strcasecmp(cmd, "mkdir")) | ||
613 | { | ||
614 | if (arg1) { | ||
615 | return dbg_mkdir(arg1); | ||
616 | } | ||
617 | } | ||
618 | |||
619 | if (!strcasecmp(cmd, "del")) | ||
620 | { | ||
621 | if (arg1) | ||
622 | return remove(arg1); | ||
623 | } | ||
624 | |||
625 | if (!strcasecmp(cmd, "rmdir")) | ||
626 | { | ||
627 | if (arg1) | ||
628 | return rmdir(arg1); | ||
629 | } | ||
630 | |||
631 | if (!strcasecmp(cmd, "dump")) | ||
632 | { | ||
633 | if (arg1) { | ||
634 | if (arg2) | ||
635 | return dbg_dump(arg1, strtol(arg2, NULL, 0)); | ||
636 | else | ||
637 | return dbg_dump(arg1, 0); | ||
638 | } | ||
639 | } | ||
640 | |||
641 | if (!strcasecmp(cmd, "wrtest")) | ||
642 | { | ||
643 | if (arg1) | ||
644 | return dbg_wrtest(arg1); | ||
645 | } | ||
646 | |||
647 | if (!strcasecmp(cmd, "append")) | ||
648 | { | ||
649 | if (arg1) | ||
650 | return dbg_append(arg1); | ||
651 | } | ||
652 | |||
653 | if (!strcasecmp(cmd, "test")) | ||
654 | { | ||
655 | if (arg1) | ||
656 | return dbg_test(arg1); | ||
657 | } | ||
658 | |||
659 | if (!strcasecmp(cmd, "trunc")) | ||
660 | { | ||
661 | if (arg1 && arg2) | ||
662 | return dbg_trunc(arg1, strtol(arg2, NULL, 0)); | ||
663 | } | ||
664 | |||
665 | if (!strcasecmp(cmd, "ren")) | ||
666 | { | ||
667 | if (arg1 && arg2) | ||
668 | return rename(arg1, arg2); | ||
669 | } | ||
670 | |||
671 | return 0; | ||
672 | } | ||
673 | |||
674 | extern void ata_exit(void); | ||
675 | |||
676 | int main(int argc, char *argv[]) | ||
677 | { | ||
678 | int rc,i; | ||
679 | struct partinfo* pinfo; | ||
680 | |||
681 | srand(clock()); | ||
682 | |||
683 | if(ata_init()) { | ||
684 | DEBUGF("*** Warning! The disk is uninitialized\n"); | ||
685 | return -1; | ||
686 | } | ||
687 | pinfo = disk_init(); | ||
688 | if (!pinfo) { | ||
689 | DEBUGF("*** Failed reading partitions\n"); | ||
690 | return -1; | ||
691 | } | ||
692 | |||
693 | for ( i=0; i<4; i++ ) { | ||
694 | if ( pinfo[i].type == PARTITION_TYPE_FAT32 | ||
695 | #ifdef HAVE_FAT16SUPPORT | ||
696 | || pinfo[i].type == PARTITION_TYPE_FAT16 | ||
697 | #endif | ||
698 | ) { | ||
699 | DEBUGF("*** Mounting at block %ld\n",pinfo[i].start); | ||
700 | rc = fat_mount(IF_MV(0,) IF_MD(0,) pinfo[i].start); | ||
701 | if(rc) { | ||
702 | DEBUGF("mount: %d",rc); | ||
703 | return -1; | ||
704 | } | ||
705 | break; | ||
706 | } | ||
707 | } | ||
708 | if ( i==4 ) { | ||
709 | if(fat_mount(IF_MV(0,) IF_MD(0,) 0)) { | ||
710 | DEBUGF("No FAT32 partition!"); | ||
711 | return -1; | ||
712 | } | ||
713 | } | ||
714 | |||
715 | rc = dbg_cmd(argc, argv); | ||
716 | |||
717 | ata_exit(); | ||
718 | |||
719 | if (rc) | ||
720 | DEBUGF("Return code: %d\n", rc); | ||
721 | |||
722 | return rc; | ||
723 | } | ||
724 | |||
diff --git a/firmware/test/fat/test.sh b/firmware/test/fat/test.sh deleted file mode 100644 index ca0a1db067..0000000000 --- a/firmware/test/fat/test.sh +++ /dev/null | |||
@@ -1,146 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | IMAGE=disk.img | ||
4 | MOUNT=/mnt/dummy | ||
5 | RESULT=result.txt | ||
6 | |||
7 | fail() { | ||
8 | echo "!! Test failed. Look in $RESULT for test logs." | ||
9 | chmod a+rw $RESULT | ||
10 | exit | ||
11 | } | ||
12 | |||
13 | check() { | ||
14 | /sbin/dosfsck -r $IMAGE | tee -a $RESULT | ||
15 | [ $RETVAL -ne 0 ] && fail | ||
16 | } | ||
17 | |||
18 | try() { | ||
19 | echo COMMAND: fat $1 "$2" "$3" | ||
20 | echo COMMAND: fat $1 "$2" "$3" >> $RESULT | ||
21 | ./fat $1 "$2" "$3" 2>> $RESULT | ||
22 | RETVAL=$? | ||
23 | [ $RETVAL -ne 0 ] && fail | ||
24 | } | ||
25 | |||
26 | buildimage() { | ||
27 | /sbin/mkdosfs -F 32 -s $1 $IMAGE > /dev/null | ||
28 | #mount -o loop $IMAGE $MOUNT | ||
29 | mount $MOUNT | ||
30 | echo "Filling it with /etc files" | ||
31 | find /etc -maxdepth 1 -type f -readable -exec cp {} $MOUNT \; | ||
32 | for i in `seq 1 120`; | ||
33 | do | ||
34 | echo apa > "$MOUNT/very $i long test filename so we can make sure they.work" | ||
35 | done | ||
36 | umount $MOUNT | ||
37 | } | ||
38 | |||
39 | runtests() { | ||
40 | rm $RESULT | ||
41 | |||
42 | echo ---Test: create a long name directory in the root | ||
43 | try mkdir "/very long subdir name" | ||
44 | check | ||
45 | try mkdir "/very long subdir name/apa.monkey.me.now" | ||
46 | check | ||
47 | |||
48 | echo ---Test: create a directory called "dir" | ||
49 | try mkdir "/dir" | ||
50 | check | ||
51 | |||
52 | echo ---Test: create a 10K file | ||
53 | try mkfile "/really long filenames rock" 10 | ||
54 | check | ||
55 | |||
56 | try mkfile /dir/apa.monkey.me.now 10 | ||
57 | check | ||
58 | try chkfile "/really long filenames rock" 10 | ||
59 | try chkfile /dir/apa.monkey.me.now 8 | ||
60 | |||
61 | echo ---Test: create a 1K file | ||
62 | try mkfile /bpa.rock 1 | ||
63 | check | ||
64 | try chkfile /bpa.rock 1 | ||
65 | |||
66 | echo ---Test: create a 40K file | ||
67 | try mkfile /cpa.rock 40 | ||
68 | check | ||
69 | try chkfile /cpa.rock 40 | ||
70 | |||
71 | echo ---Test: create a 400K file | ||
72 | try mkfile /dpa.rock 400 | ||
73 | check | ||
74 | try chkfile /dpa.rock 400 | ||
75 | |||
76 | echo ---Test: create a 1200K file | ||
77 | try mkfile /epa.rock 1200 | ||
78 | check | ||
79 | try chkfile /epa.rock 1200 | ||
80 | |||
81 | echo ---Test: rewrite first 20K of a 40K file | ||
82 | try mkfile /cpa.rock 20 | ||
83 | check | ||
84 | try chkfile /cpa.rock 20 | ||
85 | |||
86 | echo ---Test: rewrite first sector of 40K file | ||
87 | try mkfile /cpa.rock 0 | ||
88 | check | ||
89 | try chkfile /cpa.rock | ||
90 | try chkfile /bpa.rock | ||
91 | |||
92 | LOOP=50 | ||
93 | SIZE=700 | ||
94 | |||
95 | try del "/really long filenames rock" | ||
96 | |||
97 | echo ---Test: create $LOOP $SIZE k files | ||
98 | for i in `seq 1 $LOOP`; | ||
99 | do | ||
100 | echo ---Test: $i/$LOOP --- | ||
101 | try mkfile "/rockbox rocks.$i" $SIZE | ||
102 | check | ||
103 | try chkfile "/rockbox rocks.$i" $SIZE | ||
104 | check | ||
105 | try del "/rockbox rocks.$i" | ||
106 | check | ||
107 | try mkfile "/rockbox rocks.$i" $SIZE | ||
108 | check | ||
109 | try ren "/rockbox rocks.$i" "/$i is a new long filename!" | ||
110 | check | ||
111 | done | ||
112 | |||
113 | } | ||
114 | |||
115 | echo "--------------------------------------" | ||
116 | echo "Building test image (4 sector/cluster)" | ||
117 | echo "--------------------------------------" | ||
118 | buildimage 4 | ||
119 | runtests | ||
120 | |||
121 | echo "---------------------------------------" | ||
122 | echo "Building test image (32 sectors/cluster)" | ||
123 | echo "---------------------------------------" | ||
124 | buildimage 32 | ||
125 | runtests | ||
126 | |||
127 | echo "--------------------------------------" | ||
128 | echo "Building test image (1 sector/cluster)" | ||
129 | echo "--------------------------------------" | ||
130 | buildimage 1 | ||
131 | runtests | ||
132 | |||
133 | echo "--------------------------------------" | ||
134 | echo "Building test image (8 sectors/cluster)" | ||
135 | echo "--------------------------------------" | ||
136 | buildimage 8 | ||
137 | runtests | ||
138 | |||
139 | echo "----------------------------------------" | ||
140 | echo "Building test image (128 sectors/cluster)" | ||
141 | echo "----------------------------------------" | ||
142 | buildimage 128 | ||
143 | runtests | ||
144 | |||
145 | echo "== Test completed successfully ==" | ||
146 | chmod a+rw $RESULT | ||
diff --git a/firmware/test/fat/test16.sh b/firmware/test/fat/test16.sh deleted file mode 100644 index 5a1c13150c..0000000000 --- a/firmware/test/fat/test16.sh +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | IMAGE=disk.img | ||
4 | MOUNT=/mnt/dummy | ||
5 | DIR=$MOUNT/q | ||
6 | RESULT=result.txt | ||
7 | |||
8 | fail() { | ||
9 | echo "!! Test failed $RETVAL. Look in $RESULT for test logs." | ||
10 | chmod a+rw $RESULT | ||
11 | exit | ||
12 | } | ||
13 | |||
14 | check() { | ||
15 | /sbin/dosfsck -r $IMAGE | tee -a $RESULT | ||
16 | [ $RETVAL -ne 0 ] && fail | ||
17 | } | ||
18 | |||
19 | try() { | ||
20 | echo COMMAND: fat $1 "$2" "$3" | ||
21 | echo COMMAND: fat $1 "$2" "$3" >> $RESULT | ||
22 | ./fat $1 "$2" "$3" 2>> $RESULT | ||
23 | RETVAL=$? | ||
24 | [ $RETVAL -ne 0 ] && fail | ||
25 | } | ||
26 | |||
27 | buildimage() { | ||
28 | /sbin/mkdosfs -F 16 -s $1 $IMAGE > /dev/null; | ||
29 | mount -o loop,fat=16 $IMAGE $MOUNT; | ||
30 | echo "Filling it with /etc files"; | ||
31 | mkdir $DIR; | ||
32 | find /etc -type f -maxdepth 1 -exec cp {} $DIR \; | ||
33 | for i in `seq 1 120`; | ||
34 | do | ||
35 | echo apa > "$DIR/very $i long test filename so we can make sure they.work"; | ||
36 | done; | ||
37 | umount $MOUNT; | ||
38 | } | ||
39 | |||
40 | runtests() { | ||
41 | rm $RESULT | ||
42 | |||
43 | echo ---Test: create a long name directory in the root | ||
44 | try mkdir "/very long subdir name" | ||
45 | check | ||
46 | try mkdir "/very long subdir name/apa.monkey.me.now" | ||
47 | check | ||
48 | |||
49 | echo ---Test: create a directory called "dir" | ||
50 | try mkdir "/dir" | ||
51 | check | ||
52 | |||
53 | echo ---Test: create a 10K file | ||
54 | try mkfile "/really long filenames rock" 10 | ||
55 | check | ||
56 | |||
57 | try mkfile /dir/apa.monkey.me.now 10 | ||
58 | check | ||
59 | try chkfile "/really long filenames rock" 10 | ||
60 | try chkfile /dir/apa.monkey.me.now 8 | ||
61 | |||
62 | echo ---Test: create a 1K file | ||
63 | try mkfile /bpa.rock 1 | ||
64 | check | ||
65 | try chkfile /bpa.rock 1 | ||
66 | |||
67 | echo ---Test: create a 40K file | ||
68 | try mkfile /cpa.rock 40 | ||
69 | check | ||
70 | try chkfile /cpa.rock 40 | ||
71 | |||
72 | echo ---Test: create a 400K file | ||
73 | try mkfile /dpa.rock 400 | ||
74 | check | ||
75 | try chkfile /dpa.rock 400 | ||
76 | |||
77 | echo ---Test: create a 1200K file | ||
78 | try mkfile /epa.rock 1200 | ||
79 | check | ||
80 | try chkfile /epa.rock 1200 | ||
81 | |||
82 | echo ---Test: rewrite first 20K of a 40K file | ||
83 | try mkfile /cpa.rock 20 | ||
84 | check | ||
85 | try chkfile /cpa.rock 20 | ||
86 | |||
87 | echo ---Test: rewrite first sector of 40K file | ||
88 | try mkfile /cpa.rock 0 | ||
89 | check | ||
90 | try chkfile /cpa.rock | ||
91 | try chkfile /bpa.rock | ||
92 | |||
93 | LOOP=25 | ||
94 | SIZE=700 | ||
95 | |||
96 | try del "/really long filenames rock" | ||
97 | |||
98 | echo ---Test: create $LOOP $SIZE k files | ||
99 | for i in `seq 1 $LOOP`; | ||
100 | do | ||
101 | echo ---Test: $i/$LOOP --- | ||
102 | try mkfile "/q/rockbox rocks.$i" $SIZE | ||
103 | check | ||
104 | try chkfile "/q/rockbox rocks.$i" $SIZE | ||
105 | check | ||
106 | try del "/q/rockbox rocks.$i" | ||
107 | check | ||
108 | try mkfile "/q/rockbox rocks.$i" $SIZE | ||
109 | check | ||
110 | try ren "/q/rockbox rocks.$i" "/q/$i is a new long filename!" | ||
111 | check | ||
112 | done | ||
113 | |||
114 | } | ||
115 | |||
116 | echo "--------------------------------------" | ||
117 | echo "Building test image (4 sector/cluster)" | ||
118 | echo "--------------------------------------" | ||
119 | buildimage 4 | ||
120 | runtests | ||
121 | |||
122 | echo "--------------------------------------" | ||
123 | echo "Building test image (8 sectors/cluster)" | ||
124 | echo "--------------------------------------" | ||
125 | buildimage 8 | ||
126 | runtests | ||
127 | |||
128 | echo "----------------------------------------" | ||
129 | echo "Building test image (64 sectors/cluster)" | ||
130 | echo "----------------------------------------" | ||
131 | buildimage 64 | ||
132 | runtests | ||
133 | |||
134 | echo "== Test completed successfully ==" | ||
135 | chmod a+rw $RESULT | ||