All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 0/3] New library conversion for few system call tests
@ 2019-06-10  0:26 Sandeep Patil
  2019-06-10  0:26 ` [LTP] [PATCH v2 1/3] syscalls/adjtimex02: Convert to new library Sandeep Patil
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Sandeep Patil @ 2019-06-10  0:26 UTC (permalink / raw)
  To: ltp

Following series is a set of system call tests that are converted to new
library. Also deleted bdflush test at the same time. I have been going
through the system call tests alphabetically and convert them to new
library as applicable, so there will be more to come.

I have tested this on cuttlefish[1] and made sure they don't regress.

1. https://linuxplumbersconf.org/event/2/contributions/269/attachments/56/63/Kernel_Hacking_with_Cuttlefish.pdf

Sandeep Patil (3):
  syscalls/adjtimex02: Convert to new library
  syscalls/asyncio02: convert to new library.
  syscalls/bind01: convert to new library.

 .../kernel/syscalls/adjtimex/adjtimex02.c     | 313 +++++-------------
 testcases/kernel/syscalls/asyncio/.gitignore  |   1 -
 testcases/kernel/syscalls/asyncio/Makefile    |  23 --
 testcases/kernel/syscalls/asyncio/asyncio02.c | 294 ----------------
 testcases/kernel/syscalls/bind/bind01.c       | 198 +++--------
 testcases/kernel/syscalls/stat/stat02.c       |  93 ++++++
 6 files changed, 220 insertions(+), 702 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/asyncio/.gitignore
 delete mode 100644 testcases/kernel/syscalls/asyncio/Makefile
 delete mode 100644 testcases/kernel/syscalls/asyncio/asyncio02.c
 create mode 100644 testcases/kernel/syscalls/stat/stat02.c

-- 
2.22.0.rc2.383.gf4fbbf30c2-goog


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH v2 1/3] syscalls/adjtimex02: Convert to new library
  2019-06-10  0:26 [LTP] [PATCH v2 0/3] New library conversion for few system call tests Sandeep Patil
@ 2019-06-10  0:26 ` Sandeep Patil
  2019-07-04 12:51   ` Cyril Hrubis
  2019-06-10  0:26 ` [LTP] [PATCH v2 2/3] syscalls/asyncio02: convert " Sandeep Patil
  2019-06-10  0:26 ` [LTP] [PATCH v2 3/3] syscalls/bind01: " Sandeep Patil
  2 siblings, 1 reply; 9+ messages in thread
From: Sandeep Patil @ 2019-06-10  0:26 UTC (permalink / raw)
  To: ltp

remove UCLINUX checks along the way and simplify the test.

Signed-off-by: Sandeep Patil <sspatil@android.com>
---
v1->v2
======
- Remove the test case structure
- handle expected error numbers in one place (swich statement)

 .../kernel/syscalls/adjtimex/adjtimex02.c     | 313 +++++-------------
 1 file changed, 79 insertions(+), 234 deletions(-)

diff --git a/testcases/kernel/syscalls/adjtimex/adjtimex02.c b/testcases/kernel/syscalls/adjtimex/adjtimex02.c
index 492225f19..122e579cf 100644
--- a/testcases/kernel/syscalls/adjtimex/adjtimex02.c
+++ b/testcases/kernel/syscalls/adjtimex/adjtimex02.c
@@ -1,274 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0
+
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * 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.
- *
+ *  AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: adjtimex02
- *
- *    EXECUTED BY	: root / superuser
- *
- *    TEST TITLE	: Tests for error conditions
- *
- *    TEST CASE TOTAL	: 6
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	Verify that
- *	1) adjtimex(2) fails with errno set to EFAULT if buf does
- *	   not point to writable memory
- *	2) adjtimex(2) fails with errno set to EINVAL if an attempt
- *	   is  made  to set buf.tick to a value < 900000/HZ
- *	3) adjtimex(2) fails with errno set to EINVAL if an attempt
- *	   is  made  to set buf.tick to a value > 1100000/HZ
- *	4) adjtimex(2) fails with errno set to EINVAL if an attempt
- *	   is  made  to set buf.offset to a value > 512000L
- *	   (This test case will be executed only if the kernel version
- *	    is 2.6.25 or below)
- *	5) adjtimex(2) fails with errno set to EINVAL if an attempt
- *	   is  made  to set buf.offset to a value < 512000L
- *	   (This test case will be executed only if the kernel version
- *	    is 2.6.25 or below)
- *	6) adjtimex(2) fails with errno set to EPERM if buf.mode is
- *	   non-zero and the user is not super-user.
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *	  Save current parameters in tim_save
- *
- * 	Test:
- *	 Loop if the proper options are given.
- *	  Call test case specific setup if needed
- * 	  call adjtimex with saved timex structure
- *	  Check return value is between 0 & 5
- *		Test passed
- *	  Otherwise
- *		Test failed
- *	  Call test case specific cleanup if needed
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- * adjtimex02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
-
-#if defined UCLINUX && !__THROW
-/* workaround for libc bug causing failure in sys/timex.h */
-#define __THROW
-#endif
 
 #include <errno.h>
 #include <sys/timex.h>
 #include <unistd.h>
 #include <pwd.h>
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 #define SET_MODE ( ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR | \
 	ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK )
 
-static void setup(void);
-static int setup2(void);
-static int setup3(void);
-static int setup4(void);
-static int setup5(void);
-static int setup6(void);
-static void cleanup(void);
-static void cleanup6(void);
-
-char *TCID = "adjtimex02";
-
 static int hz;			/* HZ from sysconf */
 
 static struct timex tim_save;
 static struct timex buff;
 
-static char nobody_uid[] = "nobody";
 struct passwd *ltpuser;
 
-struct test_cases_t {
-	struct timex *buffp;
-	int (*setup) ();
-	void (*cleanup) ();
-	int exp_errno;
-} test_cases[] = {
-#ifndef UCLINUX
-	/* Skip since uClinux does not implement memory protection */
-	{
-	(struct timex *)-1, NULL, NULL, EFAULT},
-#endif
-	{
-	&buff, setup2, NULL, EINVAL}, {
-	&buff, setup3, NULL, EINVAL}, {
-	&buff, setup4, NULL, EINVAL}, {
-	&buff, setup5, NULL, EINVAL}, {
-	&buff, setup6, cleanup6, EPERM}
-};
-
-int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
-
-int main(int ac, char **av)
+void verify_adjtimex(unsigned int nr)
 {
-
-	int lc, i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; ++i) {
-			/*
-			 * since Linux 2.6.26, if buf.offset value is outside
-			 * the acceptable range, it is simply normalized instead
-			 * of letting the syscall fail. so just skip this test
-			 * case.
-			 */
-			if ((i == 3 || i == 4) && tst_kvercmp(2, 6, 25) > 0) {
-				tst_resm(TCONF, "this kernel normalizes buf."
-					 "offset value if it is outside"
-					 " the acceptable range.");
-				continue;
-			}
-
-			buff = tim_save;
-			buff.modes = SET_MODE;
-			if ((test_cases[i].setup) && (test_cases[i].setup())) {
-				tst_resm(TWARN, "setup() failed, skipping"
-					 " this test case");
-				continue;
-			}
-
-			/* Call adjtimex(2) */
-			TEST(adjtimex(test_cases[i].buffp));
-
-			if ((TEST_RETURN == -1) && (TEST_ERRNO ==
-						    test_cases[i].exp_errno)) {
-				tst_resm(TPASS | TTERRNO,
-					 "Test Passed, adjtimex() returned -1");
-			} else {
-				tst_resm(TFAIL | TTERRNO,
-					 "Test Failed, adjtimex() returned %ld",
-					 TEST_RETURN);
-			}
-			if (test_cases[i].cleanup) {
-				test_cases[i].cleanup();
-			}
-		}
+	struct timex *buffp;
+	int expected_errno = 0;
+
+	/*
+	 * since Linux 2.6.26, if buf.offset value is outside
+	 * the acceptable range, it is simply normalized instead
+	 * of letting the syscall fail. so just skip this test
+	 * case.
+	 */
+	if (nr > 3 && (tst_kvercmp(2, 6, 25) > 0)) {
+		tst_res(TCONF, "this kernel normalizes buf."
+				"offset value if it is outside"
+				" the acceptable range.");
+		return;
 	}
 
-	/* cleanup and exit */
-	cleanup();
+	buff = tim_save;
+	buff.modes = SET_MODE;
+	buffp = &buff;
+	switch (nr) {
+	case 0:
+		buffp = (struct timex *)-1;
+		expected_errno = EFAULT;
+		break;
+	case 1:
+		buff.tick = 900000 / hz - 1;
+		expected_errno = EINVAL;
+		break;
+	case 2:
+		buff.tick = 1100000 / hz + 1;
+		expected_errno = EINVAL;
+		break;
+	case 3:
+		/* Switch to nobody user for correct error code collection */
+		ltpuser = SAFE_GETPWNAM("nobody");
+		SAFE_SETEUID(ltpuser->pw_uid);
+		expected_errno = EPERM;
+		break;
+	case 4:
+		buff.offset = 512000L + 1;
+		expected_errno = EINVAL;
+		break;
+	case 5:
+		buff.offset = (-1) * (512000L) - 1;
+		expected_errno = EINVAL;
+		break;
+	default:
+		tst_brk(TFAIL, "Invalid test case %u ", nr);
+	}
 
-	tst_exit();
+	TEST(adjtimex(buffp));
+	if ((TST_RET == -1) && (TST_ERR == expected_errno)) {
+		tst_res(TPASS | TTERRNO,
+				"adjtimex() error %u ", expected_errno);
+	} else {
+		tst_res(TFAIL | TTERRNO,
+				"Test Failed, adjtimex() returned %ld",
+				TST_RET);
+	}
 
+	/* clean up after ourselves */
+	if (nr == 3)
+		SAFE_SETEUID(0);
 }
 
-/* setup() - performs all ONE TIME setup for this test */
 void setup(void)
 {
-	tst_require_root();
-
 	tim_save.modes = 0;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
 	/* set the HZ from sysconf */
-	hz = SAFE_SYSCONF(NULL, _SC_CLK_TCK);
+	hz = SAFE_SYSCONF(_SC_CLK_TCK);
 
-	TEST_PAUSE;
-
-	/* Save current parameters in tim_save */
-	if ((adjtimex(&tim_save)) == -1) {
-		tst_brkm(TBROK, NULL, "Failed to save current parameters");
-	}
+	/* Save current parameters */
+	if ((adjtimex(&tim_save)) == -1)
+		tst_brk(TBROK | TERRNO,
+				"adjtimex(): failed to save current params");
 }
 
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
 void cleanup(void)
 {
-
 	tim_save.modes = SET_MODE;
-	/* Restore saved parameters */
-	if ((adjtimex(&tim_save)) == -1) {
-		tst_resm(TWARN, "Failed to restore saved parameters");
-	}
-}
-
-int setup2(void)
-{
-	buff.tick = 900000 / hz - 1;
-	return 0;
-}
-
-int setup3(void)
-{
-	buff.tick = 1100000 / hz + 1;
-	return 0;
-}
-
-int setup4(void)
-{
-	buff.offset = 512000L + 1;
-	return 0;
-}
-
-int setup5(void)
-{
-	buff.offset = (-1) * (512000L) - 1;
-	return 0;
-}
 
-int setup6(void)
-{
-	/* Switch to nobody user for correct error code collection */
-	if ((ltpuser = getpwnam(nobody_uid)) == NULL) {
-		tst_brkm(TBROK, NULL, "\"nobody\" user not present");
-	}
-	if (seteuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TWARN | TERRNO, "seteuid(%d) failed", ltpuser->pw_uid);
-		return 1;
-	}
-	return 0;
+	/* Restore saved parameters */
+	if ((adjtimex(&tim_save)) == -1)
+		tst_res(TWARN, "Failed to restore saved parameters");
 }
 
-void cleanup6(void)
-{
-	/* Set effective user id back to root */
-	SAFE_SETEUID(cleanup, 0);
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.tcnt = 6,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_adjtimex,
+};
-- 
2.22.0.rc2.383.gf4fbbf30c2-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH v2 2/3] syscalls/asyncio02: convert to new library.
  2019-06-10  0:26 [LTP] [PATCH v2 0/3] New library conversion for few system call tests Sandeep Patil
  2019-06-10  0:26 ` [LTP] [PATCH v2 1/3] syscalls/adjtimex02: Convert to new library Sandeep Patil
