-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmetrics_test.go
More file actions
67 lines (55 loc) · 1.57 KB
/
Copy pathmetrics_test.go
File metadata and controls
67 lines (55 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//go:build darwin && arm64 && hypervisor
package hypervisor
import (
"testing"
)
func TestMetrics(t *testing.T) {
// Skip hypervisor tests in CI environments (no nested virtualization support)
if isCI() {
t.Skip("Skipping hypervisor tests in CI environment")
}
// Reset metrics for clean test
ResetMetrics()
// Verify initial state
metrics := GetMetrics()
if metrics.VMCreated != 0 {
t.Errorf("Expected VMCreated=0, got %d", metrics.VMCreated)
}
// Create and test VM (if entitled)
vm, err := NewVM()
if err != nil {
if err.Error() == "hv: access denied (HV_DENIED) - missing entitlement 'com.apple.security.hypervisor' or insufficient privileges" {
t.Skip("Skipping metrics test: missing hypervisor entitlements")
}
t.Fatalf("Failed to create VM: %v", err)
}
defer vm.Close()
// Check VM creation was recorded
metrics = GetMetrics()
if metrics.VMCreated != 1 {
t.Errorf("Expected VMCreated=1, got %d", metrics.VMCreated)
}
if metrics.AvgVMCreateTimeNs == 0 {
t.Errorf("Expected non-zero VM create time")
}
// Test VCPU metrics
vcpu, err := vm.NewVCPU()
if err != nil {
t.Fatalf("Failed to create VCPU: %v", err)
}
defer vcpu.Close()
metrics = GetMetrics()
if metrics.VCPUCreated != 1 {
t.Errorf("Expected VCPUCreated=1, got %d", metrics.VCPUCreated)
}
// Test register operation metrics
_, err = vcpu.GetReg(RegX0)
if err != nil {
t.Fatalf("Failed to get register: %v", err)
}
metrics = GetMetrics()
if metrics.RegisterOps != 1 {
t.Errorf("Expected RegisterOps=1, got %d", metrics.RegisterOps)
}
t.Logf("Final metrics: %+v", metrics)
}