splice02: Generate input in C
PATCH v5 1/2 splice02: Generate input in C
instead relying on shell piping data into it.
Check resulted file size and content.
Also add metadata docs.
Problem found on SLES JeOS (https://progress.opensuse.org/issues/77260).
---
Changes v4->v5:
* fix: use offset in SAFE_MMAP() to fix file checking (reported by Cyril) Offset is required to be page size aligned.
* fix: error message wording (reported by Cyril)
* Change content to write: remove randomizing the letter and instead write alphabet sequence 512*'a', 512*'b' ... This way error during check due wrong offset is detected.
runtest/smoketest | 2 +- runtest/syscalls | 2 +- testcases/kernel/syscalls/splice/splice02.c | 143 ++++++++++++++++++-- 3 files changed, 134 insertions(+), 13 deletions(-)
runtest/smoketest +1 -1
@@ -11,5 +11,5 @@ symlink01 symlink01 stat04 symlink01 -T stat04 utime01A symlink01 -T utime01 rename01A symlink01 -T rename01 -splice02 seq 1 20 | splice02 +splice02 splice02 -s 20 route4-change-dst route-change-dst.sh
runtest/syscalls +1 -1
@@ -1451,7 +1451,7 @@ socketpair02 socketpair02 sockioctl01 sockioctl01 splice01 splice01 -splice02 seq 1 20000 | splice02 +splice02 splice02 splice03 splice03 splice04 splice04 splice05 splice05
testcases/kernel/syscalls/splice/splice02.c +132 -11
172 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v5 2/2 commands: Add shell pipe test
This adds basic shell pipe testing, which was removed from splice02 in 85cebe238 ("splice02: Generate input in C").
---
The same as v4.
runtest/commands | 1 + runtest/smoketest | 1 + testcases/commands/shell/Makefile | 10 ++++++++++ testcases/commands/shell/shell_pipe01.sh | 17 +++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 testcases/commands/shell/Makefile create mode 100755 testcases/commands/shell/shell_pipe01.sh
runtest/commands +1 -0
@@ -41,3 +41,4 @@ gdb01_sh gdb01.sh unshare01_sh unshare01.sh sysctl01_sh sysctl01.sh sysctl02_sh sysctl02.sh +shell_test01 echo "SUCCESS" | shell_pipe01.sh
runtest/smoketest +1 -0
@@ -13,3 +13,4 @@ utime01A symlink01 -T utime01 rename01A symlink01 -T rename01 splice02 splice02 -s 20 route4-change-dst route-change-dst.sh +shell_test01 echo "SUCCESS" | shell_pipe01.sh
testcases/commands/shell/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) Linux Test Project, 2021 + +top_srcdir ?= ../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +INSTALL_TARGETS := *.sh + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/commands/shell/shell_pipe01.sh new file +17 -0
@@ -0,0 +1,17 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2021 Petr Vorel <[email protected]> + +TST_TESTFUNC=do_test + +. tst_test.sh + +do_test() +{ + tst_res TINFO "expecting SUCCESS string passed from stdin" + + read line + EXPECT_PASS [ "$line" = "SUCCESS" ] +} + +tst_run
Signature · 1 line
2.31.1
PATCH v5 1/2 splice02: Generate input in C
In reply to Petr VorelHi!
testcases/kernel/syscalls/splice/splice02.c line 94
Quoted 13 lines
testcases/kernel/syscalls/splice/splice02.c +12
-0SAFE_CLOSE (fd); + fd =SAFE_OPEN (TEST_FILENAME ,O_RDONLY ); + to_check = st.st_size; + + psize =sysconf (_SC_PAGESIZE); + +tst_res (TINFO ,"checking file content" ); + do { + i = 0; + size = to_check > psize ? psize : to_check; + + map = SAFE_MMAP(NULL, size, PROT_READ, MAP_PRIVATE, fd, + st.st_size - to_check);
Huh, why do we loop backward over the file?
Maybe we can just do simple loop here that would be easier to understand:
blocks = LTP_ALIGN(st.st_size, page_size) / page_size;
for (block = 0; block < blocks; block++) {
map = SAFE_MMAP(NULL, pagesize, PROT_READ, MAP_PRIVATE, fd, block * pagesize);
to_check = (block+1) * page_size < st.st_size ? page_size : st.st_size % page_size;
for (i = 0; i < to_check; i++) {
if (map[i] != get_letter(block * page_size + i))
fail++;
}
SAFE_MUNMAP(map, size);
}[Beware I haven't tested the code :-)]
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v5 1/2 splice02: Generate input in C
Quoted 35 lines
Hi!
testcases/kernel/syscalls/splice/splice02.c line 94
Quoted 13 lines
testcases/kernel/syscalls/splice/splice02.c +12
-0SAFE_CLOSE (fd); + fd =SAFE_OPEN (TEST_FILENAME ,O_RDONLY ); + to_check = st.st_size; + + psize =sysconf (_SC_PAGESIZE); + +tst_res (TINFO ,"checking file content" ); + do { + i = 0; + size = to_check > psize ? psize : to_check; + + map = SAFE_MMAP(NULL, size, PROT_READ, MAP_PRIVATE, fd, + st.st_size - to_check);Huh, why do we loop backward over the file?
Maybe we can just do simple loop here that would be easier to understand:
blocks = LTP_ALIGN(st.st_size, page_size) / page_size; for (block = 0; block < blocks; block++) { map = SAFE_MMAP(NULL, pagesize, PROT_READ, MAP_PRIVATE, fd, block * pagesize); to_check = (block+1) * page_size < st.st_size ? page_size : st.st_size % page_size; for (i = 0; i < to_check; i++) { if (map[i] != get_letter(block * page_size + i)) fail++; } SAFE_MUNMAP(map, size); }
Quoted 1 line
[Beware I haven't tested the code :-)]
Yep. In your code you expect that written letter change each time. But original code writes the same letter for whole buffer (using memset()).
I guess it does not matter whether I keep writing with memset() as is and adapt the checking code (code you proposed) or if I use your code for checking and adapt writing code: create buffer 494 (19x 26 letters), memset() it only once. Or do you have any preference of these?
Also I have to replace 2x return with goto cleanup (to close fd and exit the child).
Kind regards,
Petr
PATCH v5 1/2 splice02: Generate input in C
Hi!
Quoted 2 lines
Yep. In your code you expect that written letter change each time. But original code writes the same letter for whole buffer (using
memset()).
Ah, right, the mapping in the original code maps the remaning size to be written to a letter and uses it for whole block.
I guess that it may be easier to understand if the letter was defined as an function of a position in the file like I have expected in my snippet. That way we can also produce different patterns without changing the test code (and we can later on introduce a library functions to fill buffer and check buffer as well, these would generally take a pointer to a buffer, size and an offset).
That would mean that we will have to fill the buffer in a for loop instead of memset, but as long as the get_letter() function is inlined it should be fast enough.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v5 1/2 splice02: Generate input in C
Hi Cyril,
Quoted 7 lines
Hi!
Quoted 2 lines
Yep. In your code you expect that written letter change each time. But original code writes the same letter for whole buffer (using
memset()).Ah, right, the mapping in the original code maps the remaning size to be written to a letter and uses it for whole block.
Quoted 6 lines
I guess that it may be easier to understand if the letter was defined as an function of a position in the file like I have expected in my snippet. That way we can also produce different patterns without changing the test code (and we can later on introduce a library functions to fill buffer and check buffer as well, these would generally take a pointer to a buffer, size and an offset).
Make sense.
Quoted 3 lines
That would mean that we will have to fill the buffer in a for loop instead of memset, but as long as the
get_letter()function is inlined it should be fast enough.
Right. I guess trying to "align" buffer with alphabet size (e.g. multiple of 26) to avoid filling the buffer is not worth. Thus I keep buffer size 512 and fill it each time.
Thanks for your suggestions and time.
Kind regards,
Petr