MCPcopy Index your code
hub / github.com/google/gopacket / ngRunFileReadTest

Function ngRunFileReadTest

pcapgo/ngread_test.go:65–199  ·  view source on GitHub ↗
(test ngFileReadTest, be string, zerocopy bool, t *testing.T)

Source from the content-addressed store, hash-verified

63}
64
65func ngRunFileReadTest(test ngFileReadTest, be string, zerocopy bool, t *testing.T) {
66 var err error
67 var f io.Reader
68 if test.testContents == nil {
69 testf, err := os.Open(filepath.Join("tests", be, test.testName+".pcapng"))
70 if err != nil {
71 t.Fatal("Couldn't open file:", err)
72 }
73 defer testf.Close()
74 f = testf
75 } else {
76 f = test.testContents
77 }
78
79 var r *NgReader
80
81 section := 0
82 checkInterface := func(intf NgInterface, i int) {
83 currentInterface := test.sections[section].ifaces[i]
84
85 // fix non-zero defaults
86 if currentInterface.TimestampResolution == 0 {
87 currentInterface.TimestampResolution = 6
88 }
89 // clear private values
90 intf.scaleDown = 0
91 intf.scaleUp = 0
92 intf.secondMask = 0
93
94 if !reflect.DeepEqual(intf, currentInterface) {
95 t.Fatalf("[section %d] interface %d mismatches:\ngot:\n%#v\nwant:\n%#v\n\n", section, i, intf, currentInterface)
96 }
97 }
98 testSection := func(intf []NgInterface, sectionInfo NgSectionInfo) {
99 currentSection := test.sections[section]
100
101 if !reflect.DeepEqual(sectionInfo, currentSection.sectionInfo) {
102 t.Fatalf("[section header %d] section info mismatch:\ngot:\n%#v\nwant:\n%#v\n\n", section, sectionInfo, currentSection.sectionInfo)
103 }
104
105 if intf == nil {
106 if r.NInterfaces() != len(test.sections[section].ifaces) {
107 t.Fatalf("[section %d] Expected at least %d interfaces, but got only %d", section, len(test.sections[section].ifaces), r.NInterfaces())
108 }
109 for i := 0; i < r.NInterfaces(); i++ {
110 in, err := r.Interface(i)
111 if err != nil {
112 t.Fatalf("Unexpected error querying interface %d", i)
113 }
114 checkInterface(in, i)
115 }
116 } else {
117 if len(intf) != len(test.sections[section].ifaces) {
118 t.Fatalf("[section %d] Expected at least %d interfaces, but got only %d", section, len(test.sections[section].ifaces), len(intf))
119 }
120 for i, in := range intf {
121 checkInterface(in, i)
122 }

Callers 6

TestNgFileReadBEFunction · 0.85
TestNgFileReadLEFunction · 0.85
TestNgFileReadBEZeroFunction · 0.85
TestNgFileReadLEZeroFunction · 0.85
TestNgWriteSimpleFunction · 0.85
TestNgWriteComplexFunction · 0.85

Calls 8

NInterfacesMethod · 0.95
InterfaceMethod · 0.95
LinkTypeMethod · 0.95
ReadPacketDataMethod · 0.95
SectionInfoMethod · 0.95
NewNgReaderFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…