From e78984aa2545c852916a09b83591aa41d3a7a70e Mon Sep 17 00:00:00 2001 From: dak664 Date: Tue, 4 May 2010 14:08:01 +0000 Subject: [PATCH] Bugfixes and additional testing contributed by Mauro Greco. Still a probabe bug when coffee page size is a multiple of physical page size and FLASH_COMPLEMENT_DATA=0 --- platform/avr-raven/cfs-coffee-arch.c | 194 ++++++++++++++++++++++----- 1 file changed, 160 insertions(+), 34 deletions(-) diff --git a/platform/avr-raven/cfs-coffee-arch.c b/platform/avr-raven/cfs-coffee-arch.c index b4642a405..37d3e1992 100644 --- a/platform/avr-raven/cfs-coffee-arch.c +++ b/platform/avr-raven/cfs-coffee-arch.c @@ -54,8 +54,15 @@ #define PRINTF(...) #endif -#define TESTCOFFEE 0 +#define TESTCOFFEE 1 +#define DEBUG_CFS 1 #if TESTCOFFEE +#if DEBUG_CFS +#include +#define PRINTF_CFS(FORMAT,args...) printf_P(PSTR(FORMAT),##args) +#else +#define PRINTF_CFS(...) +#endif #include "cfs/cfs.h" #include "cfs/cfs-coffee.h" @@ -79,6 +86,8 @@ coffee_file_test(void) cfs_remove("T1"); cfs_remove("T2"); cfs_remove("T3"); + cfs_remove("T4"); + cfs_remove("T5"); wfd = rfd = afd = -1; @@ -124,14 +133,14 @@ coffee_file_test(void) if(r < 0) { FAIL(-8); } else if(r < sizeof(buf)) { - printf("r=%d\n", r); + PRINTF_CFS("r=%d\n", r); FAIL(-9); } /* Test 8: Verify that the buffer is correct. */ for(r = 0; r < sizeof(buf); r++) { if(buf[r] != r) { - printf("r=%d. buf[r]=%d\n", r, buf[r]); + PRINTF_CFS("r=%d. buf[r]=%d\n", r, buf[r]); FAIL(-10); } } @@ -190,7 +199,7 @@ coffee_file_test(void) if(r < 0) { FAIL(-21); } else if(r < sizeof(buf)) { - printf("r = %d\n", r); + PRINTF_CFS("r = %d\n", r); FAIL(-22); } @@ -240,31 +249,30 @@ coffee_file_test(void) for(i = 0; i < sizeof(buf); i++) { if(buf[i] != i) { - printf("buf[%d] != %d\n", i, buf[i]); + PRINTF_CFS("buf[%d] != %d\n", i, buf[i]); FAIL(-30); } } } - /* Test 17: Append data to the same file many times. */ -#define APPEND_BYTES 1000 +#define APPEND_BYTES 3000 #define BULK_SIZE 10 - for(i = 0; i < APPEND_BYTES; i += BULK_SIZE) { - afd = cfs_open("T3", CFS_WRITE | CFS_APPEND); - if(afd < 0) { - FAIL(-31); - } - for(j = 0; j < BULK_SIZE; j++) { - buf[j] = 1 + ((i + j) & 0x7f); - } - if((r = cfs_write(afd, buf, BULK_SIZE)) != BULK_SIZE) { - printf("r=%d\n", r); - FAIL(-32); - } - cfs_close(afd); - } + for (i = 0; i < APPEND_BYTES; i += BULK_SIZE) { + afd = cfs_open("T3", CFS_WRITE | CFS_APPEND); + if (afd < 0) { + FAIL(-31); + } + for (j = 0; j < BULK_SIZE; j++) { + buf[j] = 1 + ((i + j) & 0x7f); + } + if ((r = cfs_write(afd, buf, BULK_SIZE)) != BULK_SIZE) { + PRINTF_CFS("Count:%d, r=%d\n", i, r); + FAIL(-32); + } + cfs_close(afd); + } - /* Test 18: Read back the data written in Test 17 and verify that it + /* Test 18: Read back the data written in Test 17 and verify that it is correct. */ afd = cfs_open("T3", CFS_READ); if(afd < 0) { @@ -280,13 +288,105 @@ coffee_file_test(void) total_read += r; } if(r < 0) { + PRINTF_CFS("FAIL:-35 r=%d\n",r); FAIL(-35); } if(total_read != APPEND_BYTES) { + PRINTF_CFS("FAIL:-35 total_read=%d\n",total_read); FAIL(-35); } cfs_close(afd); +/***************T4********************/ +/* file T4 and T5 writing forces to use garbage collector in greedy mode + * this test is designed for 10kb of file system + * */ +#define APPEND_BYTES_1 2000 +#define BULK_SIZE_1 10 + for (i = 0; i < APPEND_BYTES_1; i += BULK_SIZE_1) { + afd = cfs_open("T4", CFS_WRITE | CFS_APPEND); + if (afd < 0) { + FAIL(-36); + } + for (j = 0; j < BULK_SIZE_1; j++) { + buf[j] = 1 + ((i + j) & 0x7f); + } + + + if ((r = cfs_write(afd, buf, BULK_SIZE_1)) != BULK_SIZE_1) { + PRINTF_CFS("Count:%d, r=%d\n", i, r); + FAIL(-37); + } + cfs_close(afd); + } + + afd = cfs_open("T4", CFS_READ); + if(afd < 0) { + FAIL(-38); + } + total_read = 0; + while((r = cfs_read(afd, buf2, sizeof(buf2))) > 0) { + for(j = 0; j < r; j++) { + if(buf2[j] != 1 + ((total_read + j) & 0x7f)) { + PRINTF_CFS("FAIL:-39, total_read=%d r=%d\n",total_read,r); + FAIL(-39); + } + } + total_read += r; + } + if(r < 0) { + PRINTF_CFS("FAIL:-40 r=%d\n",r); + FAIL(-40); + } + if(total_read != APPEND_BYTES_1) { + PRINTF_CFS("FAIL:-41 total_read=%d\n",total_read); + FAIL(-41); + } + cfs_close(afd); + /***************T5********************/ +#define APPEND_BYTES_2 1000 +#define BULK_SIZE_2 10 + for (i = 0; i < APPEND_BYTES_2; i += BULK_SIZE_2) { + afd = cfs_open("T5", CFS_WRITE | CFS_APPEND); + if (afd < 0) { + FAIL(-42); + } + for (j = 0; j < BULK_SIZE_2; j++) { + buf[j] = 1 + ((i + j) & 0x7f); + } + + if ((r = cfs_write(afd, buf, BULK_SIZE_2)) != BULK_SIZE_2) { + PRINTF_CFS("Count:%d, r=%d\n", i, r); + FAIL(-43); + } + + cfs_close(afd); + } + + afd = cfs_open("T5", CFS_READ); + if(afd < 0) { + FAIL(-44); + } + total_read = 0; + while((r = cfs_read(afd, buf2, sizeof(buf2))) > 0) { + for(j = 0; j < r; j++) { + if(buf2[j] != 1 + ((total_read + j) & 0x7f)) { + PRINTF_CFS("FAIL:-45, total_read=%d r=%d\n",total_read,r); + FAIL(-45); + } + } + total_read += r; + } + if(r < 0) { + PRINTF_CFS("FAIL:-46 r=%d\n",r); + FAIL(-46); + } + if(total_read != APPEND_BYTES_2) { + PRINTF_CFS("FAIL:-47 total_read=%d\n",total_read); + FAIL(-47); + } + cfs_close(afd); + error = 0; end: cfs_close(wfd); cfs_close(rfd); cfs_close(afd); @@ -380,13 +480,38 @@ avr_flash_read(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE siz This is done by calling the write routine with a null buffer and any address within each page of the sector (we choose the first byte). */ -void -avr_flash_erase(coffee_page_t sector) -{ - coffee_page_t i; - for (i=0;i>1; //Show progmem word address for debug @@ -487,7 +613,7 @@ avr_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE si } #endif - /* If buf not null, modfy the page(s) */ + /* If buf not null, modify the page(s) */ if (buf) { if (size==0) return; //nothing to write /*Copy the first part of the existing page into the write buffer */