All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] Get rid of few more useless sleep() calls
@ 2018-04-05 14:50 Cyril Hrubis
  2018-04-05 14:50 ` [LTP] [RFC PATCH 1/6] exit02: Rewrite to new library Cyril Hrubis
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Cyril Hrubis @ 2018-04-05 14:50 UTC (permalink / raw)
  To: ltp

This patchset gets rid of a few useless sleeps speeding up the syscalls
run by another ~17s. It may not seem a lot, but if we combine all the
possible speedups we may save up to five minutes which is ~30% of
the syscall testsuite runtime for me.


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

* [LTP] [RFC PATCH 1/6] exit02: Rewrite to new library
  2018-04-05 14:50 [LTP] Get rid of few more useless sleep() calls Cyril Hrubis
@ 2018-04-05 14:50 ` Cyril Hrubis
  2018-04-06  8:47   ` Jan Stancek
  2018-04-05 14:50 ` [LTP] [RFC PATCH 2/6] syscalls/pipe11: " Cyril Hrubis
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Cyril Hrubis @ 2018-04-05 14:50 UTC (permalink / raw)
  To: ltp

We get rid of the ridiculous sleep(2) in the test as a side effect.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/exit/exit02.c | 249 ++++++++------------------------
 1 file changed, 60 insertions(+), 189 deletions(-)

diff --git a/testcases/kernel/syscalls/exit/exit02.c b/testcases/kernel/syscalls/exit/exit02.c
index 7858c894d..8143870e8 100644
--- a/testcases/kernel/syscalls/exit/exit02.c
+++ b/testcases/kernel/syscalls/exit/exit02.c
@@ -1,212 +1,83 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *    07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  *
- *   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 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.
  *
- *   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
+ * 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
- * 	exit02.c
- *
- * DESCRIPTION
- *	Check that exit flushes output file buffers and closes files upon
- *	exitting
- *
- * ALGORITHM
- * 	Fork a process that creates a file and writes a few bytes, and
- * 	calls exit WITHOUT calling close(). The parent then reads the
- * 	file.  If everything that was written is present in the file, then
- *	the test passes.
- *
- * USAGE
- * 	exit02
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- * 	None
+ * Fork a process that creates a file and writes a few bytes, and
+ * calls exit WITHOUT calling close(). The parent then reads the
+ * file.  If everything that was written is present in the file, then
+ * the test passes.
  */
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <string.h>
-#include "test.h"
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "exit02";
-int TST_TOTAL = 1;
-
-#define READ  0
-#define WRITE 1
-#define MODE 0666
-
-char filen[40];
-
-int main(int ac, char **av)
+
+#include <stdlib.h>
+#include "tst_test.h"
+
+#define FNAME "test_file"
+
+static void child_write(void)
 {
-	int pid, npid, sig, nsig, exno, nexno, status;
-	int filed;
-	char wbuf[BUFSIZ], rbuf[BUFSIZ];
-	int len, rlen;
-	int rval = 0;
-	int lc;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, 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;
-
-		strcpy(wbuf, "abcd");
-		len = strlen(wbuf);
-
-		exno = sig = 0;
-
-		if ((pid = FORK_OR_VFORK()) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
-
-		if (pid == 0) {	/* child */
-			sleep(1);
-			if ((filed = creat(filen, MODE)) == -1) {
-				tst_resm(TINFO, "creat error: unable to"
-					 "open output file");
-				exit(2);
-			}
-			if (write(filed, wbuf, len) != len) {
-				tst_resm(TINFO, "write error");
-				exit(2);
-			}
-			exit(exno);
-		} else {	/* parent */
-			npid = wait(&status);
-
-			if (npid != pid) {
-				tst_resm(TFAIL, "wait error: "
-					 "unexpected pid returned");
-				rval = 1;
-			}
-
-			nsig = status % 256;
-
-			/*
-			 * to check if the core dump bit has been
-			 * set, bit # 7
-			 */
-			if (nsig >= 128)
-				nsig = nsig - 128;
-
-			/*
-			 * nsig is the signal number returned by
-			 * wait
-			 */
-			if (nsig != sig) {
-				tst_resm(TFAIL, "wait error: unexpected "
-					 "signal returned %d", nsig);
-				rval = 1;
-			}
-
-			/*
-			 * nexno is the exit number returned by wait
-			 */
-			nexno = status / 256;
-			if (nexno != exno) {
-				tst_resm(TFAIL, "wait error: unexpected exit "
-					 "number %d", nexno);
-				rval = 1;
-			}
-
-			sleep(2);	/* let child's exit close opened file */
-
-			filed = open(filen, O_RDONLY, READ);
-			if (filed == -1) {
-				tst_resm(TFAIL, "open error: "
-					 "unable to open input file");
-				rval = 1;
-			} else {
-				rlen = read(filed, rbuf, len);
-				if (len != rlen) {
-					tst_resm(TFAIL, "exit error: file "
-						 "buffer was not flushed");
-					rval = 1;
-				} else if (strncmp(rbuf, wbuf, len) != 0) {
-					tst_resm(TFAIL, "exit error: file "
-						 "buffer was not flushed");
-					rval = 1;
-				}
-			}
-			close(filed);
-			unlink(filen);
-		}
-		if (!rval) {
-			tst_resm(TPASS, "exit() test PASSED");
-		}
-	}
-	cleanup();
-	tst_exit();
+	int fd;
+
+	fd = SAFE_CREAT(FNAME, 0666);
+	SAFE_WRITE(1, fd, FNAME, sizeof(FNAME));
+	exit(0);
 }
 
