From: Subrata <sub...@us...> - 2007-11-22 13:58:29
|
Update of /cvsroot/ltp/ltp/testcases/kernel/syscalls/fadvise In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv25899/ltp/testcases/kernel/syscalls/fadvise Added Files: Makefile posix_fadvise01.c posix_fadvise02.c posix_fadvise03.c posix_fadvise04.c Log Message: New posix_fadvise and fadvise64 Testcases contributed by Masatake YAMATO <ya...@re...> --- NEW FILE: posix_fadvise03.c --- /* * * Copyright (c) Red Hat Inc., 2007 * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * NAME * posix_fadvise03.c * * DESCRIPTION * Check the value that posix_fadvise returns for wrong ADVISE value. * * USAGE * posix_fadvise03 * * HISTORY * 11/2007 Initial version by Masatake YAMATO <ya...@re...> * * RESTRICTIONS * None */ #define _XOPEN_SOURCE 600 #include <fcntl.h> #include <unistd.h> #include <signal.h> #include <errno.h> #include <limits.h> #include "test.h" #include "usctest.h" void setup(); void cleanup(); char *TCID="posix_fadvise03"; /* Test program identifier. */ extern int Tst_count; /* Test Case counter for tst_* routines */ char fname[] = "/bin/cat"; /* test executable to open */ int fd = -1; /* initialized in open */ int expected_error = EINVAL; int defined_advise[] = { POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, POSIX_FADV_DONTNEED, }; #define defined_advise_total (sizeof(defined_advise) / sizeof(defined_advise[0])) #if 0 /* Too many test cases. */ int TST_TOTAL = (INT_MAX - defined_advise_total); int advise_limit = INT_MAX; #else int TST_TOTAL = (32 - defined_advise_total); int advise_limit = 32; #endif /* 0 */ /* is_defined_advise: Return 1 if advise is in defined_advise. Return 0 if not. */ static int is_defined_advise(int advise) { int i; for (i = 0; i < defined_advise_total; i++) { if (defined_advise[i] == advise) return 1; } return 0; } int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int advise; /* * parse standard options */ if ( (msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /* * perform global setup for test */ setup(); /* * check looping state if -i option given on the command line */ for (lc=0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count=0; /* loop through the test cases */ for (advise = 0; advise < advise_limit; advise++) { /* Don't use defiend advise as an argument. */ if (is_defined_advise(advise)) { continue; } TEST(posix_fadvise(fd, 0, 0, advise)); if (TEST_RETURN == 0) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } /* Man page says: "On error, an error number is returned." */ if (TEST_RETURN == expected_error) { tst_resm(TPASS, "expected failure - " "returned value = %d, advise = %d : %s", TEST_RETURN, advise, strerror(TEST_RETURN)); } else { tst_resm(TFAIL, "unexpected returnd value - %d : %s, advise %d - " "expected %d", TEST_RETURN, strerror(TEST_RETURN), advise, expected_error); } } } /* End for TEST_LOOPING */ /* * cleanup and exit */ cleanup(); return(0); } /* End main */ /* * setup() - performs all ONE TIME setup for this test. */ void setup() { /* capture signals */ tst_sig(NOFORK, DEF_HANDLER, cleanup); /* Pause if that option was specified */ TEST_PAUSE; fd = open(fname, O_RDONLY); if (fd < 0) { tst_brkm(TBROK, cleanup, "Unable to open a file(\"%s\") for test: %s\n", fname,strerror(errno)); } } /* End setup() */ /* * cleanup() - performs all ONE TIME cleanup for this test at * completion or premature exit. */ void cleanup() { /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; if (fd != -1) { close(fd); } /* exit with return code appropriate for results */ tst_exit(); } /* End cleanup() */ --- NEW FILE: posix_fadvise04.c --- /* * * Copyright (c) Red Hat Inc., 2007 * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * NAME * posix_fadvise04.c * * DESCRIPTION * Check the value that posix_fadvise returns for pipe descriptor. * * USAGE * posix_fadvise04 * * HISTORY * 11/2007 Initial version by Masatake YAMATO <ya...@re...> * * RESTRICTIONS * None */ #define _XOPEN_SOURCE 600 #include <fcntl.h> #include <unistd.h> #include <signal.h> #include <errno.h> #include "test.h" #include "usctest.h" void setup(); void cleanup(); char *TCID="posix_fadvise04"; /* Test program identifier. */ extern int Tst_count; /* Test Case counter for tst_* routines */ #define GIVEN_IN_SETUP 42 /* No mean. Just used as padding. This is overwritten by setup(). */ struct test_case_t { int fd; off_t offset; off_t len; int advice; int error; } TC[] = { {GIVEN_IN_SETUP, 0, 0, POSIX_FADV_NORMAL, ESPIPE}, {GIVEN_IN_SETUP, 0, 0, POSIX_FADV_SEQUENTIAL, ESPIPE}, {GIVEN_IN_SETUP, 0, 0, POSIX_FADV_RANDOM, ESPIPE}, {GIVEN_IN_SETUP, 0, 0, POSIX_FADV_NOREUSE, ESPIPE}, {GIVEN_IN_SETUP, 0, 0, POSIX_FADV_WILLNEED, ESPIPE}, {GIVEN_IN_SETUP, 0, 0, POSIX_FADV_DONTNEED, ESPIPE}, }; int TST_TOTAL = sizeof(TC) / sizeof(TC[0]); int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int i; /* * parse standard options */ if ( (msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /* * perform global setup for test */ setup(); /* * check looping state if -i option given on the command line */ for (lc=0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count=0; /* loop through the test cases */ for (i = 0; i < TST_TOTAL; i++) { TEST(posix_fadvise(TC[i].fd, TC[i].offset, TC[i].len, TC[i].advice)); if (TEST_RETURN == 0) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } /* Man page says: "On error, an error number is returned." */ if (TEST_RETURN == TC[i].error) { tst_resm(TPASS, "expected failure - " "returned value = %d : %s", TEST_RETURN, strerror(TEST_RETURN)); } else { tst_resm(TFAIL, "unexpected returnd value - %d : %s - " "expected %d", TEST_RETURN, strerror(TEST_RETURN), TC[i].error); } } } /* End for TEST_LOOPING */ /* * cleanup and exit */ cleanup(); return(0); } /* End main */ /* * setup() - performs all ONE TIME setup for this test. */ void setup() { int pipedes[2]; /* capture signals */ tst_sig(NOFORK, DEF_HANDLER, cleanup); /* Pause if that option was specified */ TEST_PAUSE; /* Make a pipe */ if (pipe(pipedes) != 0) { tst_brkm(TBROK, cleanup, "Untable to make a pipe: %s\n", strerror(errno)); } else { int i; /* Close write side first. I don't use it in test. */ close(pipedes[1]); /* Fill fd field of all test cases with read side of pipe. */ for (i = 0; i < TST_TOTAL; i++) { TC[i].fd = pipedes[0]; } } } /* End setup() */ /* * cleanup() - performs all ONE TIME cleanup for this test at * completion or premature exit. */ void cleanup() { /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; /* Close pipe of read side */ close(TC[0].fd); /* exit with return code appropriate for results */ tst_exit(); } /* End cleanup() */ --- NEW FILE: posix_fadvise01.c --- /* * * Copyright (c) Red Hat Inc., 2007 * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * NAME * posix_fadvise01.c * * DESCRIPTION * Check the value that posix_fadvise returns for wrong ADVISE value. * * USAGE * posix_fadvise01 * * HISTORY * 11/2007 Initial version by Masatake YAMATO <ya...@re...> * * RESTRICTIONS * None */ #define _XOPEN_SOURCE 600 #include <fcntl.h> #include <unistd.h> #include <signal.h> #include <errno.h> #include "test.h" #include "usctest.h" void setup(); void cleanup(); char *TCID="posix_fadvise01"; /* Test program identifier. */ extern int Tst_count; /* Test Case counter for tst_* routines */ char fname[] = "/bin/cat"; /* test executable to open */ int fd = -1; /* initialized in open */ int expected_return = 0; int defined_advise[] = { POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, POSIX_FADV_DONTNEED, }; #define defined_advise_total (sizeof(defined_advise) / sizeof(defined_advise[0])) int TST_TOTAL = defined_advise_total; int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int i; /* * parse standard options */ if ( (msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /* * perform global setup for test */ setup(); /* * check looping state if -i option given on the command line */ for (lc=0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count=0; /* loop through the test cases */ for (i = 0; i < defined_advise_total; i++) { TEST(posix_fadvise(fd, 0, 0, defined_advise[i])); /* Man page says: "On error, an error number is returned." */ if (TEST_RETURN == expected_return) { tst_resm(TPASS, "call succeeded expectedly"); } else { tst_resm(TFAIL, "unexpected returnd value - %d : %s, advise %d - " "expected %d", TEST_RETURN, strerror(TEST_RETURN), defined_advise[i], expected_return); } } } /* End for TEST_LOOPING */ /* * cleanup and exit */ cleanup(); return(0); } /* End main */ /* * setup() - performs all ONE TIME setup for this test. */ void setup() { /* capture signals */ tst_sig(NOFORK, DEF_HANDLER, cleanup); /* Pause if that option was specified */ TEST_PAUSE; fd = open(fname, O_RDONLY); if (fd < 0) { tst_brkm(TBROK, cleanup, "Unable to open a file(\"%s\") for test: %s\n", fname,strerror(errno)); } } /* End setup() */ /* * cleanup() - performs all ONE TIME cleanup for this test at * completion or premature exit. */ void cleanup() { /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; if (fd != -1) { close(fd); } /* exit with return code appropriate for results */ tst_exit(); } /* End cleanup() */ --- NEW FILE: posix_fadvise02.c --- /* * * Copyright (c) Red Hat Inc., 2007 * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * NAME * posix_fadvise02.c * * DESCRIPTION * Check the value that posix_fadvise returns for wrong file descriptor. * * USAGE * posix_fadvise02 * * HISTORY * 11/2007 Initial version by Masatake YAMATO <ya...@re...> * * RESTRICTIONS * None */ #define _XOPEN_SOURCE 600 #include <fcntl.h> #include <unistd.h> #include <signal.h> #include <errno.h> #include "test.h" #include "usctest.h" void setup(); void cleanup(); char *TCID="posix_fadvise02"; /* Test program identifier. */ extern int Tst_count; /* Test Case counter for tst_* routines */ #define WRONG_FD 42 /* The number has no meaning. Just used as something wrong fd */ struct test_case_t { int fd; off_t offset; off_t len; int advice; int error; } TC[] = { {WRONG_FD, 0, 0, POSIX_FADV_NORMAL, EBADF}, {WRONG_FD, 0, 0, POSIX_FADV_SEQUENTIAL, EBADF}, {WRONG_FD, 0, 0, POSIX_FADV_RANDOM, EBADF}, {WRONG_FD, 0, 0, POSIX_FADV_NOREUSE, EBADF}, {WRONG_FD, 0, 0, POSIX_FADV_WILLNEED, EBADF}, {WRONG_FD, 0, 0, POSIX_FADV_DONTNEED, EBADF}, }; int TST_TOTAL = sizeof(TC) / sizeof(TC[0]); int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int i; /* * parse standard options */ if ( (msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /* * perform global setup for test */ setup(); /* * check looping state if -i option given on the command line */ for (lc=0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count=0; /* loop through the test cases */ for (i = 0; i < TST_TOTAL; i++) { TEST(posix_fadvise(TC[i].fd, TC[i].offset, TC[i].len, TC[i].advice)); if (TEST_RETURN == 0) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } /* Man page says: "On error, an error number is returned." */ if (TEST_RETURN == TC[i].error) { tst_resm(TPASS, "expected failure - " "returned value = %d : %s", TEST_RETURN, strerror(TEST_RETURN)); } else { tst_resm(TFAIL, "unexpected returnd value - %d : %s - " "expected %d", TEST_RETURN, strerror(TEST_RETURN), TC[i].error); } } } /* End for TEST_LOOPING */ /* * cleanup and exit */ cleanup(); return(0); } /* End main */ /* * setup() - performs all ONE TIME setup for this test. */ void setup() { /* capture signals */ tst_sig(NOFORK, DEF_HANDLER, cleanup); /* Pause if that option was specified */ TEST_PAUSE; /* Make WRONG_FD really wrong. */ retry: errno = 0; if (close(WRONG_FD) != 0) { if (errno == EBADF) ; /* Good. Do nothing. */ if (errno == EINTR) goto retry; else if (errno == EIO) tst_brkm(TBROK, cleanup, "Unable to close a file descriptor(%d): %s\n", WRONG_FD, strerror(EIO)); } } /* End setup() */ /* * cleanup() - performs all ONE TIME cleanup for this test at * completion or premature exit. */ void cleanup() { /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; /* exit with return code appropriate for results */ tst_exit(); } /* End cleanup() */ --- NEW FILE: Makefile --- # # Copied from ../open/Makefile by Masatake YAMATO # ### # # 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 posix_fadvise[0-9][0-9].c) TARGETS = $(patsubst %.c,%,$(SRCS)) $(patsubst %.c,%_64,$(SRCS)) %_64.c: %.c echo "#define _FILE_OFFSET_BITS 64" > $@ cat $< >> $@ all: $(TARGETS) install: @set -e; for i in $(TARGETS); do ln -f $$i ../../../bin/$$i ; done clean: rm -f $(TARGETS) |