[LTP] [PATCH v3 0/2] Convert syscalls/dup3_{01,02} to new API

xuyang2018.jy@fujitsu.com xuyang2018.jy@fujitsu.com
Tue Nov 16 06:30:49 CET 2021


Hi Qi

I pushed this patch set with modifying some minor things.

Thanks for your patch!

diff --git a/testcases/kernel/syscalls/dup3/dup3_01.c 
b/testcases/kernel/syscalls/dup3/dup3_01.c
index e8ed3a2..e34379b 100644
--- a/testcases/kernel/syscalls/dup3/dup3_01.c
+++ b/testcases/kernel/syscalls/dup3/dup3_01.c
@@ -5,8 +5,10 @@
   * Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com>
   * Ported to LTP - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>
   */
+
  /*\
   * [Description]
+ *
   * Testcase to check whether dup3() supports O_CLOEXEC flag.
   */

@@ -31,22 +33,17 @@ static struct tcase {

  static void cleanup(void)
  {
-       if (fd > 0)
+       if (fd > -1)
                 close(fd);
  }
+
  static void run(unsigned int i)
  {
         int ret;
         struct tcase *tc = tcases + i;
-
-       TEST(dup3(1, 4, tc->coe_flag));
+       TST_EXP_FD_SILENT(dup3(1, 4, tc->coe_flag), "dup3(1, 4, %d)", 
tc->coe_flag);

         fd = TST_RET;
-       if (TST_RET == -1) {
-               tst_res(TFAIL | TTERRNO, "%s failed", tc->desc);
-               goto free;
-       }
-
         ret = SAFE_FCNTL(fd, F_GETFD);
         if (tc->coe_flag) {
                 if (ret & FD_CLOEXEC)
@@ -59,9 +56,6 @@ static void run(unsigned int i)
                 else
                         tst_res(TPASS, "%s set close-on-exec flag", 
tc->desc);
         }
-
-free:
-       SAFE_CLOSE(fd);
  };

  static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/dup3/dup3_02.c 
b/testcases/kernel/syscalls/dup3/dup3_02.c
index e31a758..009b003 100644
--- a/testcases/kernel/syscalls/dup3/dup3_02.c
+++ b/testcases/kernel/syscalls/dup3/dup3_02.c
@@ -3,12 +3,15 @@
   * Copyright (c) 2013 Fujitsu Ltd.
   * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
   */
+
  /*\
   * [Description]
+ *
   * Test for various EINVAL error.
- * - EINVAL - oldfd is equal to newfd without using O_CLOEXEC flag
- * - EINVAL - oldfd is equal to newfd with using O_CLOEXEC flag
- * - EINVAL - flags contain an invalid value
+ *
+ * - oldfd is equal to newfd without using O_CLOEXEC flag
+ * - oldfd is equal to newfd with using O_CLOEXEC flag
+ * - flags contain an invalid value
   */

  #define _GNU_SOURCE
@@ -18,7 +21,7 @@
  #include "tst_test.h"
  #include "tst_safe_macros.h"

-static int old_fd;
+static int old_fd = 3;
  static int new_fd = 5;

  static struct tcase {
@@ -39,21 +42,7 @@ static void run(unsigned int i)
                 "dup3(%d, %d, %d)", *tc->oldfd, *tc->newfd, tc->flags);
  }

-static void setup(void)
-{
-       old_fd = SAFE_CREAT("testeinval.file", 0644);
-}
-
-static void cleanup(void)
-{
-       if (old_fd > 0)
-               SAFE_CLOSE(old_fd);
-}
-
  static struct tst_test test = {
         .tcnt = ARRAY_SIZE(tcases),
         .test = run,
-       .setup = setup,
-       .cleanup = cleanup,
-       .needs_tmpdir = 1,
  };

Best Regards
Yang Xu
> From: QI Fuli<qi.fuli@fujitsu.com>
>
> Convert syscalls/dup3_{01,02} to new API
>
> QI Fuli (2):
>    syscalls/dup3_01: Rewrite dup3_01 and convert it to new API
>    syscalls/dup3_02: Convert to new API
>
>   testcases/kernel/syscalls/dup3/dup3_01.c | 163 ++++++++---------------
>   testcases/kernel/syscalls/dup3/dup3_02.c | 119 +++++------------
>   2 files changed, 87 insertions(+), 195 deletions(-)
>


More information about the ltp mailing list