-/*
- * setup() - perform all ONE TIME setup for this test
- */
-void setup(void)
+static void check_file(void)
 {
+	int fd, len;
+	char buf[256];
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	fd = SAFE_OPEN(FNAME, O_RDONLY);
+	len = SAFE_READ(0, fd, buf, sizeof(buf));
 
-	umask(0);
+	if (len != sizeof(FNAME)) {
+		tst_res(TFAIL, "Wrong length %i expected %zu", len, sizeof(buf));
+		return;
+	}
 
-	TEST_PAUSE;
+	if (memcmp(buf, FNAME, sizeof(FNAME))) {
+		tst_res(TFAIL, "Wrong data read back");
+		return;
+	}
 
-	tst_tmpdir();
+	SAFE_CLOSE(fd);
 
-	sprintf(filen, "tfile_%d", getpid());
+	tst_res(TPASS, "File written by child read back correctly");
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at completion or
- *	       premature exit.
- */
-void cleanup(void)
+static void run(void)
 {
+	int pid;
 
-	/*
-	 * Remove tmp dir and all files in it
-	 */
-	tst_rmdir();
+	pid = SAFE_FORK();
+	if (!pid)
+		child_write();
 
-	/*
-	 * exit with return code appropriate for results
-	 */
+	tst_reap_children();
 
+	check_file();
+
+	SAFE_UNLINK(FNAME);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+	.test_all = run,
+};
-- 
2.13.6


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

* [LTP] [RFC PATCH 2/6] syscalls/pipe11: Rewrite to new library.
  2018-04-05 14:50 [LTP] Get rid of few more useless sleep() calls Cyril Hrubis
  2018-04-05 14:50 ` [LTP] [RFC PATCH 1/6] exit02: Rewrite to new library Cyril Hrubis
@ 2018-04-05 14:50 ` Cyril Hrubis
  2018-04-06  8:48   ` Jan Stancek
  2018-04-05 14:50 ` [LTP] [RFC PATCH 3/6] syscalls/alarm05: Rewrite to the " Cyril Hrubis
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Cyril Hrubis @ 2018-04-05 14:50 UTC (permalink / raw)
  To: ltp

+ Check that the buffer read in the child is correct as well

+ We got rid of sleep(5) as a side effect

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/pipe/pipe11.c | 289 +++++++++-----------------------
 1 file changed, 77 insertions(+), 212 deletions(-)

diff --git a/testcases/kernel/syscalls/pipe/pipe11.c b/testcases/kernel/syscalls/pipe/pipe11.c
index e3b274128..6964f164d 100644
--- a/testcases/kernel/syscalls/pipe/pipe11.c
+++ b/testcases/kernel/syscalls/pipe/pipe11.c
@@ -1,246 +1,111 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *    07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  *
- *   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 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.
  *
- *   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
+ * 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
- *	pipe11.c
- *
- * DESCRIPTION
- *	Check if many children can read what is written to a pipe by the
- *	parent.
+ * Check if many children can read what is written to a pipe by the parent.
  *
  * ALGORITHM
- *	1. Open a pipe and write to it
- *	2. Fork a large number of children
- *	3. Have the children read the pipe and check how many characters
- *	   each got
- *
- * USAGE:  <for command-line>
- *  pipe11 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *             -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
+ *   For a different nchilds number:
+ *	1. Open a pipe and write nchilds * (PIPE_BUF/nchilds) bytes into it
+ *	2. Fork nchilds children
+ *	3. Each child reads PIPE_BUF/nchilds characters and checks that the
+ *	   bytes read are correct
  */
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <stdio.h>
-#include <limits.h>
-#include "test.h"
-
-char *TCID = "pipe11";
-int TST_TOTAL = 1;
-
-void do_child(void);
-void do_child_uclinux(void);
-void setup(void);
-void cleanup(void);
-
-#define	NUMCHILD	50
-#define	NCPERCHILD	50
-char rawchars[] =
-    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
-int kidid;
-int numchild;			/* no of children to fork */
-int ncperchild;			/* no of chars child should read */
-int szcharbuf;			/* size of char buf */
-int pipewrcnt;			/* chars written to pipe */
-char *wrbuf, *rdbuf;
-int fd[2];			/* fds for pipe read/write */
-
-ssize_t do_read(int fd, void *buf, size_t count)
-{
-	ssize_t n;
-
-	do {
-		n = read(fd, buf, count);
-	} while (n < 0 && errno == EINTR);
+#include <stdlib.h>
+#include "tst_test.h"
 
-	return n;
-}
+static int fd[2];
+static unsigned char buf[PIPE_BUF];
+static size_t read_per_child;
 
-int main(int ac, char **av)
+void do_child(void)
 {
-	int lc;
-
-	int i;
-	int fork_ret, status;
-	int written;		/* no of chars read and written */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-#ifdef UCLINUX
-	maybe_run_child(&do_child_uclinux, "ddddd", &fd[0], &fd[1], &kidid,
-			&ncperchild, &szcharbuf);
-#endif
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
+	size_t nread;
+	unsigned char rbuf[read_per_child];
+	unsigned int i;
 
-		TEST(pipe(fd));
+	SAFE_CLOSE(fd[1]);
 
-		if (TEST_RETURN != 0) {
-			tst_resm(TFAIL, "pipe creation failed");
-			continue;
-		}
-
-		written = write(fd[1], wrbuf, szcharbuf);
-		if (written != szcharbuf) {
-			tst_brkm(TBROK, cleanup, "write to pipe failed");
-		}
-
-refork:
-		++kidid;
-		fork_ret = FORK_OR_VFORK();
-
-		if (fork_ret < 0) {
-			tst_brkm(TBROK, cleanup, "fork() failed");
-		}
-
-		if ((fork_ret != 0) && (fork_ret != -1) && (kidid < numchild)) {
-			goto refork;
-		}
+	nread = SAFE_READ(0, fd[0], rbuf, sizeof(rbuf));
 
-		if (fork_ret == 0) {	/* child */
-#ifdef UCLINUX
-			if (self_exec(av[0], "ddddd", fd[0], fd[1], kidid,
-				      ncperchild, szcharbuf) < 0) {
-				tst_brkm(TBROK, cleanup, "self_exec failed");
-			}
-#else
-			do_child();
-#endif
-		}
+	if (nread != read_per_child) {
+		tst_res(TFAIL, "Invalid read size child %i size %zu",
+		        getpid(), nread);
+		return;
+	}
 
-		/* parent */
-		sleep(5);
-		tst_resm(TINFO, "There are %d children to wait for", kidid);
-		for (i = 1; i <= kidid; ++i) {
-			wait(&status);
-			if (status == 0) {
-				tst_resm(TPASS, "child %d exited successfully",
-					 i);
-			} else {
-				tst_resm(TFAIL, "child %d exited with bad "
-					 "status", i);
-			}
+	for (i = 0; i < read_per_child; i++) {
+		if (rbuf[i] != (i % 256)) {
+			tst_res(TFAIL,
+			        "Invalid byte read child %i byte %i have %i expected %i",
+				getpid(), i, rbuf[i], i % 256);
+			return;
 		}
 	}
-	cleanup();
-
-	tst_exit();
-}
-
-/*
- * do_child()
- */
-void do_child(void)
-{
-	int nread;
 
-	if (close(fd[1])) {
-		tst_resm(TINFO, "child %d " "could not close pipe", kidid);
-		exit(0);
-	}
-	nread = do_read(fd[0], rdbuf, ncperchild);
-	if (nread == ncperchild) {
-		tst_resm(TINFO, "child %d " "got %d chars", kidid, nread);
-		exit(0);
-	} else {
-		tst_resm(TFAIL, "child %d did not receive expected no of "
-			 "characters, got %d characters", kidid, nread);
-		exit(1);
-	}
+	tst_res(TPASS, "Child %i read pipe buffer correctly", getpid());
 }
 
-/*
- * do_child_uclinux() - as above, but mallocs rdbuf first
- */
-void do_child_uclinux(void)
-{
-	if ((rdbuf = malloc(szcharbuf)) == NULL) {
-		tst_brkm(TBROK, cleanup, "malloc of rdbuf failed");
-	}
-
-	do_child();
-}
+static unsigned int childs[] = {
+	1,
+	2,
+	3,
+	4,
+	10,
+	50
+};
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(unsigned int tcase)
 {
-	int i;
-	unsigned int j;
+	pid_t pid;
+	unsigned int nchilds = childs[tcase];
+	read_per_child = PIPE_BUF/nchilds;
+	unsigned int i, j;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	tst_res(TINFO, "Reading %zu per each of %u children",
+	        read_per_child, nchilds);
 
-	TEST_PAUSE;
-
-	numchild = NUMCHILD;
-	ncperchild = NCPERCHILD;
+	for (i = 0; i < nchilds; i++) {
+		for (j = 0; j < read_per_child; j++) {
+			buf[i * read_per_child + j] = j % 256;
+		}
+	}
 
-	kidid = 0;
+	SAFE_PIPE(fd);
 
-	/* allocate read and write buffers */
-	szcharbuf = numchild * ncperchild;
+	SAFE_WRITE(1, fd[1], buf, read_per_child * nchilds);
 
-	/* make sure pipe write doesn't block */
-	if (szcharbuf == PIPE_BUF) {
-		/* adjust number of characters per child */
-		ncperchild = szcharbuf / numchild;
-	}
+	for (i = 0; i < nchilds; i++) {
+		pid = SAFE_FORK();
 
-	if ((wrbuf = malloc(szcharbuf)) == NULL) {
-		tst_brkm(TBROK, cleanup, "malloc failed");
-	}
-
-	if ((rdbuf = malloc(szcharbuf)) == NULL) {
-		tst_brkm(TBROK, cleanup, "malloc of rdbuf failed");
+		if (!pid) {
+			do_child();
+			exit(0);
+		}
 	}
 
-	/* initialize wrbuf */
-	j = 0;
-	for (i = 0; i < szcharbuf;) {
-		wrbuf[i++] = rawchars[j++];
-		if (j >= sizeof(rawchars))
-			j = 0;
-	}
+	tst_reap_children();
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.forks_child = 1,
+	.test = run,
+	.tcnt = ARRAY_SIZE(childs),
+};
-- 
2.13.6


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

* [LTP] [RFC PATCH 3/6] syscalls/alarm05: Rewrite to the new library.
  2018-04-05 14:50 [LTP] Get rid of few more useless sleep() calls Cyril Hrubis
  2018-04-05 14:50 ` [LTP] [RFC PATCH 1/6] exit02: Rewrite to new library Cyril Hrubis
  2018-04-05 14:50 ` [LTP] [RFC PATCH 2/6] syscalls/pipe11: " Cyril Hrubis
@ 2018-04-05 14:50 ` Cyril Hrubis
  2018-04-05 14:50 ` [LTP] [RFC PATCH 4/6] syscalls/alarm01: Remove Cyril Hrubis
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Cyril Hrubis @ 2018-04-05 14:50 UTC (permalink / raw)
  To: ltp

+ Speed up the test a bit, we save 6 seconds yay!

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/alarm/alarm05.c | 216 +++++++-----------------------
 1 file changed, 45 insertions(+), 171 deletions(-)

diff --git a/testcases/kernel/syscalls/alarm/alarm05.c b/testcases/kernel/syscalls/alarm/alarm05.c
index 1e93d2554..acb43c9a8 100644
--- a/testcases/kernel/syscalls/alarm/alarm05.c
+++ b/testcases/kernel/syscalls/alarm/alarm05.c
@@ -1,203 +1,77 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001,2005
+ *	07/2001 Ported by Wayne Boyer
+ *	06/2005 Test for alarm cleanup by Amos Waterland
  *
- *   Copyright (c) International Business Machines  Corp., 2001,2005
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  *
- *   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 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.
+ * 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
+ * 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
  */
 
 /*
- * Test Name: alarm05
- *
  * Test Description:
- *  Check the functionality of the Alarm system call when the time input
- *  parameter is non zero.
- *
- * Expected Result:
  *  The return value of the alarm system call should be equal to the
  *  amount previously remaining in the alarm clock.
  *  A SIGALRM signal should be received after the specified amount of
  *  time has elapsed.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *   	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *
- * Usage:  <for command-line>
- *  alarm05 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -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
- *	06/2005 Test for alarm cleanup by Amos Waterland
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  None.
  */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-
-#include "test.h"
+#include "tst_test.h"
 
-char *TCID = "alarm05";
-int TST_TOTAL = 1;
-int alarms_received = 0;	/* flag to indicate SIGALRM received or not */
+static volatile int alarms_fired = 0;
 
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-void sigproc(int sig);		/* signal catching function */
-
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
-	int time_sec1 = 10;	/* time for which 1st alarm is set */
-	int time_sec2 = 5;	/* time for which 2st alarm is set */
-	int ret_val1, ret_val2;	/* return values for alarm() calls */
-	int ret_val3;
-	int sleep_time1 = 3;	/* waiting time for the signal */
-	int sleep_time2 = 6;	/* waiting time for the signal */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	unsigned int ret;
 
-		tst_count = 0;
+	alarms_fired = 0;
 
-		/*
-		 * Reset alarms_received for every iteration, since it has
-		 * old values from previous iterations (if any) and not
-		 * a value of zero
-		 */
-		alarms_received = 0;
+	ret = alarm(10);
+	if (ret)
+		tst_res(TFAIL, "alarm() returned non-zero");
+	else
+		tst_res(TPASS, "alarm() returned zero");
 
-		/*
-		 * Call First alarm() with non-zero time parameter
-		 * 'time_sec1' to send SIGALRM to the calling process.
-		 */
-		TEST(alarm(time_sec1));
-		ret_val1 = TEST_RETURN;
+	sleep(1);
 
-		/* Wait for signal SIGALARM */
-		sleep(sleep_time1);
+	ret = alarm(1);
+	if (ret == 9)
+		tst_res(TPASS, "alarm() returned remainder correctly");
+	else
+		tst_res(TFAIL, "alarm() returned wrong remained %u", ret);
 
-		/*
-		 * Call Second alarm() with non-zero time parameter
-		 * 'time_sec2' to send SIGALRM to the calling process.
-		 */
-		TEST(alarm(time_sec2));
-		ret_val2 = TEST_RETURN;
+	sleep(2);
 
-		/* Wait for signal SIGALRM */
-		sleep(sleep_time2);
-
-		/*
-		 * Check whether the second alarm() call returned
-		 * the amount of time previously remaining in the
-		 * alarm clock of the calling process, and
-		 * sigproc() executed when SIGALRM received by the
-		 * process, the variable alarms_received is set.
-		 */
-		if ((alarms_received == 1) &&
-		    (ret_val2 == (time_sec1 - sleep_time1))) {
-
-			/*
-			 *  Make sure the system cleaned up the alarm
-			 *  after it delivered it.
-			 */
-			TEST(alarm(0));
-			ret_val3 = TEST_RETURN;
-
-			if (ret_val3 != 0)
-				tst_resm(TFAIL, "System did not "
-					 "clean up delivered " "alarm");
-			else {
-				tst_resm(TPASS, "Functionality of "
-					 "alarm(%u) successful",
-					 time_sec2);
-			}
-		} else {
-			tst_resm(TFAIL, "alarm(%u) fails, returned %d, "
-				 "alarms_received:%d",
-				 time_sec2, ret_val2, alarms_received);
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	if (alarms_fired == 1)
+		tst_res(TPASS, "alarm handler fired once");
+	else
+		tst_res(TFAIL, "alarm handler filred %u times", alarms_fired);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- *  Setup the signal handler to catch SIGALRM.
- */
-void setup(void)
+static void sighandler(int sig)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Set the signal catching function */
-	if (signal(SIGALRM, sigproc) == SIG_ERR) {
-		tst_brkm(TFAIL, cleanup,
-			 "signal() fails to catch SIGALARM, errno=%d", errno);
-	}
+	if (sig == SIGALRM)
+		alarms_fired++;
 }
 
-/*
- * sigproc(int) - This function defines the action that has to be taken
- *	          when the SIGALRM signal is caught.
- *   It also sets the variable which is used to check whether the
- *   alarm system call was successful.
- */
-void sigproc(int sig)
+static void setup(void)
 {
-	alarms_received++;
+	SAFE_SIGNAL(SIGALRM, sighandler);
 }
 
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- */
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+};
-- 
2.13.6


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

* [LTP] [RFC PATCH 4/6] syscalls/alarm01: Remove
  2018-04-05 14:50 [LTP] Get rid of few more useless sleep() calls Cyril Hrubis
                   ` (2 preceding siblings ...)
  2018-04-05 14:50 ` [LTP] [RFC PATCH 3/6] syscalls/alarm05: Rewrite to the " Cyril Hrubis
@ 2018-04-05 14:50 ` Cyril Hrubis
  2018-04-05 14:50 ` [LTP] [RFC PATCH 5/6] syscalls/waitpid01: Rewrite to the new library Cyril Hrubis
  2018-04-05 14:50 ` [LTP] [RFC PATCH 6/6] syscalls/wait401: " Cyril Hrubis
  5 siblings, 0 replies; 12+ messages in thread
From: Cyril Hrubis @ 2018-04-05 14:50 UTC (permalink / raw)
  To: ltp

The test was simply wrong alarm() does not return a failure at all.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/ltplite                           |   1 -
 runtest/quickhit                          |   2 -
 runtest/stress.part3                      |   1 -
 runtest/syscalls                          |   1 -
 testcases/kernel/syscalls/.gitignore      |   1 -
 testcases/kernel/syscalls/alarm/alarm01.c | 176 ------------------------------
 6 files changed, 182 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/alarm/alarm01.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 15dc0c20f..001325d65 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -71,7 +71,6 @@ acct01 acct01
 adjtimex01 adjtimex01
 adjtimex02 adjtimex02
 
-alarm01 alarm01
 alarm02 alarm02
 alarm03 alarm03
 alarm05 alarm05
diff --git a/runtest/quickhit b/runtest/quickhit
index 99e7c4779..2a1056971 100644
--- a/runtest/quickhit
+++ b/runtest/quickhit
@@ -3,8 +3,6 @@ access01 access01
 # Basic test for access(2) using F_OK, R_OK, W_OK and X_OK arguments.
 access03 access03
 # EFAULT error testing for access(2)
-alarm01 alarm01
-# Basic test for alarm(2)
 alarm02 alarm02
 # Boundary Value Test for alarm(2)
 #    TEST CASES
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 2a7747ce3..0d5951454 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -13,7 +13,6 @@ acct01 acct01
 adjtimex01 adjtimex01
 adjtimex02 adjtimex02
 
-alarm01 alarm01
 alarm02 alarm02
 alarm03 alarm03
 alarm05 alarm05
diff --git a/runtest/syscalls b/runtest/syscalls
index 76ab082be..71cfd2d6f 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -19,7 +19,6 @@ add_key04 add_key04
 adjtimex01 adjtimex01
 adjtimex02 adjtimex02
 
-alarm01 alarm01
 alarm02 alarm02
 alarm03 alarm03
 alarm05 alarm05
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index eea606e61..cd80cfc8f 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -12,7 +12,6 @@
 /add_key/add_key04
 /adjtimex/adjtimex01
 /adjtimex/adjtimex02
-/alarm/alarm01
 /alarm/alarm02
 /alarm/alarm03
 /alarm/alarm05
diff --git a/testcases/kernel/syscalls/alarm/alarm01.c b/testcases/kernel/syscalls/alarm/alarm01.c
deleted file mode 100644
index f17207b0a..000000000
--- a/testcases/kernel/syscalls/alarm/alarm01.c
+++ /dev/null
@@ -1,176 +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: alarm01.c,v 1.6 2009/08/28 10:57:29 vapier Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: alarm01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for alarm(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: William Roske
- *
- *    CO-PILOT		: Dave Fenner
- *
- *    DATE STARTED	: 03/30/92
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) alarm(2) returns...(See Description)
- *
- *    INPUT SPECIFICATIONS
- * 	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *    OUTPUT SPECIFICATIONS
- *$
- *    DURATION
- * 	Terminates - with frequency and infinite modes.
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    RESOURCES
- * 	None
- *
- *    ENVIRONMENTAL NEEDS
- * 	The libcuts.a and libsys.a libraries must be included in
- *	the compilation of this test.
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- * 	None
- *
- *    INTERCASE DEPENDENCIES
- * 	None
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the alarm(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	alarm(2).
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
-
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "alarm01";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call alarm(2)
-		 */
-		TEST(alarm(1));
-
-		/* check return code */
-		if (TEST_RETURN == -1)
-			tst_resm(TFAIL | TTERRNO, "alarm(1) failed");
-		else {
-			tst_resm(TPASS, "alarm(1) returned %ld",
-				 TEST_RETURN);
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-void setup(void)
-{
-	void trapper();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	signal(SIGALRM, trapper);
-
-	TEST_PAUSE;
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-}
-
-void trapper(int sig)
-{
-	signal(SIGALRM, trapper);
-}
-- 
2.13.6


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

* [LTP] [RFC PATCH 5/6] syscalls/waitpid01: Rewrite to the new library.
  2018-04-05 14:50 [LTP] Get rid of few more useless sleep() calls Cyril Hrubis
                   ` (3 preceding siblings ...)
  2018-04-05 14:50 ` [LTP] [RFC PATCH 4/6] syscalls/alarm01: Remove Cyril Hrubis
@ 2018-04-05 14:50 ` Cyril Hrubis
  2018-04-05 14:50 ` [LTP] [RFC PATCH 6/6] syscalls/wait401: " Cyril Hrubis
  5 siblings, 0 replies; 12+ messages in thread
From: Cyril Hrubis @ 2018-04-05 14:50 UTC (permalink / raw)
  To: ltp

+ use raise(SIGALRM) instead of wasting time with alarm(2)

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/waitpid/waitpid01.c | 172 ++++++++------------------
 1 file changed, 52 insertions(+), 120 deletions(-)

diff --git a/testcases/kernel/syscalls/waitpid/waitpid01.c b/testcases/kernel/syscalls/waitpid/waitpid01.c
index e05e783ef..efbc26e5a 100644
--- a/testcases/kernel/syscalls/waitpid/waitpid01.c
+++ b/testcases/kernel/syscalls/waitpid/waitpid01.c
@@ -1,142 +1,74 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *    07/2001 John George
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  *
- *   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 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.
  *
- *   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
+ * 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
- *	waitpid01.c
- *
- * DESCRIPTION
- *	Check that when a child kills itself by generating an alarm
- *	exception, the waiting parent is correctly notified.
- *
- * ALGORITHM
- *	Fork a child that sets an alarm. When the alarm goes off, causing
- *	the death of the child, the parent checks that SIG_ALRM was returned
- *
- * USAGE:  <for command-line>
- *      waitpid01 [-c n] [-i n] [-I x] [-P x] [-t]
- *      where,  -c n : Run n copies concurrently.
- *              -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
+ * Check that when a child kills itself by SIGALRM the waiting parent is
+ * correctly notified.
  *
- * Restrictions
- *	None
+ * Fork a child that raises(SIGALRM), the parent checks that SIGALRM was
+ * returned.
  */
-
-#include <sys/signal.h>
-#include <sys/types.h>
+#include <stdlib.h>
 #include <sys/wait.h>
-#include <errno.h>
-#include "test.h"
-
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "waitpid01";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
-int main(int argc, char **argv)
+static void run(void)
 {
-	int lc;
-
-	int pid, npid, sig, nsig;
-	int exno, nexno, status;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
+	pid_t pid, rpid;
+	int status;
 
-	setup();
-
-	/* check for looping state if -i option is given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		exno = 1;
-		sig = 14;
+	pid = SAFE_FORK();
+	if (!pid) {
+		raise(SIGALRM);
+		exit(0);
+	}
 
-		pid = FORK_OR_VFORK();
-		if (pid < 0) {
-			tst_brkm(TFAIL, cleanup, "Fork Failed");
-		} else if (pid == 0) {
-			alarm(2);
-			pause();
-			exit(exno);
-		} else {
-			errno = 0;
-			while (((npid = waitpid(pid, &status, 0)) != -1) ||
-			       (errno == EINTR)) {
-				if (errno == EINTR)
-					continue;
+	rpid = waitpid(pid, &status, 0);
+	if (rpid < 0)
+		tst_brk(TBROK | TERRNO, "waitpid() failed");
 
-				if (npid != pid) {
-					tst_resm(TFAIL, "waitpid error: "
-						 "unexpected pid returned");
-				} else {
-					tst_resm(TPASS,
-						 "recieved expected pid");
-				}
+	if (rpid != pid) {
+		tst_res(TFAIL, "waitpid() returned wrong pid %i, expected %i",
+		        rpid, pid);
+	} else {
+		tst_res(TPASS, "waitpid() returned correct pid %i", pid);
+	}
 
-				nsig = WTERMSIG(status);
+	if (!WIFSIGNALED(status)) {
+		tst_res(TFAIL, "WIFSIGNALED() not set in status (%s)",
+		        tst_strstatus(status));
+		return;
+	}
 
-				/*
-				 * nsig is the signal number returned by
-				 * waitpid
-				 */
-				if (nsig != sig) {
-					tst_resm(TFAIL, "waitpid error: "
-						 "unexpected signal "
-						 "returned");
-				} else {
-					tst_resm(TPASS, "recieved expected "
-						 "signal");
-				}
+	tst_res(TPASS, "WIFSIGNALED() set in status");
 
-				/*
-				 * nexno is the exit number returned by
-				 * waitpid
-				 */
-				nexno = WEXITSTATUS(status);
-				if (nexno != 0) {
-					tst_resm(TFAIL, "signal error: "
-						 "unexpected exit number "
-						 "returned");
-				}
-			}
-		}
+	if (WTERMSIG(status) != SIGALRM) {
+		tst_res(TFAIL, "WTERMSIG() != SIGALRM but %s",
+		        tst_strsig(WTERMSIG(status)));
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS, "WTERMSIG() == SIGALRM");
 }
 
-static void setup(void)
-{
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-}
+static struct tst_test test = {
+	.forks_child = 1,
+	.test_all = run,
+};
-- 
2.13.6


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

* [LTP] [RFC PATCH 6/6] syscalls/wait401: Rewrite to the new library
  2018-04-05 14:50 [LTP] Get rid of few more useless sleep() calls Cyril Hrubis
                   ` (4 preceding siblings ...)
  2018-04-05 14:50 ` [LTP] [RFC PATCH 5/6] syscalls/waitpid01: Rewrite to the new library Cyril Hrubis
@ 2018-04-05 14:50 ` Cyril Hrubis
  2018-04-06  8:54   ` Jan Stancek
  5 siblings, 1 reply; 12+ messages in thread
From: Cyril Hrubis @ 2018-04-05 14:50 UTC (permalink / raw)
  To: ltp

+ Get rid of the sleep(1) in the process

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/wait4/wait401.c | 122 +++++++++++-------------------
 1 file changed, 45 insertions(+), 77 deletions(-)

diff --git a/testcases/kernel/syscalls/wait4/wait401.c b/testcases/kernel/syscalls/wait4/wait401.c
index 26a5c7002..eb5f41f42 100644
--- a/testcases/kernel/syscalls/wait4/wait401.c
+++ b/testcases/kernel/syscalls/wait4/wait401.c
@@ -1,106 +1,74 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ * Copyright (c) 2012-2018 Cyril Hrubis <chrubis@suse.cz>
  *
- *   Copyright (c) International Business Machines  Corp., 2001
- *   Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
+ * 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 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.
  *
- *   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
+ * 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
  */
 
 /*
- *	wait401 - check that a call to wait4() correctly waits for a child
- *		  process to exit
+ * wait401 - check that a call to wait4() correctly waits for a child
+ *           process to exit
  */
 
-#include "test.h"
-
+#include <stdlib.h>
 #include <errno.h>
 #define _USE_BSD
 #include <sys/types.h>
 #include <sys/resource.h>
 #include <sys/wait.h>
+#include "tst_test.h"
 
-char *TCID = "wait401";
-int TST_TOTAL = 1;
-
-static void cleanup(void);
-static void setup(void);
-
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
 	pid_t pid;
 	int status = 1;
 	struct rusage rusage;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		pid = FORK_OR_VFORK();
-
-		switch (pid) {
-		case -1:
-			tst_brkm(TBROK, cleanup, "fork() failed");
-			break;
-		case 0:
-			sleep(1);
-			exit(0);
-			break;
-		default:
-			TEST(wait4(pid, &status, 0, &rusage));
-			break;
-		}
+	pid = SAFE_FORK();
+	if (!pid)
+		exit(0);
 
-		if (TEST_RETURN == -1) {
-			tst_brkm(TFAIL, cleanup, "%s call failed - errno = %d "
-				 ": %s", TCID, TEST_ERRNO,
-				 strerror(TEST_ERRNO));
-		}
-
-		if (WIFEXITED(status) == 0) {
-			tst_brkm(TFAIL, cleanup,
-				 "%s call succeeded but "
-				 "WIFEXITED() did not return expected value "
-				 "- %d", TCID, WIFEXITED(status));
-		} else if (TEST_RETURN != pid) {
-			tst_resm(TFAIL, "%s did not return the "
-				 "expected value (%d), actual: %ld",
-				 TCID, pid, TEST_RETURN);
-		} else {
+	TEST(wait4(pid, &status, 0, &rusage));
+	if (TEST_RETURN == -1) {
+		tst_res(TFAIL | TERRNO, "wait4() failed");
+		return;
+	}
 
-			tst_resm(TPASS,
-				 "Received child pid as expected.");
-		}
+	if (TEST_RETURN != pid) {
+		tst_res(TFAIL, "waitpid() returned wrong pid %li, expected %i",
+		        TEST_RETURN, pid);
+	} else {
+		tst_res(TPASS, "waitpid() returned correct pid %i", pid);
+	}
 
-		tst_resm(TPASS, "%s call succeeded", TCID);
+	if (!WIFEXITED(status)) {
+		tst_res(TFAIL, "WIFEXITED() not set in status (%s)",
+		        tst_strstatus(status));
+		return;
 	}
 
-	cleanup();
-	tst_exit();
-}
+	tst_res(TPASS, "WIFEXITED() is set in status");
 
-static void setup(void)
-{
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	if (WEXITSTATUS(status))
+		tst_res(TFAIL, "WEXITSTATUS() != 0 but %i", WEXITSTATUS(status));
+	else
+		tst_res(TPASS, "WEXITSTATUS() == 0");
 
-	TEST_PAUSE;
 }
 
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.forks_child = 1,
+	.test_all = run,
+};
-- 
2.13.6


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

* [LTP] [RFC PATCH 1/6] exit02: Rewrite to new library
  2018-04-05 14:50 ` [LTP] [RFC PATCH 1/6] exit02: Rewrite to new library Cyril Hrubis
@ 2018-04-06  8:47   ` Jan Stancek
  0 siblings, 0 replies; 12+ messages in thread
From: Jan Stancek @ 2018-04-06  8:47 UTC (permalink / raw)
  To: ltp



----- Original Message -----
> We get rid of the ridiculous sleep(2) in the test as a side effect.
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>

ACK to 3/6 4/6 5/6 patches.

Just a small observation here, subject doesn't have "syscalls/" as
the rest of series.

One more note below.

> ---
>  testcases/kernel/syscalls/exit/exit02.c | 249
>  ++++++++------------------------
>  1 file changed, 60 insertions(+), 189 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/exit/exit02.c
> b/testcases/kernel/syscalls/exit/exit02.c
> index 7858c894d..8143870e8 100644
> --- a/testcases/kernel/syscalls/exit/exit02.c
> +++ b/testcases/kernel/syscalls/exit/exit02.c
> @@ -1,212 +1,83 @@
>  /*
> + * Copyright (c) International Business Machines  Corp., 2001
> + *    07/2001 Ported by Wayne Boyer
> + * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
>   *
> - *   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 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.
>   *
> - *   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
> + * 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
> - * 	exit02.c
> - *
> - * DESCRIPTION
> - *	Check that exit flushes output file buffers and closes files upon
> - *	exitting
> - *
> - * ALGORITHM
> - * 	Fork a process that creates a file and writes a few bytes, and
> - * 	calls exit WITHOUT calling close(). The parent then reads the
> - * 	file.  If everything that was written is present in the file, then
> - *	the test passes.
> - *
> - * USAGE
> - * 	exit02
> - *
> - * HISTORY
> - *	07/2001 Ported by Wayne Boyer
> - *
> - * RESTRICTIONS
> - * 	None
> + * Fork a process that creates a file and writes a few bytes, and
> + * calls exit WITHOUT calling close(). The parent then reads the
> + * file.  If everything that was written is present in the file, then
> + * the test passes.
>   */
> -#include <sys/types.h>
> -#include <sys/wait.h>
> -#include <sys/stat.h>
> -#include <stdio.h>
> -#include <string.h>
> -#include <errno.h>
> -#include <signal.h>
> -#include <fcntl.h>
> -#include <string.h>
> -#include "test.h"
> -
> -void cleanup(void);
> -void setup(void);
> -
> -char *TCID = "exit02";
> -int TST_TOTAL = 1;
> -
> -#define READ  0
> -#define WRITE 1
> -#define MODE 0666
> -
> -char filen[40];
> -
> -int main(int ac, char **av)
> +
> +#include <stdlib.h>
> +#include "tst_test.h"
> +
> +#define FNAME "test_file"
> +
> +static void child_write(void)
>  {
> -	int pid, npid, sig, nsig, exno, nexno, status;
> -	int filed;
> -	char wbuf[BUFSIZ], rbuf[BUFSIZ];
> -	int len, rlen;
> -	int rval = 0;
> -	int lc;
> -
> -	/*
> -	 * parse standard options
> -	 */
> -	tst_parse_opts(ac, av, 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;
> -
> -		strcpy(wbuf, "abcd");
> -		len = strlen(wbuf);
> -
> -		exno = sig = 0;
> -
> -		if ((pid = FORK_OR_VFORK()) == -1)
> -			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
> -
> -		if (pid == 0) {	/* child */
> -			sleep(1);
> -			if ((filed = creat(filen, MODE)) == -1) {
> -				tst_resm(TINFO, "creat error: unable to"
> -					 "open output file");
> -				exit(2);
> -			}
> -			if (write(filed, wbuf, len) != len) {
> -				tst_resm(TINFO, "write error");
> -				exit(2);
> -			}
> -			exit(exno);
> -		} else {	/* parent */
> -			npid = wait(&status);
> -
> -			if (npid != pid) {
> -				tst_resm(TFAIL, "wait error: "
> -					 "unexpected pid returned");
> -				rval = 1;
> -			}
> -
> -			nsig = status % 256;
> -
> -			/*
> -			 * to check if the core dump bit has been
> -			 * set, bit # 7
> -			 */
> -			if (nsig >= 128)
> -				nsig = nsig - 128;
> -
> -			/*
> -			 * nsig is the signal number returned by
> -			 * wait
> -			 */
> -			if (nsig != sig) {
> -				tst_resm(TFAIL, "wait error: unexpected "
> -					 "signal returned %d", nsig);
> -				rval = 1;
> -			}
> -
> -			/*
> -			 * nexno is the exit number returned by wait
> -			 */
> -			nexno = status / 256;
> -			if (nexno != exno) {
> -				tst_resm(TFAIL, "wait error: unexpected exit "
> -					 "number %d", nexno);
> -				rval = 1;
> -			}
> -
> -			sleep(2);	/* let child's exit close opened file */
> -
> -			filed = open(filen, O_RDONLY, READ);
> -			if (filed == -1) {
> -				tst_resm(TFAIL, "open error: "
> -					 "unable to open input file");
> -				rval = 1;
> -			} else {
> -				rlen = read(filed, rbuf, len);
> -				if (len != rlen) {
> -					tst_resm(TFAIL, "exit error: file "
> -						 "buffer was not flushed");
> -					rval = 1;
> -				} else if (strncmp(rbuf, wbuf, len) != 0) {
> -					tst_resm(TFAIL, "exit error: file "
> -						 "buffer was not flushed");
> -					rval = 1;
> -				}
> -			}
> -			close(filed);
> -			unlink(filen);
> -		}
> -		if (!rval) {
> -			tst_resm(TPASS, "exit() test PASSED");
> -		}
> -	}
> -	cleanup();
> -	tst_exit();
> +	int fd;
> +
> +	fd = SAFE_CREAT(FNAME, 0666);
> +	SAFE_WRITE(1, fd, FNAME, sizeof(FNAME));
> +	exit(0);
>  }
>  
> -/*
> - * setup() - perform all ONE TIME setup for this test
> - */
> -void setup(void)
> +static void check_file(void)
>  {
> +	int fd, len;
> +	char buf[256];
>  
> -	tst_sig(FORK, DEF_HANDLER, cleanup);
> +	fd = SAFE_OPEN(FNAME, O_RDONLY);
> +	len = SAFE_READ(0, fd, buf, sizeof(buf));
>  
> -	umask(0);
> +	if (len != sizeof(FNAME)) {
> +		tst_res(TFAIL, "Wrong length %i expected %zu", len, sizeof(buf));
> +		return;
> +	}
>  
> -	TEST_PAUSE;
> +	if (memcmp(buf, FNAME, sizeof(FNAME))) {
> +		tst_res(TFAIL, "Wrong data read back");

We don't close fd here, but things are already going south,
so it's not that big deal.

ACK

Regards,
Jan

> +		return;
> +	}
>  
> -	tst_tmpdir();
> +	SAFE_CLOSE(fd);
>  
> -	sprintf(filen, "tfile_%d", getpid());
> +	tst_res(TPASS, "File written by child read back correctly");
>  }
>  
> -/*
> - * cleanup() - performs all ONE TIME cleanup for this test at completion or
> - *	       premature exit.
> - */
> -void cleanup(void)
> +static void run(void)
>  {
> +	int pid;
>  
> -	/*
> -	 * Remove tmp dir and all files in it
> -	 */
> -	tst_rmdir();
> +	pid = SAFE_FORK();
> +	if (!pid)
> +		child_write();
>  
> -	/*
> -	 * exit with return code appropriate for results
> -	 */
> +	tst_reap_children();
>  
> +	check_file();
> +
> +	SAFE_UNLINK(FNAME);
>  }
> +
> +static struct tst_test test = {
> +	.needs_tmpdir = 1,
> +	.forks_child = 1,
> +	.test_all = run,
> +};
> --
> 2.13.6
> 
> 
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
> 

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

* [LTP] [RFC PATCH 2/6] syscalls/pipe11: Rewrite to new library.
  2018-04-05 14:50 ` [LTP] [RFC PATCH 2/6] syscalls/pipe11: " Cyril Hrubis
@ 2018-04-06  8:48   ` Jan Stancek
  0 siblings, 0 replies; 12+ messages in thread
From: Jan Stancek @ 2018-04-06  8:48 UTC (permalink / raw)
  To: ltp



----- Original Message -----
> + Check that the buffer read in the child is correct as well
> 
> + We got rid of sleep(5) as a side effect
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  testcases/kernel/syscalls/pipe/pipe11.c | 289
>  +++++++++-----------------------
>  1 file changed, 77 insertions(+), 212 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/pipe/pipe11.c
> b/testcases/kernel/syscalls/pipe/pipe11.c
> index e3b274128..6964f164d 100644
> --- a/testcases/kernel/syscalls/pipe/pipe11.c
> +++ b/testcases/kernel/syscalls/pipe/pipe11.c
> @@ -1,246 +1,111 @@
>  /*
> + * Copyright (c) International Business Machines  Corp., 2001
> + *    07/2001 Ported by Wayne Boyer
> + * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
>   *
> - *   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 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.
>   *
> - *   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
> + * 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
> - *	pipe11.c
> - *
> - * DESCRIPTION
> - *	Check if many children can read what is written to a pipe by the
> - *	parent.
> + * Check if many children can read what is written to a pipe by the parent.
>   *
>   * ALGORITHM
> - *	1. Open a pipe and write to it
> - *	2. Fork a large number of children
> - *	3. Have the children read the pipe and check how many characters
> - *	   each got
> - *
> - * USAGE:  <for command-line>
> - *  pipe11 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
> - *     where,  -c n : Run n copies concurrently.
> - *             -f   : Turn off functionality Testing.
> - *             -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
> + *   For a different nchilds number:
> + *	1. Open a pipe and write nchilds * (PIPE_BUF/nchilds) bytes into it
> + *	2. Fork nchilds children
> + *	3. Each child reads PIPE_BUF/nchilds characters and checks that the
> + *	   bytes read are correct
>   */
> -#include <sys/types.h>
> -#include <sys/wait.h>
> -#include <errno.h>
> -#include <stdio.h>
> -#include <limits.h>
> -#include "test.h"
> -
> -char *TCID = "pipe11";
> -int TST_TOTAL = 1;
> -
> -void do_child(void);
> -void do_child_uclinux(void);
> -void setup(void);
> -void cleanup(void);
> -
> -#define	NUMCHILD	50
> -#define	NCPERCHILD	50
> -char rawchars[] =
> -
> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
> -int kidid;
> -int numchild;			/* no of children to fork */
> -int ncperchild;			/* no of chars child should read */
> -int szcharbuf;			/* size of char buf */
> -int pipewrcnt;			/* chars written to pipe */
> -char *wrbuf, *rdbuf;
> -int fd[2];			/* fds for pipe read/write */
> -
> -ssize_t do_read(int fd, void *buf, size_t count)
> -{
> -	ssize_t n;
> -
> -	do {
> -		n = read(fd, buf, count);
> -	} while (n < 0 && errno == EINTR);
> +#include <stdlib.h>
> +#include "tst_test.h"
>  
> -	return n;
> -}
> +static int fd[2];
> +static unsigned char buf[PIPE_BUF];
> +static size_t read_per_child;
>  
> -int main(int ac, char **av)
> +void do_child(void)
>  {
> -	int lc;
> -
> -	int i;
> -	int fork_ret, status;
> -	int written;		/* no of chars read and written */
> -
> -	tst_parse_opts(ac, av, NULL, NULL);
> -#ifdef UCLINUX
> -	maybe_run_child(&do_child_uclinux, "ddddd", &fd[0], &fd[1], &kidid,
> -			&ncperchild, &szcharbuf);
> -#endif
> -
> -	setup();
> -
> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
> -
> -		/* reset tst_count in case we are looping */
> -		tst_count = 0;
> +	size_t nread;
> +	unsigned char rbuf[read_per_child];
> +	unsigned int i;
>  
> -		TEST(pipe(fd));
> +	SAFE_CLOSE(fd[1]);
>  
> -		if (TEST_RETURN != 0) {
> -			tst_resm(TFAIL, "pipe creation failed");
> -			continue;
> -		}
> -
> -		written = write(fd[1], wrbuf, szcharbuf);
> -		if (written != szcharbuf) {
> -			tst_brkm(TBROK, cleanup, "write to pipe failed");
> -		}
> -
> -refork:
> -		++kidid;
> -		fork_ret = FORK_OR_VFORK();
> -
> -		if (fork_ret < 0) {
> -			tst_brkm(TBROK, cleanup, "fork() failed");
> -		}
> -
> -		if ((fork_ret != 0) && (fork_ret != -1) && (kidid < numchild)) {
> -			goto refork;
> -		}
> +	nread = SAFE_READ(0, fd[0], rbuf, sizeof(rbuf));
>  
> -		if (fork_ret == 0) {	/* child */
> -#ifdef UCLINUX
> -			if (self_exec(av[0], "ddddd", fd[0], fd[1], kidid,
> -				      ncperchild, szcharbuf) < 0) {
> -				tst_brkm(TBROK, cleanup, "self_exec failed");
> -			}
> -#else
> -			do_child();
> -#endif
> -		}
> +	if (nread != read_per_child) {
> +		tst_res(TFAIL, "Invalid read size child %i size %zu",
> +		        getpid(), nread);
> +		return;
> +	}
>  
> -		/* parent */
> -		sleep(5);
> -		tst_resm(TINFO, "There are %d children to wait for", kidid);
> -		for (i = 1; i <= kidid; ++i) {
> -			wait(&status);
> -			if (status == 0) {
> -				tst_resm(TPASS, "child %d exited successfully",
> -					 i);
> -			} else {
> -				tst_resm(TFAIL, "child %d exited with bad "
> -					 "status", i);
> -			}
> +	for (i = 0; i < read_per_child; i++) {
> +		if (rbuf[i] != (i % 256)) {
> +			tst_res(TFAIL,
> +			        "Invalid byte read child %i byte %i have %i expected %i",
> +				getpid(), i, rbuf[i], i % 256);
> +			return;
>  		}
>  	}
> -	cleanup();
> -
> -	tst_exit();
> -}
> -
> -/*
> - * do_child()
> - */
> -void do_child(void)
> -{
> -	int nread;
>  
> -	if (close(fd[1])) {
> -		tst_resm(TINFO, "child %d " "could not close pipe", kidid);
> -		exit(0);
> -	}
> -	nread = do_read(fd[0], rdbuf, ncperchild);
> -	if (nread == ncperchild) {
> -		tst_resm(TINFO, "child %d " "got %d chars", kidid, nread);
> -		exit(0);
> -	} else {
> -		tst_resm(TFAIL, "child %d did not receive expected no of "
> -			 "characters, got %d characters", kidid, nread);
> -		exit(1);
> -	}
> +	tst_res(TPASS, "Child %i read pipe buffer correctly", getpid());
>  }
>  
> -/*
> - * do_child_uclinux() - as above, but mallocs rdbuf first
> - */
> -void do_child_uclinux(void)
> -{
> -	if ((rdbuf = malloc(szcharbuf)) == NULL) {
> -		tst_brkm(TBROK, cleanup, "malloc of rdbuf failed");
> -	}
> -
> -	do_child();
> -}
> +static unsigned int childs[] = {
> +	1,
> +	2,
> +	3,
> +	4,
> +	10,
> +	50
> +};
>  
> -/*
> - * setup() - performs all ONE TIME setup for this test.
> - */
> -void setup(void)
> +static void run(unsigned int tcase)
>  {
> -	int i;
> -	unsigned int j;
> +	pid_t pid;
> +	unsigned int nchilds = childs[tcase];
> +	read_per_child = PIPE_BUF/nchilds;
> +	unsigned int i, j;
>  
> -	tst_sig(FORK, DEF_HANDLER, cleanup);
> +	tst_res(TINFO, "Reading %zu per each of %u children",
> +	        read_per_child, nchilds);
>  
> -	TEST_PAUSE;
> -
> -	numchild = NUMCHILD;
> -	ncperchild = NCPERCHILD;
> +	for (i = 0; i < nchilds; i++) {
> +		for (j = 0; j < read_per_child; j++) {
> +			buf[i * read_per_child + j] = j % 256;
> +		}
> +	}
>  
> -	kidid = 0;
> +	SAFE_PIPE(fd);
>  
> -	/* allocate read and write buffers */
> -	szcharbuf = numchild * ncperchild;
> +	SAFE_WRITE(1, fd[1], buf, read_per_child * nchilds);
>  
> -	/* make sure pipe write doesn't block */
> -	if (szcharbuf == PIPE_BUF) {
> -		/* adjust number of characters per child */
> -		ncperchild = szcharbuf / numchild;
> -	}
> +	for (i = 0; i < nchilds; i++) {
> +		pid = SAFE_FORK();
>  
> -	if ((wrbuf = malloc(szcharbuf)) == NULL) {
> -		tst_brkm(TBROK, cleanup, "malloc failed");
> -	}
> -
> -	if ((rdbuf = malloc(szcharbuf)) == NULL) {
> -		tst_brkm(TBROK, cleanup, "malloc of rdbuf failed");
> +		if (!pid) {
> +			do_child();
> +			exit(0);
> +		}
>  	}
>  
> -	/* initialize wrbuf */
> -	j = 0;
> -	for (i = 0; i < szcharbuf;) {
> -		wrbuf[i++] = rawchars[j++];
> -		if (j >= sizeof(rawchars))
> -			j = 0;
> -	}
> +	tst_reap_children();

pipe fds are not closed, and this could in theory repeat many times.
Other than that ACK.

Regards,
Jan

>  }
>  
> -/*
> - * cleanup() - performs all ONE TIME cleanup for this test at
> - *	       completion or premature exit.
> - */
> -void cleanup(void)
> -{
> -
> -}
> +static struct tst_test test = {
> +	.forks_child = 1,
> +	.test = run,
> +	.tcnt = ARRAY_SIZE(childs),
> +};
> --
> 2.13.6
> 
> 
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
> 

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

* [LTP] [RFC PATCH 6/6] syscalls/wait401: Rewrite to the new library
  2018-04-05 14:50 ` [LTP] [RFC PATCH 6/6] syscalls/wait401: " Cyril Hrubis
@ 2018-04-06  8:54   ` Jan Stancek
  2018-04-09  9:44     ` Cyril Hrubis
  0 siblings, 1 reply; 12+ messages in thread
From: Jan Stancek @ 2018-04-06  8:54 UTC (permalink / raw)
  To: ltp



----- Original Message -----
> + Get rid of the sleep(1) in the process
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>

> +	pid = SAFE_FORK();
> +	if (!pid)
> +		exit(0);

This doesn't seem to test that wait4() waits. The child can
end before call to wait4().

What if added call to tst_process_state_wait() to child,
so it waits on parent to sleep? If parent sleeps, then
it's likely waiting on child.

Regards,
Jan

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

* [LTP] [RFC PATCH 6/6] syscalls/wait401: Rewrite to the new library
  2018-04-06  8:54   ` Jan Stancek
@ 2018-04-09  9:44     ` Cyril Hrubis
  2018-04-13 13:40       ` Jan Stancek
  0 siblings, 1 reply; 12+ messages in thread
From: Cyril Hrubis @ 2018-04-09  9:44 UTC (permalink / raw)
  To: ltp

Hi!
> This doesn't seem to test that wait4() waits. The child can
> end before call to wait4().
> 
> What if added call to tst_process_state_wait() to child,
> so it waits on parent to sleep? If parent sleeps, then
> it's likely waiting on child.

That's a good idea, I've changed the test to do exactly that.

OK to commit with the changes you requested or should I resend the fixed
patchset?

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [RFC PATCH 6/6] syscalls/wait401: Rewrite to the new library
  2018-04-09  9:44     ` Cyril Hrubis
@ 2018-04-13 13:40       ` Jan Stancek
  0 siblings, 0 replies; 12+ messages in thread
From: Jan Stancek @ 2018-04-13 13:40 UTC (permalink / raw)
  To: ltp





----- Original Message -----
> From: "Cyril Hrubis" <chrubis@suse.cz>
> To: "Jan Stancek" <jstancek@redhat.com>
> Cc: ltp@lists.linux.it
> Sent: Monday, 9 April, 2018 11:44:40 AM
> Subject: Re: [LTP] [RFC PATCH 6/6] syscalls/wait401: Rewrite to the new library
> 
> Hi!
> > This doesn't seem to test that wait4() waits. The child can
> > end before call to wait4().
> > 
> > What if added call to tst_process_state_wait() to child,
> > so it waits on parent to sleep? If parent sleeps, then
> > it's likely waiting on child.
> 
> That's a good idea, I've changed the test to do exactly that.
> 
> OK to commit with the changes you requested or should I resend the fixed
> patchset?

Sorry for delay, I overlooked this email. No need to resend, ACK.

Regards,
Jan

> 
> --
> Cyril Hrubis
> chrubis@suse.cz
> 

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

end of thread, other threads:[~2018-04-13 13:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-05 14:50 [LTP] Get rid of few more useless sleep() calls Cyril Hrubis
2018-04-05 14:50 ` [LTP] [RFC PATCH 1/6] exit02: Rewrite to new library Cyril Hrubis
2018-04-06  8:47   ` Jan Stancek
2018-04-05 14:50 ` [LTP] [RFC PATCH 2/6] syscalls/pipe11: " Cyril Hrubis
2018-04-06  8:48   ` Jan Stancek
2018-04-05 14:50 ` [LTP] [RFC PATCH 3/6] syscalls/alarm05: Rewrite to the " Cyril Hrubis
2018-04-05 14:50 ` [LTP] [RFC PATCH 4/6] syscalls/alarm01: Remove Cyril Hrubis
2018-04-05 14:50 ` [LTP] [RFC PATCH 5/6] syscalls/waitpid01: Rewrite to the new library Cyril Hrubis
2018-04-05 14:50 ` [LTP] [RFC PATCH 6/6] syscalls/wait401: " Cyril Hrubis
2018-04-06  8:54   ` Jan Stancek
2018-04-09  9:44     ` Cyril Hrubis
2018-04-13 13:40       ` Jan Stancek

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.