KVM: selftests: Add a test case for debugfs directory
PATCH 1/1 KVM: selftests: 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.
---
tools/testing/selftests/kvm/Makefile | 6 ++--
.../testing/selftests/kvm/include/test_util.h | 2 ++
...m_binary_stats_test.c => kvm_stats_test.c} | 31 +++++++++++++++++++
3 files changed, 36 insertions(+), 3 deletions(-)
rename tools/testing/selftests/kvm/{kvm_binary_stats_test.c => kvm_stats_test.c} (88%)tools/testing/selftests/kvm/Makefile +3 -3
@@ -82,7 +82,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
@@ -94,7 +94,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
@@ -104,7 +104,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 +31 -0
@@ -13,6 +13,7 @@#include <stdlib.h> #include <string.h> #include <errno.h> +#include <sys/stat.h> #include "test_util.h"
@@ -179,6 +180,7 @@ static void vcpu_stats_test(struct kvm_vm *vm, int vcpu_id)#define DEFAULT_NUM_VM 4#define DEFAULT_NUM_VCPU 4 +#define INT_MAX_LEN 10/* * Usage: kvm_bin_form_stats [#vm] [#vcpu]
@@ -230,8 +232,37 @@ 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 ; + + len =strlen (KVM_DEBUGFS_PATH ) +2 *INT_MAX_LEN +3 ; + vm_dir_path =malloc (len); +TEST_ASSERT (vm_dir_path,"Allocate memory for VM directory path" ); + vcpu_dir_path =malloc (len +INT_MAX_LEN +6 ); +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),"VCPU 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
Quoted 6 lines · Krish Sadhukhan
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.cto check that KVM debugfs contains the correct directory entries for the test VMs and test VCPUs. Also, rename the file tokvm_stats_test.c.
Quoted 8 lines
Signed-off-by Krish Sadhukhan <[email protected]>--- tools/testing/selftests/kvm/Makefile | 6 ++-- .../testing/selftests/kvm/include/test_util.h | 2 ++ ...m_binary_stats_test.c => kvm_stats_test.c} | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-)rename
tools/testing/selftests/kvm/{kvm_binary_stats_test.c=>kvm_stats_test.c} (88%)
Binary name needs to be updated in tools/testing/selftests/kvm/.gitignore also
Otherwise
Quoted 106 lines
tools/testing/selftests/kvm/Makefile +3
-3@@ -82,7 +82,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@@ -94,7 +94,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@@ -104,7 +104,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 +31
-0@@ -13,6 +13,7 @@#include <stdlib.h> #include <string.h> #include <errno.h> +#include <sys/stat.h> #include "test_util.h" @@ -179,6 +180,7 @@ static void vcpu_stats_test(struct kvm_vm *vm, int vcpu_id)#define DEFAULT_NUM_VM 4#define DEFAULT_NUM_VCPU 4 +#define INT_MAX_LEN 10/* * Usage: kvm_bin_form_stats [#vm] [#vcpu] @@ -230,8 +232,37 @@ 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 ; + + len =strlen (KVM_DEBUGFS_PATH ) +2 *INT_MAX_LEN +3 ; + vm_dir_path =malloc (len); +TEST_ASSERT (vm_dir_path,"Allocate memory for VM directory path" ); + vcpu_dir_path =malloc (len +INT_MAX_LEN +6 ); +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),"VCPU 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 ; }
Paolo Bonzini
maintainerQuoted 18 lines · Krish Sadhukhan
tools/testing/selftests/kvm/kvm_stats_test.c renamed from tools/testing/selftests/kvm/kvm_binary_stats_test.c +17
-0+/* +* Check debugfs directory for every VM and VCPU +*/ +struct stat buf; +int len; +char *vm_dir_path =NULL ; +char *vcpu_dir_path =NULL ; + + len =strlen (KVM_DEBUGFS_PATH ) +2 *INT_MAX_LEN +3 ; + vm_dir_path =malloc (len); +TEST_ASSERT (vm_dir_path,"Allocate memory for VM directory path" ); + vcpu_dir_path =malloc (len +INT_MAX_LEN +6 ); +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);
tools/testing/selftests/kvm/kvm_stats_test.c int main(int argc, char *argv[]) · line 261
Quoted 10 lines
tools/testing/selftests/kvm/kvm_stats_test.c renamed from tools/testing/selftests/kvm/kvm_binary_stats_test.c +10
-0+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),"VCPU directory %s does not exist" , + vcpu_dir_path); + } + } +
Hi,
please ensure that the tests don't fail if thy don't run as root.
Paolo