@ 2019-06-10  0:26 ` Sandeep Patil
  2019-06-13 16:11   ` Cyril Hrubis
  2019-06-10  0:26 ` [LTP] [PATCH v2 3/3] syscalls/bind01: " Sandeep Patil
  2 siblings, 1 reply; 9+ messages in thread
From: Sandeep Patil @ 2019-06-10  0:26 UTC (permalink / raw)
  To: ltp

Move the test to stat/stat02 and drop several
duplicate test cases along the way

Signed-off-by: Sandeep Patil <sspatil@android.com>
---

v1->v2
------
- Move the test to stat/stat02.c
- Delete the asyncio skeleton for good.

 testcases/kernel/syscalls/asyncio/.gitignore  |   1 -
 testcases/kernel/syscalls/asyncio/Makefile    |  23 --
 testcases/kernel/syscalls/asyncio/asyncio02.c | 294 ------------------
 testcases/kernel/syscalls/stat/stat02.c       |  93 ++++++
 4 files changed, 93 insertions(+), 318 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/asyncio/.gitignore
 delete mode 100644 testcases/kernel/syscalls/asyncio/Makefile
 delete mode 100644 testcases/kernel/syscalls/asyncio/asyncio02.c
 create mode 100644 testcases/kernel/syscalls/stat/stat02.c

diff --git a/testcases/kernel/syscalls/asyncio/.gitignore b/testcases/kernel/syscalls/asyncio/.gitignore
deleted file mode 100644
index 35f65a6a9..000000000
--- a/testcases/kernel/syscalls/asyncio/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/asyncio02
diff --git a/testcases/kernel/syscalls/asyncio/Makefile b/testcases/kernel/syscalls/asyncio/Makefile
deleted file mode 100644
index bd617d806..000000000
--- a/testcases/kernel/syscalls/asyncio/Makefile
+++ /dev/null
@@ -1,23 +0,0 @@
-#
-#  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
-#
-
-top_srcdir		?= ../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/asyncio/asyncio02.c b/testcases/kernel/syscalls/asyncio/asyncio02.c
deleted file mode 100644
index e532cc287..000000000
--- a/testcases/kernel/syscalls/asyncio/asyncio02.c
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * 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.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * 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.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: asyncio02.c,v 1.6 2009/08/28 11:17:39 vapier Exp $ */
-/************************************************************
- * OS Test - Silicon Graphics, Inc.
- * Mendota Heights, Minnesota
- *
- * TEST IDENTIFIER:  aiotcs02:  write/close flushes data to the file
- *
- * PARENT DOCUMENT:  aiotds01:  kernel i/o
- *
- * AUTHOR: Barrie Kletscher
- *
- * CO-PILOT: Dave Baumgartner
- *
- * TEST ITEMS:
- * 	for each open flags set used:
- * 	1. Multiple writes to a file work as specified for
- * 	   more than BUFSIZ bytes.
- * 	2. Multiple writes to a file work as specified for
- * 	   BUFSIZ bytes.
- * 	3. Multiple writes to a file work as specified for
- * 	   lower than BUFSIZ bytes.
- *
- * INPUT SPECIFICATIONS:
- * 	Standard parse_opts supported options.
- *$
- * OUTPUT SPECIFICATIONS
- * 	Standard tst_res output format
- *
- * ENVIRONMENTAL NEEDS:
- * 	This program uses the environment variable TMPDIR for the location
- * 	of the temporary directory.
- *
- *
- * SPECIAL PROCEDURAL REQUIREMENTS:
- * 	The program must be linked with tst_*.o and parse_opts.o.
- *
- * INTERCASE DEPENDENCIES:
- * 	NONE.
- *
- * DETAILED DESCRIPTION:
- * 	Attempt to get some memory to work with.
- * 	Call testrun writing (BUFSIZ + 1) bytes
- * 	Call testrun writing BUFSIZ bytes
- * 	Repeated call to testrun() with decreasing write sizes
- * 		less than BUFSIZ
- * 	End
- *
- * 	Start testrun()
- * 	Attempt to open a temporary file.
- * 	Write the memory to the file.
- * 	Attempt to close the file which also flushes the buffers.
- * 	Now check to see if the number of bytes written is the
- * 		same as the number of bytes in the file.
- * 	Cleanup
- *
- * BUGS:
- * 	NONE.
- *
-************************************************************/
-
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/signal.h>
-#include <errno.h>
-#include <stdlib.h>
-#include "test.h"
-#include "safe_macros.h"
-
-#define FLAG O_RDWR | O_CREAT | O_TRUNC	/* Flags used when opening temp tile */
-#define MODE  0777		/* Mode to open file with */
-#define WRITES 10		/* Number of times buffer is written */
-#define DECR 1000		/* Number of bytes decremented between */
-					/* Calls to testrun() */
-#define OK -1			/* Return value from testrun() */
-
-#define FNAME1	"aio02.1"
-#define FNAME2	"aio02.2"
-#define FNAME3	"aio02.3"
-
-#define ERR_MSG1 "Bytes in file not equal to bytes written."
-#define ERR_MSG2 "Bytes in file (%d) not equal to bytes written (%d)."
-
-char *dp;			/* pointer to area of memory */
-
-void setup();
-void cleanup();
-int testrun(int flag, int bytes, int ti);
-
-char *TCID = "asyncio02";
-int TST_TOTAL = 6;
-
-char *filename;			/* name of the temporary file */
-
-char *Progname;
-int Open_flags;
-
-int Flags[] = {
-	O_RDWR | O_CREAT | O_TRUNC,
-	O_RDWR | O_CREAT | O_TRUNC
-};
-
-int Num_flags;
-
-/***********************************************************************
- * MAIN
- ***********************************************************************/
-int main(int ac, char **av)
-{
-
-	int i;
-	int ret_val;
-	int eok;		/* everything is ok flag */
-	int lc;
-	int flag_cnt;
-
-	Num_flags = sizeof(Flags) / sizeof(int);
-	TST_TOTAL = 3 * Num_flags;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (flag_cnt = 0; flag_cnt < Num_flags; flag_cnt++) {
-
-			/*
-			 * call testrun writing (BUFSIZ + 1) byte chunks
-			 */
-
-			filename = FNAME1;
-			if (testrun(Flags[flag_cnt], BUFSIZ + 1, 1) != OK) {
-				tst_resm(TFAIL, ERR_MSG1);
-			} else {
-				tst_resm(TPASS,
-					 "More than BUFSIZE bytes multiple synchronous writes to a file check out ok");
-			}
-
-			/*
-			 * call testrun writing BUFSIZ byte chunks
-			 */
-
-			filename = FNAME2;
-			if (testrun(Flags[flag_cnt], BUFSIZ, 2) != OK) {
-				tst_resm(TFAIL, ERR_MSG1);
-			} else {
-				tst_resm(TPASS,
-					 "BUFSIZE bytes multiple synchronous writes to a file checks out ok");
-			}
-
-			/*
-			 * while the byte chunks are greater than 0
-			 *      call testrun() with decreasing chunk sizes
-			 */
-
-			filename = FNAME3;
-			eok = 1;
-			for (i = BUFSIZ - 1; i >= 0; i -= DECR) {
-				if ((ret_val =
-				     testrun(Flags[flag_cnt], i, 3)) != OK) {
-					tst_resm(TFAIL, ERR_MSG2, ret_val,
-						 i * WRITES);
-				}
-			}
-
-			if (eok) {
-				tst_resm(TPASS,
-					 "Less than BUFSIZE bytes multiple synchronous writes to a file checks out ok");
-			}
-		}
-	}
-	cleanup();
-	tst_exit();
-}				/* end main() */
-
-int testrun(int flag, int bytes, int ti)
-{
-
-	int fildes, i, ret;
-
-	struct stat buffer;	/* buffer of memory required for stat command */
-
-	/*
-	 *      Attempt to open a temporary file.
-	 */
-
-	if ((fildes = open(filename, flag, MODE)) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup, "open(%s) failed", filename);
-	}
-
-	/*
-	 *      Write the memory to the file.
-	 */
-
-	for (i = 0; i < WRITES; i++) {
-		TEST(write(fildes, dp, (unsigned)bytes));
-
-		if (TEST_RETURN == -1) {
-			tst_brkm(TBROK | TTERRNO, cleanup, "write() failed");
-		}
-	}			/* end for () */
-
-	/*
-	 *      Attempt to close the file which also flushes the buffers.
-	 */
-
-	SAFE_CLOSE(cleanup, fildes);
-
-	ret = OK;
-
-	/*
-	 *  Now check to see if the number of bytes written is the
-	 *  same as the number of bytes in the file.
-	 */
-
-	SAFE_STAT(cleanup, filename, &buffer);
-
-	if (buffer.st_size != (off_t) (bytes * WRITES)) {
-		ret = (int)buffer.st_size;
-	}
-
-	SAFE_UNLINK(cleanup, filename);
-
-	return ret;
-
-}				/* end testrun() */
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* create a temporary directory and go to it */
-	tst_tmpdir();
-
-	/*
-	 *  Attempt to get some memory to work with.
-	 */
-
-	if ((dp = malloc((unsigned)BUFSIZ + 1)) == NULL) {
-		tst_brkm(TBROK | TERRNO, cleanup, "malloc() failed");
-	}
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *              completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/stat/stat02.c b/testcases/kernel/syscalls/stat/stat02.c
new file mode 100644
index 000000000..8dbac7236
--- /dev/null
+++ b/testcases/kernel/syscalls/stat/stat02.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * AUTHOR: Barrie Kletscher
+ * CO-PILOT: Dave Baumgartner
+ */
+
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/signal.h>
+#include <errno.h>
+#include <stdlib.h>
+#include "tst_test.h"
+
+/* Temporary file names */
+#define FNAME1	"stat02.1"
+#define FNAME2	"stat02.2"
+
+/* Number of times each buffer is written */
+#define NUM_WRITES	(10)
+#define BUFSIZE		(4096)
+
+char *buffer;
+
+static struct test_case {
+	const char *filename;
+	size_t bytes_to_write;
+	size_t decrement;
+} tcases[] = {
+	/* Write and verify BUFSIZE byte chunks */
+	{ FNAME1, BUFSIZE, BUFSIZE },
+	/* Write and verify decreasing chunk sizes */
+	{ FNAME2, BUFSIZE, 1000 }
+};
+
+void verify(const char *fname, size_t bytes, size_t decrement)
+{
+	struct stat s;
+	int fd, i;
+	size_t bytes_written = 0;
+
+	fd = SAFE_OPEN(fname, O_CREAT | O_TRUNC | O_RDWR, 0777);
+	while (bytes > 0) {
+		for (i = 0; i < NUM_WRITES; i++) {
+			SAFE_WRITE(1, fd, buffer, bytes);
+			bytes_written += bytes;
+		}
+		bytes -= bytes > decrement ? decrement : bytes;
+	}
+
+	SAFE_CLOSE(fd);
+	SAFE_STAT(fname, &s);
+	SAFE_UNLINK(fname);
+
+	/*
+	 *  Now check to see if the number of bytes written was
+	 *  the same as the number of bytes in the file.
+	 */
+	if (s.st_size != (off_t) bytes_written) {
+		tst_res(TFAIL, "file size (%zu) not as expected (%zu) bytes",
+				s.st_size, bytes_written);
+		return;
+	}
+
+	tst_res(TPASS, "File size reported as expected");
+}
+
+void verify_stat_size(unsigned int nr)
+{
+	struct test_case *tcase = &tcases[nr];
+
+	verify(tcase->filename, tcase->bytes_to_write, tcase->decrement);
+}
+
+void setup(void)
+{
+	buffer = SAFE_MALLOC(BUFSIZE);
+}
+
+void cleanup(void)
+{
+	free(buffer);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.needs_tmpdir = 1,
+	.test = verify_stat_size,
+	.setup = setup,
+	.cleanup = cleanup,
+};
-- 
2.22.0.rc2.383.gf4fbbf30c2-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH v2 3/3] syscalls/bind01: convert to new library.
  2019-06-10  0:26 [LTP] [PATCH v2 0/3] New library conversion for few system call tests Sandeep Patil
  2019-06-10  0:26 ` [LTP] [PATCH v2 1/3] syscalls/adjtimex02: Convert to new library Sandeep Patil
  2019-06-10  0:26 ` [LTP] [PATCH v2 2/3] syscalls/asyncio02: convert " Sandeep Patil
@ 2019-06-10  0:26 ` Sandeep Patil
  2019-06-13 14:55   ` Cyril Hrubis
  2 siblings, 1 reply; 9+ messages in thread
From: Sandeep Patil @ 2019-06-10  0:26 UTC (permalink / raw)
  To: ltp

Drop UCLINUX specific tests along the way.

Signed-off-by: Sandeep Patil <sspatil@android.com>
---

v1->v2
------
- Rebased after commit 'fa6a4e708 ("net: Introduce TST_GET_UNUSED_PORT() macro..)'

 testcases/kernel/syscalls/bind/bind01.c | 198 ++++++------------------
 1 file changed, 48 insertions(+), 150 deletions(-)

diff --git a/testcases/kernel/syscalls/bind/bind01.c b/testcases/kernel/syscalls/bind/bind01.c
index d2f50e806..49b5d866e 100644
--- a/testcases/kernel/syscalls/bind/bind01.c
+++ b/testcases/kernel/syscalls/bind/bind01.c
@@ -1,43 +1,7 @@
-/*
- *
- *   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
- */
+// SPDX-License-Identifier: GPL-2.0
 
 /*
- * Test Name: bind01
- *
- * Test Description:
- *  Verify that bind() returns the proper errno for various failure cases
- *
- * Usage:  <for command-line>
- *  bind01 [-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
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  None.
- *
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
 #include <stdio.h>
@@ -51,104 +15,51 @@
 
 #include <netinet/in.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
-char *TCID = "bind01";
-int testno;
+int inet_socket;
+int dev_null;
 
-int s;				/* socket descriptor */
 struct sockaddr_in sin1, sin2, sin3;
-struct sockaddr_un sun1;
-
-void setup(void), setup0(void), setup1(void), setup2(void),
-cleanup(void), cleanup0(void), cleanup1(void);
+struct sockaddr_un sun;
 
-struct test_case_t {		/* test case structure */
-	int domain;		/* PF_INET, PF_UNIX, ... */
-	int type;		/* SOCK_STREAM, SOCK_DGRAM ... */
-	int proto;		/* protocol number (usually 0 = default) */
+static struct test_case {
+	int *socket_fd;		/* file descriptor for test case */
 	struct sockaddr *sockaddr;	/* socket address buffer */
-	int salen;		/* bind's 3rd argument */
-	int retval;		/* syscall return value */
+	socklen_t salen;		/* bind's 3rd argument */
+	int retval;		/* expected return value */
 	int experrno;		/* expected errno */
-	void (*setup) (void);
-	void (*cleanup) (void);
 	char *desc;
-} tdat[] = {
-#ifndef UCLINUX
-/* Skip since uClinux does not implement memory protection */
-	{
-	PF_INET, SOCK_STREAM, 0, (struct sockaddr *)-1,
-		    sizeof(struct sockaddr_in), -1, EFAULT, setup0,
-		    cleanup0, "invalid sockaddr"},
-#endif
-	{
-	PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&sin1,
-		    3, -1, EINVAL, setup0, cleanup0, "invalid salen"}, {
-	0, 0, 0, (struct sockaddr *)&sin1,
-		    sizeof(sin1), -1, ENOTSOCK, setup1, cleanup1,
-		    "invalid socket"}
-	, {
-	PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&sin2,
-		    sizeof(sin2), 0, 0, setup0, cleanup0, "INADDR_ANYPORT"}
-	, {
-	PF_UNIX, SOCK_STREAM, 0, (struct sockaddr *)&sun1,
-		    sizeof(sun1), -1, EADDRINUSE, setup0, cleanup0,
-		    "UNIX-domain of current directory"}
-	, {
-	PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&sin3,
-		    sizeof(sin3), -1, EADDRNOTAVAIL, setup0, cleanup0,
-		    "non-local address"}
-,};
-
-int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
-
-int main(int argc, char *argv[])
+} tcases[] = {
+	{ &inet_socket, (struct sockaddr *)&sin1, 3, -1,
+	  EINVAL, "invalid salen" },
+	{ &dev_null, (struct sockaddr *)&sin1, sizeof(sin1), -1,
+	  ENOTSOCK, "invalid socket" },
+	{ &inet_socket, (struct sockaddr *)&sin2, sizeof(sin2), 0,
+	  0, "INADDR_ANYPORT"},
+	{ &inet_socket, (struct sockaddr *)&sun, sizeof(sun), -1,
+	  EAFNOSUPPORT, "UNIX-domain of current directory" },
+	{ &inet_socket, (struct sockaddr *)&sin3, sizeof(sin3), -1,
+	  EADDRNOTAVAIL, "non-local address" },
+};
+
+void verify_bind(unsigned int nr)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
-
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-			tdat[testno].setup();
-
-			TEST(bind
-			     (s, tdat[testno].sockaddr, tdat[testno].salen));
-			if (TEST_RETURN > 0) {
-				TEST_RETURN = 0;
-			} else {
-			}
-			if (TEST_RETURN != tdat[testno].retval ||
-			    (TEST_RETURN < 0 &&
-			     TEST_ERRNO != tdat[testno].experrno)) {
-				tst_resm(TFAIL, "%s ; returned"
-					 " %ld (expected %d), errno %d (expected"
-					 " %d)", tdat[testno].desc,
-					 TEST_RETURN, tdat[testno].retval,
-					 TEST_ERRNO, tdat[testno].experrno);
-			} else {
-				tst_resm(TPASS, "%s successful",
-					 tdat[testno].desc);
-			}
-			tdat[testno].cleanup();
-		}
+	struct test_case *tcase = &tcases[nr];
+
+	TEST(bind(*tcase->socket_fd, tcase->sockaddr, tcase->salen));
+	if (TST_RET != tcase->retval && TST_ERR != tcase->experrno) {
+		tst_res(TFAIL, "%s ; returned"
+			" %ld (expected %d), errno %d (expected"
+			" %d)", tcase->desc, TST_RET, tcase->retval,
+			TST_ERR, tcase->experrno);
+	} else {
+		tst_res(TPASS, "%s successful", tcase->desc);
 	}
-	cleanup();
-
-	tst_exit();
 }
 
-void setup(void)
+void test_setup(void)
 {
-
-	TEST_PAUSE;		/* if -p option specified */
-
 	/* initialize sockaddr's */
 	sin1.sin_family = AF_INET;
 	/* this port must be unused! */
@@ -164,35 +75,22 @@ void setup(void)
 	/* assumes 10.255.254.253 is not a local interface address! */
 	sin3.sin_addr.s_addr = htonl(0x0AFFFEFD);
 
-	sun1.sun_family = AF_UNIX;
-	strncpy(sun1.sun_path, ".", sizeof(sun1.sun_path));
-
-}
-
-void cleanup(void)
-{
-}
+	sun.sun_family = AF_UNIX;
+	strncpy(sun.sun_path, ".", sizeof(sun.sun_path));
 
-void setup0(void)
-{
-	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
-		        tdat[testno].proto);
+	inet_socket = SAFE_SOCKET(PF_INET, SOCK_STREAM, 0);
+	dev_null = SAFE_OPEN("/dev/null", O_WRONLY);
 }
 
-void cleanup0(void)
+void test_cleanup(void)
 {
-	(void)close(s);
+	SAFE_CLOSE(inet_socket);
+	SAFE_CLOSE(dev_null);
 }
 
-void setup1(void)
-{
-	/* setup for the "not a socket" case */
-	if ((s = open("/dev/null", O_WRONLY)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open(/dev/null) failed");
-
-}
-
-void cleanup1(void)
-{
-	s = -1;
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = test_setup,
+	.cleanup = test_cleanup,
+	.test = verify_bind,
+};
-- 
2.22.0.rc2.383.gf4fbbf30c2-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH v2 3/3] syscalls/bind01: convert to new library.
  2019-06-10  0:26 ` [LTP] [PATCH v2 3/3] syscalls/bind01: " Sandeep Patil
