From cfd52c886b1d8266517b73b059bedf40acabb3e9 Mon Sep 17 00:00:00 2001 From: kim jin hong Date: Fri, 28 Jul 2017 18:45:39 +0900 Subject: [PATCH] filesystem : add test application add : procfs_test.c : procfs test application ramfs_test.c : ramfs test application romfs_test.c : romfs test application write_remove_test.c : smartfs test application Change-Id: Ic729e154335245368cb5030836cb861a3e6a03bd Signed-off-by: kim jin hong --- apps/examples/fs_helper/Kconfig | 52 ++++++ apps/examples/fs_helper/Make.defs | 21 +++ apps/examples/fs_helper/Makefile | 187 +++++++++++++++++++++ apps/examples/fs_helper/procfs_test.c | 156 +++++++++++++++++ apps/examples/fs_helper/ramfs_test.c | 201 ++++++++++++++++++++++ apps/examples/fs_helper/romfs_test.c | 249 ++++++++++++++++++++++++++++ apps/examples/fs_helper/write_remove_test.c | 171 +++++++++++++++++++ 7 files changed, 1037 insertions(+) create mode 100644 apps/examples/fs_helper/Kconfig create mode 100644 apps/examples/fs_helper/Make.defs create mode 100644 apps/examples/fs_helper/Makefile create mode 100644 apps/examples/fs_helper/procfs_test.c create mode 100644 apps/examples/fs_helper/ramfs_test.c create mode 100644 apps/examples/fs_helper/romfs_test.c create mode 100644 apps/examples/fs_helper/write_remove_test.c diff --git a/apps/examples/fs_helper/Kconfig b/apps/examples/fs_helper/Kconfig new file mode 100644 index 0000000..a8d4196 --- /dev/null +++ b/apps/examples/fs_helper/Kconfig @@ -0,0 +1,52 @@ +# +# For a description of the syntax of this configuration file, +# see kconfig-language at https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt +# + +menu "filesystem helper application" + +config FILESYSTEM_HELPER_ENABLE + bool "enable filesystem helper application" + default n + ---help--- + enable filesystem helper application + +if FILESYSTEM_HELPER_ENABLE + +config WRITE_REMOVE_TEST + bool "repeat write & remove test" + default n + ---help--- + Enable "rw_test" application + +config ROMFS_TEST + bool "romfs test" + default n + select FS_ROMFS + ---help--- + Enable "romfs_test" application + +config RAMFS_TEST + bool "ramfs test" + default n + select RAMMTD + ---help--- + Enable "ramfs_test" application + +if RAMFS_TEST + +config RAMFS_TEST_RAMFS_NEBLOCKS + int "nblocks of ramfs test" + default 32 + +endif #RAMFS_TEST + +config PROCFS_TEST + bool "procfs test" + default n + ---help--- + Enable "procfs_test" application + +endif #FILESYSTEM_HELPER_ENABLE + +endmenu diff --git a/apps/examples/fs_helper/Make.defs b/apps/examples/fs_helper/Make.defs new file mode 100644 index 0000000..a5dea29 --- /dev/null +++ b/apps/examples/fs_helper/Make.defs @@ -0,0 +1,21 @@ +########################################################################### +# +# Copyright 2017 Samsung Electronics All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the License. +# +########################################################################### + +ifeq ($(CONFIG_FILESYSTEM_HELPER_ENABLE),y) +CONFIGURED_APPS += examples/fs_helper +endif diff --git a/apps/examples/fs_helper/Makefile b/apps/examples/fs_helper/Makefile new file mode 100644 index 0000000..936a5ed --- /dev/null +++ b/apps/examples/fs_helper/Makefile @@ -0,0 +1,187 @@ +########################################################################### +# +# Copyright 2017 Samsung Electronics All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the License. +# +########################################################################### +############################################################################ +# apps/examples/fs_helper/Makefile +# +# Copyright (C) 2008, 2010-2013 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +THREADEXEC = TASH_EXECMD_ASYNC + +ASRCS = +CSRCS = + +ifeq ($(CONFIG_WRITE_REMOVE_TEST),y) +CSRCS += write_remove_test.c +endif + +ifeq ($(CONFIG_ROMFS_TEST),y) +CSRCS += romfs_test.c +endif + +ifeq ($(CONFIG_RAMFS_TEST),y) +CSRCS += ramfs_test.c +endif + +ifeq ($(CONFIG_PROCFS_TEST),y) +CSRCS += procfs_test.c +endif + + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) +MAINOBJ = $(MAINSRC:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) $(MAINSRC) +OBJS = $(AOBJS) $(COBJS) + +ifneq ($(CONFIG_BUILD_KERNEL),y) + OBJS += $(MAINOBJ) +endif + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\libapps$(LIBEXT) +else + BIN = ../../libapps$(LIBEXT) +endif +endif + +ifeq ($(WINTOOL),y) + INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}" +else + INSTALL_DIR = $(BIN_DIR) +endif + +CONFIG_EXAMPLES_FS_HELPER_PROGNAME ?= romfs_test(EXEEXT) +PROGNAME = $(CONFIG_EXAMPLES_FS_HELPEFS_HELPERGNAME) + +ROOTDEPPATH = --dep-path . + +# Common build + +VPATH = + +all: .built +.PHONY: clean depend distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + @touch .built + +ifeq ($(CONFIG_BUILD_KERNEL),y) +$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ) + @echo "LD: $(PROGNAME)" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS) + $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME) + +install: $(BIN_DIR)$(DELIM)$(PROGNAME) + +else +install: + +endif + +ifeq ($(CONFIG_BUILTIN_APPS)$(CONFIG_FILESYSTEM_HELPER_ENABLE),yy) + +ifeq ($(CONFIG_WRITE_REMOVE_TEST),y) +$(BUILTIN_REGISTRY)$(DELIM)write_remove_test_main.bdat: $(DEPCONFIG) Makefile + $(Q) $(call REGISTER,write_remove,write_remove_test_main,$(THREADEXEC),$(PRIORITY),$(STACKSIZE)) +context: $(BUILTIN_REGISTRY)$(DELIM)write_remove_test_main.bdat +endif + +ifeq ($(CONFIG_ROMFS_TEST),y) +$(BUILTIN_REGISTRY)$(DELIM)romfs_test_main.bdat: $(DEPCONFIG) Makefile + $(Q) $(call REGISTER,romfs_test,romfs_test_main,$(THREADEXEC),$(PRIORITY),$(STACKSIZE)) +context: $(BUILTIN_REGISTRY)$(DELIM)romfs_test_main.bdat +endif + +ifeq ($(CONFIG_RAMFS_TEST),y) +$(BUILTIN_REGISTRY)$(DELIM)ramfs_test_main.bdat: $(DEPCONFIG) Makefile + $(Q) $(call REGISTER,ramfs_test,ramfs_test_main,$(THREADEXEC),$(PRIORITY),$(STACKSIZE)) +context: $(BUILTIN_REGISTRY)$(DELIM)ramfs_test_main.bdat +endif + +ifeq ($(CONFIG_PROCFS_TEST),y) +$(BUILTIN_REGISTRY)$(DELIM)procfs_test_main.bdat: $(DEPCONFIG) Makefile + $(Q) $(call REGISTER,procfs_test,procfs_test_main,$(THREADEXEC),$(PRIORITY),$(STACKSIZE)) +context: $(BUILTIN_REGISTRY)$(DELIM)procfs_test_main.bdat +endif + +else +context: + +endif + +.depend: Makefile $(SRCS) + @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + @touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep +.PHONY: preconfig +preconfig: diff --git a/apps/examples/fs_helper/procfs_test.c b/apps/examples/fs_helper/procfs_test.c new file mode 100644 index 0000000..d753aa6 --- /dev/null +++ b/apps/examples/fs_helper/procfs_test.c @@ -0,0 +1,156 @@ +/**************************************************************************** + * + * Copyright 2017 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ +/** + * @file procfs_test.c + * @brief This is test application for proc file system. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +#define BUFFER_SIZE 1024 +/**************************************************************************** + * Private data + ****************************************************************************/ +struct pthread_arg { + int argc; + char **argv; +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ +static int read_file(const char *srcpath) +{ + int nbytesread; + int rdfd; + static char buffer[BUFFER_SIZE]; + + /* Open the source file for reading */ + + rdfd = open(srcpath, O_RDONLY); + if (rdfd < 0) { + printf("ERROR: Failed to open %s for reading: %s\n", srcpath, strerror(errno)); + return -1; + } + + /* read the file */ + + for (;;) { + do { + nbytesread = read(rdfd, buffer, BUFFER_SIZE); + if (nbytesread == 0) { + /* End of file */ + + close(rdfd); + return OK; + } else if (nbytesread < 0) { + /* EINTR is not an error (but will still stop the copy) */ + + printf("ERROR: Read failure: %s\n", strerror(errno)); + return -1; + } + printf("read file string[%s]", buffer); + + } while (nbytesread <= 0); + } + close(rdfd); + return OK; +} + +int procfs_commands(void *args) +{ + char filename[100] = "/proc/0/status"; + int ret; + + ret = read_file(filename); + if (ret < 0) { + printf("procfs error!\n"); + } else { + printf("success procfs test!\n"); + } + if (umount("/proc") < 0) { + printf("umount procfs fail\n"); + return -1; + } + return 0; +} + +/**************************************************************************** + * fs_command_main + ****************************************************************************/ +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int procfs_test_main(int argc, char **argv) +#endif +{ + pthread_t tid; + pthread_attr_t attr; + struct sched_param sparam; + int r; + + struct pthread_arg args; + + args.argc = argc; + args.argv = argv; + + /* Initialize the attribute variable */ + r = pthread_attr_init(&attr); + if (r != 0) { + printf("%s: pthread_attr_init failed, status=%d\n", __func__, r); + } + + /* 1. set a priority */ + sparam.sched_priority = 100; + r = pthread_attr_setschedparam(&attr, &sparam); + if (r != 0) { + printf("%s: pthread_attr_setschedparam failed, status=%d\n", __func__, r); + } + + r = pthread_attr_setschedpolicy(&attr, SCHED_RR); + if (r != 0) { + printf("%s: pthread_attr_setschedpolicy failed, status=%d\n", __func__, r); + } + + /* 2. set a stacksize */ + r = pthread_attr_setstacksize(&attr, 51200); + if (r != 0) { + printf("%s: pthread_attr_setstacksize failed, status=%d\n", __func__, r); + } + + /* 3. create pthread with entry function */ + r = pthread_create(&tid, &attr, (pthread_startroutine_t)procfs_commands, (void *)&args); + if (r != 0) { + printf("%s: pthread_create failed, status=%d\n", __func__, r); + } + + /* Wait for the threads to stop */ + pthread_join(tid, NULL); + + return 0; +} diff --git a/apps/examples/fs_helper/ramfs_test.c b/apps/examples/fs_helper/ramfs_test.c new file mode 100644 index 0000000..c144e64 --- /dev/null +++ b/apps/examples/fs_helper/ramfs_test.c @@ -0,0 +1,201 @@ +/**************************************************************************** + * + * Copyright 2017 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ +/** + * @file ramfs_test.c + * @brief This is test application for ram file system + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include +#include +#include + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +#define BUFFER_SIZE 12 + +// 1. at least, have to set CONFIG_EXAMPLES_RAMFS_NEBLOCKS to 16 for ramfs test +#ifdef CONFIG_RAMFS_TEST +#define EXAMPLES_RAMFS_BUFSIZE \ + (CONFIG_RAMMTD_ERASESIZE * CONFIG_RAMFS_TEST_RAMFS_NEBLOCKS) +#endif + +// 2. If you enable CONFIG_MTD and CONFIG_MTD_SMART, +// ramfs is mounted to /ramfs automatically when boot system. + +/**************************************************************************** + * Private data + ****************************************************************************/ +struct pthread_arg { + int argc; + char **argv; +}; + + +static int read_file(const char *srcpath) +{ + int nbytesread; + int rdfd; + char buffer[BUFFER_SIZE]; + + /* Open the source file for reading */ + + rdfd = open(srcpath, O_RDONLY); + if (rdfd < 0) { + printf("ERROR: Failed to open %s for reading: %s\n", srcpath, strerror(errno)); + return -1; + } + + /* read the file */ + printf("read file string :\n"); + for (;;) { + do { + memset(buffer, 0, BUFFER_SIZE); + nbytesread = read(rdfd, buffer, BUFFER_SIZE); + if (nbytesread == 0) { + /* End of file */ + close(rdfd); + return OK; + } else if (nbytesread < 0) { + /* EINTR is not an error (but will still stop the copy) */ + printf("ERROR: Read failure: %s\n", strerror(errno)); + close(rdfd); + return -1; + } + printf("%s\n", buffer); + } while (nbytesread <= 0); + } + close(rdfd); + return OK; +} + +/**************************************************************************** + * Name: make_file + * + * Description: make file. + * + ****************************************************************************/ + +static int make_file(char *filename) +{ + FILE *fp; + char *in_string = "test string"; + + fp = fopen(filename, "w"); + if (fp == NULL) { + printf("Cannot make file %s\n", filename); + return -1; + } + + if (fwrite(in_string, BUFFER_SIZE, 1, fp) < 0) { + printf("Cannot write file %s\n", filename); + return -1; + } + + if (fclose(fp) != 0) { + printf("Cannot close file %s\n", filename); + return -1; + } + return OK; +} + +int ramfs_commands(void *args) +{ + char filename[100] = "/ramfs/test_file"; + + printf("ramfs size is %d byte\n", EXAMPLES_RAMFS_BUFSIZE); + + if (make_file(filename) < 0) { + printf("ERROR: make file for ramfs %s\n", filename); + fflush(stdout); + goto EXIT_FILE_SYSTEM_TEST_RAMTD; + } + + if (read_file(filename) < 0) { + printf("ERROR: read file for ramfs %s\n", filename); + fflush(stdout); + goto EXIT_FILE_SYSTEM_TEST_RAMTD; + } + + return OK; + +EXIT_FILE_SYSTEM_TEST_RAMTD: + return -1; +} + +/**************************************************************************** + * fs_command_main + ****************************************************************************/ +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int ramfs_test_main(int argc, char **argv) +#endif +{ + pthread_t tid; + pthread_attr_t attr; + struct sched_param sparam; + int r; + + struct pthread_arg args; + + args.argc = argc; + args.argv = argv; + + /* Initialize the attribute variable */ + r = pthread_attr_init(&attr); + if (r != 0) { + printf("%s: pthread_attr_init failed, status=%d\n", __func__, r); + } + + /* 1. set a priority */ + sparam.sched_priority = 100; + r = pthread_attr_setschedparam(&attr, &sparam); + if (r != 0) { + printf("%s: pthread_attr_setschedparam failed, status=%d\n", __func__, r); + } + + r = pthread_attr_setschedpolicy(&attr, SCHED_RR); + if (r != 0) { + printf("%s: pthread_attr_setschedpolicy failed, status=%d\n", __func__, r); + } + + /* 2. set a stacksize */ + r = pthread_attr_setstacksize(&attr, 51200); + if (r != 0) { + printf("%s: pthread_attr_setstacksize failed, status=%d\n", __func__, r); + } + + /* 3. create pthread with entry function */ + r = pthread_create(&tid, &attr, (pthread_startroutine_t) ramfs_commands, (void *)&args); + if (r != 0) { + printf("%s: pthread_create failed, status=%d\n", __func__, r); + } + + /* Wait for the threads to stop */ + pthread_join(tid, NULL); + + return 0; +} diff --git a/apps/examples/fs_helper/romfs_test.c b/apps/examples/fs_helper/romfs_test.c new file mode 100644 index 0000000..ee25f11 --- /dev/null +++ b/apps/examples/fs_helper/romfs_test.c @@ -0,0 +1,249 @@ +/**************************************************************************** + * + * Copyright 2017 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ +/** + * @file romfs_test.c + * @brief This is test application for ram filesystem. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include +#include +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +#define WRITE_DATA_SIZE 1024 +#define BUFFER_SIZE 1024 +/**************************************************************************** + * Private data + ****************************************************************************/ +struct pthread_arg { + int argc; + char **argv; +}; + +static const unsigned char romfs_img[] = { + 0x2d, 0x72, 0x6f, 0x6d, 0x31, 0x66, 0x73, 0x2d, 0x00, 0x00, 0x02, 0x10, + 0xad, 0x5b, 0x65, 0xae, 0x4e, 0x53, 0x48, 0x49, 0x6e, 0x69, 0x74, 0x56, + 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0xd1, 0xff, 0xff, 0x97, + 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x00, 0xd1, 0xd1, 0xff, 0x80, 0x2e, 0x2e, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x68, 0x2d, 0x96, 0x03, 0x69, 0x6e, 0x69, 0x74, 0x2e, 0x64, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0xd1, 0xd1, 0xff, 0x40, + 0x2e, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x60, + 0x00, 0x00, 0x00, 0x00, 0xd1, 0xff, 0xfe, 0xe0, 0x2e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x29, + 0x8d, 0x9c, 0xab, 0xcd, 0x72, 0x63, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x63, 0x68, 0x6f, + 0x20, 0x22, 0x56, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6c, 0x65, 0x20, + 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x20, 0x4e, 0x6f, 0x64, 0x65, 0x20, + 0x56, 0x31, 0x2e, 0x32, 0x2c, 0x20, 0x77, 0x77, 0x77, 0x2e, 0x6e, 0x65, + 0x74, 0x43, 0x6c, 0x61, 0x6d, 0x70, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x22, + 0x0a, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x20, 0x61, + 0x20, 0x52, 0x41, 0x4d, 0x44, 0x49, 0x53, 0x4b, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x69, 0x74, 0x20, 0x61, 0x74, + 0x20, 0x2f, 0x74, 0x6d, 0x70, 0x0a, 0x23, 0x6d, 0x6b, 0x72, 0x64, 0x20, + 0x2d, 0x6d, 0x20, 0x31, 0x20, 0x2d, 0x73, 0x20, 0x35, 0x31, 0x32, 0x20, + 0x34, 0x30, 0x0a, 0x23, 0x6d, 0x6b, 0x66, 0x61, 0x74, 0x66, 0x73, 0x20, + 0x2f, 0x64, 0x65, 0x76, 0x2f, 0x72, 0x61, 0x6d, 0x31, 0x0a, 0x23, 0x6d, + 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x2d, 0x74, 0x20, 0x76, 0x66, 0x61, 0x74, + 0x20, 0x2f, 0x64, 0x65, 0x76, 0x2f, 0x72, 0x61, 0x6d, 0x31, 0x20, 0x2f, + 0x74, 0x6d, 0x70, 0x0a, 0x0a, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x2d, + 0x74, 0x20, 0x62, 0x69, 0x6e, 0x66, 0x73, 0x20, 0x2f, 0x64, 0x65, 0x76, + 0x2f, 0x72, 0x61, 0x6d, 0x30, 0x20, 0x2f, 0x73, 0x62, 0x69, 0x6e, 0x0a, + 0x0a, 0x72, 0x61, 0x6d, 0x74, 0x72, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x61, + 0x72, 0x74, 0x20, 0x33, 0x0a, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x2d, + 0x74, 0x20, 0x76, 0x66, 0x61, 0x74, 0x20, 0x2f, 0x64, 0x65, 0x76, 0x2f, + 0x6d, 0x74, 0x64, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x30, 0x20, 0x2f, 0x75, + 0x73, 0x72, 0x0a, 0x0a, 0x73, 0x64, 0x63, 0x61, 0x72, 0x64, 0x20, 0x73, + 0x74, 0x61, 0x72, 0x74, 0x20, 0x30, 0x0a, 0x6d, 0x6f, 0x75, 0x6e, 0x74, + 0x20, 0x2d, 0x74, 0x20, 0x76, 0x66, 0x61, 0x74, 0x20, 0x2f, 0x64, 0x65, + 0x76, 0x2f, 0x6d, 0x6d, 0x63, 0x73, 0x64, 0x30, 0x20, 0x2f, 0x73, 0x64, + 0x63, 0x61, 0x72, 0x64, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; + +static int read_file(const char *srcpath) +{ + int nbytesread; + int rdfd; + static char g_buffer[BUFFER_SIZE]; + + /* Open the source file for reading */ + + rdfd = open(srcpath, O_RDONLY); + if (rdfd < 0) { + printf("ERROR: Failed to open %s for reading: %s\n", srcpath, strerror(errno)); + return -1; + } + + /* read the file */ + + for (;;) { + do { + nbytesread = read(rdfd, g_buffer, BUFFER_SIZE); + if (nbytesread == 0) { + /* End of file */ + + close(rdfd); + return OK; + } else if (nbytesread < 0) { + /* EINTR is not an error (but will still stop the copy) */ + + printf("ERROR: Read failure: %s\n", strerror(errno)); + return -1; + } + printf("read file string[%s]", g_buffer); + + } while (nbytesread <= 0); + } + close(rdfd); + return OK; +} + +int romfs_commands(void *args) +{ + char filename[100] = "/rom/init.d/rcS"; + romdisk_register(0, (FAR uint8_t *) romfs_img, 32, 512); + mount("/dev/ram0", "/rom", "romfs", 1, NULL); + + int ret = read_file(filename); + if (ret < 0) { + printf("romfs error!\n"); + } else { + printf("success romfs test!\n"); + } + + ret = umount("/rom"); + if (ret < 0) { + printf("umount romfs fail\n"); + } + + return 0; +} + +/**************************************************************************** + * fs_command_main + ****************************************************************************/ +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int romfs_test_main(int argc, char **argv) +#endif +{ + pthread_t tid; + pthread_attr_t attr; + struct sched_param sparam; + int r; + + struct pthread_arg args; + + args.argc = argc; + args.argv = argv; + + /* Initialize the attribute variable */ + r = pthread_attr_init(&attr); + if (r != 0) { + printf("%s: pthread_attr_init failed, status=%d\n", __func__, r); + } + + /* 1. set a priority */ + sparam.sched_priority = 100; + r = pthread_attr_setschedparam(&attr, &sparam); + if (r != 0) { + printf("%s: pthread_attr_setschedparam failed, status=%d\n", __func__, r); + } + + r = pthread_attr_setschedpolicy(&attr, SCHED_RR); + if (r != 0) { + printf("%s: pthread_attr_setschedpolicy failed, status=%d\n", __func__, r); + } + + /* 2. set a stacksize */ + r = pthread_attr_setstacksize(&attr, 51200); + if (r != 0) { + printf("%s: pthread_attr_setstacksize failed, status=%d\n", __func__, r); + } + + /* 3. create pthread with entry function */ + r = pthread_create(&tid, &attr, (pthread_startroutine_t) romfs_commands, (void *)&args); + if (r != 0) { + printf("%s: pthread_create failed, status=%d\n", __func__, r); + } + + /* Wait for the threads to stop */ + pthread_join(tid, NULL); + + return 0; +} diff --git a/apps/examples/fs_helper/write_remove_test.c b/apps/examples/fs_helper/write_remove_test.c new file mode 100644 index 0000000..6de1f05 --- /dev/null +++ b/apps/examples/fs_helper/write_remove_test.c @@ -0,0 +1,171 @@ +/**************************************************************************** + * + * Copyright 2017 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ +/** + * @file write_remove_test.c + * @brief This is test application for smart filesystem. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +#define WRITE_DATA_SIZE 1024 +/**************************************************************************** + * Private data + ****************************************************************************/ +struct pthread_arg { + int argc; + char **argv; +}; + +static int make_file(char *filename) +{ + FILE *fp; + int i, ret; + + fp = fopen(filename, "w+"); + if (fp == NULL) { + printf("Cannot make file %s\n", filename); + return -1; + } + + for (i = 0; i < WRITE_DATA_SIZE; i++) { + ret = fwrite(&i, 4, 1, fp); + if (ret < 0) { + printf("fwrite error[%d]\n", ret); + return ret; + } + } + + ret = fclose(fp); + if (ret != 0) { + printf("fclose error[%d]\n", ret); + return ret; + } + return OK; +} + +int wr_commands(void *args) +{ + char **argv; + int repeat; + int count; + int ret; + char path[100] = "/mnt/wr_test"; + + argv = ((struct pthread_arg *)args)->argv; + + repeat = atoi(argv[1]); + printf("repeat = %d\n", repeat); + + printf("\n"); + + for (count = 1; count != repeat; count++) { + printf("\r%d", count); + + //write file + if (make_file(path) < 0) { + return -1; + } + //remove file + ret = unlink(path); + if (ret < 0) { + printf("unlink fail [%d]\n", ret); + return -1; + } + } + printf("\ntest complete!\n"); + + return 0; +} + +void usage_write_remove(void) +{ + printf("Usage : \n"); + printf("write and remove test for filesystem(smartfs) \n"); + printf("ex) write_remove 10\n"); +} + +/**************************************************************************** + * fs_command_main + ****************************************************************************/ +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int write_remove_test_main(int argc, char **argv) +#endif +{ + pthread_t tid; + pthread_attr_t attr; + struct sched_param sparam; + int r; + + struct pthread_arg args; + + args.argc = argc; + args.argv = argv; + + if (argc != 2) { + usage_write_remove(); + return 0; + } + + /* Initialize the attribute variable */ + r = pthread_attr_init(&attr); + if (r != 0) { + printf("%s: pthread_attr_init failed, status=%d\n", __func__, r); + } + + /* 1. set a priority */ + sparam.sched_priority = 100; + r = pthread_attr_setschedparam(&attr, &sparam); + if (r != 0) { + printf("%s: pthread_attr_setschedparam failed, status=%d\n", __func__, r); + } + + r = pthread_attr_setschedpolicy(&attr, SCHED_RR); + if (r != 0) { + printf("%s: pthread_attr_setschedpolicy failed, status=%d\n", __func__, r); + } + + /* 2. set a stacksize */ + r = pthread_attr_setstacksize(&attr, 51200); + if (r != 0) { + printf("%s: pthread_attr_setstacksize failed, status=%d\n", __func__, r); + } + + /* 3. create pthread with entry function */ + r = pthread_create(&tid, &attr, (pthread_startroutine_t) wr_commands, (void *)&args); + if (r != 0) { + printf("%s: pthread_create failed, status=%d\n", __func__, r); + } + + /* Wait for the threads to stop */ + pthread_join(tid, NULL); + + return 0; + +} -- 2.7.4