gpu_test.go 909 B

123456789101112131415161718192021222324252627282930
  1. package env
  2. import "testing"
  3. func TestGetGPUMemorySaturationThreshold(t *testing.T) {
  4. cases := map[string]struct {
  5. value string
  6. want float64
  7. }{
  8. "unset uses default": {"", 0.9},
  9. "valid value": {"0.8", 0.8},
  10. "upper bound inclusive": {"1.0", 1.0},
  11. "zero rejected": {"0", 0.9},
  12. "negative rejected": {"-0.5", 0.9},
  13. "above one rejected": {"1.5", 0.9},
  14. "non-numeric uses default": {"high", 0.9},
  15. }
  16. for name, tc := range cases {
  17. t.Run(name, func(t *testing.T) {
  18. // Set unconditionally (empty for the "unset" case) so an
  19. // externally-configured value cannot leak in and make the
  20. // default-path subtests non-hermetic.
  21. t.Setenv(GPUMemorySaturationThresholdEnvVar, tc.value)
  22. if got := GetGPUMemorySaturationThreshold(); got != tc.want {
  23. t.Errorf("GetGPUMemorySaturationThreshold() = %v, want %v", got, tc.want)
  24. }
  25. })
  26. }
  27. }