summaryrefslogtreecommitdiff
path: root/firmware/test/fat
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-10-31 16:09:28 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-10-31 16:09:28 +0000
commita5e77d8f943e602c56036f0f21b60b7f442a3976 (patch)
tree324101cf4060f4f06bd522bd49d4f57469a6dad3 /firmware/test/fat
parent3bf2f7858188c222abde85643ce980963dc7e4c9 (diff)
downloadrockbox-a5e77d8f943e602c56036f0f21b60b7f442a3976.tar.gz
rockbox-a5e77d8f943e602c56036f0f21b60b7f442a3976.zip
Fat writing update. File creation now works, though still only short filenames.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2790 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/test/fat')
-rw-r--r--firmware/test/fat/ata-sim.c19
-rw-r--r--firmware/test/fat/main.c21
-rw-r--r--firmware/test/fat/test.sh39
3 files changed, 50 insertions, 29 deletions
diff --git a/firmware/test/fat/ata-sim.c b/firmware/test/fat/ata-sim.c
index a64e0a4d4d..661cc79a1f 100644
--- a/firmware/test/fat/ata-sim.c
+++ b/firmware/test/fat/ata-sim.c
@@ -2,6 +2,7 @@
2#include <stdlib.h> 2#include <stdlib.h>
3#include <string.h> 3#include <string.h>
4#include "debug.h" 4#include "debug.h"
5#include "panic.h"
5 6
6#define BLOCK_SIZE 512 7#define BLOCK_SIZE 512
7 8
@@ -9,7 +10,10 @@ static FILE* file;
9 10
10int ata_read_sectors(unsigned long start, unsigned char count, void* buf) 11int ata_read_sectors(unsigned long start, unsigned char count, void* buf)
11{ 12{
12 DEBUGF("[Reading block 0x%lx]\n",start); 13 int i;
14 for (i=0; i<count; i++ )
15 DEBUGF("[Reading block 0x%lx]\n",start+i);
16
13 if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { 17 if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) {
14 perror("fseek"); 18 perror("fseek");
15 return -1; 19 return -1;
@@ -17,6 +21,7 @@ int ata_read_sectors(unsigned long start, unsigned char count, void* buf)
17 if(!fread(buf,BLOCK_SIZE,count,file)) { 21 if(!fread(buf,BLOCK_SIZE,count,file)) {
18 printf("Failed reading %d blocks starting at block 0x%lx\n",count,start); 22 printf("Failed reading %d blocks starting at block 0x%lx\n",count,start);
19 perror("fread"); 23 perror("fread");
24 panicf("Disk error\n");
20 return -2; 25 return -2;
21 } 26 }
22 return 0; 27 return 0;
@@ -24,20 +29,22 @@ int ata_read_sectors(unsigned long start, unsigned char count, void* buf)
24 29
25int ata_write_sectors(unsigned long start, unsigned char count, void* buf) 30int ata_write_sectors(unsigned long start, unsigned char count, void* buf)
26{ 31{
27 DEBUGF("[Writing block 0x%lx]\n",start); 32 int i;
33 for (i=0; i<count; i++ )
34 DEBUGF("[Writing block 0x%lx]\n",start+i);
28 35
29 if (start == 0) { 36 if (start == 0)
30 DEBUGF("Holy crap! You're writing on sector 0!\n"); 37 panicf("Writing on sector 0!\n");
31 exit(0);
32 }
33 38
34 if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { 39 if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) {
35 perror("fseek"); 40 perror("fseek");
36 return -1; 41 return -1;
42 panicf("Disk error\n");
37 } 43 }
38 if(!fwrite(buf,BLOCK_SIZE,count,file)) { 44 if(!fwrite(buf,BLOCK_SIZE,count,file)) {
39 perror("fwrite"); 45 perror("fwrite");
40 return -2; 46 return -2;
47 panicf("Disk error\n");
41 } 48 }
42 return 0; 49 return 0;
43} 50}
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c
index 708ee454c8..0259be410b 100644
--- a/firmware/test/fat/main.c
+++ b/firmware/test/fat/main.c
@@ -12,7 +12,7 @@ extern int ata_init(char*);
12extern void ata_read_sectors(int, int, char*); 12extern void ata_read_sectors(int, int, char*);
13 13
14void dbg_dump_sector(int sec); 14void dbg_dump_sector(int sec);
15void dbg_dump_buffer(unsigned char *buf, int len); 15void dbg_dump_buffer(unsigned char *buf, int len, int offset);
16void dbg_console(void); 16void dbg_console(void);
17 17
18void panicf( char *fmt, ...) 18void panicf( char *fmt, ...)
@@ -31,10 +31,10 @@ void dbg_dump_sector(int sec)
31 31
32 ata_read_sectors(sec,1,buf); 32 ata_read_sectors(sec,1,buf);
33 DEBUGF("---< Sector %d >-----------------------------------------\n", sec); 33 DEBUGF("---< Sector %d >-----------------------------------------\n", sec);
34 dbg_dump_buffer(buf, 512); 34 dbg_dump_buffer(buf, 512, 0);
35} 35}
36 36
37void dbg_dump_buffer(unsigned char *buf, int len) 37void dbg_dump_buffer(unsigned char *buf, int len, int offset)
38{ 38{
39 int i, j; 39 int i, j;
40 unsigned char c; 40 unsigned char c;
@@ -42,7 +42,7 @@ void dbg_dump_buffer(unsigned char *buf, int len)
42 42
43 for(i = 0;i < len/16;i++) 43 for(i = 0;i < len/16;i++)
44 { 44 {
45 DEBUGF("%03x: ", i*16); 45 DEBUGF("%03x: ", i*16 + offset);
46 for(j = 0;j < 16;j++) 46 for(j = 0;j < 16;j++)
47 { 47 {
48 c = buf[i*16+j]; 48 c = buf[i*16+j];
@@ -102,7 +102,7 @@ int dbg_mkfile(char* name, int num)
102 int len = num > sizeof text ? sizeof text : num; 102 int len = num > sizeof text ? sizeof text : num;
103 103
104 for (i=0; i<len/CHUNKSIZE; i++ ) 104 for (i=0; i<len/CHUNKSIZE; i++ )
105 sprintf(text+i*CHUNKSIZE,"%07x,",x++); 105 sprintf(text+i*CHUNKSIZE,"%c%06x,",name[1],x++);
106 106
107 if (write(fd, text, len) < 0) { 107 if (write(fd, text, len) < 0) {
108 DEBUGF("Failed writing data\n"); 108 DEBUGF("Failed writing data\n");
@@ -139,12 +139,15 @@ int dbg_chkfile(char* name)
139 if (!rc) 139 if (!rc)
140 break; 140 break;
141 for (i=0; i<rc/CHUNKSIZE; i++ ) { 141 for (i=0; i<rc/CHUNKSIZE; i++ ) {
142 sprintf(tmp,"%07x,",x++); 142 sprintf(tmp,"%c%06x,",name[1],x++);
143 if (strncmp(text+i*CHUNKSIZE,tmp,CHUNKSIZE)) { 143 if (strncmp(text+i*CHUNKSIZE,tmp,CHUNKSIZE)) {
144 DEBUGF("Mismatch in byte %d (%.4s != %.4s)\n", 144 DEBUGF("Mismatch in byte %x (sector %d). Expected %.8s found %.8s\n",
145 block*sizeof(text)+i*CHUNKSIZE, tmp, 145 block*sizeof(text)+i*CHUNKSIZE,
146 (block*sizeof(text)+i*CHUNKSIZE) / SECTOR_SIZE,
147 tmp,
146 text+i*CHUNKSIZE); 148 text+i*CHUNKSIZE);
147 dbg_dump_buffer(text+i*CHUNKSIZE - 0x20, 0x40); 149 dbg_dump_buffer(text+i*CHUNKSIZE - 0x20, 0x40,
150 block*sizeof(text)+i*CHUNKSIZE - 0x20);
148 return -1; 151 return -1;
149 } 152 }
150 } 153 }
diff --git a/firmware/test/fat/test.sh b/firmware/test/fat/test.sh
index 0b00d765c2..476b0e4542 100644
--- a/firmware/test/fat/test.sh
+++ b/firmware/test/fat/test.sh
@@ -2,32 +2,34 @@
2 2
3IMAGE=disk.img 3IMAGE=disk.img
4MOUNT=/mnt/dummy 4MOUNT=/mnt/dummy
5RESULT=result.txt
5 6
6fail() { 7fail() {
7 echo "!! Test failed. Look in result.txt for test log." 8 echo "!! Test failed. Look in $RESULT for test logs."
8 exit 9 exit
9} 10}
10 11
11check() { 12check() {
12 /sbin/dosfsck -r $IMAGE | tee -a result.txt 13 /sbin/dosfsck -r $IMAGE | tee -a $RESULT
13 [ $RETVAL -ne 0 ] && fail 14 [ $RETVAL -ne 0 ] && fail
14} 15}
15 16
16try() { 17try() {
17 ./fat $1 $2 $3 2> result.txt 18 ./fat $1 $2 $3 2>> $RESULT
18 RETVAL=$? 19 RETVAL=$?
19 [ $RETVAL -ne 0 ] && fail 20 [ $RETVAL -ne 0 ] && fail
20} 21}
21 22
22buildimage() { 23buildimage() {
23 umount $MOUNT 24 /sbin/mkdosfs -F 32 -s $1 $IMAGE > /dev/null
24 /sbin/mkdosfs -F 32 -s $1 disk.img >/dev/null
25 mount -o loop $IMAGE $MOUNT 25 mount -o loop $IMAGE $MOUNT
26 echo "Filling it with /etc files" 26 echo "Filling it with /etc files"
27 find /etc -type f -maxdepth 1 -exec cp {} $MOUNT \; 27 find /etc -type f -maxdepth 1 -exec cp {} $MOUNT \;
28 umount $MOUNT
28} 29}
29 30
30runtests() { 31runtests() {
32 rm $RESULT
31 33
32 echo ---Test: create a 10K file 34 echo ---Test: create a 10K file
33 try mkfile /apa.txt 10 35 try mkfile /apa.txt 10
@@ -53,29 +55,38 @@ runtests() {
53 try mkfile /cpa.txt 0 55 try mkfile /cpa.txt 0
54 check 56 check
55 try chkfile /cpa.txt 57 try chkfile /cpa.txt
58 try chkfile /apa.txt
59 try chkfile /bpa.txt
56 60
57 echo ---Test: create 20 1k files 61 echo ---Test: create 10 1k files
58 for i in `seq 1 10`; 62 for i in `seq 1 10`;
59 do 63 do
60 echo -n $i 64 echo ---Test: $i/10 ---
61 try mkfile /rockbox.$i 65 try mkfile /rockbox.$i
62 check 66 check
67 try chkfile /bpa.txt
63 done 68 done
64 69
65} 70}
66 71
67echo "Building test image A (2 sectors/cluster)" 72echo "Building test image (1 sector/cluster)"
68buildimage 2 73buildimage 1
69runtests 74runtests
70 75
71echo "Building test image B (8 sectors/cluster)" 76echo "Building test image (4 sector/cluster)"
77buildimage 4
78runtests
79
80echo "Building test image (8 sectors/cluster)"
72buildimage 8 81buildimage 8
73runtests 82runtests
74 83
75echo "Building test image B (1 sector/cluster)" 84echo "Building test image (32 sectors/cluster)"
76buildimage 1 85buildimage 32
77runtests 86runtests
78 87
79umount $MOUNT 88echo "Building test image (128 sectors/cluster)"
89buildimage 128
90runtests
80 91
81echo "-- Test complete --" 92echo "== Test completed sucessfully =="