Hi
I am attaching a test cases written for testing fallocate() system call. Please go through the tests and let us know of your opinion.
  A few points I wanted to put forth.
o It needs to be executed from a folder that has EXT4 partition.
        else it will come out with error
o __NR_FALLOCATE needs to be declared under     
                    include/linux_syscall_numbers.h
Some of the architecture specific values:
x86             324
x86_64          324
ia64            1303
s390            314

Thanks
Yeehaw
/******************************************************************************
 *          			 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"

#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	
int TST_TOTAL ;
int block_size;
int buf_size;

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;

/******************************************************************************
 * 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   argc,    /* number of command line parameters                      */
        char **argv)   /* pointer to the array of the command line parameters.   */
{
	int fd;
	enum {DEFAULT, FALLOC_FL_KEEP_SIZE} mode;
	loff_t expected_size;
	int lc;

	TST_TOTAL = 2;
	/* perform global test setup, call setup() function. */

	/* 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);
	}
	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);
}

/*****************************************************************************
 * 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(syscall(__NR_FALLOCATE, fd, mode, offset,len));
         /* check return code */
         if ( TEST_RETURN != 0 ) {
          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);
        	}
	}
	
}
/******************************************************************************
 *          			 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"

#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

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; 

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;

/******************************************************************************
 * 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));
                }
        }
}



/*****************************************************************************
 * Main function that calls the system call with the  appropriate parameters
 ******************************************************************************/
int
main(int   argc,    /* number of command line parameters                      */
        char **argv)   /* pointer to the array of the command line parameters.   */
{

	int test_index = 0;
	int lc;
	int fd;
	char fname[255];
	
	/* parse options. - Currently none */
	
	/* 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(syscall(__NR_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 ) {
		            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);
}

/******************************************************************************
 *          			 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"

#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

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;

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;

/******************************************************************************
 * 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));
		}
	}
}



/*****************************************************************************
 * Main function that calls the system call with the  appropriate parameters
 ******************************************************************************/
int
main(int   argc,    /* number of command line parameters                      */
        char **argv)   /* pointer to the array of the command line parameters.   */
{
	int test_index = 0;
	int lc;

	/* parse options. - Currently none */
	
	/* 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(syscall(__NR_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 ) {
		            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);
}
-------------------------------------------------------------------------
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

Reply via email to