1
0

message_freebsd_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package route
  5. import (
  6. "testing"
  7. "unsafe"
  8. )
  9. func TestFetchAndParseRIBOnFreeBSD(t *testing.T) {
  10. for _, typ := range []RIBType{sysNET_RT_IFMALIST} {
  11. var lastErr error
  12. var ms []Message
  13. for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
  14. rs, err := fetchAndParseRIB(af, typ)
  15. if err != nil {
  16. lastErr = err
  17. continue
  18. }
  19. ms = append(ms, rs...)
  20. }
  21. if len(ms) == 0 && lastErr != nil {
  22. t.Error(typ, lastErr)
  23. continue
  24. }
  25. ss, err := msgs(ms).validate()
  26. if err != nil {
  27. t.Error(typ, err)
  28. continue
  29. }
  30. for _, s := range ss {
  31. t.Log(s)
  32. }
  33. }
  34. }
  35. func TestFetchAndParseRIBOnFreeBSD10AndAbove(t *testing.T) {
  36. if _, err := FetchRIB(sysAF_UNSPEC, sysNET_RT_IFLISTL, 0); err != nil {
  37. t.Skip("NET_RT_IFLISTL not supported")
  38. }
  39. var p uintptr
  40. if kernelAlign != int(unsafe.Sizeof(p)) {
  41. t.Skip("NET_RT_IFLIST vs. NET_RT_IFLISTL doesn't work for 386 emulation on amd64")
  42. }
  43. var tests = [2]struct {
  44. typ RIBType
  45. b []byte
  46. msgs []Message
  47. ss []string
  48. }{
  49. {typ: sysNET_RT_IFLIST},
  50. {typ: sysNET_RT_IFLISTL},
  51. }
  52. for i := range tests {
  53. var lastErr error
  54. for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
  55. rs, err := fetchAndParseRIB(af, tests[i].typ)
  56. if err != nil {
  57. lastErr = err
  58. continue
  59. }
  60. tests[i].msgs = append(tests[i].msgs, rs...)
  61. }
  62. if len(tests[i].msgs) == 0 && lastErr != nil {
  63. t.Error(tests[i].typ, lastErr)
  64. continue
  65. }
  66. tests[i].ss, lastErr = msgs(tests[i].msgs).validate()
  67. if lastErr != nil {
  68. t.Error(tests[i].typ, lastErr)
  69. continue
  70. }
  71. for _, s := range tests[i].ss {
  72. t.Log(s)
  73. }
  74. }
  75. for i := len(tests) - 1; i > 0; i-- {
  76. if len(tests[i].ss) != len(tests[i-1].ss) {
  77. t.Errorf("got %v; want %v", tests[i].ss, tests[i-1].ss)
  78. continue
  79. }
  80. for j, s1 := range tests[i].ss {
  81. s0 := tests[i-1].ss[j]
  82. if s1 != s0 {
  83. t.Errorf("got %s; want %s", s1, s0)
  84. }
  85. }
  86. }
  87. }