knobs_linux_test.go 809 B

123456789101112131415161718192021222324252627282930313233
  1. package kernel
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/containerd/log"
  6. "gotest.tools/v3/assert"
  7. is "gotest.tools/v3/assert/cmp"
  8. )
  9. func TestReadWriteKnobs(t *testing.T) {
  10. for _, k := range []string{
  11. "net.ipv4.neigh.default.gc_thresh1",
  12. "net.ipv4.neigh.default.gc_thresh2",
  13. "net.ipv4.neigh.default.gc_thresh3",
  14. } {
  15. // Check if the test is able to read the value
  16. v, err := readSystemProperty(k)
  17. if err != nil {
  18. log.G(context.TODO()).WithError(err).Warnf("Path %v not readable", k)
  19. // the path is not there, skip this key
  20. continue
  21. }
  22. // Test the write
  23. assert.Check(t, writeSystemProperty(k, "10000"))
  24. newV, err := readSystemProperty(k)
  25. assert.NilError(t, err)
  26. assert.Check(t, is.Equal(newV, "10000"))
  27. // Restore value
  28. assert.Check(t, writeSystemProperty(k, v))
  29. }
  30. }