History

KVM: selftests: Clean up stats fd in common stats_test() helper

Move the stats fd cleanup code into stats_test() and drop the superfluous vm_stats_test() and vcpu_stats_test() helpers in order to decouple creation of the stats file from consuming/testing the file (deduping code is a bonus). This will make it easier to test various edge cases related to stats, e.g. that userspace can dup() a stats fd, that userspace can have multiple stats files for a singleVM/vCPU, etc.

Sean Christopherson committed 3 years ago

Commit 87d53581 parent 625646a1 file · +4 −18Browse files

Unified · Split

tools/testing/selftests/kvm/kvm_binary_stats_test.c+4−18
@@ -167,23 +167,7 @@ static void stats_test(int stats_fd) · 166 unmodified lines
167 free(stats_data);167 free(stats_data);
168 free(stats_desc);168 free(stats_desc);
169 free(id);169 free(id);
170}
171
172
173static void vm_stats_test(struct kvm_vm *vm)
174{
175 int stats_fd = vm_get_stats_fd(vm);
176
177 stats_test(stats_fd);
178 close(stats_fd);
179 TEST_ASSERT(fcntl(stats_fd, F_GETFD) == -1, "Stats fd not freed");
180}
181
182static void vcpu_stats_test(struct kvm_vcpu *vcpu)
183{
184 int stats_fd = vcpu_get_stats_fd(vcpu);
185 170
186 stats_test(stats_fd);
187 close(stats_fd);171 close(stats_fd);
188 TEST_ASSERT(fcntl(stats_fd, F_GETFD) == -1, "Stats fd not freed");172 TEST_ASSERT(fcntl(stats_fd, F_GETFD) == -1, "Stats fd not freed");
189}173}
@@ -241,9 +225,11 @@ int main(int argc, char *argv[]) · 51 unmodified lines
241 225
242 /* Check stats read for every VM and VCPU */226 /* Check stats read for every VM and VCPU */
243 for (i = 0; i < max_vm; ++i) {227 for (i = 0; i < max_vm; ++i) {
244 vm_stats_test(vms[i]);228 stats_test(vm_get_stats_fd(vms[i]));
229
245 for (j = 0; j < max_vcpu; ++j)230 for (j = 0; j < max_vcpu; ++j)
246 vcpu_stats_test(vcpus[i * max_vcpu + j]);231 stats_test(vcpu_get_stats_fd(vcpus[i * max_vcpu + j]));
232
247 ksft_test_result_pass("vm%i\n", i);233 ksft_test_result_pass("vm%i\n", i);
248 }234 }
249 235

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t