(t *testing.T)
| 148 | } |
| 149 | |
| 150 | func TestClientRun(t *testing.T) { |
| 151 | cfg := &Config{ |
| 152 | Address: "blah", |
| 153 | Iface: "ethBlah", |
| 154 | Timeout: 5 * time.Second, |
| 155 | Duration: 5 * time.Second, |
| 156 | } |
| 157 | // we simply append samples to the array to match what we collected in the end |
| 158 | history := []*MeasurementResult{} |
| 159 | c := New(cfg, func(m *MeasurementResult) { |
| 160 | history = append(history, m) |
| 161 | }) |
| 162 | |
| 163 | ctrl := gomock.NewController(t) |
| 164 | defer ctrl.Finish() |
| 165 | |
| 166 | genConn := NewMockUDPConn(ctrl) |
| 167 | c.genConn = genConn |
| 168 | // handle whatever client is sending over genConn |
| 169 | genConn.EXPECT().WriteTo(gomock.Any(), gomock.Any()).DoAndReturn(func(b []byte, _ net.Addr) (int, error) { |
| 170 | r := bytes.NewReader(b) |
| 171 | h := &ptp.Header{} |
| 172 | err := binary.Read(r, binary.BigEndian, h) |
| 173 | require.Nil(t, err, "reading header") |
| 174 | require.Equal(t, ptp.MessageSignaling, h.SdoIDAndMsgType.MsgType(), "only expect signaling msgs over genConn") |
| 175 | signaling := &ptp.Signaling{} |
| 176 | err = ptp.FromBytes(b, signaling) |
| 177 | require.Nil(t, err, "reading signaling msg") |
| 178 | require.Equal(t, 1, len(signaling.TLVs), "expect only 1 TLV in signaling msg") |
| 179 | tlv := signaling.TLVs[0] |
| 180 | // we only expect SIGNALING messages where client asks for unicast grants. |
| 181 | // for each such request we grant it. |
| 182 | switch v := tlv.(type) { |
| 183 | case *ptp.RequestUnicastTransmissionTLV: |
| 184 | msgType := v.MsgTypeAndReserved.MsgType() |
| 185 | switch msgType { |
| 186 | case ptp.MessageAnnounce: |
| 187 | grantAnnounce := grantUnicastPkt(0, c.clockID, c.cfg.Duration, ptp.MessageAnnounce) |
| 188 | grantAnnounceBytes, err := ptp.Bytes(grantAnnounce) |
| 189 | require.Nil(t, err) |
| 190 | c.inChan <- &inPacket{ |
| 191 | data: grantAnnounceBytes, |
| 192 | ts: time.Now(), |
| 193 | } |
| 194 | return 20, nil |
| 195 | case ptp.MessageSync: |
| 196 | grantSync := grantUnicastPkt(1, c.clockID, c.cfg.Duration, ptp.MessageSync) |
| 197 | grantSyncBytes, err := ptp.Bytes(grantSync) |
| 198 | require.Nil(t, err) |
| 199 | c.inChan <- &inPacket{ |
| 200 | data: grantSyncBytes, |
| 201 | ts: time.Now(), |
| 202 | } |
| 203 | return 20, nil |
| 204 | case ptp.MessageDelayResp: |
| 205 | grantDelayResp := grantUnicastPkt(2, c.clockID, c.cfg.Duration, ptp.MessageDelayResp) |
| 206 | grantDelayRespBytes, err := ptp.Bytes(grantDelayResp) |
| 207 | require.Nil(t, err) |
nothing calls this directly
no test coverage detected
searching dependent graphs…