test_hooks_linux.go 567 B

123456789101112131415161718192021222324
  1. //go:build linux
  2. package serialtransport
  3. import "sync/atomic"
  4. // Test-only write fault injection. Zero cap means unlimited.
  5. var testWriteCap atomic.Int32
  6. var testForceErr atomic.Bool
  7. var testIgnoreContext atomic.Bool
  8. func SetTestWriteCap(n int) {
  9. testWriteCap.Store(int32(n))
  10. }
  11. func SetTestForceWriteError(v bool) {
  12. testForceErr.Store(v)
  13. }
  14. // SetTestIgnoreContext makes ReadFrame ignore ctx cancellation until the FD
  15. // is closed. Production code never enables this; it models a stuck driver.
  16. func SetTestIgnoreContext(v bool) {
  17. testIgnoreContext.Store(v)
  18. }