Skip to contentSkip to conversation

KVM: selftests: Move test_read() into elf.c and delete lib/io.c

PATCH Applied Gokul K 2 participants 2 messages Sep 18 – Oct 2

Subsystems (2)
lore
Share & tools
lore

Gokul K

author
#0 lore raw

PATCH v2 1/1 KVM: selftests: Move test_read() into elf.c and delete lib/io.c

lib/io.c has outlived its purpose. test_read() has exactly one caller, lib/elf.c; test_write() has none at all; and test_seq_read() is a declaration in test_util.h with no definition anywhere in the tree.

Both surviving helpers open with

	TEST_ASSERT(count >= 0, "Unexpected count, count: %li", count);

which can never fire, because @count is a size_t. Building with -Wextra points this out:

lib/io.c:51:27: warning: comparison of unsigned expression in '>= 0'
is always true [-Wtype-limits]
lib/io.c:128:27: warning: comparison of unsigned expression in '>= 0'
is always true [-Wtype-limits]

The comment above each assertion is worse than the assertion itself: it cites the read(2) and write(2) manpages to claim that a count of zero is allowed, but a zero count lands in "case 0" and fails the test outright. The helper has never accepted what the comment promises.

Move test_read() into elf.c as a static elf_read(), named for what it does rather than reading as "test the read() syscall", and assert that @count is non-zero, which is what the code has always required and what every caller already passes. Drop the commentary describing retry behaviour that the code makes obvious. Nothing is then left in lib/io.c, so remove the file along with test_write() and the stale test_seq_read() declaration.

No functional change intended.

---
v2: Implement Sean's suggestion instead of the original one-line
deletion: move test_read() into elf.c as a static elf_read(), assert @count is non-zero rather than >= 0, and delete lib/io.c along with test_write() and the test_seq_read() declaration.
v1: https://lore.kernel.org/all/[email protected]

The only deviation from the diff Sean posted is the indentation of the continuation line in the last elf_read() call: elf_read is one character shorter than test_read, so checkpatch --strict flags the alignment. With that the patch is checkpatch-clean apart from the MAINTAINERS warning any file deletion produces, and MAINTAINERS covers the directory rather than lib/io.c individually.

Built with and without -Wextra: both -Wtype-limits warnings are gone, and the patch introduces no diagnostic the tree did not already have. kvm_binary_stats_test and ten other x86 selftests give identical results before and after, which exercises the moved code for real -- every VM goes through kvm_vm_elf_load(), which is the only caller of elf_read().

 tools/testing/selftests/kvm/Makefile.kvm      |   1 -
 .../testing/selftests/kvm/include/test_util.h |   4 -
 tools/testing/selftests/kvm/lib/elf.c         |  48 +++++-
 tools/testing/selftests/kvm/lib/io.c          | 157 ------------------
 4 files changed, 43 insertions(+), 167 deletions(-)
 delete mode 100644 tools/testing/selftests/kvm/lib/io.c
tools/testing/selftests/kvm/Makefile.kvm +0 -1
index 96bab7002d39..d12c1c738956 100644
@@ -6,7 +6,6 @@ all:
 LIBKVM += lib/assert.c
 LIBKVM += lib/elf.c
 LIBKVM += lib/guest_modes.c
-LIBKVM += lib/io.c
 LIBKVM += lib/kvm_util.c
 LIBKVM += lib/lru_gen_util.c
 LIBKVM += lib/memstress.c
tools/testing/selftests/kvm/include/test_util.h +0 -4
index a6a3e1657895..e558346c3b69 100644
@@ -49,10 +49,6 @@ do {								\
 
 #define TEST_REQUIRE(f) __TEST_REQUIRE(f, "Requirement not met: %s", #f)
 
-ssize_t test_write(int fd, const void *buf, size_t count);
-ssize_t test_read(int fd, void *buf, size_t count);
-int test_seq_read(const char *path, char **bufp, size_t *sizep);
-
 void __printf(5, 6) test_assert(bool exp, const char *exp_str,
 				const char *file, unsigned int line,
 				const char *fmt, ...);
tools/testing/selftests/kvm/lib/elf.c +43 -5

78 lines not on this page · raw message

tools/testing/selftests/kvm/lib/io.c deleted +0 -157

157 lines not on this page · raw message

Signature · 1 line
2.54.0
reviewer Applied
#1 lore raw
Quoted 9 lines · Gokul K

lib/io.c has outlived its purpose. test_read() has exactly one caller, lib/elf.c; test_write() has none at all; and test_seq_read() is a declaration in test_util.h with no definition anywhere in the tree.

Both surviving helpers open with

	TEST_ASSERT(count >= 0, "Unexpected count, count: %li", count);

[...]

Applied to kvm-x86 misc, thanks!

[1/1] KVM: selftests: Move test_read() into elf.c and delete lib/io.c

      https://github.com/kvm-x86/linux/commit/3069f4036dff

--
https://github.com/kvm-x86/linux/tree/next