Skip to contentSkip to conversation

Add new test for pipe2 with/without O_NONBLOCK mode

LTP New [email protected] 3 participants 8 messages Apr 9, 2020 – Apr 17, 2020 1 message not in the archive Library code

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 67fdc846a8cd8616c9eb13cf89463b9d637e6849

#1 lore raw

Hi.

I added a new test file (pipe2_03.c) to test pipe2 system call with and without O_NONBLOCK enabled.
This test uses the macro SAFE_PIPE2 that I added, this macro is just the equivalent of SAFE_PIPE for pipe2.

I do not know if it is correct to do that but at the end of the test function we need to set the pipe in the same state as it was at the end of setup function:
1. Set the O_NONBLOCK flag to the pipe.
2. Read the pipe to empty it.
3. We do not set its size to default because we do not care of it. If we do not do that, there will be problem when this test is run multiple time (this problem was found when running ./pipe2_03 -i 10).

The diff --stat output is the following:

 include/old/safe_macros.h                  |   3 +++
 include/tst_safe_macros.h                  |   6 ++++++
 lib/safe_macros.c                          |  15 ++++++++++++++
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/pipe2/.gitignore |   1 +
 testcases/kernel/syscalls/pipe2/pipe2_03.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 161 insertions(+)

Best regards.

#2 lore raw

Hi Laniel

Quoted 8 lines

Hi.

I added a new test file (pipe2_03.c) to test pipe2 system call with and without O_NONBLOCK enabled.
This test uses the macro SAFE_PIPE2 that I added, this macro is just the equivalent of SAFE_PIPE for pipe2.

Quoted 4 lines

I do not know if it is correct to do that but at the end of the test function we need to set the pipe in the same state as it was at the end of setup function:
1. Set the O_NONBLOCK flag to the pipe.
2. Read the pipe to empty it.

As my previous mail said, fill up the pipe in setup, so we don't need to read the pipe. we only need to set the non_block flag when using -i parameter.

I modify your patch and merged into my ltp own fork. see
https://github.com/xuyang0410/ltp/commits/Laniel_francis_pipe2_03_v3.fixes

ps: I will convert pipe2_01/02.c into new libray and use SAFE_PIPE2 macro.

Best Regards
Yang Xu

Quoted 18 lines

3. We do not set its size to default because we do not care of it. If we do not do that, there will be problem when this test is run multiple time (this problem was found when running ./pipe2_03 -i 10).

The diff --stat output is the following:

  include/old/safe_macros.h                  |   3 +++
  include/tst_safe_macros.h                  |   6 ++++++
  lib/safe_macros.c                          |  15 ++++++++++++++
  runtest/syscalls                           |   1 +
  testcases/kernel/syscalls/pipe2/.gitignore |   1 +
  testcases/kernel/syscalls/pipe2/pipe2_03.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  6 files changed, 161 insertions(+)

Best regards.

#3 lore raw

Hi Li

Quoted 22 lines

Hi Laniel

Quoted 9 lines

Hi.

I added a new test file (pipe2_03.c) to test pipe2 system call with and without
O_NONBLOCK enabled.
This test uses the macro SAFE_PIPE2 that I added, this macro is just the equivalent of SAFE_PIPE for pipe2.

Quoted 6 lines

I do not know if it is correct to do that but at the end of the test function we
need to set the pipe in the same state as it was at the end of setup function:
1. Set the O_NONBLOCK flag to the pipe.
2. Read the pipe to empty it.

As my previous mail said, fill up the pipe in setup, so we don't need to read the pipe. we only need to set the non_block flag when using -i parameter.

Quoted 5 lines

I modify your patch and merged into my ltp own fork. see
https://github.com/xuyang0410/ltp/commits/Laniel_francis_pipe2_03_v3.fixes

ps: I will convert pipe2_01/02.c into new libray and use SAFE_PIPE2 macro.