@ 2019-06-13 14:55   ` Cyril Hrubis
  2019-06-13 15:17     ` Cyril Hrubis
  2019-06-18 20:25     ` Sandeep Patil
  0 siblings, 2 replies; 9+ messages in thread
From: Cyril Hrubis @ 2019-06-13 14:55 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with minor changes, thanks.

However the test fails with -i 2 after this patch since on second
iteration since the socket is already bind for the possitive test
because we no longer close the socket after each iteration. Looking at
the bind tests we should move this one into a separate testcase and add
a few more positive tests as well we seem to test only AF_INET,
SOCK_STREAM combination which does not even cover ipv4 nor we attemp to
connect to the socket that have been bind.

> +// SPDX-License-Identifier: GPL-2.0

Changed this to GPL-2.0-or-later to match the original license.

And removed the NULL parameter from the TST_GET_UNUSED_PORT(), since
newlib variant does not have the cleanup callback parameter.


-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH v2 3/3] syscalls/bind01: convert to new library.
  2019-06-13 14:55   ` Cyril Hrubis
@ 2019-06-13 15:17     ` Cyril Hrubis
  2019-06-18 20:25     ` Sandeep Patil
  1 sibling, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2019-06-13 15:17 UTC (permalink / raw)
  To: ltp

Hi!
> However the test fails with -i 2 after this patch since on second
> iteration since the socket is already bind for the possitive test
> because we no longer close the socket after each iteration. Looking at
> the bind tests we should move this one into a separate testcase and add
> a few more positive tests as well we seem to test only AF_INET,
> SOCK_STREAM combination which does not even cover ipv4 nor we attemp to
> connect to the socket that have been bind.

