From: Dai Shili <daisl.fnst@fujitsu.com>
To: <ltp@lists.linux.it>
Subject: [LTP] [PATCH 1/2] syscalls/fcntl12: Convert to new API
Date: Fri, 3 Dec 2021 16:16:43 -0500 [thread overview]
Message-ID: <1638566204-6212-1-git-send-email-daisl.fnst@fujitsu.com> (raw)
1) use SAFE macro
2) use TST_EXP_FAIL2 macro
Signed-off-by: Dai Shili <daisl.fnst@fujitsu.com>
---
testcases/kernel/syscalls/fcntl/fcntl12.c | 135 ++++++++----------------------
1 file changed, 36 insertions(+), 99 deletions(-)
diff --git a/testcases/kernel/syscalls/fcntl/fcntl12.c b/testcases/kernel/syscalls/fcntl/fcntl12.c
index ae382dd..e4dbe42 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl12.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl12.c
@@ -1,120 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- *
- * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) Linux Test Project, 2021
+ * Copyright (c) International Business Machines Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
*/
-/*
- * NAME
- * fcntl12.c
+/*\
+ * [Description]
*
- * DESCRIPTION
- * Testcase to test that fcntl() sets EMFILE for F_DUPFD command.
+ * Tests basic error handling of the fcntl syscall.
*
- * ALGORITHM
- * Get the size of the descriptor table of a process, by calling the
- * getdtablesize() system call. Then attempt to use the F_DUPFD command
- * for fcntl(), which should fail with EMFILE.
- *
- * USAGE
- * fcntl12
- *
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- * NONE
+ * - EMFILE when cmd refers to F_DUPFD after gets the size of the descriptor table of a process
*/
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <errno.h>
-#include "test.h"
+#include <stdlib.h>
+#include "tst_test.h"
-char *TCID = "fcntl12";
-int TST_TOTAL = 1;
+static pid_t pid;
+static char fname[20] = "testfile";
+static int fd = -1;
+static int i, max_files;
-int fail;
-char fname[20];
-void setup(void);
-void cleanup(void);
-
-int main(int ac, char **av)
+static void verify_fcntl(void)
{
- int lc;
-
- pid_t pid;
- int fd, i, status, max_files;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- /* check for looping state if -i option is given */
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
-
- tst_resm(TINFO, "Test for errno EMFILE");
- fail = 0;
-
- pid = FORK_OR_VFORK();
- if (pid < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "Fork failed");
- } else if (pid == 0) {
- max_files = getdtablesize();
- for (i = 0; i < max_files; i++) {
- if ((fd = open(fname, O_CREAT | O_RDONLY,
- 0444)) == -1) {
- break;
- }
- }
-
- if (fcntl(1, F_DUPFD, 1) != -1) {
- tst_resm(TFAIL, "fcntl failed to FAIL");
- exit(1);
- } else if (errno != EMFILE) {
- tst_resm(TFAIL, "Expected EMFILE got %d",
- errno);
- exit(1);
- }
- exit(0);
+ pid = SAFE_FORK();
+ if (pid == 0) {
+ max_files = getdtablesize();
+ for (i = 0; i < max_files; i++) {
+ fd = open(fname, O_CREAT | O_RDONLY, 0444);
+ if (fd == -1)
+ break;
}
- waitpid(pid, &status, 0);
- if (WEXITSTATUS(status) == 0)
- tst_resm(TPASS, "block 1 PASSED");
- else
- tst_resm(TFAIL, "block 1 FAILED");
+ TST_EXP_FAIL2(fcntl(1, F_DUPFD, 1), EMFILE,
+ "fcntl() got EMFILE");
}
- cleanup();
- tst_exit();
+ tst_reap_children();
+
}
-void setup(void)
+static void cleanup(void)
{
- tst_sig(FORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
+ if (fd > -1)
+ SAFE_CLOSE(fd);
- sprintf(fname, "fcnlt12.%d", getpid());
- tst_tmpdir();
+ SAFE_UNLINK(fname);
}
-void cleanup(void)
-{
- unlink(fname);
- tst_rmdir();
-}
+static struct tst_test test = {
+ .forks_child = 1,
+ .needs_tmpdir = 1,
+ .cleanup = cleanup,
+ .test_all = verify_fcntl,
+};
--
1.8.3.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2021-12-03 8:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-03 21:16 Dai Shili [this message]
2021-12-03 21:16 ` [LTP] [PATCH 2/2] syscalls/fcntl13: Convert to new API Dai Shili
2021-12-06 6:09 ` xuyang2018.jy
2021-12-06 6:06 ` [LTP] [PATCH 1/2] syscalls/fcntl12: " xuyang2018.jy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1638566204-6212-1-git-send-email-daisl.fnst@fujitsu.com \
--to=daisl.fnst@fujitsu.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox