From: Timothy Manning Date: Thu, 6 Jan 2011 22:43:00 +0000 (+1300) Subject: yaffs Added another test to direct/timothy_tests/threading X-Git-Tag: linux-mainline-patchset-4~3^2~4 X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=commitdiff_plain;h=5f61aa469fb4b46a5a1f4aacbe459323b5d13edd yaffs Added another test to direct/timothy_tests/threading Signed-off-by: Timothy Manning --- diff --git a/direct/timothy_tests/linux_tests/mkdir_link b/direct/timothy_tests/linux_tests/mkdir_link new file mode 100755 index 0000000..7f92f37 Binary files /dev/null and b/direct/timothy_tests/linux_tests/mkdir_link differ diff --git a/direct/timothy_tests/linux_tests/mkdir_link.c b/direct/timothy_tests/linux_tests/mkdir_link.c new file mode 100644 index 0000000..d466958 --- /dev/null +++ b/direct/timothy_tests/linux_tests/mkdir_link.c @@ -0,0 +1,18 @@ +#include +#include + + +int main() +{ + int output=0; + int error_code =0 ; + output =symlink("timothy/home/tests/new_dir" "timothy/home/test/new_dir_link"); + output=mkdir("timothy/home/test/new_dir_link" ); + printf("output %d\n",output); + if (output <0 ) { + error_code = errno; + printf("error code %d\n",error_code); + printf("Error description is : %s\n",strerror(errno)); + } + return 0; +} diff --git a/direct/timothy_tests/linux_tests/mkdir_link.h b/direct/timothy_tests/linux_tests/mkdir_link.h new file mode 100644 index 0000000..e69de29 diff --git a/direct/timothy_tests/linux_tests/rename b/direct/timothy_tests/linux_tests/rename new file mode 100755 index 0000000..a168978 Binary files /dev/null and b/direct/timothy_tests/linux_tests/rename differ diff --git a/direct/timothy_tests/linux_tests/rename.c b/direct/timothy_tests/linux_tests/rename.c new file mode 100644 index 0000000..9c40c2f --- /dev/null +++ b/direct/timothy_tests/linux_tests/rename.c @@ -0,0 +1,17 @@ +#include +#include + + +int main() +{ + int output=0; + int error_code =0 ; + output=rename( "/home/timothy/test/cat/","/home/timothy/test/dog/"); + printf("output %d\n",output); + if (output <0 ) { + error_code = errno; + printf("error code %d\n",error_code); + printf("Error description is : %s\n",strerror(errno)); + } + return 0; +} diff --git a/direct/timothy_tests/linux_tests/rename.h b/direct/timothy_tests/linux_tests/rename.h new file mode 100644 index 0000000..e69de29 diff --git a/direct/timothy_tests/threading/Makefile b/direct/timothy_tests/threading/Makefile new file mode 100644 index 0000000..8006b79 --- /dev/null +++ b/direct/timothy_tests/threading/Makefile @@ -0,0 +1,115 @@ +# Makefile for YAFFS direct stress tests +# +# +# YAFFS: Yet another Flash File System. A NAND-flash specific file system. +# +# Copyright (C) 2003-2010 Aleph One Ltd. +# +# +# Created by Charles Manning +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# NB Warning this Makefile does not include header dependencies. +# +# $Id: Makefile,v 1.7 2010-02-25 22:34:47 charles Exp $ + +#EXTRA_COMPILE_FLAGS = -DYAFFS_IGNORE_TAGS_ECC + +CFLAGS = -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_YAFFS2 +CFLAGS += -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES +CFLAGS += -Wall -g $(EXTRA_COMPILE_FLAGS) -Wstrict-aliasing +#CFLAGS += -fno-strict-aliasing +CFLAGS += -O0 +CFLAGS += -Wextra -Wpointer-arith +#CFLAGS += -DCONFIG_YAFFS_VALGRIND_TEST + +#CFLAGS+= -Wshadow -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-declarations +#CFLAGS+= -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline + + +COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o yaffs_hweight.o \ + yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \ + yaffs_packedtags1.o yaffs_ramdisk.o yaffs_ramem2k.o \ + yaffs_tagscompat.o yaffs_packedtags2.o yaffs_tagsvalidity.o yaffs_nand.o \ + yaffs_checkptrw.o yaffs_qsort.o\ + yaffs_nameval.o yaffs_attribs.o \ + yaffs_norif1.o ynorsim.o \ + yaffs_allocator.o \ + yaffs_bitmap.o \ + yaffs_yaffs1.o \ + yaffs_yaffs2.o \ + yaffs_verify.o \ + yaffs_error.o + +# yaffs_checkptrwtest.o\ + +TESTFILES = threading.o thread_function.o \ + test_a.o test_b.o lib.o + + + +YAFFSTESTOBJS = $(COMMONTESTOBJS) $(TESTFILES) + +ALLOBJS = $(sort $(YAFFSTESTOBJS)) + +YAFFSSYMLINKS = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscompat.c yaffs_tagscompat.h \ + yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h \ + yaffs_nand.c yaffs_nand.h yaffs_getblockinfo.h \ + yaffs_tagsvalidity.c yaffs_tagsvalidity.h yaffs_checkptrw.h yaffs_checkptrw.c \ + yaffs_nameval.c yaffs_nameval.h \ + yaffs_trace.h yaffs_attribs.h \ + yaffs_allocator.c yaffs_allocator.h \ + yaffs_yaffs1.c yaffs_yaffs1.h \ + yaffs_yaffs2.c yaffs_yaffs2.h \ + yaffs_bitmap.c yaffs_bitmap.h \ + yaffs_verify.c yaffs_verify.h + +YAFFSDIRECTSYMLINKS = yaffsfs.c yaffs_flashif.h yaffs_flashif2.h\ + yaffsfs.h ydirectenv.h \ + yaffs_flashif.c yaffscfg.h yaffs_qsort.c \ + yaffs_nandemul2k.h yaffs_list.h \ + yaffs_attribs.c yaffs_osglue.h \ + yaffs_nandif.c yaffs_nandif.h yportenv.h \ + yaffs_hweight.h yaffs_hweight.c \ + yaffs_error.c + + +DIRECTEXTRASYMLINKS = yaffscfg2k.c yaffs_fileem2k.c yaffs_fileem2k.h\ + yaffs_fileem.c yaffs_norif1.c yaffs_norif1.h \ + yaffs_ramdisk.c yaffs_ramdisk.h yaffs_ramem2k.c \ + ynorsim.h ynorsim.c yaffs_osglue.c + +SYMLINKS = $(YAFFSSYMLINKS) $(YAFFSDIRECTSYMLINKS) $(DIRECTEXTRASYMLINKS) $(PYTONOSYMLINKS) +#all: directtest2k boottest + +all: threading + +$(ALLOBJS): %.o: %.c + gcc -c $(CFLAGS) -o $@ $< + +$(PYTONOSYMLINKS): + ln -s ../../python/$@ $@ + +$(YAFFSSYMLINKS): + ln -s ../../../$@ $@ + +$(YAFFSDIRECTSYMLINKS): + ln -s ../../$@ $@ + +$(DIRECTEXTRASYMLINKS): + ln -s ../../basic-test/$@ $@ + + +threading: $(SYMLINKS) $(ALLOBJS) + gcc $(CFLLAG) -o $@ $(ALLOBJS) -lpthread + + + + + + +clean: + rm -f threading $(ALLOBJS) core $(SYMLINKS) diff --git a/direct/timothy_tests/threading/lib.c b/direct/timothy_tests/threading/lib.c new file mode 100644 index 0000000..6456958 --- /dev/null +++ b/direct/timothy_tests/threading/lib.c @@ -0,0 +1,42 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Timothy Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include "lib.h" +static unsigned int *p_counter; +static unsigned int numberOfThreads=5; + +unsigned int get_num_of_threads(void) +{ + return numberOfThreads; +} + +void number_of_threads(unsigned int num) +{ + numberOfThreads=num; +} + +int get_counter(int x) +{ + return p_counter[x]; +} + +void set_counter(int x, unsigned int value) +{ + p_counter[x]=value; +} + +void init_counter(unsigned int size_of_counter) +{ + p_counter=malloc(size_of_counter*sizeof(int)); +} + diff --git a/direct/timothy_tests/threading/lib.h b/direct/timothy_tests/threading/lib.h new file mode 100644 index 0000000..f635294 --- /dev/null +++ b/direct/timothy_tests/threading/lib.h @@ -0,0 +1,38 @@ +/* + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Timothy Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation. + * + * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. + */ + +#ifndef __lib_h__ +#define __lib_h__ + +#define BOVVER_HANDLES 10 +#include "yaffsfs.h" +struct bovver_context { + int bovverType; + int threadId; + char baseDir[200]; + int h[BOVVER_HANDLES]; + yaffs_DIR *dirH; + int opMax; + int op; + int cycle; +}; + +int get_counter(int x); +void set_counter(int x, unsigned int value); +void init_counter(unsigned int size_of_counter); +void number_of_threads(unsigned int num); +unsigned int get_num_of_threads(void); + +#endif diff --git a/direct/timothy_tests/threading/test_a.c b/direct/timothy_tests/threading/test_a.c new file mode 100644 index 0000000..391530c --- /dev/null +++ b/direct/timothy_tests/threading/test_a.c @@ -0,0 +1,99 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Timothy Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include "test_a.h" + + + + + +void test_a(void *x) +{ + struct bovver_context *bc = (struct bovver_context *)x; + + int i; + int op; + int pos; + int n; + int n1; + + char name[200]; + char name1[200]; + + int start_op; + + + i = rand() % BOVVER_HANDLES; + op = rand() % bc->opMax; + pos = rand() & 20000000; + n = rand() % 100; + n1 = rand() % 100; + + start_op = op; + + sprintf(name, "%s/xx%d",bc->baseDir,n); + sprintf(name1,"%s/xx%d",bc->baseDir,n1); + + bc->op = op; + bc->cycle++; + + op-=1; + if(op < 0){ + if(bc->h[i]>= 0){ + yaffs_close(bc->h[i]); + bc->h[i] = -1; + } + return; + } + + op-=1; + if(op < 0){ + if(bc->h[i] < 0) + bc->h[i] = yaffs_open(name,O_CREAT| O_RDWR, 0666); + return; + } + + op-=5; + if(op< 0){ + yaffs_lseek(bc->h[i],pos,SEEK_SET); + yaffs_write(bc->h[i],name,n); + return; + } + + op-=1; + if(op < 0){ + yaffs_unlink(name); + return; + } + op-=1; + if(op < 0){ + yaffs_rename(name,name1); + return; + } + op-=1; + if(op < 0){ + yaffs_mkdir(name,0666); + return; + } + op-=1; + if(op < 0){ + yaffs_rmdir(name); + return; + } + + bc->opMax = (start_op - op -1); + + return; + +} + diff --git a/direct/timothy_tests/threading/test_a.h b/direct/timothy_tests/threading/test_a.h new file mode 100644 index 0000000..87cb3df --- /dev/null +++ b/direct/timothy_tests/threading/test_a.h @@ -0,0 +1,22 @@ +/* + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Timothy Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation. + * + * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. + */ + +#ifndef __test_a_h__ +#define __test_a_h__ + +#include "yaffsfs.h" +#include "lib.h" +void test_a(void *x); +#endif diff --git a/direct/timothy_tests/threading/test_b.c b/direct/timothy_tests/threading/test_b.c new file mode 100644 index 0000000..0476113 --- /dev/null +++ b/direct/timothy_tests/threading/test_b.c @@ -0,0 +1,39 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Timothy Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include "test_b.h" + +void test_b(void *x) +{ + struct bovver_context *bc = (struct bovver_context *)x; + int n = rand() % 20; + + bc->cycle++; + + if(!bc->dirH) + bc->dirH = yaffs_opendir(bc->baseDir); + + if(!bc->dirH) + return; + + if(n == 0){ + yaffs_closedir(bc->dirH); + bc->dirH = NULL; + } else { + while(n > 1){ + n--; + yaffs_readdir(bc->dirH); + } + } +} + diff --git a/direct/timothy_tests/threading/test_b.h b/direct/timothy_tests/threading/test_b.h new file mode 100644 index 0000000..c242a93 --- /dev/null +++ b/direct/timothy_tests/threading/test_b.h @@ -0,0 +1,21 @@ +/* + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Timothy Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation. + * + * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. + */ + +#ifndef __test_b_h__ +#define __test_b_h__ +#include "yaffsfs.h" +#include "lib.h" +void test_b(void *x); +#endif diff --git a/direct/timothy_tests/threading/thread_function.c b/direct/timothy_tests/threading/thread_function.c new file mode 100644 index 0000000..52b78d0 --- /dev/null +++ b/direct/timothy_tests/threading/thread_function.c @@ -0,0 +1,70 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Timothy Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include "thread_function.h" + + + +int number_of_tests=2; + + +void * init(int threadId, const char *baseDir, int bovver_type) +{ + struct bovver_context *bc = malloc(sizeof(struct bovver_context)); + + if(bc){ + memset(bc,0,sizeof(*bc)); + bc->threadId = threadId; + strncpy(bc->baseDir,baseDir,200); + bc->bovverType = bovver_type; + bc->opMax = 99; + printf("bovver_init %d \"%s\"\n",threadId,baseDir); + } + return (void *)bc; +} + + +typedef struct test { + void (*p_function)(void *); /*pointer to test function*/ + /*char pass_message[50]; will not need a pass message*/ + char *name_of_test; /*pointer to fail message, needs to include name of test*/ +}test_template; + + +test_template test_list[]={ + //{dummy_test,dummy_test_clean,"dummy_test"}, + {test_a, "test_a"}, + {test_b, "test_b"} +}; + +int thread_function(void *thread_id_ptr) +{ + int thread_id = (int) thread_id_ptr; + int test_id=0; + unsigned int y=0; + printf("Starting thread %d, id %d\n", pthread_self(),thread_id); + void *x=init(thread_id,"/yaffs2/",0); + while(1){ + y++; + //set_counter(thread_id,y); + test_id=(rand()%(number_of_tests-1)); + test_list[test_id].p_function(x); + //printf("thread: %d. ran test: %d\n",thread_id,y); + //printf("counter before %d\n",get_counter(thread_id)); + set_counter(thread_id,y); + //printf("counter after setting %d\n",get_counter(thread_id)); + } + //select random file name from a list. + //run a random function on the file. + return 1; +} diff --git a/direct/timothy_tests/threading/thread_function.h b/direct/timothy_tests/threading/thread_function.h new file mode 100644 index 0000000..106793f --- /dev/null +++ b/direct/timothy_tests/threading/thread_function.h @@ -0,0 +1,28 @@ +/* + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Timothy Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation. + * + * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. + */ + +#ifndef __thread_function_h__ +#define __thread_function_h__ + + +#include +#include + +#include "test_a.h" +#include "test_b.h" +#include "lib.h" +int thread_function(void * thread_id); +void * init(int threadId, const char *baseDir, int bovver_type); +#endif diff --git a/direct/timothy_tests/threading/threading.c b/direct/timothy_tests/threading/threading.c new file mode 100644 index 0000000..a9ed1bb --- /dev/null +++ b/direct/timothy_tests/threading/threading.c @@ -0,0 +1,81 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Timothy Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include "threading.h" + +int random_seed; +int simulate_power_failure = 0; + +const struct option long_options[]={ + {"help", 0,NULL,'h'}, + {"threads", 1,NULL,'t'} +}; + +const char short_options[]="hqn:t:cv"; + + + + +void main_init(int argc, char *argv[]) +{ + int new_option; + int x=0; + int new_num_of_threads=5; + do{ + new_option=getopt_long(argc,argv,short_options,long_options,NULL); + if (0==strcmp(argv[x],"-h")){ + printf("help\n"); + printf("-h will print the commands available\n"); + printf("-c will continue after a test failes else the program will exit\n"); + printf("-v will print all messages\n"); + printf("-q quiet mode only the number of tests passed and failed will be printed\n"); + printf("-t [number] set yaffs_trace to number\n"); + printf("-n [number] sets the number of random loops to run after the the test has run\n"); + exit(0); + } else if (new_option=='t') { + new_num_of_threads=atoi(optarg); + } + }while (new_option!=-1); + number_of_threads(new_num_of_threads); + init_counter(new_num_of_threads); + +} + +int main(int argc, char *argv[]) +{ + main_init(argc,argv); + pthread_t threads[get_num_of_threads()]; + unsigned int x=0; + int output=0; + int y=0; + + for (x=0;x0){ + printf("failed to create thread %d. Error is %d\n",x,output); + } + + } + while (1){ + y=0; + printf("thread counter: %d ",get_counter(y)); + for (y=1;y + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation. + * + * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. + */ + +#ifndef __threading_h__ +#define __threading_h__ + +#include +#include +#include "thread_function.h" +#include "lib.h" +#include +#endif