From: Charles Manning Date: Wed, 21 Dec 2011 03:41:57 +0000 (+1300) Subject: yaffs large file support: Add more tests X-Git-Tag: pre-driver-refactoring~34^2~2 X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=commitdiff_plain;h=236044674b17ac4455b44cb4bdb0ea99107d9a99 yaffs large file support: Add more tests Signed-off-by: Charles Manning --- diff --git a/linux-tests/Makefile b/linux-tests/Makefile index 1f1d56e..5266481 100644 --- a/linux-tests/Makefile +++ b/linux-tests/Makefile @@ -1,6 +1,6 @@ CFLAGS += -Wall -D_FILE_OFFSET_BITS=64 -TARGETS = xattrtest writebigsparse +TARGETS = xattrtest writebigsparse verifybigsparse all: $(TARGETS) xattrtest: xattrtest.c @@ -8,6 +8,9 @@ xattrtest: xattrtest.c writebigsparse: writebigsparse.c gcc $(CFLAGS) -o $@ $< + +verifybigsparse: verifybigsparse.c + gcc $(CFLAGS) -o $@ $< .PHONEY: clean diff --git a/linux-tests/verifybigsparse.c b/linux-tests/verifybigsparse.c new file mode 100644 index 0000000..84ff53b --- /dev/null +++ b/linux-tests/verifybigsparse.c @@ -0,0 +1,110 @@ +#define _LARGEFILE64_SOURCE +#include +#include +#include +#include +#include +#include +#include + + +#define N_WRITES 2000 +#define STRIDE 2000 + +#define BUFFER_N 1100 +unsigned xxbuffer[BUFFER_N]; + + +void set_buffer(int n) +{ + int i; + for(i = 0; i < BUFFER_N; i++) + xxbuffer[i] = i + n; +} + + +void verify_big_sparse_file(int h) +{ + unsigned check_buffer[BUFFER_N]; + int i; + loff_t offset = 0; + loff_t pos; + int n = sizeof(check_buffer); + int result; + const char * check_type; + int checks_failed = 0; + int checks_passed = 0; + + for(i = 0; i < N_WRITES * STRIDE; i++) { + if(i % STRIDE) { + check_type = "zero"; + memset(xxbuffer,0, n); + } else { + check_type = "buffer"; + set_buffer(i/STRIDE); + } + printf("%s checking %lld\n", check_type, offset); + pos = lseek64(h, offset, SEEK_SET); + if(pos != offset) { + printf("mismatched seek pos %lld offset %lld\n", + pos, offset); + perror("lseek64"); + exit(1); + } + result = read(h, check_buffer, n); + + if(result != n) { + printf("mismatched read result %d n %d\n", result, n); + exit(1); + } + + + + + if(memcmp(xxbuffer, check_buffer, n)) { + int j; + + printf("buffer at %lld mismatches\n", pos); + printf("xxbuffer "); + for(j = 0; j < 20; j++) + printf(" %d",xxbuffer[j]); + printf("\n"); + printf("check_buffer "); + for(j = 0; j < 20; j++) + printf(" %d",check_buffer[j]); + printf("\n"); + + checks_failed++; + } else { + checks_passed++; + } + + offset += sizeof(xxbuffer); + } + + printf("%d checks passed, %d checks failed\n", checks_passed, checks_failed); + +} + + +int main(int argc, char *argv[]) +{ + int handle; + + if(argc < 2) { + printf("Gimme a file name!\n"); + exit(1); + } + + handle = open(argv[1], O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE); + + if(handle < 0) { + perror("opening file"); + exit(1); + } + + verify_big_sparse_file(handle); + + printf("Job done\n"); + return 0; +} diff --git a/linux-tests/writebigsparse.c b/linux-tests/writebigsparse.c index fab2d16..9f95d24 100644 --- a/linux-tests/writebigsparse.c +++ b/linux-tests/writebigsparse.c @@ -6,31 +6,31 @@ #include #include -int handle; -#define N_WRITES 8000 -#define STRIDE 1000 +#define N_WRITES 2000 +#define STRIDE 2000 -#define BUFFER_N 2000 -unsigned buffer[BUFFER_N]; +#define BUFFER_N 1100 +unsigned xxbuffer[BUFFER_N]; void set_buffer(int n) { int i; for(i = 0; i < BUFFER_N; i++) - buffer[i] = i + n; + xxbuffer[i] = i + n; } void write_big_sparse_file(int h) { int i; - off64_t offset = 0; - off64_t pos; - int n = sizeof(buffer); + loff_t offset = 0; + loff_t pos; + int n = sizeof(xxbuffer); int wrote; - - for(i = 0; i < 4000; i++) { + + for(i = 0; i < N_WRITES; i++) { + printf("writing at %lld\n", offset); set_buffer(i); pos = lseek64(h, offset, SEEK_SET); if(pos != offset) { @@ -39,43 +39,39 @@ void write_big_sparse_file(int h) perror("lseek64"); exit(1); } - wrote = write(h, buffer, n); - + wrote = write(h, xxbuffer, n); + if(wrote != n) { printf("mismatched write wrote %d n %d\n", wrote, n); exit(1); } - - offset += (STRIDE * sizeof(buffer)); - } -} - + offset += (STRIDE * sizeof(xxbuffer)); + } + ftruncate(h, offset); -void verify_big_sparse_file(int h) -{ } + int main(int argc, char *argv[]) { + int handle; if(argc < 2) { printf("Gimme a file name!\n"); exit(1); } - + handle = open(argv[1], O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE); - + if(handle < 0) { perror("opening file"); exit(1); } - + write_big_sparse_file(handle); - system("sudo echo 3 > /proc/sys/vm/drop_caches"); - verify_big_sparse_file(handle); - + printf("Job done\n"); return 0; }