I am attaching with a modification as suggested in the mailing list:--
Path of execution:-
o You can execute tests along with other test suites, if the file system
doesn't support the call, kernel returns EOPNOTSUPP. Test is considered
passed in this case (with TCONF status).
o In case test needs to be executed individually on required
partition/directory
I have provided run.sh script, using which you can execute the test
suites on any partition of your choice.
Thanks for all the feed back and guidelines. Let me know of you views.
Thanks
Sharyathi
Index: ltp-full-20070930/testcases/kernel/include/i386.in
===================================================================
--- ltp-full-20070930.orig/testcases/kernel/include/i386.in 2006-09-10 15:42:01.000000000 +0530
+++ ltp-full-20070930/testcases/kernel/include/i386.in 2008-01-07 13:35:21.000000000 +0530
@@ -20,3 +20,4 @@
__NR_splice 313
__NR_tee 315
__NR_vmsplice 316
+__NR_fallocate 324
Index: ltp-full-20070930/testcases/kernel/include/ia64.in
===================================================================
--- ltp-full-20070930.orig/testcases/kernel/include/ia64.in 2006-09-10 15:42:01.000000000 +0530
+++ ltp-full-20070930/testcases/kernel/include/ia64.in 2008-01-07 13:36:26.000000000 +0530
@@ -15,3 +15,4 @@
__NR_splice 1297
__NR_tee 1301
__NR_vmsplice 1302
+__NR_fallocate 1303
Index: ltp-full-20070930/testcases/kernel/include/powerpc.in
===================================================================
--- ltp-full-20070930.orig/testcases/kernel/include/powerpc.in 2006-09-10 15:42:01.000000000 +0530
+++ ltp-full-20070930/testcases/kernel/include/powerpc.in 2008-01-07 13:54:45.000000000 +0530
@@ -20,3 +20,4 @@
__NR_readlinkat (__NR_openat + 10)
__NR_fchmodat (__NR_openat + 11)
__NR_faccessat (__NR_openat + 12)
+__NR_fallocate 309
Index: ltp-full-20070930/testcases/kernel/include/powerpc64.in
===================================================================
--- ltp-full-20070930.orig/testcases/kernel/include/powerpc64.in 2006-09-10 15:42:01.000000000 +0530
+++ ltp-full-20070930/testcases/kernel/include/powerpc64.in 2008-01-07 13:59:19.000000000 +0530
@@ -20,3 +20,4 @@
__NR_readlinkat (__NR_openat + 10)
__NR_fchmodat (__NR_openat + 11)
__NR_faccessat (__NR_openat + 12)
+__NR_fallocate 309
Index: ltp-full-20070930/testcases/kernel/include/s390.in
===================================================================
--- ltp-full-20070930.orig/testcases/kernel/include/s390.in 2006-09-10 15:42:01.000000000 +0530
+++ ltp-full-20070930/testcases/kernel/include/s390.in 2008-01-07 13:43:51.000000000 +0530
@@ -15,3 +15,4 @@
__NR_splice 306
__NR_tee 308
__NR_vmsplice 309
+__NR_fallocate 314
Index: ltp-full-20070930/testcases/kernel/include/s390x.in
===================================================================
--- ltp-full-20070930.orig/testcases/kernel/include/s390x.in 2006-09-10 15:23:10.000000000 +0530
+++ ltp-full-20070930/testcases/kernel/include/s390x.in 2008-01-07 13:59:55.000000000 +0530
@@ -12,3 +12,4 @@
__NR_readlinkat (__NR_openat + 10)
__NR_fchmodat (__NR_openat + 11)
__NR_faccessat (__NR_openat + 12)
+__NR_fallocate 314
Index: ltp-full-20070930/testcases/kernel/include/sparc.in
===================================================================
--- ltp-full-20070930.orig/testcases/kernel/include/sparc.in 2006-09-10 15:42:01.000000000 +0530
+++ ltp-full-20070930/testcases/kernel/include/sparc.in 2008-01-07 13:56:21.000000000 +0530
@@ -15,3 +15,4 @@
__NR_readlinkat (__NR_openat + 10)
__NR_fchmodat (__NR_openat + 11)
__NR_faccessat (__NR_openat + 12)
+__NR_fallocate 314
Index: ltp-full-20070930/testcases/kernel/include/sparc64.in
===================================================================
--- ltp-full-20070930.orig/testcases/kernel/include/sparc64.in 2006-09-10 15:42:01.000000000 +0530
+++ ltp-full-20070930/testcases/kernel/include/sparc64.in 2008-01-07 13:56:57.000000000 +0530
@@ -15,3 +15,4 @@
__NR_readlinkat (__NR_openat + 10)
__NR_fchmodat (__NR_openat + 11)
__NR_faccessat (__NR_openat + 12)
+__NR_fallocate 314
Index: ltp-full-20070930/testcases/kernel/include/x86_64.in
===================================================================
--- ltp-full-20070930.orig/testcases/kernel/include/x86_64.in 2006-09-10 15:42:01.000000000 +0530
+++ ltp-full-20070930/testcases/kernel/include/x86_64.in 2008-01-07 13:58:00.000000000 +0530
@@ -20,3 +20,4 @@
__NR_splice 275
__NR_tee 276
__NR_vmsplice 278
+__NR_fallocate 285
Index: ltp-full-20070930/testcases/kernel/syscalls/fallocate/Makefile
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ ltp-full-20070930/testcases/kernel/syscalls/fallocate/Makefile 2008-01-07 14:09:23.000000000 +0530
@@ -0,0 +1,32 @@
+
+#
+# Copyright (c) International Business Machines Corp., 2001
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+# the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+CFLAGS += -I../../../../include -Wall
+LDLIBS += -L../../../../lib -lltp
+
+SRCS = $(wildcard *.c)
+TARGETS = $(patsubst %.c,%,$(SRCS))
+
+all: $(TARGETS)
+
+install:
+ @set -e; for i in $(TARGETS); do ln -f $$i ../../../bin/$$i ; done
+
+clean:
+ rm -f $(TARGETS)
Index: ltp-full-20070930/testcases/kernel/syscalls/fallocate/fallocate01.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ ltp-full-20070930/testcases/kernel/syscalls/fallocate/fallocate01.c 2008-01-07 14:05:14.000000000 +0530
@@ -0,0 +1,374 @@
+
+/******************************************************************************
+ * fallocate01.c
+ * Mon Dec 24 2007
+ * Copyright (c) International Business Machines Corp., 2007
+ * Emali : [EMAIL PROTECTED]
+ ******************************************************************************/
+
+
+/***************************************************************************
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+***************************************************************************/
+
+
+/*****************************************************************************
+ *
+ * OS Test - International Business Machines Corp. 2007.
+ *
+ * TEST IDENTIFIER : fallocate01
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : Basic test for fallocate()
+ *
+ * TEST CASE TOTAL : 2
+ *
+ * CPU ARCHITECTURES : PPC,X86, X86_64
+ *
+ * AUTHOR : Sharyathi Nagesh
+ *
+ * CO-PILOT :
+ *
+ * DATE STARTED : 24/12/2007
+ *
+ * TEST CASES
+ * (Working of fallocate under 2 modes)
+ * 1) DEFAULT 2)FALLOC_FL_KEEP_SIZE
+ *
+ * INPUT SPECIFICATIONS
+ * No input needs to be specified
+ * fallocate() in puts are generated randomly
+ *
+ * OUTPUT SPECIFICATIONS
+ * Output describing whether test cases passed or failed.
+ *
+ * ENVIRONMENTAL NEEDS
+ * Test Needs to be executed on file system supporting ext4
+ * LTP {TMP} Needs to be set to such a folder
+ *
+ * SPECIAL PROCEDURAL REQUIREMENTS
+ * None
+ *
+ * DETAILED DESCRIPTION
+ * This is a test case for fallocate() system call.
+ * This test suite tests basic working of fallocate under different modes
+ * It trys to fallocate memory blocks and write into that block
+ *
+ * Total 2 Test Cases :-
+ * (1) Test Case for DEFAULT MODE
+ * (2) Test Case for FALLOC_FL_KEEP_SIZE
+ *
+ * Setup:
+ * Setup file on which fallocate is to be called
+ * Set up 2 files for each mode
+ *
+ * Test:
+ * Loop if the proper options are given.
+ * Execute system call
+ * Check return code, if system call did fail
+ * lseek to some random location with in allocate block
+ * write data into the locattion Report if any error encountered
+ * PASS the test otherwise
+ *
+ * Cleanup:
+ * Cleanup the temporary folder
+ *
+*************************************************************************/
+
+/* Standard Include Files */
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <error.h>
+
+/* Harness Specific Include Files. */
+#include "test.h"
+#include "usctest.h"
+#include "linux_syscall_numbers.h"
+
+
+#define BLOCKS_WRITTEN 12
+
+#ifndef __NR_fallocate
+# define __NR_fallocate -1 //Dummy Value
+ int arch_support = 0; //Architecure is not supported
+#else
+ int arch_support = 1; //Architecture is supported
+#endif
+
+
+/* Local Function */
+static inline long fallocate();
+void get_blocksize(int);
+void populate_files(int fd);
+void runtest(int,int,loff_t);
+
+/* Extern Global Variables */
+extern int Tst_count; /* counter for tst_xxx routines. */
+/* Global Variables */
+char *TCID = "fallocate01"; /* test program identifier. */
+char fname_mode1[255], fname_mode2[255]; /* Files used for testing */
+int fd_mode1, fd_mode2;
+int TST_TOTAL ;
+int block_size;
+int buf_size;
+
+/******************************************************************************
+ * Performs all one time clean up for this test on successful
+ * completion, premature exit or failure. Closes all temporary
+ * files, removes all temporary directories exits the test with
+ * appropriate return code by calling tst_exit() function.
+******************************************************************************/
+extern void
+cleanup()
+{
+/* Close all open file descriptors. */
+
+ if(close(fd_mode1) == -1)
+ {
+ tst_resm(TWARN, "close(%s) Failed, errno=%d : %s",
+ fname_mode1, errno, strerror(errno));
+ }
+
+ if(close(fd_mode2) == -1)
+ {
+ tst_resm(TWARN, "close(%s) Failed, errno=%d : %s",
+ fname_mode2, errno, strerror(errno));
+ }
+ //remove tem directory and all the files in it
+ tst_rmdir();
+ //Exit with appropriate return code
+ tst_exit();
+}
+
+
+/*****************************************************************************
+ * Performs all one time setup for this test. This function is
+ * used to create temporary dirs and temporary files
+ * that may be used in the course of this test
+ ******************************************************************************/
+void
+setup()
+{
+
+ /* Create temporary directories */
+ TEST_PAUSE;
+
+ tst_tmpdir();
+
+ sprintf(fname_mode1,"tfile_mode1_%d",getpid());
+ if ((fd_mode1 = open(fname_mode1, O_RDWR|O_CREAT, 0700)) == -1 )
+ {
+ tst_brkm(TBROK, cleanup, "Unable to open %s for read/write. Error:%d, %s\n", \
+ fname_mode1, errno, strerror(errno));
+ }
+
+ get_blocksize(fd_mode1);
+
+ populate_files(fd_mode1);
+ sprintf(fname_mode2,"tfile_mode2_%d",getpid());
+ if ((fd_mode2 = open(fname_mode2, O_RDWR|O_CREAT, 0700)) == -1 )
+ {
+ tst_brkm(TBROK, cleanup, "Unable to open %s for read/write. Error:%d, %s\n", \
+ fname_mode2, errno, strerror(errno));
+ }
+ populate_files(fd_mode2);
+
+}
+
+/*****************************************************************************
+ * Gets the block size for the file system
+ ******************************************************************************/
+void
+get_blocksize(int fd)
+{
+ struct stat file_stat;
+
+ if( fstat(fd, &file_stat) < 0 )
+ tst_resm(TFAIL, "fstat failed while getting block_size errno=%d : %s",
+ TEST_ERRNO, strerror(TEST_ERRNO));
+
+ block_size = (int) file_stat.st_blksize;
+ buf_size = block_size;
+}
+/*****************************************************************************
+ * Writes data into the file
+ ******************************************************************************/
+
+void
+populate_files(int fd)
+{
+ char buf[buf_size + 1];
+ char *fname;
+ int index;
+ int blocks;
+ int data;
+
+ if( fd == fd_mode1 )
+ fname = fname_mode1;
+ else
+ fname = fname_mode2;
+
+ for (blocks = 0; blocks < BLOCKS_WRITTEN ; blocks++)
+ {
+ for (index = 0; index < buf_size; index++)
+ buf[index] = 'A' + (index % 26);
+ buf[buf_size]='\0';
+ if (( data = write(fd, buf, buf_size)) < 0 )
+ {
+ tst_brkm(TBROK, cleanup, "Unable to write to %s. Error: %d, %s", \
+ fname,errno, strerror(errno));
+ }
+ }
+}
+
+
+int
+main(int ac, /* number of command line parameters */
+ char **av) /* pointer to the array of the command line parameters. */
+{
+ int fd;
+ enum {DEFAULT, FALLOC_FL_KEEP_SIZE} mode;
+ loff_t expected_size;
+ int lc;
+ char *msg;
+
+ TST_TOTAL = 2;
+
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL )
+ tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+
+
+ /* This test needs kernel version > 2.6.23 and
+ * either of x86, x86_64 or ppc architecture
+ */
+ if ( !arch_support || (tst_kvercmp(2,6,23) < 0)) {
+ tst_resm(TWARN," System doesn't support execution of the test");
+
+ exit(0);
+ }
+
+
+ /* perform global test setup, call setup() function. */
+ setup();
+
+
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+ for ( mode = DEFAULT; mode <= FALLOC_FL_KEEP_SIZE; mode++)
+ {
+ switch(mode){
+ case DEFAULT: fd = fd_mode1;
+ expected_size = BLOCKS_WRITTEN * block_size + block_size;
+ break;
+ case FALLOC_FL_KEEP_SIZE: fd = fd_mode2;
+ expected_size = BLOCKS_WRITTEN * block_size;
+ break;
+ }
+ runtest(mode, fd, expected_size);
+ }
+ }
+
+ cleanup();
+ return(0);
+}
+
+
+/*****************************************************************************
+ * Wraper function to call fallocate system call
+ ******************************************************************************/
+static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
+{
+ return syscall(__NR_fallocate, fd, mode, offset,len);
+}
+
+/*****************************************************************************
+ * Calls the system call, with appropriate parameters and writes data
+ ******************************************************************************/
+void
+runtest(int mode, int fd, loff_t expected_size)
+{
+ loff_t offset;
+ loff_t len = block_size;
+ loff_t write_offset, lseek_offset;
+ offset = lseek(fd,0,SEEK_END);
+ struct stat file_stat;
+ errno = 0;
+
+ TEST(fallocate(fd, mode, offset,len));
+ /* check return code */
+ if ( TEST_RETURN != 0 ) {
+ if ( TEST_ERRNO == EOPNOTSUPP ) {
+ tst_resm( TCONF, " fallocate system call" \
+ " is not implemented");
+ tst_exit();
+ }
+ TEST_ERROR_LOG(TEST_ERRNO);
+ tst_resm(TFAIL, "fallocate(%d, %d, %lld, %lld) Failed, errno=%d : %s",
+ fd, mode, offset, len, TEST_ERRNO, strerror(TEST_ERRNO));
+ return ;
+ } else {
+ if ( STD_FUNCTIONAL_TEST ) {
+ /* No Verification test, yet... */
+ tst_resm(TPASS, "fallocate(%d, %d, %lld, %lld) returned %d ",
+ fd, mode, offset, len, TEST_RETURN);
+ }
+ }
+
+ if( fstat(fd, &file_stat) < 0 )
+ tst_resm(TFAIL, "fstat failed after fallocate() errno=%d : %s",
+ TEST_ERRNO, strerror(TEST_ERRNO));
+
+ if ( file_stat.st_size != expected_size)
+ tst_resm(TFAIL, "fstat test fails on fallocate (%d, %d, %lld, %lld) Failed on mode:%d, errno=%d : %s",
+ fd, mode, offset,len, TEST_ERRNO, strerror(TEST_ERRNO));
+
+ write_offset = random() % len;
+ lseek_offset = lseek(fd,write_offset,SEEK_CUR);
+ if ( lseek_offset != offset + write_offset)
+ {
+ tst_resm(TFAIL, "lseek fails in fallocate(%d, %d, %lld, %lld) Failed, errno=%d : %s",
+ fd,mode, offset,len, TEST_ERRNO, strerror(TEST_ERRNO));
+ return;
+ }
+
+ //Write a character to file at random location
+ TEST(write(fd,"A",1));
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ tst_resm(TFAIL, "write fails in fallocate(%d, %d, %lld, %lld) Failed, errno=%d : %s",
+ fd,mode, offset, len, TEST_ERRNO, strerror(TEST_ERRNO));
+ } else {
+ if ( STD_FUNCTIONAL_TEST ) {
+ /* No Verification test, yet... */
+ tst_resm(TPASS, "write operation on fallocated(%d, %d, %lld, %lld) returned %d ",
+ fd,mode, offset,len, TEST_RETURN);
+ }
+ }
+
+}
Index: ltp-full-20070930/testcases/kernel/syscalls/fallocate/fallocate02.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ ltp-full-20070930/testcases/kernel/syscalls/fallocate/fallocate02.c 2008-01-07 14:07:14.000000000 +0530
@@ -0,0 +1,337 @@
+
+/******************************************************************************
+ * fallocate02.c
+ * Mon Dec 24 2007
+ * Copyright (c) International Business Machines Corp., 2007
+ * Emali : [EMAIL PROTECTED]
+ ******************************************************************************/
+
+
+/***************************************************************************
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+***************************************************************************/
+
+
+/*****************************************************************************
+ *
+ * OS Test - International Business Machines Corp. 2007.
+ *
+ * TEST IDENTIFIER : fallocate02
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : Checks for Errors from fallocate()
+ *
+ * TEST CASE TOTAL : 7
+ *
+ * CPU ARCHITECTURES : PPC,X86, X86_64
+ *
+ * AUTHOR : Sharyathi Nagesh
+ *
+ * CO-PILOT :
+ *
+ * DATE STARTED : 24/12/2007
+ *
+ * TEST CASES
+ * (Tests fallocate() for different test cases as reported in map page)
+ *
+ * INPUT SPECIFICATIONS
+ * No input needs to be specified
+ * fallocate() in-puts are specified through test_data
+ *
+ * OUTPUT SPECIFICATIONS
+ * fallocate Error message matches with the expected error message.
+ *
+ * ENVIRONMENTAL NEEDS
+ * Test Needs to be executed on file system supporting ext4
+ * LTP {TMP} Needs to be set to such a folder
+ *
+ * SPECIAL PROCEDURAL REQUIREMENTS
+ * None
+ *
+ * DETAILED DESCRIPTION
+ * This is a test case for fallocate() system call.
+ * This test suite tests various error messages from fallocate
+ * If the error message received matches with the expected
+ * test is considered passed else test fails
+ * Provided TEST_DEFAULT to switch b/w modes
+ *
+ * Total 7 Test Cases :-
+ * Various error messages from the man page
+ *
+ * Setup:
+ * Setup files on which fallocate is to be called
+ *
+ * Test:
+ * Loop if the proper options are given.
+ * Execute system call
+ * Check return code.
+ * If error obtained matches with the expected error
+ * PASS the test, otherwise TEST FAILS
+ * Provided TEST_DEFAULT to switch b/w modes
+ *
+ * Cleanup:
+ * Cleanup the temporary folder
+ *
+*************************************************************************/
+
+/* Standard Include Files */
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+/* Harness Specific Include Files. */
+#include "test.h"
+#include "usctest.h"
+#include "linux_syscall_numbers.h"
+
+#define BLOCKS_WRITTEN 12
+
+#ifdef TEST_DEFAULT
+ #define DEFAULT_TEST_MODE 0 //DEFAULT MODE
+#else
+ #define DEFAULT_TEST_MODE 1 //FALLOC_FL_KEEP_SIZE MODE
+#endif
+
+#ifndef __NR_fallocate
+# define __NR_fallocate -1 //DUMMY VALUE
+ int arch_support = 0;
+#else
+ int arch_support = 1;
+#endif
+
+#define OFFSET 12
+
+/*Local Functions*/
+static inline long fallocate();
+void populate_file();
+void create_fifo();
+void create_pipe();
+void get_blocksize(int fd);
+
+/* Extern Global Variables */
+extern int Tst_count; /* counter for tst_xxx routines. */
+/* Global Variables */
+char *TCID = "fallocate02"; /* test program identifier. */
+char fnamew[255]; /* Files used for testing */
+char fnamer[255]; /* Files used for testing */
+int fdw;
+int fdr;
+enum {RFILE,WFILE,PIPE,FIFO};
+struct test_data_t
+{
+ int file;
+ int mode;
+ loff_t offset;
+ loff_t len;
+ int error;
+} test_data[] = {
+ {RFILE, DEFAULT_TEST_MODE, 0, 1, EBADF},
+ {WFILE, DEFAULT_TEST_MODE, -1, 1, EINVAL},
+ {WFILE, DEFAULT_TEST_MODE, 1, -1, EINVAL},
+ {WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN, 0, EINVAL},
+ {WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN, -1, EINVAL},
+ {WFILE, DEFAULT_TEST_MODE,-( BLOCKS_WRITTEN + OFFSET ), 1 , EINVAL},
+ {WFILE, DEFAULT_TEST_MODE, BLOCKS_WRITTEN - OFFSET, 1 , 0}
+};
+int TST_TOTAL = sizeof(test_data)/sizeof(test_data[0]); /* total number of tests in this file. */
+int block_size;
+int buf_size;
+
+
+/******************************************************************************
+ * Performs all one time clean up for this test on successful
+ * completion, premature exit or failure. Closes all temporary
+ * files, removes all temporary directories exits the test with
+ * appropriate return code by calling tst_exit() function.
+******************************************************************************/
+extern void
+cleanup()
+{
+ /* Close all open file descriptors. */
+ if(close(fdw) == -1)
+ {
+ tst_resm(TWARN, "close(%s) Failed, errno=%d : %s",
+ fnamew, errno, strerror(errno));
+ }
+
+ if(close(fdr) == -1)
+ {
+ tst_resm(TWARN, "close(%s) Failed, errno=%d : %s",
+ fnamer, errno, strerror(errno));
+ }
+
+ /* Remove tmp dir and all files in it */
+ tst_rmdir();
+
+ /* Exit with appropriate return code. */
+ tst_exit();
+
+}
+
+/*****************************************************************************
+ * Performs all one time setup for this test. This function is
+ * used to create temporary dirs and temporary files
+ * that may be used in the course of this test
+ ******************************************************************************/
+void
+setup()
+{
+ /* capture signals */
+ tst_sig(FORK, DEF_HANDLER, cleanup);
+
+ /* Pause if that option was specified */
+ TEST_PAUSE;
+
+ /* make a temp directory and cd to it */
+ tst_tmpdir();
+
+ sprintf(fnamer,"tfile_read_%d",getpid());
+ sprintf(fnamew,"tfile_write_%d",getpid());
+
+ if ((fdr = open(fnamer,O_RDONLY|O_CREAT,S_IRUSR)) == -1) {
+ tst_brkm(TBROK, cleanup, "open(%s,O_RDONLY|O_CREAT,S_IRUSR) Failed, errno=%d : %s",
+ fnamer, errno, strerror(errno));
+ }
+ if ((fdw = open(fnamew,O_RDWR|O_CREAT,S_IRWXU)) == -1) {
+ tst_brkm(TBROK, cleanup, "open(%s,O_RDWR|O_CREAT,S_IRWXU) Failed, errno=%d : %s",
+ fnamew, errno, strerror(errno));
+ }
+ get_blocksize(fdr);
+ populate_file();
+}
+
+/*****************************************************************************
+ * Gets the block size for the file system
+ ******************************************************************************/
+void
+get_blocksize(int fd)
+{
+ struct stat file_stat;
+
+ if( fstat(fd, &file_stat) < 0 )
+ tst_resm(TFAIL, "fstat failed while getting block_size errno=%d : %s",
+ TEST_ERRNO, strerror(TEST_ERRNO));
+
+ block_size = (int) file_stat.st_blksize;
+ buf_size = block_size;
+}
+
+/*****************************************************************************
+ * Writes data into the file
+ ******************************************************************************/
+void
+populate_file()
+{
+ char buf[buf_size + 1];
+ int index;
+ int blocks;
+ int data;
+ for (blocks = 0; blocks < BLOCKS_WRITTEN ; blocks++)
+ {
+ for (index = 0; index < buf_size; index++)
+ buf[index] = 'A' + (index % 26);
+ buf[buf_size]='\0';
+ if (( data = write(fdw, buf, buf_size)) < 0 )
+ {
+ tst_brkm(TBROK, cleanup, "Unable to write to %s. Error: %d, %s", \
+ fnamew,errno, strerror(errno));
+ }
+ }
+}
+
+
+/*****************************************************************************
+ * Wraper function to call fallocate system call
+ ******************************************************************************/
+static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
+{
+ return syscall(__NR_fallocate, fd, mode, offset,len);
+}
+
+
+/*****************************************************************************
+ * Main function that calls the system call with the appropriate parameters
+ ******************************************************************************/
+int
+main(int ac, /* number of command line parameters */
+ char **av) /* pointer to the array of the command line parameters. */
+{
+
+ int test_index = 0;
+ int lc;
+ int fd;
+ char fname[255], *msg;
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL )
+ tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+
+ /* This test needs kernel version > 2.6.23 and
+ * either of x86, x86_64 or ppc architecture
+ */
+ if ( !arch_support || (tst_kvercmp(2,6,23) < 0)) {
+ tst_resm(TWARN," System doesn't support execution of the test");
+ exit(0);
+ }
+
+ /* perform global test setup, call setup() function. */
+ setup();
+
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+ for(test_index = 0 ; test_index < TST_TOTAL; test_index ++)
+ {
+ switch(test_data[test_index].file){
+ case RFILE: fd = fdr;
+ strcpy(fname,fnamer);
+ break;
+ case WFILE: fd = fdw;
+ strcpy(fname,fnamew);
+ break;
+ }
+
+ TEST(fallocate( fd, test_data[test_index].mode,
+ test_data[test_index].offset * block_size, test_data[test_index].len * block_size));
+ /* check return code */
+ if ( TEST_ERRNO != test_data[test_index].error ) {
+ if ( TEST_ERRNO == EOPNOTSUPP ) {
+ tst_resm( TCONF, " fallocate system call" \
+ " is not implemented");
+ tst_exit();
+ }
+ TEST_ERROR_LOG(TEST_ERRNO);
+ tst_resm(TFAIL, "fallocatee(%s:%d, %d, %lld, %lld) Failed, expected errno:%d \
+ instead errno=%d : %s", fname, fd,test_data[test_index].mode,
+ test_data[test_index].offset * block_size, test_data[test_index].len * block_size,
+ test_data[test_index].error, TEST_ERRNO, strerror(TEST_ERRNO));
+ } else {
+ /* No Verification test, yet... */
+ tst_resm(TPASS, "fallocatee(%s:%d, %d, %lld, %lld) returned %d ",
+ fname, fd,test_data[test_index].mode, test_data[test_index].offset * block_size,
+ test_data[test_index].len * block_size, TEST_ERRNO);
+ }
+ }
+ }
+ cleanup();
+ return(0);
+}
+
Index: ltp-full-20070930/testcases/kernel/syscalls/fallocate/fallocate03.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ ltp-full-20070930/testcases/kernel/syscalls/fallocate/fallocate03.c 2008-01-07 14:08:08.000000000 +0530
@@ -0,0 +1,317 @@
+
+/******************************************************************************
+ * fallocate03.c
+ * Mon Dec 24 2007
+ * Copyright (c) International Business Machines Corp., 2007
+ * Emali : [EMAIL PROTECTED]
+ ******************************************************************************/
+
+
+/***************************************************************************
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+***************************************************************************/
+
+/*****************************************************************************
+ *
+ * OS Test - International Business Machines Corp. 2007.
+ *
+ * TEST IDENTIFIER : fallocate03
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : fallocate
+ *
+ * TEST CASE TOTAL : 8
+ *
+ * CPU ARCHITECTURES : PPC,X86, X86_64
+ *
+ * AUTHOR : Sharyathi Nagesh
+ *
+ * CO-PILOT :
+ *
+ * DATE STARTED : 24/12/2007
+ *
+ * TEST CASES
+ * (Working of fallocate on a sparse file)
+ *
+ *
+ * INPUT SPECIFICATIONS
+ * No input needs to be specified
+ * fallocate() in-puts are specified through test_data
+ *
+ * OUTPUT SPECIFICATIONS
+ * Output describing whether test cases passed or failed.
+ *
+ * ENVIRONMENTAL NEEDS
+ * Test Needs to be executed on file system supporting ext4
+ * LTP {TMP} Needs to be set to such a folder
+ *
+ * SPECIAL PROCEDURAL REQUIREMENTS
+ * None
+ *
+ * DETAILED DESCRIPTION
+ * This is a test case for fallocate() system call.
+ * This test suite tests working of fallocate on sparse file
+ * fallocate is tested for different offsets
+ *
+ * Total 8 Test Cases :-
+ * Different offsets with in a sparse file is tested
+ *
+ * Setup:
+ * Setup file on which fallocate is to be called
+ * Set up a file with hole, created through lseek
+ *
+ * Test:
+ * Loop if the proper options are given
+ * Execute system call
+ * Check return code, if system call failed
+ * TEST fails, PASS the test otherwise
+ *
+ * Cleanup:
+ * Cleanup the temporary folder
+ *
+*************************************************************************/
+
+/* Standard Include Files */
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h> //Can be done with out
+#include <fcntl.h>
+#include <unistd.h>
+
+/* Harness Specific Include Files. */
+#include "test.h"
+#include "usctest.h"
+#include "linux_syscall_numbers.h"
+
+#define BLOCKS_WRITTEN 12
+#define HOLE_SIZE_IN_BLOCKS 12
+#define DEFAULT_MODE 0
+#define FALLOC_FL_KEEP_SIZE 1 //Need to be removed once the glibce support is provided
+#define TRUE 0
+
+#ifndef __NR_fallocate
+# define __NR_fallocate -1 //DUMMY VALUE
+ int arch_support = 0;
+#else
+ int arch_support = 1;
+#endif
+
+/*Local Functions*/
+static inline long fallocate();
+void get_blocksize(int);
+void populate_file();
+void file_seek(off_t);
+
+/* Extern Global Variables */
+extern int Tst_count; /* counter for tst_xxx routines. */
+
+/* Global Variables */
+char *TCID = "fallocate03"; /* test program identifier. */
+char fname[255];
+int fd;
+struct test_data_t
+{
+ int mode;
+ loff_t offset;
+ loff_t len;
+ int error;
+}test_data[] = {
+ {DEFAULT_MODE, 2, 1, TRUE},
+ {DEFAULT_MODE, BLOCKS_WRITTEN, 1, TRUE},
+ {DEFAULT_MODE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS/2 -1 , 1, TRUE},
+ {DEFAULT_MODE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS + 1 , 1, TRUE},
+ {FALLOC_FL_KEEP_SIZE,2, 1, TRUE},
+ {FALLOC_FL_KEEP_SIZE, BLOCKS_WRITTEN , 1, TRUE},
+ {FALLOC_FL_KEEP_SIZE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS/2 + 1 , 1, TRUE},
+ {FALLOC_FL_KEEP_SIZE, BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS + 2 , 1, TRUE}
+};
+int TST_TOTAL = sizeof(test_data)/sizeof(test_data[0]); /* total number of tests in this file. */
+int block_size;
+int buf_size;
+
+/******************************************************************************
+ * Performs all one time clean up for this test on successful
+ * completion, premature exit or failure. Closes all temporary
+ * files, removes all temporary directories exits the test with
+ * appropriate return code by calling tst_exit() function.
+******************************************************************************/
+extern void
+cleanup()
+{
+ /* Close all open file descriptors. */
+ if(close(fd) == -1)
+ {
+ tst_resm(TWARN, "close(%s) Failed, errno=%d : %s",
+ fname, errno, strerror(errno));
+ }
+
+ /* Remove tmp dir and all files in it */
+ tst_rmdir();
+
+ /* Exit with appropriate return code. */
+ tst_exit();
+}
+
+
+/*****************************************************************************
+ * Performs all one time setup for this test. This function is
+ * used to create temporary dirs and temporary files
+ * that may be used in the course of this test
+ ******************************************************************************/
+
+void
+setup()
+{
+
+ /* Create temporary directories */
+ TEST_PAUSE;
+
+ tst_tmpdir();
+
+ sprintf(fname,"tfile_sparse_%d",getpid());
+ if ((fd = open(fname, O_RDWR|O_CREAT, 0700)) == -1 )
+ {
+ tst_brkm(TBROK, cleanup, "Unable to open %s for read/write. Error:%d, %s\n", \
+ fname, errno, strerror(errno));
+ }
+ get_blocksize(fd);
+ populate_file();
+ file_seek(BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS); //create holes
+ populate_file();
+ file_seek(0); //Rewind
+}
+
+/*****************************************************************************
+ * Gets the block size for the file system
+ ******************************************************************************/
+void
+get_blocksize(int fd)
+{
+ struct stat file_stat;
+
+ if( fstat(fd, &file_stat) < 0 )
+ tst_resm(TFAIL, "fstat failed while getting block_size errno=%d : %s",
+ TEST_ERRNO, strerror(TEST_ERRNO));
+
+ block_size = (int) file_stat.st_blksize;
+ buf_size = block_size;
+}
+
+/*****************************************************************************
+ * Create a Hole in the file
+ ******************************************************************************/
+void
+file_seek(off_t offset)
+{
+ offset *= block_size;
+ lseek(fd,offset,SEEK_SET);
+}
+
+
+/*****************************************************************************
+ * Writes data into the file
+ ******************************************************************************/
+void
+populate_file()
+{
+ char buf[buf_size + 1];
+ int index;
+ int blocks;
+ int data;
+ for (blocks = 0; blocks < BLOCKS_WRITTEN ; blocks++)
+ {
+ for (index = 0; index < buf_size; index++)
+ buf[index] = 'A' + (index % 26);
+ buf[buf_size]='\0';
+ if (( data = write(fd, buf, buf_size)) < 0 )
+ {
+ tst_brkm(TBROK, cleanup, "Unable to write to %s. Error: %d, %s", \
+ fname,errno, strerror(errno));
+ }
+ }
+}
+
+
+
+/*****************************************************************************
+ * Wraper function to call fallocate system call
+ ******************************************************************************/
+static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
+{
+ return syscall(__NR_fallocate, fd, mode, offset,len);
+}
+
+/*****************************************************************************
+ * Main function that calls the system call with the appropriate parameters
+ ******************************************************************************/
+int
+main(int ac, /* number of command line parameters */
+ char **av) /* pointer to the array of the command line parameters. */
+{
+ int test_index = 0;
+ int lc;
+ char *msg;
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL )
+ tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+
+ /* This test needs kernel version > 2.6.23 and
+ * either of x86, x86_64 or ppc architecture
+ */
+ if ( !arch_support || (tst_kvercmp(2,6,23) < 0)) {
+ tst_resm(TWARN," System doesn't support execution of the test");
+ exit(0);
+ }
+
+ /* perform global test setup, call setup() function. */
+ setup();
+
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+ for(test_index = 0 ; test_index < TST_TOTAL; test_index ++)
+ {
+ TEST(fallocate(fd, test_data[test_index].mode,
+ test_data[test_index].offset * block_size, test_data[test_index].len * block_size));
+
+ /* check return code */
+ if ( TEST_RETURN != test_data[test_index].error ) {
+ if ( TEST_ERRNO == EOPNOTSUPP ) {
+ tst_resm( TCONF, " fallocate system call" \
+ " is not implemented");
+ tst_exit();
+ }
+ TEST_ERROR_LOG(TEST_ERRNO);
+ tst_resm(TFAIL, "fallocatee(%s, %d, %lld, %lld) Failed, errno=%d : %s",
+ fname,test_data[test_index].mode, test_data[test_index].offset * block_size,
+ test_data[test_index].len * block_size, TEST_ERRNO, strerror(TEST_ERRNO));
+ } else {
+ if ( STD_FUNCTIONAL_TEST ) {
+ /* No Verification test, yet... */
+ tst_resm(TPASS, "fallocatee(%s, %d, %lld, %lld) returned %d ",
+ fname,test_data[test_index].mode, test_data[test_index].offset * block_size,
+ test_data[test_index].len * block_size, TEST_RETURN); }
+ }
+ }
+ }
+ cleanup();
+ return(0);
+}
Index: ltp-full-20070930/testcases/kernel/syscalls/fallocate/run.sh
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ ltp-full-20070930/testcases/kernel/syscalls/fallocate/run.sh 2008-01-07 14:10:17.000000000 +0530
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+if [ $# -le 0 ]; then
+ echo "Usage run.sh <Test Dir>"
+ echo "Give Absolute Path"
+ exit;
+fi
+
+TEST_DIR=$1
+
+export LTPROOT=${TEST_DIR}
+export TMPBASE=${TEST_DIR}
+export TMP="${TMPBASE}/ltp-$$"
+export TMPDIR=${TMP}
+
+mkdir $TMPDIR
+
+./fallocate01
+./fallocate02
+./fallocate03
+
+rm -rf $TMPDIR
+
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list