KVM: selftests: Add a test case for debugfs directory
v2 cover KVM: selftests: Add a test case for debugfs directory
v1 -> v2:
tools/testing/selftests/kvm/.gitignore updated to reflect the new name.
[TEST PATCH 1/1 v2] x86: Add a test case for debugfs directory
tools/testing/selftests/kvm/.gitignore | 2 +-
tools/testing/selftests/kvm/Makefile | 6 ++--
tools/testing/selftests/kvm/include/test_util.h | 2 ++
.../{kvm_binary_stats_test.c => kvm_stats_test.c} | 32 ++++++++++++++++++++++
4 files changed, 38 insertions(+), 4 deletions(-)Krish Sadhukhan (1):
x86: Add a test case for debugfs directory
PATCH v2 1/1 x86: Add a test case for debugfs directory
Along with testing the binary interface for KVM statistics, it's good to do a small sanity check of the KVM debugfs interface. So, add a test case to the existing kvm_binary_stats_test.c to check that KVM debugfs contains the correct directory entries for the test VMs and test VCPUs. Also, rename the file to kvm_stats_test.c.
Signed-off-by Krish Sadhukhan <[email protected]>
Reviewed-by Liam Merwick <[email protected]>
---
tools/testing/selftests/kvm/.gitignore | 2 +-
tools/testing/selftests/kvm/Makefile | 6 ++--
.../testing/selftests/kvm/include/test_util.h | 2 ++
...m_binary_stats_test.c => kvm_stats_test.c} | 32 +++++++++++++++++++
4 files changed, 38 insertions(+), 4 deletions(-)
rename tools/testing/selftests/kvm/{kvm_binary_stats_test.c => kvm_stats_test.c} (88%)tools/testing/selftests/kvm/.gitignore +1 -1
@@ -50,4 +50,4 @@ /memslot_perf_test /set_memory_region_test /steal_time -/kvm_binary_stats_test +/kvm_stats_test
tools/testing/selftests/kvm/Makefile +3 -3
@@ -83,7 +83,7 @@ TEST_GEN_PROGS_x86_64 += memslot_modification_stress_test TEST_GEN_PROGS_x86_64 += memslot_perf_test TEST_GEN_PROGS_x86_64 += set_memory_region_test TEST_GEN_PROGS_x86_64 += steal_time -TEST_GEN_PROGS_x86_64 += kvm_binary_stats_test +TEST_GEN_PROGS_x86_64 += kvm_stats_test TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
@@ -95,7 +95,7 @@ TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus TEST_GEN_PROGS_aarch64 += kvm_page_table_test TEST_GEN_PROGS_aarch64 += set_memory_region_test TEST_GEN_PROGS_aarch64 += steal_time -TEST_GEN_PROGS_aarch64 += kvm_binary_stats_test +TEST_GEN_PROGS_aarch64 += kvm_stats_test TEST_GEN_PROGS_s390x = s390x/memop TEST_GEN_PROGS_s390x += s390x/resets
@@ -105,7 +105,7 @@ TEST_GEN_PROGS_s390x += dirty_log_test TEST_GEN_PROGS_s390x += kvm_create_max_vcpus TEST_GEN_PROGS_s390x += kvm_page_table_test TEST_GEN_PROGS_s390x += set_memory_region_test -TEST_GEN_PROGS_s390x += kvm_binary_stats_test +TEST_GEN_PROGS_s390x += kvm_stats_test TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M)) LIBKVM += $(LIBKVM_$(UNAME_M))
tools/testing/selftests/kvm/include/test_util.h +2 -0
@@ -59,6 +59,8 @@ void test_assert(bool exp, const char *exp_str,#define TEST_FAIL (fmt, ...) \ TEST_ASSERT(false, fmt, ##__VA_ARGS__) +#define KVM_DEBUGFS_PATH "/sys/kernel/debug/kvm" +size_t parse_size (const char *size);int64_t timespec_to_ns (struct timespec ts);
tools/testing/selftests/kvm/kvm_stats_test.c renamed from tools/testing/selftests/kvm/kvm_binary_stats_test.c +32 -0
@@ -13,6 +13,7 @@#include <stdlib.h> #include <string.h> #include <errno.h> +#include <sys/stat.h> #include "test_util.h"
@@ -230,8 +231,39 @@ int main(int argc, char *argv[])vcpu_stats_test (vms[i], j); } +/* +* Check debugfs directory for every VM and VCPU +*/ +struct stat buf; +int len; +char *vm_dir_path =NULL ; +char *vcpu_dir_path =NULL ; + +#define INT_MAX_LEN 10 + + len =strlen (KVM_DEBUGFS_PATH ) +2 *INT_MAX_LEN +2 ; + vm_dir_path =malloc (len); +TEST_ASSERT (vm_dir_path,"Allocate memory for VM directory path" ); + vcpu_dir_path =malloc (len +INT_MAX_LEN +5 ); +TEST_ASSERT (vm_dir_path,"Allocate memory for VCPU directory path" ); +for (i =0 ; i < max_vm; ++i) { +sprintf (vm_dir_path,"%s/%d-%d" ,KVM_DEBUGFS_PATH ,getpid (), +vm_get_fd (vms[i])); +stat (vm_dir_path, &buf); +TEST_ASSERT (S_ISDIR (buf.st_mode),"VM directory %s does not " +"exist" , vm_dir_path); +for (j =0 ; j < max_vcpu; ++j) { +sprintf (vcpu_dir_path,"%s/vcpu%d" , vm_dir_path, j); +stat (vcpu_dir_path, &buf); +TEST_ASSERT (S_ISDIR (buf.st_mode),"CPU directory %s " +"does not exist" , vcpu_dir_path); + } + } +for (i =0 ; i < max_vm; ++i)kvm_vm_free (vms[i]);free (vms); +free (vm_dir_path); +free (vcpu_dir_path);return 0 ; }
Signature · 1 line
2.27.0