FYI I've added an issue so that this is not forgotten:

https://github.com/linux-test-project/ltp/issues/538

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH v2 2/3] syscalls/asyncio02: convert to new library.
  2019-06-10  0:26 ` [LTP] [PATCH v2 2/3] syscalls/asyncio02: convert " Sandeep Patil
@ 2019-06-13 16:11   ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2019-06-13 16:11 UTC (permalink / raw)
  To: ltp

Hi!
> diff --git a/testcases/kernel/syscalls/stat/stat02.c b/testcases/kernel/syscalls/stat/stat02.c
> new file mode 100644
> index 000000000..8dbac7236
> --- /dev/null
> +++ b/testcases/kernel/syscalls/stat/stat02.c
> @@ -0,0 +1,93 @@
> +// SPDX-License-Identifier: GPL-2.0

Changed this to GPL-2.0-or-later to match the original here as well and
pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH v2 3/3] syscalls/bind01: convert to new library.
  2019-06-13 14:55   ` Cyril Hrubis
  2019-06-13 15:17     ` Cyril Hrubis
@ 2019-06-18 20:25     ` Sandeep Patil
  1 sibling, 0 replies; 9+ messages in thread
From: Sandeep Patil @ 2019-06-18 20:25 UTC (permalink / raw)
  To: ltp