Can you merge the safe_pipe2 patch(don't need to add this macro into old safe_macro header) into master? so then I can write new test cases (using this macro) to test O_DIRECT and O_CLOEXEC flag function.

Also, feel free to comment the Laniel_francis_pipe2_03_v3.fixes branch (laniel write this case to test O_NONBLOCK mode, it is similar with vmsplice04.c).

Best Regards
Yang Xu

Quoted 24 lines

Best Regards
Yang Xu

Quoted 21 lines

3. We do not set its size to default because we do not care of it. If we do not do that, there will be problem when this test is run multiple time
(this problem was found when running ./pipe2_03 -i 10).

The diff --stat output is the following:

? include/old/safe_macros.h????????????????? |?? 3 +++
? include/tst_safe_macros.h????????????????? |?? 6 ++++++
? lib/safe_macros.c????????????????????????? |? 15 ++++++++++++++
? runtest/syscalls?????????????????????????? |?? 1 +
? testcases/kernel/syscalls/pipe2/.gitignore |?? 1 +
? testcases/kernel/syscalls/pipe2/pipe2_03.c | 135 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

? 6 files changed, 161 insertions(+)

Best regards.

#4 lore raw

Hi Xu,

Thanks for reviewing the patches.

Quoted 11 lines · Yang Xu

...

Quoted 3 lines

I modify your patch and merged into my ltp own fork. see

https://github.com/xuyang0410/ltp/commits/Laniel_francis_pipe2_03_v3.fixes

Quoted 2 lines

ps: I will convert pipe2_01/02.c into new libray and use SAFE_PIPE2

macro.
Can you merge the safe_pipe2 patch(don't need to add this macro into old safe_macro header) into master? so then I can write new test cases

I'm ok with only support it in the new library.

But if we export the safe macro only to use by new API, we'd better add it into lib/tst_safe_macros.c
but not lib/safe_macros.c, this patch leaves the 'void (*cleanup_fn) (void)' hook in function safe_pipe2()
and put in safe_macros.c that is compatible with both API using.

Do you think so? if yes I can help to move it to tst_safe_macros.c and apply it.

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200417/1982f0dc/attachment-0001.htm>
#5 lore raw

Hi Li

Quoted 22 lines

Hi Xu,

Thanks for reviewing the patches.

Yang Xu <[email protected]
<mailto:[email protected]>> wrote:

...
> I modify your patch and merged into my ltp own fork. > see
>
https://github.com/xuyang0410/ltp/commits/Laniel_francis_pipe2_03_v3.fixes
>
> ps: I will convert pipe2_01/02.c into new libray and use
SAFE_PIPE2 macro.
Can you merge the safe_pipe2 patch(don't need to add this macro into old
safe_macro header) into master? so then I can write new test cases

I'm ok with only support it in the new library.

Quoted 8 lines

But if we export the safe macro only to use by new API, we'd better add it into lib/tst_safe_macros.c
but not lib/safe_macros.c, this patch leaves the 'void (*cleanup_fn) (void)'?hook in function safe_pipe2()
and put in safe_macros.c that is compatible?with both API using.

Do you think so? if yes I can help to move it to?tst_safe_macros.c and apply it.

Yes. I only noticed header file place and forgot C file place.

Quoted 4 lines
Signature · 3 lines
-- 
Regards,
Li Wang
#6 lore raw

Hi Xu, Laniel,

Patchset changed as the following and pushed:

* [1/2] move safe_pipe2() to tst_safe_macro.c
* [1/2] remove cleanup_fn callback from function
* [1/2] replace tst_brk() by tst_brk_()
* [1/2] add flag in the print message
* [2/2] rename to pipe2_04.c
* [2/2] remove useless status variable
* [2/2] code indent cleanup

@Laniel, remember to use '-s' in the git-commit command next time, then it will help add the Signed-off-by: automatically.

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200417/19996939/attachment-0001.htm>
#7 lore raw

PATCH v3 1/2 Add SAFE_PIPE2.

In reply to a message not in the archive

From: Francis Laniel <[email protected]>

This macro is the equivalent of SAFE_PIPE for pipe2 system call.

---
 include/old/safe_macros.h |  3 +++
 include/tst_safe_macros.h |  6 ++++++
 lib/safe_macros.c         | 15 +++++++++++++++
 3 files changed, 24 insertions(+)
include/old/safe_macros.h +3 -0
index e778d3077..a7bd43c80 100644
@@ -66,6 +66,9 @@
 #define SAFE_PIPE(cleanup_fn, fildes)	\
 	safe_pipe(__FILE__, __LINE__, cleanup_fn, (fildes))
 
+#define SAFE_PIPE2(fildes, flags) \
+	safe_pipe2(__FILE__, __LINE__, NULL, (fildes), (flags))
+
 #define SAFE_READ(cleanup_fn, len_strict, fildes, buf, nbyte)	\
 	safe_read(__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \
 	    (buf), (nbyte))
include/tst_safe_macros.h +6 -0
index d95d26219..a21d75646 100644
@@ -87,6 +87,12 @@ static inline int safe_dup(const char *file, const int lineno,
 #define SAFE_PIPE(fildes) \
 	safe_pipe(__FILE__, __LINE__, NULL, (fildes))
 
+int safe_pipe2(const char *file, const int lineno, void (*cleanup_fn) (void),
+	       int fildes[2], int flags);
+
+#define SAFE_PIPE2(fildes, flags) \
+	safe_pipe2(__FILE__, __LINE__, NULL, (fildes), (flags))
+
 #define SAFE_READ(len_strict, fildes, buf, nbyte) \
 	safe_read(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte))
 
lib/safe_macros.c +15 -0
index dde9b7b5e..780245821 100644
@@ -248,6 +248,21 @@ int safe_pipe(const char *file, const int lineno, void (*cleanup_fn) (void),
 	return rval;
 }
 
+int safe_pipe2(const char *file, const int lineno, void (*cleanup_fn) (void),
+               int fildes[2], int flags)
+{
+	int rval;
+
+	rval = pipe2(fildes, flags);
+	if (rval == -1) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: pipe2({%d,%d}) failed",
+			 file, lineno, fildes[0], fildes[1]);
+	}
+
+	return rval;
+}
+
 ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),
                   char len_strict, int fildes, void *buf, size_t nbyte)
 {
Signature · 1 line
2.20.1
#8 lore raw

PATCH v3 2/2 Add new test for pipe2 with/without O_NONBLOCK mode.

In reply to a message not in the archive

From: Francis Laniel <[email protected]>

The new test (pipe2_03.c) checks the following:
1. Create a pipe with O_NONBLOCK.
2. Check that this flag is set.
3. Check that pipe size is 16 * PAGE_SIZE.
4. Reduce pipe size to PAGE_SIZE.
5. Write buffer bigger than page size and see that second write fails.
6. Set pipe's flags to default.
7. Fork and do a write in the child, its state must be 'S' and is checked from the father.

---
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/pipe2/.gitignore |   1 +
 testcases/kernel/syscalls/pipe2/pipe2_03.c | 135 +++++++++++++++++++++
 3 files changed, 137 insertions(+)
 create mode 100644 testcases/kernel/syscalls/pipe2/pipe2_03.c
runtest/syscalls +1 -0
index 0ad66ca5e..24bc90472 100644
@@ -909,6 +909,7 @@ pipe13 pipe13
 
 pipe2_01 pipe2_01
 pipe2_02 pipe2_02
+pipe2_03 pipe2_03
 
 pivot_root01 pivot_root01
 
testcases/kernel/syscalls/pipe2/.gitignore +1 -0
index cd38bb309..01d980dba 100644
@@ -1,2 +1,3 @@
 /pipe2_01
 /pipe2_02
+/pipe2_03
testcases/kernel/syscalls/pipe2/pipe2_03.c new file +135 -0

136 lines not on this page · raw message

Signature · 1 line
2.20.1