public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT
@ 2020-01-22 13:42 Jorik Cronenberg
  2020-01-22 13:42 ` [LTP] [PATCH 2/2] syscalls/vmsplice: Add NONBLOCK testcase Jorik Cronenberg
  2020-01-23  6:21 ` [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT Yang Xu
  0 siblings, 2 replies; 7+ messages in thread
From: Jorik Cronenberg @ 2020-01-22 13:42 UTC (permalink / raw)
  To: ltp

Add the possibility to add a timeout to TST_PROCESS_STATE_WAIT.
Like checkpoints add TST_PROCESS_STATE_WAIT2()
for specifying a timeout. The original TST_PROCESS_STATE_WAIT()
works the same as before. Timeout can be specified in milliseconds.

Signed-off-by: Jorik Cronenberg <jcronenberg@suse.de>
---
 include/tst_process_state.h | 12 ++++++++----
 lib/tst_process_state.c     | 19 ++++++++++++++-----
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/include/tst_process_state.h b/include/tst_process_state.h
index fab0491d9..27a8ffc36 100644
--- a/include/tst_process_state.h
+++ b/include/tst_process_state.h
@@ -47,9 +47,13 @@
  */
 #ifdef TST_TEST_H__
 
+#define TST_PROCESS_STATE_WAIT2(pid, state, msec_timeout) \
+	tst_process_state_wait(__FILE__, __LINE__, NULL, \
+	                       (pid), (state), msec_timeout)
+
 #define TST_PROCESS_STATE_WAIT(pid, state) \
 	tst_process_state_wait(__FILE__, __LINE__, NULL, \
-	                       (pid), (state))
+	                       (pid), (state), 0)
 #else
 /*
  * The same as above but does not use tst_brkm() interface.
@@ -65,8 +69,8 @@ int tst_process_state_wait2(pid_t pid, const char state);
 	                        (pid), (state))
 #endif
 
-void tst_process_state_wait(const char *file, const int lineno,
-                            void (*cleanup_fn)(void),
-                            pid_t pid, const char state);
+int tst_process_state_wait(const char *file, const int lineno,
+                            void (*cleanup_fn)(void), pid_t pid,
+			    const char state, unsigned int msec_timeout);
 
 #endif /* TST_PROCESS_STATE__ */
diff --git a/lib/tst_process_state.c b/lib/tst_process_state.c
index 7a7824959..32b44992c 100644
--- a/lib/tst_process_state.c
+++ b/lib/tst_process_state.c
@@ -28,11 +28,12 @@
 #include "test.h"
 #include "tst_process_state.h"
 
-void tst_process_state_wait(const char *file, const int lineno,
-                            void (*cleanup_fn)(void),
-                            pid_t pid, const char state)
+int tst_process_state_wait(const char *file, const int lineno,
+                            void (*cleanup_fn)(void), pid_t pid,
+			    const char state, unsigned int msec_timeout)
 {
 	char proc_path[128], cur_state;
+	unsigned int msecs = 0;
 
 	snprintf(proc_path, sizeof(proc_path), "/proc/%i/stat", pid);
 
@@ -41,10 +42,18 @@ void tst_process_state_wait(const char *file, const int lineno,
 		                "%*i %*s %c", &cur_state);
 
 		if (state == cur_state)
-			return;
+			break;
 
-		usleep(10000);
+		usleep(1000);
+		msecs += 1;
+
+		if (msecs >= msec_timeout) {
+			errno = ETIMEDOUT;
+			return -1;
+		}
 	}
+
+	return 0;
 }
 
 int tst_process_state_wait2(pid_t pid, const char state)
-- 
2.24.1


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

