public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] syscall/write02.c: Cleanup && convert to new API.
@ 2017-04-21 10:48 Jinhui Huang
  2017-04-21 10:48 ` [LTP] [PATCH 2/2] syscall/write03.c: " Jinhui Huang
  2017-05-26 14:16 ` [LTP] [PATCH 1/2] syscall/write02.c: " Cyril Hrubis
  0 siblings, 2 replies; 8+ messages in thread
From: Jinhui Huang @ 2017-04-21 10:48 UTC (permalink / raw)
  To: ltp

Signed-off-by: Jinhui Huang <huangjh.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/write/write02.c | 142 ++++++++----------------------
 1 file changed, 37 insertions(+), 105 deletions(-)

diff --git a/testcases/kernel/syscalls/write/write02.c b/testcases/kernel/syscalls/write/write02.c
index 4924422..2ce94cd 100644
--- a/testcases/kernel/syscalls/write/write02.c
+++ b/testcases/kernel/syscalls/write/write02.c
@@ -1,6 +1,8 @@
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
+ *	07/2001 ported by John George
+ *   Copyright (c) 2017 Fujitsu Ltd.
+ *	04/2017 Modified by Jinhui Huang
  *
  *   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
@@ -18,129 +20,59 @@
  */
 
 /*
- * NAME
- *	write02.c
- *
  * DESCRIPTION
  *	Basic functionality test: does the return from write match the count
  *	of the number of bytes written.
- *
- *
- * ALGORITHM
- *	Create a file and write some bytes out to it.
- *	Check the return count against the number returned.
- *
- * USAGE:  <for command-line>
- *      write02 [-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 John George
- *		-Ported
- *
- * Restrictions
- *	None
  */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdio.h>
-#include "test.h"
 
-char *TCID = "write02";
-int TST_TOTAL = 1;
-
-void cleanup(void);
-void setup(void);
+#include <stdio.h>
+#include <errno.h>
+#include "tst_test.h"
 
-char pfiln[40] = "";
+static int fd, iws;
+static char pwbuf[BUFSIZ + 1];
 
