[LTP] [PATCH 2/2] fchdir/fchdir02: Convert to new API

tangmeng tangmeng@uniontech.com
Mon Nov 8 06:32:25 CET 2021


Signed-off-by: tangmeng <tangmeng@uniontech.com>
---
 testcases/kernel/syscalls/fchdir/fchdir02.c | 103 ++------------------
 1 file changed, 8 insertions(+), 95 deletions(-)

diff --git a/testcases/kernel/syscalls/fchdir/fchdir02.c b/testcases/kernel/syscalls/fchdir/fchdir02.c
index cf11bf6b9..b0ba9ad58 100644
--- a/testcases/kernel/syscalls/fchdir/fchdir02.c
+++ b/testcases/kernel/syscalls/fchdir/fchdir02.c
@@ -1,110 +1,23 @@
+// 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
  */

 /*
- * NAME
- *	fchdir02.c
- *
  * DESCRIPTION
  *	fchdir02 - try to cd into a bad directory (bad fd).
- *
- * CALLS
- *	fchdir()
- *
- * ALGORITHM
- *	loop if that option was specified
- *	call fchdir() with an invalid file descriptor
- *	check the errno value
- *	  issue a PASS message if we get EBADF - errno 9
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  fchdir02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
  */

-#include "test.h"
+#include "tst_test.h"

-#include <errno.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "fchdir02";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_fchdir(void)
 {
 	const int bad_fd = -5;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(fchdir(bad_fd));
-
-		if (TEST_RETURN != -1)
-			tst_brkm(TFAIL, cleanup, "call succeeded unexpectedly");
-
-		if (TEST_ERRNO == EBADF)
-			tst_resm(TPASS, "failed as expected with EBADF");
-		else
-			tst_brkm(TFAIL | TTERRNO, cleanup,
-				 "call failed unexpectedly");
-	}

-	cleanup();
-
-	tst_exit();
+	TST_EXP_FAIL(fchdir(bad_fd), EBADF);
 }

-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-}
-
-void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.test_all = verify_fchdir,
+	.needs_tmpdir = 1,
+};
--
2.20.1





More information about the ltp mailing list