knobs_linux_test.go 784 B

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