tools/testing/selftests/kvm/kvm_binary_stats_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/kvm_binary_stats_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/kvm_binary_stats_test.c- Extension
.c- Size
- 8300 bytes
- Lines
- 274
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
fcntl.hstdio.hstdlib.hstring.herrno.htest_util.hkvm_util.hasm/kvm.hlinux/kvm.hkselftest.h
Detected Declarations
function Copyrightfunction main
Annotated Snippet
switch (pdesc->flags & KVM_STATS_UNIT_MASK) {
case KVM_STATS_UNIT_NONE:
case KVM_STATS_UNIT_BYTES:
case KVM_STATS_UNIT_CYCLES:
TEST_ASSERT(pdesc->exponent >= 0,
"Unsupported KVM stats (%s) exponent: %i",
pdesc->name, pdesc->exponent);
break;
case KVM_STATS_UNIT_SECONDS:
TEST_ASSERT(pdesc->exponent <= 0,
"Unsupported KVM stats (%s) exponent: %i",
pdesc->name, pdesc->exponent);
break;
case KVM_STATS_UNIT_BOOLEAN:
TEST_ASSERT(pdesc->exponent == 0,
"Unsupported KVM stats (%s) exponent: %d",
pdesc->name, pdesc->exponent);
break;
}
/* Check size field, which should not be zero */
TEST_ASSERT(pdesc->size,
"KVM descriptor(%s) with size of 0", pdesc->name);
/* Check bucket_size field */
switch (pdesc->flags & KVM_STATS_TYPE_MASK) {
case KVM_STATS_TYPE_LINEAR_HIST:
TEST_ASSERT(pdesc->bucket_size,
"Bucket size of Linear Histogram stats (%s) is zero",
pdesc->name);
break;
default:
TEST_ASSERT(!pdesc->bucket_size,
"Bucket size of stats (%s) is not zero",
pdesc->name);
}
size_data = max(size_data, pdesc->offset + pdesc->size * sizeof(*stats_data));
}
/*
* Now that the size of the data block is known, verify the data block
* doesn't overlap the descriptor block.
*/
TEST_ASSERT(header.data_offset >= header.desc_offset ||
header.data_offset + size_data <= header.desc_offset,
"Data block is overlapped with Descriptor block");
/* Check validity of all stats data size */
TEST_ASSERT(size_data >= header.num_desc * sizeof(*stats_data),
"Data size is not correct");
/* Allocate memory for stats data */
stats_data = malloc(size_data);
TEST_ASSERT(stats_data, "Allocate memory for stats data");
/* Read kvm stats data as a bulk */
ret = pread(stats_fd, stats_data, size_data, header.data_offset);
TEST_ASSERT(ret == size_data, "Read KVM stats data");
/* Read kvm stats data one by one */
for (i = 0; i < header.num_desc; ++i) {
pdesc = get_stats_descriptor(stats_desc, i, &header);
read_stat_data(stats_fd, &header, pdesc, stats_data,
pdesc->size);
}
free(stats_data);
free(stats_desc);
free(id);
close(stats_fd);
TEST_ASSERT(fcntl(stats_fd, F_GETFD) == -1, "Stats fd not freed");
}
#define DEFAULT_NUM_VM 4
#define DEFAULT_NUM_VCPU 4
/*
* Usage: kvm_bin_form_stats [#vm] [#vcpu]
* The first parameter #vm set the number of VMs being created.
* The second parameter #vcpu set the number of VCPUs being created.
* By default, DEFAULT_NUM_VM VM and DEFAULT_NUM_VCPU VCPU for the VM would be
* created for testing.
*/
int main(int argc, char *argv[])
{
int vm_stats_fds, *vcpu_stats_fds;
int i, j;
struct kvm_vcpu **vcpus;
struct kvm_vm **vms;
int max_vm = DEFAULT_NUM_VM;
int max_vcpu = DEFAULT_NUM_VCPU;
Annotation
- Immediate include surface: `fcntl.h`, `stdio.h`, `stdlib.h`, `string.h`, `errno.h`, `test_util.h`, `kvm_util.h`, `asm/kvm.h`.
- Detected declarations: `function Copyright`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.