* [LTP] [PATCH 2/2] syscalls/vmsplice: Add NONBLOCK testcase
  2020-01-22 13:42 [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT Jorik Cronenberg
@ 2020-01-22 13:42 ` Jorik Cronenberg
  2020-01-23  6:57   ` Yang Xu
  2020-01-23  6:21 ` [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT Yang Xu
  1 sibling, 1 reply; 7+ messages in thread
From: Jorik Cronenberg @ 2020-01-22 13:42 UTC (permalink / raw)
  To: ltp

Add a testcase for vmsplice() with the flag SPLICE_F_NONBLOCK.
And also test that vmsplice() blocks when writing to a full pipe
without the flag specified.

Signed-off-by: Jorik Cronenberg <jcronenberg@suse.de>
---
 testcases/kernel/syscalls/vmsplice/.gitignore |  1 +
 .../kernel/syscalls/vmsplice/vmsplice04.c     | 87 +++++++++++++++++++
 2 files changed, 88 insertions(+)
 create mode 100644 testcases/kernel/syscalls/vmsplice/vmsplice04.c

diff --git a/testcases/kernel/syscalls/vmsplice/.gitignore b/testcases/kernel/syscalls/vmsplice/.gitignore
index 03922073c..042c32585 100644
--- a/testcases/kernel/syscalls/vmsplice/.gitignore
+++ b/testcases/kernel/syscalls/vmsplice/.gitignore
@@ -1,3 +1,4 @@
 /vmsplice01
 /vmsplice02
 /vmsplice03
+/vmsplice04
diff --git a/testcases/kernel/syscalls/vmsplice/vmsplice04.c b/testcases/kernel/syscalls/vmsplice/vmsplice04.c
new file mode 100644
index 000000000..c49657d84
--- /dev/null
+++ b/testcases/kernel/syscalls/vmsplice/vmsplice04.c
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 SUSE LLC
+ * Author: Jorik Cronenberg <jcronenberg@suse.de>
+ *
+ * Test vmsplice() to a full pipe with SPLICE_F_NONBLOCK and without
+ * With SPLICE_F_NONBLOCK vmsplice() should return with errno EAGAIN
+ * Without SPLICE_F_NONBLOCK it should block
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/vmsplice.h"
+#include <stdlib.h>
+
+
+static int pipes[2];
+static ssize_t pipe_max_size;
+static char *write_buffer;
+
+static void vmsplice_test(void)
+{
+	int status;
+	struct iovec iov;
+	int pid;
+
+	iov.iov_base = write_buffer;
+	iov.iov_len = pipe_max_size;
+
+
+	TEST(vmsplice(pipes[1], &iov, 1, 0));
+	if (TST_RET < 0)
+		tst_brk(TBROK | TTERRNO,
+		    "Initial vmsplice() to fill pipe failed");
+
+	TEST(vmsplice(pipes[1], &iov, 1, SPLICE_F_NONBLOCK));
+	if (TST_RET < 0 && TST_ERR == EAGAIN)
+		tst_res(TPASS | TTERRNO, "vmsplice failed as expected");
+	else if (TST_RET < 0)
+		tst_res(TFAIL | TTERRNO,
+		    "vmsplice failed with unexpected errno");
+	else
+		tst_res(TFAIL, "vmsplice wrote to a full pipe");
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		TEST(vmsplice(pipes[1], &iov, 1, 0));
+		if (TST_RET < 0)
+			tst_res(TFAIL | TTERRNO, "vmsplice() failed");
+		else
+			tst_res(TFAIL, "vmsplice() wrote to a full pipe");
+		exit(0);
+	} else {
+		if (TST_PROCESS_STATE_WAIT2(pid, 'S', 1000) < 0)
+			return;
+		else
+			tst_res(TPASS, "vmsplice() blocked");
+		SAFE_KILL(pid, SIGKILL);
+		SAFE_WAIT(&status);
+	}
+
+}
+static void cleanup(void)
+{
+	if (pipes[1] > 0)
+		SAFE_CLOSE(pipes[1]);
+	if (pipes[0] > 0)
+		SAFE_CLOSE(pipes[0]);
+	if (write_buffer)
+		free(write_buffer);
+}
+static void setup(void)
+{
+	SAFE_PIPE(pipes);
+
+	pipe_max_size = SAFE_FCNTL(pipes[1], F_GETPIPE_SZ);
+	write_buffer = SAFE_MALLOC(pipe_max_size);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = vmsplice_test,
+	.min_kver = "2.6.17",
+	.forks_child = 1,
+};
-- 
2.24.1


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

* [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT
  2020-01-22 13:42 [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT Jorik Cronenberg
  2020-01-22 13:42 ` [LTP] [PATCH 2/2] syscalls/vmsplice: Add NONBLOCK testcase Jorik Cronenberg
@ 2020-01-23  6:21 ` Yang Xu
  2020-01-23 12:16   ` Jorik Cronenberg
  1 sibling, 1 reply; 7+ messages in thread
From: Yang Xu @ 2020-01-23  6:21 UTC (permalink / raw)
  To: ltp


> Add the possibility to add a timeout to TST_PROCESS_STATE_WAIT.
> Like checkpoints add TST_PROCESS_STATE_WAIT2()
> for specifying a timeout. The original TST_PROCESS_STATE_WAIT()
> works the same as before. Timeout can be specified in milliseconds.
> 
Hi Jorik

We have tst_process_state_wait2 since commit dbf270c5 ("lib: Add 
tst_process_state_wait2()"), this api has same functions as 
tst_process_state_wait but only return error instead of TBROK.

I think using TST_PROCESS_STATE_WAIT2 is confused and we can only expand
tst_process_state_wait make it support sleep specifying in milliseconds.

Best Regards
Yang Xu
> Signed-off-by: Jorik Cronenberg <jcronenberg@suse.de>
> ---
>   include/tst_process_state.h | 12 ++++++++----
>   lib/tst_process_state.c     | 19 ++++++++++++++-----
>   2 files changed, 22 insertions(+), 9 deletions(-)
> 
> diff --git a/include/tst_process_state.h b/include/tst_process_state.h
> index fab0491d9..27a8ffc36 100644
> --- a/include/tst_process_state.h
> +++ b/include/tst_process_state.h
> @@ -47,9 +47,13 @@
>    */
>   #ifdef TST_TEST_H__
>   
> +#define TST_PROCESS_STATE_WAIT2(pid, state, msec_timeout) \
> +	tst_process_state_wait(__FILE__, __LINE__, NULL, \
> +	                       (pid), (state), msec_timeout)
> +
>   #define TST_PROCESS_STATE_WAIT(pid, state) \
>   	tst_process_state_wait(__FILE__, __LINE__, NULL, \
> -	                       (pid), (state))
> +	                       (pid), (state), 0)
>   #else
>   /*
>    * The same as above but does not use tst_brkm() interface.
> @@ -65,8 +69,8 @@ int tst_process_state_wait2(pid_t pid, const char state);
>   	                        (pid), (state))
>   #endif
>   
> -void tst_process_state_wait(const char *file, const int lineno,
> -                            void (*cleanup_fn)(void),
> -                            pid_t pid, const char state);
> +int tst_process_state_wait(const char *file, const int lineno,
> +                            void (*cleanup_fn)(void), pid_t pid,
> +			    const char state, unsigned int msec_timeout);
>   
>   #endif /* TST_PROCESS_STATE__ */
> diff --git a/lib/tst_process_state.c b/lib/tst_process_state.c
> index 7a7824959..32b44992c 100644
> --- a/lib/tst_process_state.c
> +++ b/lib/tst_process_state.c
> @@ -28,11 +28,12 @@
>   #include "test.h"
>   #include "tst_process_state.h"
>   
> -void tst_process_state_wait(const char *file, const int lineno,
> -                            void (*cleanup_fn)(void),
> -                            pid_t pid, const char state)
> +int tst_process_state_wait(const char *file, const int lineno,
> +                            void (*cleanup_fn)(void), pid_t pid,
> +			    const char state, unsigned int msec_timeout)
>   {
>   	char proc_path[128], cur_state;
> +	unsigned int msecs = 0;
>   
>   	snprintf(proc_path, sizeof(proc_path), "/proc/%i/stat", pid);
>   
> @@ -41,10 +42,18 @@ void tst_process_state_wait(const char *file, const int lineno,
>   		                "%*i %*s %c", &cur_state);
>   
>   		if (state == cur_state)
> -			return;
> +			break;
>   
> -		usleep(10000);
> +		usleep(1000);
> +		msecs += 1;
> +
> +		if (msecs >= msec_timeout) {
> +			errno = ETIMEDOUT;
> +			return -1;
> +		}
>   	}
> +
> +	return 0;
>   }
>   
>   int tst_process_state_wait2(pid_t pid, const char state)
> 



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

