package host import "testing" func TestPagingFileGrowth(t *testing.T) { cases := []struct { name string files []PagingFile want float64 }{ {"no paging file", nil, 0}, // The measured host: system-managed 5.6 GB file, max 37.5 GB (1/8 of C:), 141.7 GB free. {"system managed", []PagingFile{{Volume: `C:\`, CurrentGB: 5.6, MaxGB: 37.5, VolumeFreeGB: 141.7}}, 31.9}, {"fixed size", []PagingFile{{Volume: `C:\`, CurrentGB: 16, MaxGB: 16, VolumeFreeGB: 100}}, 0}, {"max below current", []PagingFile{{Volume: `C:\`, CurrentGB: 8, MaxGB: 4, VolumeFreeGB: 100}}, 0}, {"disk nearly full", []PagingFile{{Volume: `C:\`, CurrentGB: 4, MaxGB: 40, VolumeFreeGB: 5}}, 3}, {"disk below reserve", []PagingFile{{Volume: `C:\`, CurrentGB: 4, MaxGB: 40, VolumeFreeGB: 1}}, 0}, {"two files share one volume", []PagingFile{ {Volume: `D:\`, CurrentGB: 2, MaxGB: 10, VolumeFreeGB: 12}, {Volume: `d:\`, CurrentGB: 2, MaxGB: 10, VolumeFreeGB: 12}, }, 10}, {"files on two volumes", []PagingFile{ {Volume: `C:\`, CurrentGB: 2, MaxGB: 6, VolumeFreeGB: 50}, {Volume: `D:\`, CurrentGB: 1, MaxGB: 3, VolumeFreeGB: 50}, }, 6}, } for _, tc := range cases { got := PagingFileGrowthGB(tc.files) if diff := got - tc.want; diff > 1e-9 || diff < -1e-9 { t.Errorf("%s: got %.2f, want %.2f", tc.name, got, tc.want) } } } func TestCommitHeadroomAddsGrowth(t *testing.T) { // Task Manager on the measured host: 30.7 / 37.4 GB committed. The current // limit leaves 6.7 GB, which refused an 8G guest that starts fine. limit, avail := CommitHeadroom(37.4, 6.7, []PagingFile{{Volume: `C:\`, CurrentGB: 5.6, MaxGB: 37.5, VolumeFreeGB: 141.7}}) if limit < 69.2 || limit > 69.4 || avail < 38.5 || avail > 38.7 { t.Fatalf("got limit %.2f avail %.2f, want ~69.3 / ~38.6", limit, avail) } if limit, avail := CommitHeadroom(37.4, 6.7, nil); limit != 37.4 || avail != 6.7 { t.Fatalf("no paging file info: got %.2f / %.2f, want the current values", limit, avail) } } func TestRecommendedMemoryFollowsCommitMemory(t *testing.T) { // 32 GB host with 14.7 GiB commit Windows can still grant -> 8G. if got := RecommendedMemoryGB(Report{TotalRAMGB: 31.8, CommitAvailGB: 14.7}); got != 8 { t.Fatalf("got %v, want 8", got) } if got := RecommendedMemoryGB(Report{TotalRAMGB: 64, CommitAvailGB: 60}); got != 32 { t.Fatalf("got %v, want 32", got) } if got := RecommendedMemoryGB(Report{TotalRAMGB: 8, CommitAvailGB: 3}); got != 4 { t.Fatalf("got %v, want the 4 GB floor", got) } if got := RecommendedMemoryGB(Report{TotalRAMGB: 32}); got != 16 { t.Fatalf("unknown commit: got %v, want 16", got) } }