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.zip
rockbox-a5e77d8f943e602c56036f0f21b60b7f442a3976.tar.gz
rockbox-a5e77d8f943e602c56036f0f21b60b7f442a3976.tar.bz2
rockbox-a5e77d8f943e602c56036f0f21b60b7f442a3976.tar.xz
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 a64e0a4..661cc79 100644
--- a/firmware/test/fat/ata-sim.c
+++ b/firmware/test/fat/ata-sim.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include "debug.h"
+#include "panic.h"
#define BLOCK_SIZE 512
@@ -9,7 +10,10 @@ static FILE* file;
int ata_read_sectors(unsigned long start, unsigned char count, void* buf)
{
- DEBUGF("[Reading block 0x%lx]\n",start);
+ int i;
+ for (i=0; i<count; i++ )
+ DEBUGF("[Reading block 0x%lx]\n",start+i);
+
if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) {
perror("fseek");
return -1;
@@ -17,6 +21,7 @@ int ata_read_sectors(unsigned long start, unsigned char count, void* buf)
if(!fread(buf,BLOCK_SIZE,count,file)) {
printf("Failed reading %d blocks starting at block 0x%lx\n",count,start);
perror("fread");
+ panicf("Disk error\n");
return -2;
}
return 0;
@@ -24,20 +29,22 @@ int ata_read_sectors(unsigned long start, unsigned char count, void* buf)
int ata_write_sectors(unsigned long start, unsigned char count, void* buf)
{
- DEBUGF("[Writing block 0x%lx]\n",start);
+ int i;
+ for (i=0; i<count; i++ )
+ DEBUGF("[Writing block 0x%lx]\n",start+i);
- if (start == 0) {
- DEBUGF("Holy crap! You're writing on sector 0!\n");
- exit(0);
- }
+ if (start == 0)
+ panicf("Writing on sector 0!\n");
if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) {
perror("fseek");
return -1;
+ panicf("Disk error\n");
}
if(!fwrite(buf,BLOCK_SIZE,count,file)) {
perror("fwrite");
return -2;
+ panicf("Disk error\n");
}
return 0;
}
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c
index 708ee45..0259be4 100644
--- a/firmware/test/fat/main.c
+++ b/firmware/test/fat/main.c
@@ -12,7 +12,7 @@ extern int ata_init(char*);
extern void ata_read_sectors(int, int, char*);
void dbg_dump_sector(int sec);
-void dbg_dump_buffer(unsigned char *buf, int len);
+void dbg_dump_buffer(unsigned char *buf, int len, int offset);
void dbg_console(void);
void panicf( char *fmt, ...)
@@ -31,10 +31,10 @@ void dbg_dump_sector(int sec)
ata_read_sectors(sec,1,buf);
DEBUGF("---< Sector %d >-----------------------------------------\n", sec);
- dbg_dump_buffer(buf, 512);
+ dbg_dump_buffer(buf, 512, 0);
}
-void dbg_dump_buffer(unsigned char *buf, int len)
+void dbg_dump_buffer(unsigned char *buf, int len, int offset)
{
int i, j;
unsigned char c;
@@ -42,7 +42,7 @@ void dbg_dump_buffer(unsigned char *buf, int len)
for(i = 0;i < len/16;i++)
{
- DEBUGF("%03x: ", i*16);
+ DEBUGF("%03x: ", i*16 + offset);
for(j = 0;j < 16;j++)
{
c = buf[i*16+j];
@@ -102,7 +102,7 @@ int dbg_mkfile(char* name, int num)
int len = num > sizeof text ? sizeof text : num;
for (i=0; i<len/CHUNKSIZE; i++ )
- sprintf(text+i*CHUNKSIZE,"%07x,",x++);
+ sprintf(text+i*CHUNKSIZE,"%c%06x,",name[1],x++);
if (write(fd, text, len) < 0) {
DEBUGF("Failed writing data\n");
@@ -139,12 +139,15 @@ int dbg_chkfile(char* name)
if (!rc)
break;
for (i=0; i<rc/CHUNKSIZE; i++ ) {
- sprintf(tmp,"%07x,",x++);
+ sprintf(tmp,"%c%06x,",name[1],x++);
if (strncmp(text+i*CHUNKSIZE,tmp,CHUNKSIZE)) {
- DEBUGF("Mismatch in byte %d (%.4s != %.4s)\n",
- block*sizeof(text)+i*CHUNKSIZE, tmp,
+ DEBUGF("Mismatch in byte %x (sector %d). Expected %.8s found %.8s\n",
+ block*sizeof(text)+i*CHUNKSIZE,
+ (block*sizeof(text)+i*CHUNKSIZE) / SECTOR_SIZE,
+ tmp,
text+i*CHUNKSIZE);
- dbg_dump_buffer(text+i*CHUNKSIZE - 0x20, 0x40);
+ dbg_dump_buffer(text+i*CHUNKSIZE - 0x20, 0x40,
+ block*sizeof(text)+i*CHUNKSIZE - 0x20);
return -1;
}
}
diff --git a/firmware/test/fat/test.sh b/firmware/test/fat/test.sh
index 0b00d76..476b0e4 100644
--- a/firmware/test/fat/test.sh
+++ b/firmware/test/fat/test.sh
@@ -2,32 +2,34 @@
IMAGE=disk.img
MOUNT=/mnt/dummy
+RESULT=result.txt
fail() {
- echo "!! Test failed. Look in result.txt for test log."
+ echo "!! Test failed. Look in $RESULT for test logs."
exit
}
check() {
- /sbin/dosfsck -r $IMAGE | tee -a result.txt
+ /sbin/dosfsck -r $IMAGE | tee -a $RESULT
[ $RETVAL -ne 0 ] && fail
}
try() {
- ./fat $1 $2 $3 2> result.txt
+ ./fat $1 $2 $3 2>> $RESULT
RETVAL=$?
[ $RETVAL -ne 0 ] && fail
}
buildimage() {
- umount $MOUNT
- /sbin/mkdosfs -F 32 -s $1 disk.img >/dev/null
+ /sbin/mkdosfs -F 32 -s $1 $IMAGE > /dev/null
mount -o loop $IMAGE $MOUNT
echo "Filling it with /etc files"
find /etc -type f -maxdepth 1 -exec cp {} $MOUNT \;
+ umount $MOUNT
}
runtests() {
+ rm $RESULT
echo ---Test: create a 10K file
try mkfile /apa.txt 10
@@ -53,29 +55,38 @@ runtests() {
try mkfile /cpa.txt 0
check
try chkfile /cpa.txt
+ try chkfile /apa.txt
+ try chkfile /bpa.txt
- echo ---Test: create 20 1k files
+ echo ---Test: create 10 1k files
for i in `seq 1 10`;
do
- echo -n $i
+ echo ---Test: $i/10 ---
try mkfile /rockbox.$i
check
+ try chkfile /bpa.txt
done
}
-echo "Building test image A (2 sectors/cluster)"
-buildimage 2
+echo "Building test image (1 sector/cluster)"
+buildimage 1
runtests
-echo "Building test image B (8 sectors/cluster)"
+echo "Building test image (4 sector/cluster)"
+buildimage 4
+runtests
+
+echo "Building test image (8 sectors/cluster)"
buildimage 8
runtests
-echo "Building test image B (1 sector/cluster)"
-buildimage 1
+echo "Building test image (32 sectors/cluster)"
+buildimage 32
runtests
-umount $MOUNT
+echo "Building test image (128 sectors/cluster)"
+buildimage 128
+runtests
-echo "-- Test complete --"
+echo "== Test completed sucessfully =="