* [LTP] [PATCH 2/2] syscalls/vmsplice: Add NONBLOCK testcase
  2020-01-22 13:42 ` [LTP] [PATCH 2/2] syscalls/vmsplice: Add NONBLOCK testcase Jorik Cronenberg
@ 2020-01-23  6:57   ` Yang Xu
  0 siblings, 0 replies; 7+ messages in thread
From: Yang Xu @ 2020-01-23  6:57 UTC (permalink / raw)
  To: ltp

Hi
> Add a testcase for vmsplice() with the flag SPLICE_F_NONBLOCK.
> And also test that vmsplice() blocks when writing to a full pipe
> without the flag specified.
> 
> Signed-off-by: Jorik Cronenberg <jcronenberg@suse.de>
> ---
>   testcases/kernel/syscalls/vmsplice/.gitignore |  1 +
>   .../kernel/syscalls/vmsplice/vmsplice04.c     | 87 +++++++++++++++++++
>   2 files changed, 88 insertions(+)
>   create mode 100644 testcases/kernel/syscalls/vmsplice/vmsplice04.c
add vmsplice04 into runtest/syscalls
> 
> diff --git a/testcases/kernel/syscalls/vmsplice/.gitignore b/testcases/kernel/syscalls/vmsplice/.gitignore
> index 03922073c..042c32585 100644
> --- a/testcases/kernel/syscalls/vmsplice/.gitignore
> +++ b/testcases/kernel/syscalls/vmsplice/.gitignore
> @@ -1,3 +1,4 @@
>   /vmsplice01
>   /vmsplice02
>   /vmsplice03
> +/vmsplice04
> diff --git a/testcases/kernel/syscalls/vmsplice/vmsplice04.c b/testcases/kernel/syscalls/vmsplice/vmsplice04.c
> new file mode 100644
> index 000000000..c49657d84
> --- /dev/null
> +++ b/testcases/kernel/syscalls/vmsplice/vmsplice04.c
> @@ -0,0 +1,87 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2019 SUSE LLC
> + * Author: Jorik Cronenberg <jcronenberg@suse.de>
> + *
> + * Test vmsplice() to a full pipe with SPLICE_F_NONBLOCK and without
> + * With SPLICE_F_NONBLOCK vmsplice() should return with errno EAGAIN
> + * Without SPLICE_F_NONBLOCK it should block
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include "tst_test.h"
> +#include "lapi/vmsplice.h"
> +#include <stdlib.h>
miss "lapi/fcntl.h". it will compile failed because of undefined 
F_GETPIPE_SZ error on centos6 like my pipe12.c(v1)

