splice02: Generate input in C
PATCH v4 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 v3->v4:
* write by 512 bytes (performance, suggested by Cyril)
* check also file content, for performance reason use mmap() in loop
* randomize input char
* change option to -s
* change variable names, help
runtest/smoketest | 2 +- runtest/syscalls | 2 +- testcases/kernel/syscalls/splice/splice02.c | 137 ++++++++++++++++++-- 3 files changed, 128 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 +126 -11
166 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v4 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").
---
Changes v3->v4:
* Add missing Makefile
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 v4 1/2 splice02: Generate input in C
In reply to Petr VorelHi!
testcases/kernel/syscalls/splice/splice02.c line 89
Quoted 6 lines
testcases/kernel/syscalls/splice/splice02.c +5
-1- fd =SAFE_OPEN ("splice02-temp" ,O_WRONLY |O_CREAT |O_TRUNC ,0644 ); +tst_res (TINFO ,"checking file content" ); + do { + i = 0; + size = to_check > SPLICE_SIZE ? SPLICE_SIZE : to_check; + map = SAFE_MMAP(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
^ This offset should increase by size on each iteration.
As it is we check only the first few pages of the file again and again.
testcases/kernel/syscalls/splice/splice02.c line 90
Quoted 1 line
testcases/kernel/syscalls/splice/splice02.c +1
-0+while (map[i] && i < size) {
^
Why map[i]? The i < size should be enough to make sure we newer get bytes after end of the file.
Quoted 6 lines
testcases/kernel/syscalls/splice/splice02.c +6
-0+if (map[i] != letter) + fail++; + i++; + } +SAFE_MUNMAP (map, size); + to_check -= size;
testcases/kernel/syscalls/splice/splice02.c line 100
Quoted 10 lines
testcases/kernel/syscalls/splice/splice02.c +3
-6+ }while (to_check >0 ); -TEST (splice (STDIN_FILENO ,NULL , fd,NULL ,SPLICE_SIZE ,0 )); -if (TST_RET <0 ) { -tst_res (TFAIL ,"splice failed - errno = %d : %s" , -TST_ERR ,strerror (TST_ERR )); - }else { -tst_res (TPASS ,"splice() system call Passed" ); +if (fail) { +tst_res (TFAIL ,"%ld failed bytes found" , fail);
^ Wrong? Unexpected?
Quoted 59 lines
testcases/kernel/syscalls/splice/splice02.c +46
-1+return ; } +tst_res (TPASS ,"splice() system call passed" ); + +cleanup:SAFE_CLOSE (fd); +exit (0 ); +} + +static void run (void ) +{ +size_t size, written, max_pipe_size, to_write; +char buf[BUFSIZE ]; + +SAFE_PIPE (pipe_fd); + +memset (buf, letter,BUFSIZE ); + +if (!file_size) { + max_pipe_size =SAFE_FCNTL (pipe_fd[1 ],F_GETPIPE_SZ ); + file_size = max_pipe_size <<4 ; + } + + to_write = file_size; + +if (!SAFE_FORK ()) +do_child (); + +tst_res (TINFO ,"writting %d bytes" , file_size); + +while (to_write >0 ) { + size = to_write >BUFSIZE ?BUFSIZE : to_write; + written =SAFE_WRITE (1 , pipe_fd[1 ], &buf, size); + to_write -= written; + } + +SAFE_CLOSE (pipe_fd[0 ]); +SAFE_CLOSE (pipe_fd[1 ]); + +tst_reap_children (); }static struct tst_test test = { - .test_all = splice_test, + .test_all = run, + .setup = setup, + .needs_checkpoints =1 , .needs_tmpdir =1 , + .forks_child =1 , .min_kver ="2.6.17" , + .options = (struct tst_option []) { + {"s:" , &sarg,"-s x Size of output file in bytes (default: 16x max pipe size, i.e. 1M on intel)" }, + {} + }, };Signature · 1 line
2.31.1
Signature · 2 lines
Cyril Hrubis [email protected]