Ping. :)

Best regards,
Zeng

On Fri, 2014-06-27 at 10:02 +0800, Zeng Linggang wrote:
> * Add EINVAL errno testes for timerfd_create(2)
>       - The clockid argument is neither CLOCK_MONOTONIC nor CLOCK_REALTIME,
>         EINVAL would return.
>       - flags is invalid, EINVAL would return.
> 
> * Add EBADF, EFAULT and EINVAL errno testes for timerfd_gettime(2)
>       - fd is not a valid file descriptor, EBADF would return.
>       - curr_value is not valid a pointer, EFAULT would return.
>       - fd is not a valid timerfd file descriptor, EINVAL would return.
> 
> * Add EBADF, EFAULT and EINVAL errno testes for timerfd_settime(2)
>       - fd is not a valid file descriptor, EBADF would return.
>       - old_value is not valid a pointer, EFAULT would return.
>       - fd is not a valid timerfd file descriptor, EINVAL would return.
>       - flags is invalid, EINVAL would return.
> 
> Signed-off-by: Zeng Linggang <zenglg...@cn.fujitsu.com>
> ---
>  configure.ac                                       |   1 +
>  include/lapi/timerfd.h                             |  52 ++++++++
>  m4/ltp-timerfd.m4                                  |  26 ++++
>  runtest/syscalls                                   |   3 +
>  testcases/kernel/syscalls/.gitignore               |   3 +
>  .../kernel/syscalls/timerfd/timerfd_create01.c     | 106 ++++++++++++++++
>  .../kernel/syscalls/timerfd/timerfd_gettime01.c    | 131 ++++++++++++++++++++
>  .../kernel/syscalls/timerfd/timerfd_settime01.c    | 136 
> +++++++++++++++++++++
>  8 files changed, 458 insertions(+)
>  create mode 100644 include/lapi/timerfd.h
>  create mode 100644 m4/ltp-timerfd.m4
>  create mode 100644 testcases/kernel/syscalls/timerfd/timerfd_create01.c
>  create mode 100644 testcases/kernel/syscalls/timerfd/timerfd_gettime01.c
>  create mode 100644 testcases/kernel/syscalls/timerfd/timerfd_settime01.c
> 
> diff --git a/configure.ac b/configure.ac
> index ceb1d18..036cdd9 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -186,5 +186,6 @@ LTP_CHECK_TIRPC
>  LTP_CHECK_TEE
>  LTP_CHECK_SPLICE
>  LTP_CHECK_VMSPLICE
> +LTP_CHECK_TIMERFD
>  
>  AC_OUTPUT
> diff --git a/include/lapi/timerfd.h b/include/lapi/timerfd.h
> new file mode 100644
> index 0000000..f574ecf
> --- /dev/null
> +++ b/include/lapi/timerfd.h
> @@ -0,0 +1,52 @@
> +/*
> + * Copyright (c) International Business Machines  Corp., 2007
> + * Copyright (c) 2014 Fujitsu Ltd.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +#ifndef TIMERFD_H
> +#define TIMERFD_H
> +
> +#include <time.h>
> +#include "config.h"
> +#include "linux_syscall_numbers.h"
> +
> +#ifdef HAVE_SYS_TIMERFD_H
> +#include <sys/timerfd.h>
> +#endif
> +
> +#if !defined(HAVE_TIMERFD_CREATE)
> +int timerfd_create(int clockid, int flags)
> +{
> +     return ltp_syscall(__NR_timerfd_create, clockid, flags);
> +}
> +#endif
> +
> +#if !defined(HAVE_TIMERFD_GETTIME)
> +int timerfd_settime(int fd, int flags, const struct itimerspec *new_value,
> +                 struct itimerspec *old_value)
> +{
> +     return ltp_syscall(__NR_timerfd_settime, fd, flags, new_value,
> +                        old_value);
> +}
> +#endif
> +
> +#if !defined(HAVE_TIMERFD_SETTIME)
> +int timerfd_gettime(int fd, struct itimerspec *curr_value)
> +{
> +     return ltp_syscall(__NR_timerfd_gettime, fd, curr_value);
> +}
> +#endif
> +
> +#endif /* TIMERFD_H */
> diff --git a/m4/ltp-timerfd.m4 b/m4/ltp-timerfd.m4
> new file mode 100644
> index 0000000..a86a3a2
> --- /dev/null
> +++ b/m4/ltp-timerfd.m4
> @@ -0,0 +1,26 @@
> +dnl
> +dnl Copyright (c) Linux Test Project, 2014
> +dnl
> +dnl This program is free software;  you can redistribute it and/or modify
> +dnl it under the terms of the GNU General Public License as published by
> +dnl the Free Software Foundation; either version 2 of the License, or
> +dnl (at your option) any later version.
> +dnl
> +dnl This program is distributed in the hope that it will be useful,
> +dnl but WITHOUT ANY WARRANTY;  without even the implied warranty of
> +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> +dnl the GNU General Public License for more details.
> +dnl
> +dnl You should have received a copy of the GNU General Public License
> +dnl along with this program;  if not, write to the Free Software
> +dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> +dnl
> +
> +dnl
> +dnl LTP_CHECK_TIMERFD
> +dnl ----------------------------
> +dnl
> +AC_DEFUN([LTP_CHECK_TIMERFD],[
> +AC_CHECK_FUNCS([timerfd_create timerfd_settime timerfd_gettime])
> +AC_CHECK_HEADERS([sys/timerfd.h])
> +])
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 1c8eefa..7bf0ead 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1252,6 +1252,9 @@ times03 times03
>  timerfd01 timerfd01
>  timerfd02 timerfd02
>  timerfd03 timerfd03
> +timerfd_create01 timerfd_create01
> +timerfd_gettime01 timerfd_gettime01
> +timerfd_settime01 timerfd_settime01
>  
>  timer_getoverrun01 timer_getoverrun01
>  timer_gettime01 timer_gettime01
> diff --git a/testcases/kernel/syscalls/.gitignore 
> b/testcases/kernel/syscalls/.gitignore
> index 83b1a38..8bf55fe 100644
> --- a/testcases/kernel/syscalls/.gitignore
> +++ b/testcases/kernel/syscalls/.gitignore
> @@ -964,6 +964,9 @@
>  /timerfd/timerfd01
>  /timerfd/timerfd02
>  /timerfd/timerfd03
> +/timerfd/timerfd_create01
> +/timerfd/timerfd_gettime01
> +/timerfd/timerfd_settime01
>  /times/times01
>  /times/times03
>  /tkill/tkill01
> diff --git a/testcases/kernel/syscalls/timerfd/timerfd_create01.c 
> b/testcases/kernel/syscalls/timerfd/timerfd_create01.c
> new file mode 100644
> index 0000000..4793928
> --- /dev/null
> +++ b/testcases/kernel/syscalls/timerfd/timerfd_create01.c
> @@ -0,0 +1,106 @@
> +/*
> + * Copyright (c) 2014 Fujitsu Ltd.
> + * Author: Zeng Linggang <zenglg...@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +/*
> + * DESCRIPTION
> + *  Verify that,
> + *   1. The clockid argument is neither CLOCK_MONOTONIC nor CLOCK_REALTIME,
> + *   EINVAL would return.
> + *   2. flags is invalid, EINVAL would return.
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <errno.h>
> +
> +#include "test.h"
> +#include "usctest.h"
> +#include "lapi/timerfd.h"
> +
> +char *TCID = "timerfd_create01";
> +
> +static struct test_case_t {
> +     int clockid;
> +     int flags;
> +     int exp_errno;
> +} test_cases[] = {
> +     {-1, 0, EINVAL},
> +     {0, -1, EINVAL},
> +};
> +
> +int TST_TOTAL = ARRAY_SIZE(test_cases);
> +static void setup(void);
> +static void timerfd_create_verify(const struct test_case_t *);
> +static void cleanup(void);
> +static int exp_enos[] = { EINVAL, 0 };
> +
> +int main(int argc, char *argv[])
> +{
> +     int lc;
> +     const char *msg;
> +     int i;
> +
> +     msg = parse_opts(argc, argv, NULL, NULL);
> +     if (msg != NULL)
> +             tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> +     setup();
> +
> +     for (lc = 0; TEST_LOOPING(lc); lc++) {
> +             tst_count = 0;
> +             for (i = 0; i < TST_TOTAL; i++)
> +                     timerfd_create_verify(&test_cases[i]);
> +     }
> +
> +     cleanup();
> +     tst_exit();
> +}
> +
> +static void setup(void)
> +{
> +     if ((tst_kvercmp(2, 6, 25)) < 0)
> +             tst_brkm(TCONF, NULL, "This test needs kernel 2.6.25 or newer");
> +
> +     tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +
> +     TEST_PAUSE;
> +
> +     TEST_EXP_ENOS(exp_enos);
> +}
> +
> +static void timerfd_create_verify(const struct test_case_t *test)
> +{
> +     TEST(timerfd_create(test->clockid, test->flags));
> +
> +     if (TEST_RETURN != -1) {
> +             tst_resm(TFAIL, "timerfd_create() succeeded unexpectedly");
> +             return;
> +     }
> +
> +     if (TEST_ERRNO == test->exp_errno) {
> +             tst_resm(TPASS | TTERRNO,
> +                      "timerfd_create() failed as expected");
> +     } else {
> +             tst_resm(TFAIL | TTERRNO,
> +                      "timerfd_create() failed unexpectedly; expected: "
> +                      "%d - %s", test->exp_errno, strerror(test->exp_errno));
> +     }
> +}
> +
> +static void cleanup(void)
> +{
> +     TEST_CLEANUP;
> +}
> diff --git a/testcases/kernel/syscalls/timerfd/timerfd_gettime01.c 
> b/testcases/kernel/syscalls/timerfd/timerfd_gettime01.c
> new file mode 100644
> index 0000000..f8d07fb
> --- /dev/null
> +++ b/testcases/kernel/syscalls/timerfd/timerfd_gettime01.c
> @@ -0,0 +1,131 @@
> +/*
> + * Copyright (c) 2014 Fujitsu Ltd.
> + * Author: Zeng Linggang <zenglg...@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +/*
> + * DESCRIPTION
> + *  Verify that,
> + *   1. fd is not a valid file descriptor, EBADF would return.
> + *   2. curr_value is not valid a pointer, EFAULT would return.
> + *   3. fd is not a valid timerfd file descriptor, EINVAL would return.
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <errno.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +
> +#include "test.h"
> +#include "usctest.h"
> +#include "safe_macros.h"
> +#include "lapi/timerfd.h"
> +
> +char *TCID = "timerfd_gettime01";
> +
> +static int bad_clockfd = -1;
> +static int clockfd;
> +static int fd;
> +
> +static struct test_case_t {
> +     int *fd;
> +     struct itimerspec *curr_value;
> +     int exp_errno;
> +} test_cases[] = {
> +     {&bad_clockfd, NULL, EBADF},
> +     {&clockfd, (struct itimerspec *)-1, EFAULT},
> +     {&fd, NULL, EINVAL},
> +};
> +
> +int TST_TOTAL = ARRAY_SIZE(test_cases);
> +static void setup(void);
> +static void timerfd_gettime_verify(const struct test_case_t *);
> +static void cleanup(void);
> +static int exp_enos[] = { EBADF, EFAULT, EINVAL, 0 };
> +
> +int main(int argc, char *argv[])
> +{
> +     int lc;
> +     const char *msg;
> +     int i;
> +
> +     msg = parse_opts(argc, argv, NULL, NULL);
> +     if (msg != NULL)
> +             tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> +     setup();
> +
> +     for (lc = 0; TEST_LOOPING(lc); lc++) {
> +             tst_count = 0;
> +             for (i = 0; i < TST_TOTAL; i++)
> +                     timerfd_gettime_verify(&test_cases[i]);
> +     }
> +
> +     cleanup();
> +     tst_exit();
> +}
> +
> +static void setup(void)
> +{
> +     if ((tst_kvercmp(2, 6, 25)) < 0)
> +             tst_brkm(TCONF, NULL, "This test needs kernel 2.6.25 or newer");
> +
> +     tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +
> +     TEST_PAUSE;
> +
> +     TEST_EXP_ENOS(exp_enos);
> +
> +     tst_tmpdir();
> +
> +     clockfd = timerfd_create(CLOCK_REALTIME, 0);
> +     if (clockfd == -1)
> +             tst_brkm(TBROK | TERRNO, cleanup, "timerfd_create() fail");
> +
> +     fd = SAFE_OPEN(cleanup, "test_file", O_RDWR | O_CREAT, 0644);
> +}
> +
> +static void timerfd_gettime_verify(const struct test_case_t *test)
> +{
> +     TEST(timerfd_gettime(*test->fd, test->curr_value));
> +
> +     if (TEST_RETURN != -1) {
> +             tst_resm(TFAIL, "timerfd_gettime() succeeded unexpectedly");
> +             return;
> +     }
> +
> +     if (TEST_ERRNO == test->exp_errno) {
> +             tst_resm(TPASS | TTERRNO,
> +                      "timerfd_gettime() failed as expected");
> +     } else {
> +             tst_resm(TFAIL | TTERRNO,
> +                      "timerfd_gettime() failed unexpectedly; expected: "
> +                      "%d - %s", test->exp_errno, strerror(test->exp_errno));
> +     }
> +}
> +
> +static void cleanup(void)
> +{
> +     TEST_CLEANUP;
> +
> +     if (clockfd > 0)
> +             close(clockfd);
> +
> +     if (fd > 0)
> +             close(fd);
> +
> +     tst_rmdir();
> +}
> diff --git a/testcases/kernel/syscalls/timerfd/timerfd_settime01.c 
> b/testcases/kernel/syscalls/timerfd/timerfd_settime01.c
> new file mode 100644
> index 0000000..d12e40a
> --- /dev/null
> +++ b/testcases/kernel/syscalls/timerfd/timerfd_settime01.c
> @@ -0,0 +1,136 @@
> +/*
> + * Copyright (c) 2014 Fujitsu Ltd.
> + * Author: Zeng Linggang <zenglg...@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +/*
> + * DESCRIPTION
> + *  Verify that,
> + *   1. fd is not a valid file descriptor, EBADF would return.
> + *   2. old_value is not valid a pointer, EFAULT would return.
> + *   3. fd is not a valid timerfd file descriptor, EINVAL would return.
> + *   4. flags is invalid, EINVAL would return.
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <errno.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +
> +#include "test.h"
> +#include "usctest.h"
> +#include "safe_macros.h"
> +#include "lapi/timerfd.h"
> +
> +char *TCID = "timerfd_settime01";
> +
> +static int bad_clockfd = -1;
> +static int clockfd;
> +static int fd;
> +
> +static struct test_case_t {
> +     int *fd;
> +     int flags;
> +     struct itimerspec *old_value;
> +     int exp_errno;
> +} test_cases[] = {
> +     {&bad_clockfd, 0, NULL, EBADF},
> +     {&clockfd, 0, (struct itimerspec *)-1, EFAULT},
> +     {&fd, 0, NULL, EINVAL},
> +     {&clockfd, -1, NULL, EINVAL},
> +};
> +
> +int TST_TOTAL = ARRAY_SIZE(test_cases);
> +static void setup(void);
> +static void timerfd_settime_verify(const struct test_case_t *);
> +static void cleanup(void);
> +static int exp_enos[] = { EBADF, EFAULT, EINVAL, 0 };
> +
> +int main(int argc, char *argv[])
> +{
> +     int lc;
> +     const char *msg;
> +     int i;
> +
> +     msg = parse_opts(argc, argv, NULL, NULL);
> +     if (msg != NULL)
> +             tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> +     setup();
> +
> +     for (lc = 0; TEST_LOOPING(lc); lc++) {
> +             tst_count = 0;
> +             for (i = 0; i < TST_TOTAL; i++)
> +                     timerfd_settime_verify(&test_cases[i]);
> +     }
> +
> +     cleanup();
> +     tst_exit();
> +}
> +
> +static void setup(void)
> +{
> +     if ((tst_kvercmp(2, 6, 25)) < 0)
> +             tst_brkm(TCONF, NULL, "This test needs kernel 2.6.25 or newer");
> +
> +     tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +
> +     TEST_PAUSE;
> +
> +     TEST_EXP_ENOS(exp_enos);
> +
> +     tst_tmpdir();
> +
> +     clockfd = timerfd_create(CLOCK_REALTIME, 0);
> +     if (clockfd == -1)
> +             tst_brkm(TBROK | TERRNO, cleanup, "timerfd_create() fail");
> +
> +     fd = SAFE_OPEN(cleanup, "test_file", O_RDWR | O_CREAT, 0644);
> +}
> +
> +static void timerfd_settime_verify(const struct test_case_t *test)
> +{
> +     struct itimerspec new_value;
> +     TEST(timerfd_settime(*test->fd, test->flags, &new_value,
> +                          test->old_value));
> +
> +     if (TEST_RETURN != -1) {
> +             tst_resm(TFAIL, "timerfd_settime() succeeded unexpectedly");
> +             return;
> +     }
> +
> +     if (TEST_ERRNO == test->exp_errno) {
> +             tst_resm(TPASS | TTERRNO,
> +                      "timerfd_settime() failed as expected");
> +     } else {
> +             tst_resm(TFAIL | TTERRNO,
> +                      "timerfd_settime() failed unexpectedly; expected: "
> +                      "%d - %s", test->exp_errno, strerror(test->exp_errno));
> +     }
> +}
> +
> +static void cleanup(void)
> +{
> +     TEST_CLEANUP;
> +
> +     if (clockfd > 0)
> +             close(clockfd);
> +
> +     if (fd > 0)
> +             close(fd);
> +
> +     tst_rmdir();
> +}



------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to