https://travis-ci.org/xuyang0410/ltp/jobs/629597516?utm_medium=notification&utm_source=github_status

> +
> +
> +static int pipes[2];
> +static ssize_t pipe_max_size;
> +static char *write_buffer;
> +
> +static void vmsplice_test(void)
> +{
> +	int status;
> +	struct iovec iov;
> +	int pid;
> +
> +	iov.iov_base = write_buffer;
> +	iov.iov_len = pipe_max_size;
> +
> +
> +	TEST(vmsplice(pipes[1], &iov, 1, 0));
> +	if (TST_RET < 0)
> +		tst_brk(TBROK | TTERRNO,
> +		    "Initial vmsplice() to fill pipe failed");
> +
> +	TEST(vmsplice(pipes[1], &iov, 1, SPLICE_F_NONBLOCK));
> +	if (TST_RET < 0 && TST_ERR == EAGAIN)
> +		tst_res(TPASS | TTERRNO, "vmsplice failed as expected");
I think we should add more info. such as "vmsplice failed EAGAIN to full 
pipe with SPLICE_F_NONBLOCK mode"
> +	else if (TST_RET < 0)
> +		tst_res(TFAIL | TTERRNO,
> +		    "vmsplice failed with unexpected errno");
here as well
> +	else
> +		tst_res(TFAIL, "vmsplice wrote to a full pipe");
here as well
> +
> +	pid = SAFE_FORK();
> +	if (!pid) {
> +		TEST(vmsplice(pipes[1], &iov, 1, 0));
> +		if (TST_RET < 0)
> +			tst_res(TFAIL | TTERRNO, "vmsplice() failed");
> +		else
> +			tst_res(TFAIL, "vmsplice() wrote to a full pipe");
> +		exit(0);
> +	} else {
> +		if (TST_PROCESS_STATE_WAIT2(pid, 'S', 1000) < 0)
> +			return;
> +		else
> +			tst_res(TPASS, "vmsplice() blocked");
here as well (without SPLICE_F_NONBLOCK mode)
> +		SAFE_KILL(pid, SIGKILL);
> +		SAFE_WAIT(&status);
> +	}
> +
> +}
> +static void cleanup(void)
> +{
> +	if (pipes[1] > 0)
> +		SAFE_CLOSE(pipes[1]);
> +	if (pipes[0] > 0)
> +		SAFE_CLOSE(pipes[0]);
> +	if (write_buffer)
> +		free(write_buffer);
> +}
> +static void setup(void)
> +{
> +	SAFE_PIPE(pipes);
> +
> +	pipe_max_size = SAFE_FCNTL(pipes[1], F_GETPIPE_SZ);
> +	write_buffer = SAFE_MALLOC(pipe_max_size);
Can we use guarded buffer for iov in setup?
https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#2231-guarded-buffers

other than, this patch looks good to me.
> +}
> +
> +static struct tst_test test = {
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = vmsplice_test,
> +	.min_kver = "2.6.17",
> +	.forks_child = 1,
> +};
> 



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