-int main(int argc, char **argv)
+static void verify_write(void)
 {
-	int lc;
-
-	int cwrite;
-	int fild;
-	int iws;
 	int badcount = 0;
-	char pwbuf[BUFSIZ + 1];
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	fd = SAFE_CREAT("testfile", 0777);
 
-	setup();		/* global setup for test */
+	for (iws = BUFSIZ; iws > 0; iws--) {
+		TEST(write(fd, pwbuf, iws));
 
-	/* The following loop checks looping state if -i option given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-//block1:
-		tst_resm(TINFO, "Block 1: test to see write() returns proper "
-			 "write count");
-
-		for (iws = 0; iws < BUFSIZ; iws++) {
-			pwbuf[iws] = 'A' + (iws % 26);
+		if (TEST_RETURN != iws) {
+			tst_res(TINFO, "bad write count");
+			badcount++;
 		}
-		pwbuf[BUFSIZ] = '\n';
-
-		if ((fild = creat(pfiln, 0777)) == -1) {
-			tst_brkm(TBROK, cleanup, "Can't creat Xwrit");
-		}
-		for (iws = BUFSIZ; iws > 0; iws--) {
-			if ((cwrite = write(fild, pwbuf, iws)) != iws) {
-				badcount++;
-				tst_resm(TINFO, "bad write count");
-			}
-		}
-		if (badcount != 0) {
-			tst_resm(TFAIL, "write() FAILED to return proper cnt");
-		} else {
-			tst_resm(TPASS, "write() PASSED");
-		}
-		tst_resm(TINFO, "block 1 passed");
-		close(fild);
 	}
-	cleanup();
-	tst_exit();
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test
- */
-void setup(void)
-{
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	if (badcount != 0)
+		tst_res(TFAIL, "write() failed to return proper count");
+	else
+		tst_res(TPASS, "write() returned proper count");
 
-	umask(0);
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(pfiln, "write1.%d", getpid());
+	SAFE_CLOSE(fd);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at completion or
- * premature exit.
- */
-void cleanup(void)
+static void setup(void)
 {
+	for (iws = 0; iws < BUFSIZ; iws++)
+		pwbuf[iws] = 'A' + (iws % 26);
 
-	unlink(pfiln);
+	pwbuf[BUFSIZ] = '\n';
+}
 
-	tst_rmdir();
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.tid = "write02",
+	.test_all = verify_write,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 2/2] syscall/write03.c: Cleanup && convert to new API.
  2017-04-21 10:48 [LTP] [PATCH 1/2] syscall/write02.c: Cleanup && convert to new API Jinhui Huang
@ 2017-04-21 10:48 ` Jinhui Huang
  2017-05-26 14:14   ` Cyril Hrubis
  2017-05-26 14:16 ` [LTP] [PATCH 1/2] syscall/write02.c: " Cyril Hrubis
  1 sibling, 1 reply; 8+ messages in thread
From: Jinhui Huang @ 2017-04-21 10:48 UTC (permalink / raw)
  To: ltp

Signed-off-by: Jinhui Huang <huangjh.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/write/write03.c | 177 +++++++-----------------------
 1 file changed, 42 insertions(+), 135 deletions(-)

diff --git a/testcases/kernel/syscalls/write/write03.c b/testcases/kernel/syscalls/write/write03.c
index 63ef35a..4fabd62 100644
--- a/testcases/kernel/syscalls/write/write03.c
+++ b/testcases/kernel/syscalls/write/write03.c
@@ -1,6 +1,8 @@
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
+ *	07/2001 Ported by John George
+ *   Copyright (c) 2017 Fujitsu Ltd.
+ *	04/2017 Modified by Jinhui Huang
  *
  *   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
@@ -18,9 +20,6 @@
  */
 
 /*
- * NAME
- *	write03.c
- *
  * DESCRIPTION
  *	Testcase to check that write(2) doesn't corrupt a file when it fails
  *
@@ -29,154 +28,62 @@
  *	fail with some erroneous parameter, close the fd. Then reopen the
  *	file in RDONLY mode, and read the contents of the file. Compare the
  *	buffers, to see whether they are same.
- *
- * USAGE:  <for command-line>
- *      write03 [-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 John George
- *		-Ported
- *
- * Restrictions
- *	NONE
  */
 
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
+#include <stdio.h>
 #include <errno.h>
-#include "test.h"
-#include <sys/mman.h>
-
-char *TCID = "write03";
-int TST_TOTAL = 1;
-
-char *bad_addr = 0;
+#include "tst_test.h"
 
-void setup(void);
-void cleanup(void);
+static char *bad_addr;
+static char wbuf[BUFSIZ], rbuf[BUFSIZ];
+static int fd;
 
-char filename[100];
-
-#if !defined(UCLINUX)
-
-int main(int argc, char **argv)
+static void verify_write(void)
 {
-	int lc;
-
-	char wbuf[BUFSIZ], rbuf[BUFSIZ];
-	int fd;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	/* global setup */
-	setup();
-
-	/* The following loop checks looping state if -i option given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-//block1:
-		tst_resm(TINFO, "Enter Block 1: test to check if write "
-			 "corrupts the file when write fails");
-
-		fd = creat(filename, 0644);
-		if (fd < 0) {
-			tst_resm(TBROK, "creating a new file failed");
-			cleanup();
-		}
-
-		(void)memset(wbuf, '0', 100);
-
-		if (write(fd, wbuf, 100) == -1) {
-			tst_resm(TFAIL, "failed to write to %s", filename);
-			cleanup();
-		}
-
-		if (write(fd, bad_addr, 100) != -1) {
-			tst_resm(TFAIL, "write(2) failed to fail");
-			cleanup();
-		}
-		close(fd);
-
-		if ((fd = open(filename, O_RDONLY)) == -1) {
-			tst_resm(TBROK, "open(2) failed, errno: %d", errno);
-			cleanup();
-		}
-
-		if (read(fd, rbuf, 100) == -1) {
-			tst_resm(TBROK, "read(2) failed, errno: %d", errno);
-			cleanup();
-		}
-
-		if (memcmp(wbuf, rbuf, 100) == 0) {
-			tst_resm(TPASS, "failure of write(2) didnot corrupt "
-				 "the file");
-		} else {
-			tst_resm(TFAIL, "failure of write(2) corrupted the "
-				 "file");
-		}
-		tst_resm(TINFO, "Exit block 1");
-		close(fd);
-	}
-	cleanup();
-	tst_exit();
-}
+	fd = SAFE_CREAT("testfile", 0644);
 
-#else
+	SAFE_WRITE(1, fd, wbuf, 100);
 
-int main(void)
-{
-	tst_resm(TINFO, "test is not available on uClinux");
-	tst_exit();
-}
-
-#endif /* if !defined(UCLINUX) */
-
-/*
- * setup() - performs all ONE TIME setup for this test
- */
-void setup(void)
-{
+	if (write(fd, bad_addr, 100) != -1) {
+		tst_res(TFAIL, "write() failed to fail");
+		SAFE_CLOSE(fd);
+		return;
+	}
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	SAFE_CLOSE(fd);
 
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
-	TEST_PAUSE;
+	fd = SAFE_OPEN("testfile", O_RDONLY);
 
-	/* Create a unique temporary directory and chdir() to it. */
-	tst_tmpdir();
+	memset(rbuf, 0, BUFSIZ);
 
-	sprintf(filename, "./write03.%d", getpid());
+	SAFE_READ(0, fd, rbuf, 100);
 
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		printf("mmap failed\n");
-	}
+	if (memcmp(wbuf, rbuf, 100) == 0)
+		tst_res(TPASS, "failure of write() didnot corrupt the file");
+	else
+		tst_res(TFAIL, "failure of write() corrupted the file");
 
+	SAFE_CLOSE(fd);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit
- */
-void cleanup(void)
+static void setup(void)
 {
+	bad_addr = SAFE_MMAP(0, 1, PROT_NONE,
+			MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
 
-	unlink(filename);
-	tst_rmdir();
+	memset(wbuf, '0', 100);
+}
 
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.tid = "write03",
+	.test_all = verify_write,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 2/2] syscall/write03.c: Cleanup && convert to new API.
  2017-04-21 10:48 ` [LTP] [PATCH 2/2] syscall/write03.c: " Jinhui Huang
@ 2017-05-26 14:14   ` Cyril Hrubis
  0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2017-05-26 14:14 UTC (permalink / raw)
  To: ltp

Hi!
Applied, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 1/2] syscall/write02.c: Cleanup && convert to new API.
  2017-04-21 10:48 [LTP] [PATCH 1/2] syscall/write02.c: Cleanup && convert to new API Jinhui Huang
  2017-04-21 10:48 ` [LTP] [PATCH 2/2] syscall/write03.c: " Jinhui Huang
@ 2017-05-26 14:16 ` Cyril Hrubis
  2017-06-12  7:27   ` [LTP] [PATCH v2] syscalls/write01.c: Add test with different buffer sizes && Remove write02 Jinhui Huang
  1 sibling, 1 reply; 8+ messages in thread
From: Cyril Hrubis @ 2017-05-26 14:16 UTC (permalink / raw)
  To: ltp

Hi!
The write01 seems to do pretty much the same but only with a buffer
sized 1 byte. Can you rather add a few lines of code to the write01.c
test so that it tries with different buffer sizes and remove write02.c?

It does not make much sense to keep two tests that does basically the
same.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2] syscalls/write01.c: Add test with different buffer sizes && Remove write02
  2017-05-26 14:16 ` [LTP] [PATCH 1/2] syscall/write02.c: " Cyril Hrubis
@ 2017-06-12  7:27   ` Jinhui Huang
  2017-06-13 10:59     ` Cyril Hrubis
  0 siblings, 1 reply; 8+ messages in thread
From: Jinhui Huang @ 2017-06-12  7:27 UTC (permalink / raw)
  To: ltp

Signed-off-by: Jinhui Huang <huangjh.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/write/write01.c |  40 +++++---
 testcases/kernel/syscalls/write/write02.c | 146 ------------------------------
 2 files changed, 25 insertions(+), 161 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/write/write02.c

diff --git a/testcases/kernel/syscalls/write/write01.c b/testcases/kernel/syscalls/write/write01.c
index 1a60052..14fa7c9 100644
--- a/testcases/kernel/syscalls/write/write01.c
+++ b/testcases/kernel/syscalls/write/write01.c
@@ -20,17 +20,9 @@
  * 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/
  */
 
+#include <stdio.h>
 #include <errno.h>
 #include "tst_test.h"
 
@@ -38,17 +30,35 @@ static int fd;
 
 static void verify_write(void)
 {
-	TEST(write(fd, "w", 1));
+	int i, badcount = 0;
+	char buf[BUFSIZ];
+
+	memset(buf, 'w', BUFSIZ);
 
-	if (TEST_RETURN == -1)
-		tst_res(TFAIL | TTERRNO, "write(2) failed");
+	SAFE_LSEEK(fd, 0, SEEK_SET);
+
+	for (i = BUFSIZ; i > 0; i--) {
+		TEST(write(fd, &buf, i));
+		if (TEST_RETURN == -1) {
+			tst_res(TFAIL | TTERRNO, "write failed");
+			return;
+		}
+
+		if (TEST_RETURN != i) {
+			badcount++;
+			tst_res(TINFO, "bad write count");
+		}
+	}
+
+	if (badcount != 0)
+		tst_res(TFAIL, "write() failed to return proper count");
 	else
-		tst_res(TPASS, "write(2) returned %ld", TEST_RETURN);
+		tst_res(TPASS, "write() passed");
 }
 
 static void setup(void)
 {
-	fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0700);
+	fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0700);
 }
 
 static void cleanup(void)
@@ -58,8 +68,8 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
-	.test_all = verify_write,
 	.setup = setup,
 	.cleanup = cleanup,
+	.test_all = verify_write,
 	.needs_tmpdir = 1,
 };
diff --git a/testcases/kernel/syscalls/write/write02.c b/testcases/kernel/syscalls/write/write02.c
deleted file mode 100644
index 4924422..0000000
--- a/testcases/kernel/syscalls/write/write02.c
+++ /dev/null
@@ -1,146 +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 Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * NAME
- *	write02.c
- *
- * DESCRIPTION
- *	Basic functionality test: does the return from write match the count
- *	of the number of bytes written.
- *
- *
- * ALGORITHM
- *	Create a file and write some bytes out to it.
- *	Check the return count against the number returned.
- *
- * USAGE:  <for command-line>
- *      write02 [-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 John George
- *		-Ported
- *
- * Restrictions
- *	None
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdio.h>
-#include "test.h"
-
-char *TCID = "write02";
-int TST_TOTAL = 1;
-
-void cleanup(void);
-void setup(void);
-
-char pfiln[40] = "";
-
-int main(int argc, char **argv)
-{
-	int lc;
-
-	int cwrite;
-	int fild;
-	int iws;
-	int badcount = 0;
-	char pwbuf[BUFSIZ + 1];
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();		/* global setup for test */
-
-	/* The following loop checks looping state if -i option given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-//block1:
-		tst_resm(TINFO, "Block 1: test to see write() returns proper "
-			 "write count");
-
-		for (iws = 0; iws < BUFSIZ; iws++) {
-			pwbuf[iws] = 'A' + (iws % 26);
-		}
-		pwbuf[BUFSIZ] = '\n';
-
-		if ((fild = creat(pfiln, 0777)) == -1) {
-			tst_brkm(TBROK, cleanup, "Can't creat Xwrit");
-		}
-		for (iws = BUFSIZ; iws > 0; iws--) {
-			if ((cwrite = write(fild, pwbuf, iws)) != iws) {
-				badcount++;
-				tst_resm(TINFO, "bad write count");
-			}
-		}
-		if (badcount != 0) {
-			tst_resm(TFAIL, "write() FAILED to return proper cnt");
-		} else {
-			tst_resm(TPASS, "write() PASSED");
-		}
-		tst_resm(TINFO, "block 1 passed");
-		close(fild);
-	}
-	cleanup();
-	tst_exit();
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test
- */
-void setup(void)
-{
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	umask(0);
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(pfiln, "write1.%d", getpid());
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at completion or
- * premature exit.
- */
-void cleanup(void)
-{
-
-	unlink(pfiln);
-
-	tst_rmdir();
-}
-- 
1.8.3.1




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

* [LTP] [PATCH v2] syscalls/write01.c: Add test with different buffer sizes && Remove write02
  2017-06-12  7:27   ` [LTP] [PATCH v2] syscalls/write01.c: Add test with different buffer sizes && Remove write02 Jinhui Huang
@ 2017-06-13 10:59     ` Cyril Hrubis
  2017-06-15  9:26       ` [LTP] [PATCH v3] " Jinhui Huang
  0 siblings, 1 reply; 8+ messages in thread
From: Cyril Hrubis @ 2017-06-13 10:59 UTC (permalink / raw)
  To: ltp

Hi!
>  testcases/kernel/syscalls/write/write01.c |  40 +++++---
>  testcases/kernel/syscalls/write/write02.c | 146 ------------------------------

If you are removing a test you have to update runtest/* files as well as
syscalls/.gitignore.

> diff --git a/testcases/kernel/syscalls/write/write01.c b/testcases/kernel/syscalls/write/write01.c
> index 1a60052..14fa7c9 100644
> --- a/testcases/kernel/syscalls/write/write01.c
> +++ b/testcases/kernel/syscalls/write/write01.c
> @@ -20,17 +20,9 @@
>   * 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/
>   */
>  
> +#include <stdio.h>

Isn't memset() defined in string.h? Or for which definition do we need
stdio.h here?

>  #include <errno.h>
>  #include "tst_test.h"
>  
> @@ -38,17 +30,35 @@ static int fd;
>  
>  static void verify_write(void)
>  {
> -	TEST(write(fd, "w", 1));
> +	int i, badcount = 0;
> +	char buf[BUFSIZ];
> +
> +	memset(buf, 'w', BUFSIZ);
>  
> -	if (TEST_RETURN == -1)
> -		tst_res(TFAIL | TTERRNO, "write(2) failed");
> +	SAFE_LSEEK(fd, 0, SEEK_SET);
> +
> +	for (i = BUFSIZ; i > 0; i--) {
> +		TEST(write(fd, &buf, i));

The &buf == buf for arrays, but I find simply passing buf a bit less
confusing.

> +		if (TEST_RETURN == -1) {
> +			tst_res(TFAIL | TTERRNO, "write failed");
> +			return;
> +		}
> +
> +		if (TEST_RETURN != i) {
> +			badcount++;
> +			tst_res(TINFO, "bad write count");

Maybe we should write something as:

"write() returned %ld, expected %d", TEST_RETURN, i

> +		}
> +	}
> +
> +	if (badcount != 0)
> +		tst_res(TFAIL, "write() failed to return proper count");
>  	else
> -		tst_res(TPASS, "write(2) returned %ld", TEST_RETURN);
> +		tst_res(TPASS, "write() passed");
>  }

Otherwise it looks OK.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v3] syscalls/write01.c: Add test with different buffer sizes && Remove write02
  2017-06-13 10:59     ` Cyril Hrubis
@ 2017-06-15  9:26       ` Jinhui Huang
  2017-06-15 14:56         ` Cyril Hrubis
  0 siblings, 1 reply; 8+ messages in thread
From: Jinhui Huang @ 2017-06-15  9:26 UTC (permalink / raw)
  To: ltp

Signed-off-by: Jinhui Huang <huangjh.jy@cn.fujitsu.com>
---
 runtest/ltplite                           |   1 -
 runtest/stress.part3                      |   1 -
 runtest/syscalls                          |   1 -
 testcases/kernel/syscalls/write/write01.c |  42 ++++++---
 testcases/kernel/syscalls/write/write02.c | 146 ------------------------------
 5 files changed, 27 insertions(+), 164 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/write/write02.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 0c2e5be..909bbdb 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -1028,7 +1028,6 @@ waitpid12 waitpid12
 waitpid13 waitpid13
 
 write01 write01
-write02 write02
 write03 write03
 write04 write04
 write05 write05
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index bd84752..d5db1c2 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -888,7 +888,6 @@ waitpid12 waitpid12
 waitpid13 waitpid13
 
 write01 write01
-write02 write02
 write03 write03
 write04 write04
 write05 write05
diff --git a/runtest/syscalls b/runtest/syscalls
index fe52272..1cf351a 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1433,7 +1433,6 @@ waitid01 waitid01
 waitid02 waitid02
 
 write01 write01
-write02 write02
 write03 write03
 write04 write04
 write05 write05
diff --git a/testcases/kernel/syscalls/write/write01.c b/testcases/kernel/syscalls/write/write01.c
index 1a60052..c6c8fa8 100644
--- a/testcases/kernel/syscalls/write/write01.c
+++ b/testcases/kernel/syscalls/write/write01.c
@@ -20,17 +20,10 @@
  * 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/
  */
 
+#include <stdio.h>
+#include <string.h>
 #include <errno.h>
 #include "tst_test.h"
 
@@ -38,17 +31,36 @@ static int fd;
 
 static void verify_write(void)
 {
-	TEST(write(fd, "w", 1));
+	int i, badcount = 0;
+	char buf[BUFSIZ];
+
+	memset(buf, 'w', BUFSIZ);
 
-	if (TEST_RETURN == -1)
-		tst_res(TFAIL | TTERRNO, "write(2) failed");
+	SAFE_LSEEK(fd, 0, SEEK_SET);
+
+	for (i = BUFSIZ; i > 0; i--) {
+		TEST(write(fd, buf, i));
+		if (TEST_RETURN == -1) {
+			tst_res(TFAIL | TTERRNO, "write failed");
+			return;
+		}
+
+		if (TEST_RETURN != i) {
+			badcount++;
+			tst_res(TINFO, "write() returned %ld, expected %d",
+				TEST_RETURN, i);
+		}
+	}
+
+	if (badcount != 0)
+		tst_res(TFAIL, "write() failed to return proper count");
 	else
-		tst_res(TPASS, "write(2) returned %ld", TEST_RETURN);
+		tst_res(TPASS, "write() passed");
 }
 
 static void setup(void)
 {
-	fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0700);
+	fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0700);
 }
 
 static void cleanup(void)
@@ -58,8 +70,8 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
-	.test_all = verify_write,
 	.setup = setup,
 	.cleanup = cleanup,
+	.test_all = verify_write,
 	.needs_tmpdir = 1,
 };
diff --git a/testcases/kernel/syscalls/write/write02.c b/testcases/kernel/syscalls/write/write02.c
deleted file mode 100644
index 4924422..0000000
--- a/testcases/kernel/syscalls/write/write02.c
+++ /dev/null
@@ -1,146 +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 Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * NAME
- *	write02.c
- *
- * DESCRIPTION
- *	Basic functionality test: does the return from write match the count
- *	of the number of bytes written.
- *
- *
- * ALGORITHM
- *	Create a file and write some bytes out to it.
- *	Check the return count against the number returned.
- *
- * USAGE:  <for command-line>
- *      write02 [-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 John George
- *		-Ported
- *
- * Restrictions
- *	None
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdio.h>
-#include "test.h"
-
-char *TCID = "write02";
-int TST_TOTAL = 1;
-
-void cleanup(void);
-void setup(void);
-
-char pfiln[40] = "";
-
-int main(int argc, char **argv)
-{
-	int lc;
-
-	int cwrite;
-	int fild;
-	int iws;
-	int badcount = 0;
-	char pwbuf[BUFSIZ + 1];
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();		/* global setup for test */
-
-	/* The following loop checks looping state if -i option given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-//block1:
-		tst_resm(TINFO, "Block 1: test to see write() returns proper "
-			 "write count");
-
-		for (iws = 0; iws < BUFSIZ; iws++) {
-			pwbuf[iws] = 'A' + (iws % 26);
-		}
-		pwbuf[BUFSIZ] = '\n';
-
-		if ((fild = creat(pfiln, 0777)) == -1) {
-			tst_brkm(TBROK, cleanup, "Can't creat Xwrit");
-		}
-		for (iws = BUFSIZ; iws > 0; iws--) {
-			if ((cwrite = write(fild, pwbuf, iws)) != iws) {
-				badcount++;
-				tst_resm(TINFO, "bad write count");
-			}
-		}
-		if (badcount != 0) {
-			tst_resm(TFAIL, "write() FAILED to return proper cnt");
-		} else {
-			tst_resm(TPASS, "write() PASSED");
-		}
-		tst_resm(TINFO, "block 1 passed");
-		close(fild);
-	}
-	cleanup();
-	tst_exit();
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test
- */
-void setup(void)
-{
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	umask(0);
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(pfiln, "write1.%d", getpid());
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at completion or
- * premature exit.
- */
-void cleanup(void)
-{
-
-	unlink(pfiln);
-
-	tst_rmdir();
-}
-- 
1.8.3.1




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

* [LTP] [PATCH v3] syscalls/write01.c: Add test with different buffer sizes && Remove write02
  2017-06-15  9:26       ` [LTP] [PATCH v3] " Jinhui Huang
@ 2017-06-15 14:56         ` Cyril Hrubis
  0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2017-06-15 14:56 UTC (permalink / raw)
  To: ltp

Hi!
I've changed the patch to remove the write02 from the .gitignore file as
well and pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2017-06-15 14:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-21 10:48 [LTP] [PATCH 1/2] syscall/write02.c: Cleanup && convert to new API Jinhui Huang
2017-04-21 10:48 ` [LTP] [PATCH 2/2] syscall/write03.c: " Jinhui Huang
2017-05-26 14:14   ` Cyril Hrubis
2017-05-26 14:16 ` [LTP] [PATCH 1/2] syscall/write02.c: " Cyril Hrubis
2017-06-12  7:27   ` [LTP] [PATCH v2] syscalls/write01.c: Add test with different buffer sizes && Remove write02 Jinhui Huang
2017-06-13 10:59     ` Cyril Hrubis
2017-06-15  9:26       ` [LTP] [PATCH v3] " Jinhui Huang
2017-06-15 14:56         ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox