port_linux_test.go 738 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //go:build linux
  2. package serialtransport_test
  3. import (
  4. "testing"
  5. "time"
  6. "golang.org/x/sys/unix"
  7. "hth/internal/serialtransport"
  8. )
  9. func TestBackoffCapped(t *testing.T) {
  10. d := time.Duration(0)
  11. seen := map[time.Duration]bool{}
  12. for i := 0; i < 20; i++ {
  13. d = serialtransport.NextBackoff(d, serialtransport.MaxBackoff)
  14. if d > serialtransport.MaxBackoff {
  15. t.Fatal(d)
  16. }
  17. seen[d] = true
  18. }
  19. if !seen[serialtransport.MaxBackoff] {
  20. t.Fatal("never reached cap")
  21. }
  22. }
  23. func TestPTYOpenConfigure(t *testing.T) {
  24. m, hold, name, err := serialtransport.OpenPTY()
  25. if err != nil {
  26. t.Fatal(err)
  27. }
  28. defer m.Close()
  29. defer unixClose(hold)
  30. if name == "" {
  31. t.Fatal("slave name")
  32. }
  33. }
  34. func unixClose(fd int) {
  35. _ = unix.Close(fd)
  36. }