* [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT
  2020-01-23  6:21 ` [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT Yang Xu
@ 2020-01-23 12:16   ` Jorik Cronenberg
  2020-01-23 13:17     ` Yang Xu
  0 siblings, 1 reply; 7+ messages in thread
From: Jorik Cronenberg @ 2020-01-23 12:16 UTC (permalink / raw)
  To: ltp

Hi Yang, thanks for the review!

>
>> Add the possibility to add a timeout to TST_PROCESS_STATE_WAIT.
>> Like checkpoints add TST_PROCESS_STATE_WAIT2()
>> for specifying a timeout. The original TST_PROCESS_STATE_WAIT()
>> works the same as before. Timeout can be specified in milliseconds.
>>
> Hi Jorik
>
> We have tst_process_state_wait2 since commit dbf270c5 ("lib: Add
> tst_process_state_wait2()"), this api has same functions as
> tst_process_state_wait but only return error instead of TBROK.
>
> I think using TST_PROCESS_STATE_WAIT2 is confused and we can only expand
> tst_process_state_wait make it support sleep specifying in milliseconds.
>
> Best Regards
> Yang Xu

I don't think I quite understand what you mean. I can see that using
TST_PROCESS_STATE_WAIT2 is confusing. But I didn't want to touch the
existing TST_PROCESS_STATE_WAIT to ensure all older tests still run the
same. Are you saying i should go through all tests that use
TST_PROCESS_STATE_WAIT and specify that they use a timeout of 0(which
according to a git grep doesn't seem too many, so it wouldn't be too
much effort) and then change TST_PROCESS_STATE_WAIT to include a timeout
or should I just rename TST_PROCESS_STATE_WAIT2 to something that
seperates it more from tst_process_state_wait2?

regards,
Jorik Cronenberg
>> Signed-off-by: Jorik Cronenberg <jcronenberg@suse.de>
>> ---
>> ? include/tst_process_state.h | 12 ++++++++----
>> ? lib/tst_process_state.c???? | 19 ++++++++++++++-----
>> ? 2 files changed, 22 insertions(+), 9 deletions(-)
>>
>> diff --git a/include/tst_process_state.h b/include/tst_process_state.h
>> index fab0491d9..27a8ffc36 100644
>> --- a/include/tst_process_state.h
>> +++ b/include/tst_process_state.h
>> @@ -47,9 +47,13 @@
>> ?? */
>> ? #ifdef TST_TEST_H__
>> ? +#define TST_PROCESS_STATE_WAIT2(pid, state, msec_timeout) \
>> +??? tst_process_state_wait(__FILE__, __LINE__, NULL, \
>> +?????????????????????????? (pid), (state), msec_timeout)
>> +
>> ? #define TST_PROCESS_STATE_WAIT(pid, state) \
>> ????? tst_process_state_wait(__FILE__, __LINE__, NULL, \
>> -?????????????????????????? (pid), (state))
>> +?????????????????????????? (pid), (state), 0)
>> ? #else
>> ? /*
>> ?? * The same as above but does not use tst_brkm() interface.
>> @@ -65,8 +69,8 @@ int tst_process_state_wait2(pid_t pid, const char
>> state);
>> ????????????????????????????? (pid), (state))
>> ? #endif
>> ? -void tst_process_state_wait(const char *file, const int lineno,
>> -??????????????????????????? void (*cleanup_fn)(void),
>> -??????????????????????????? pid_t pid, const char state);
>> +int tst_process_state_wait(const char *file, const int lineno,
>> +??????????????????????????? void (*cleanup_fn)(void), pid_t pid,
>> +??????????????? const char state, unsigned int msec_timeout);
>> ? ? #endif /* TST_PROCESS_STATE__ */
>> diff --git a/lib/tst_process_state.c b/lib/tst_process_state.c
>> index 7a7824959..32b44992c 100644
>> --- a/lib/tst_process_state.c
>> +++ b/lib/tst_process_state.c
>> @@ -28,11 +28,12 @@
>> ? #include "test.h"
>> ? #include "tst_process_state.h"
>> ? -void tst_process_state_wait(const char *file, const int lineno,
>> -??????????????????????????? void (*cleanup_fn)(void),
>> -??????????????????????????? pid_t pid, const char state)
>> +int tst_process_state_wait(const char *file, const int lineno,
>> +??????????????????????????? void (*cleanup_fn)(void), pid_t pid,
>> +??????????????? const char state, unsigned int msec_timeout)
>> ? {
>> ????? char proc_path[128], cur_state;
>> +??? unsigned int msecs = 0;
>> ? ????? snprintf(proc_path, sizeof(proc_path), "/proc/%i/stat", pid);
>> ? @@ -41,10 +42,18 @@ void tst_process_state_wait(const char *file,
>> const int lineno,
>> ????????????????????????? "%*i %*s %c", &cur_state);
>> ? ????????? if (state == cur_state)
>> -??????????? return;
>> +??????????? break;
>> ? -??????? usleep(10000);
>> +??????? usleep(1000);
>> +??????? msecs += 1;
>> +
>> +??????? if (msecs >= msec_timeout) {
>> +??????????? errno = ETIMEDOUT;
>> +??????????? return -1;
>> +??????? }
>> ????? }
>> +
>> +??? return 0;
>> ? }
>> ? ? int tst_process_state_wait2(pid_t pid, const char state)
>>
>
>

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

* [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT
  2020-01-23 12:16   ` Jorik Cronenberg
@ 2020-01-23 13:17     ` Yang Xu
  2020-01-23 13:33       ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Yang Xu @ 2020-01-23 13:17 UTC (permalink / raw)
  To: ltp

Hi Jorik
> Hi Yang, thanks for the review!
> 
>>
>>> Add the possibility to add a timeout to TST_PROCESS_STATE_WAIT.
>>> Like checkpoints add TST_PROCESS_STATE_WAIT2()
>>> for specifying a timeout. The original TST_PROCESS_STATE_WAIT()
>>> works the same as before. Timeout can be specified in milliseconds.
>>>
>> Hi Jorik
>>
>> We have tst_process_state_wait2 since commit dbf270c5 ("lib: Add
>> tst_process_state_wait2()"), this api has same functions as
>> tst_process_state_wait but only return error instead of TBROK.
>>
>> I think using TST_PROCESS_STATE_WAIT2 is confused and we can only expand
>> tst_process_state_wait make it support sleep specifying in milliseconds.
>>
>> Best Regards
>> Yang Xu
> 
> I don't think I quite understand what you mean. I can see that using
> TST_PROCESS_STATE_WAIT2 is confusing. But I didn't want to touch the
> existing TST_PROCESS_STATE_WAIT to ensure all older tests still run the
> same. Are you saying i should go through all tests that use
> TST_PROCESS_STATE_WAIT and specify that they use a timeout of 0(which
> according to a git grep doesn't seem too many, so it wouldn't be too
> much effort) and then change TST_PROCESS_STATE_WAIT to include a timeout
Yes.
> or should I just rename TST_PROCESS_STATE_WAIT2 to something that
> seperates it more from tst_process_state_wait2?
Also, I am fine with the second way. Let we listen cyril's advise.
@Cyril What do you think about it?
> 
> regards,
> Jorik Cronenberg
>>> Signed-off-by: Jorik Cronenberg <jcronenberg@suse.de>
>>> ---
>>>  ? include/tst_process_state.h | 12 ++++++++----
>>>  ? lib/tst_process_state.c???? | 19 ++++++++++++++-----
>>>  ? 2 files changed, 22 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/include/tst_process_state.h b/include/tst_process_state.h
>>> index fab0491d9..27a8ffc36 100644
>>> --- a/include/tst_process_state.h
>>> +++ b/include/tst_process_state.h
>>> @@ -47,9 +47,13 @@
>>>  ?? */
>>>  ? #ifdef TST_TEST_H__
>>>  ? +#define TST_PROCESS_STATE_WAIT2(pid, state, msec_timeout) \
>>> +??? tst_process_state_wait(__FILE__, __LINE__, NULL, \
>>> +?????????????????????????? (pid), (state), msec_timeout)
>>> +
>>>  ? #define TST_PROCESS_STATE_WAIT(pid, state) \
>>>  ????? tst_process_state_wait(__FILE__, __LINE__, NULL, \
>>> -?????????????????????????? (pid), (state))
>>> +?????????????????????????? (pid), (state), 0)
>>>  ? #else
>>>  ? /*
>>>  ?? * The same as above but does not use tst_brkm() interface.
>>> @@ -65,8 +69,8 @@ int tst_process_state_wait2(pid_t pid, const char
>>> state);
>>>  ????????????????????????????? (pid), (state))
>>>  ? #endif
>>>  ? -void tst_process_state_wait(const char *file, const int lineno,
>>> -??????????????????????????? void (*cleanup_fn)(void),
>>> -??????????????????????????? pid_t pid, const char state);
>>> +int tst_process_state_wait(const char *file, const int lineno,
>>> +??????????????????????????? void (*cleanup_fn)(void), pid_t pid,
>>> +??????????????? const char state, unsigned int msec_timeout);
>>>  ? ? #endif /* TST_PROCESS_STATE__ */
>>> diff --git a/lib/tst_process_state.c b/lib/tst_process_state.c
>>> index 7a7824959..32b44992c 100644
>>> --- a/lib/tst_process_state.c
>>> +++ b/lib/tst_process_state.c
>>> @@ -28,11 +28,12 @@
>>>  ? #include "test.h"
>>>  ? #include "tst_process_state.h"
>>>  ? -void tst_process_state_wait(const char *file, const int lineno,
>>> -??????????????????????????? void (*cleanup_fn)(void),
>>> -??????????????????????????? pid_t pid, const char state)
>>> +int tst_process_state_wait(const char *file, const int lineno,
>>> +??????????????????????????? void (*cleanup_fn)(void), pid_t pid,
>>> +??????????????? const char state, unsigned int msec_timeout)
>>>  ? {
>>>  ????? char proc_path[128], cur_state;
>>> +??? unsigned int msecs = 0;
>>>  ? ????? snprintf(proc_path, sizeof(proc_path), "/proc/%i/stat", pid);
>>>  ? @@ -41,10 +42,18 @@ void tst_process_state_wait(const char *file,
>>> const int lineno,
>>>  ????????????????????????? "%*i %*s %c", &cur_state);
>>>  ? ????????? if (state == cur_state)
>>> -??????????? return;
>>> +??????????? break;
>>>  ? -??????? usleep(10000);
>>> +??????? usleep(1000);
>>> +??????? msecs += 1;
>>> +
>>> +??????? if (msecs >= msec_timeout) {
>>> +??????????? errno = ETIMEDOUT;
>>> +??????????? return -1;
>>> +??????? }
>>>  ????? }
>>> +
>>> +??? return 0;
>>>  ? }
>>>  ? ? int tst_process_state_wait2(pid_t pid, const char state)
>>>
>>
>>
> 


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

* [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT
  2020-01-23 13:17     ` Yang Xu
@ 2020-01-23 13:33       ` Cyril Hrubis
  0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2020-01-23 13:33 UTC (permalink / raw)
  To: ltp

Hi!
> >> We have tst_process_state_wait2 since commit dbf270c5 ("lib: Add
> >> tst_process_state_wait2()"), this api has same functions as
> >> tst_process_state_wait but only return error instead of TBROK.
> >>
> >> I think using TST_PROCESS_STATE_WAIT2 is confused and we can only expand
> >> tst_process_state_wait make it support sleep specifying in milliseconds.
> >>
> >> Best Regards
> >> Yang Xu
> > 
> > I don't think I quite understand what you mean. I can see that using
> > TST_PROCESS_STATE_WAIT2 is confusing. But I didn't want to touch the
> > existing TST_PROCESS_STATE_WAIT to ensure all older tests still run the
> > same. Are you saying i should go through all tests that use
> > TST_PROCESS_STATE_WAIT and specify that they use a timeout of 0(which
> > according to a git grep doesn't seem too many, so it wouldn't be too
> > much effort) and then change TST_PROCESS_STATE_WAIT to include a timeout
> Yes.
> > or should I just rename TST_PROCESS_STATE_WAIT2 to something that
> > seperates it more from tst_process_state_wait2?
> Also, I am fine with the second way. Let we listen cyril's advise.
> @Cyril What do you think about it?

Well that function is only supposed to be used from the old API while
the macro is defined for the new API so they are never exported at the
same time.

On the other hand we can change these few testcases quite easily, so we
may as well do that.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2020-01-23 13:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-22 13:42 [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT Jorik Cronenberg
2020-01-22 13:42 ` [LTP] [PATCH 2/2] syscalls/vmsplice: Add NONBLOCK testcase Jorik Cronenberg
2020-01-23  6:57   ` Yang Xu
2020-01-23  6:21 ` [LTP] [PATCH 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT Yang Xu
2020-01-23 12:16   ` Jorik Cronenberg
2020-01-23 13:17     ` Yang Xu
2020-01-23 13:33       ` Cyril Hrubis

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