On Thu, Jun 13, 2019 at 04:55:07PM +0200, Cyril Hrubis wrote:
> Hi!
> Pushed with minor changes, thanks.
> 
> However the test fails with -i 2 after this patch since on second
> iteration since the socket is already bind for the possitive test
> because we no longer close the socket after each iteration.

Ew, sorry about that. I guess I never ran it with the option as I only tried
what is listed in runtest.

I'll try it with '-i 2'.

> Looking at
> the bind tests we should move this one into a separate testcase and add
> a few more positive tests as well we seem to test only AF_INET,
> SOCK_STREAM combination which does not even cover ipv4 nor we attemp to
> connect to the socket that have been bind.

Agree, added to my to-do list. I am mostly burning through tests and
converting them to the new library manually.

> 
> > +// SPDX-License-Identifier: GPL-2.0
> 
> Changed this to GPL-2.0-or-later to match the original license.

I thought the original was GPL-2.0 (may be I misread the text, sorry).

> 
> And removed the NULL parameter from the TST_GET_UNUSED_PORT(), since
> newlib variant does not have the cleanup callback parameter.

Ack, thanks for doing this Cyril. Hopefully the next ones will apply without
edits ;0)

- ssp

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH v2 1/3] syscalls/adjtimex02: Convert to new library
  2019-06-10  0:26 ` [LTP] [PATCH v2 1/3] syscalls/adjtimex02: Convert to new library Sandeep Patil
@ 2019-07-04 12:51   ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2019-07-04 12:51 UTC (permalink / raw)
  To: ltp

Hi!
Pushed, thanks.

(I've added a few missing static keywords to cleanup/setup...)

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-07-04 12:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-10  0:26 [LTP] [PATCH v2 0/3] New library conversion for few system call tests Sandeep Patil
2019-06-10  0:26 ` [LTP] [PATCH v2 1/3] syscalls/adjtimex02: Convert to new library Sandeep Patil
2019-07-04 12:51   ` Cyril Hrubis
2019-06-10  0:26 ` [LTP] [PATCH v2 2/3] syscalls/asyncio02: convert " Sandeep Patil
2019-06-13 16:11   ` Cyril Hrubis
2019-06-10  0:26 ` [LTP] [PATCH v2 3/3] syscalls/bind01: " Sandeep Patil
2019-06-13 14:55   ` Cyril Hrubis
2019-06-13 15:17     ` Cyril Hrubis
2019-06-18 20:25     ` Sandeep Patil

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.