Commit d5cd7348 authored by Mikio Hara's avatar Mikio Hara

ipv6: simplify log message format

This change replaces the existing log format separated by commas and
spaces with space-separated one.

Also removes unnecessary log output in test.

Change-Id: I7fc5da1b58734a7ee1d06da4e15408bef0162b0b
Reviewed-on: https://go-review.googlesource.com/16323Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 09f95eed
...@@ -63,7 +63,7 @@ func (cm *ControlMessage) String() string { ...@@ -63,7 +63,7 @@ func (cm *ControlMessage) String() string {
if cm == nil { if cm == nil {
return "<nil>" return "<nil>"
} }
return fmt.Sprintf("tclass: %#x, hoplim: %v, src: %v, dst: %v, ifindex: %v, nexthop: %v, mtu: %v", cm.TrafficClass, cm.HopLimit, cm.Src, cm.Dst, cm.IfIndex, cm.NextHop, cm.MTU) return fmt.Sprintf("tclass=%#x hoplim=%d src=%v dst=%v ifindex=%d nexthop=%v mtu=%d", cm.TrafficClass, cm.HopLimit, cm.Src, cm.Dst, cm.IfIndex, cm.NextHop, cm.MTU)
} }
// Ancillary data socket options // Ancillary data socket options
......
...@@ -30,7 +30,7 @@ func (h *Header) String() string { ...@@ -30,7 +30,7 @@ func (h *Header) String() string {
if h == nil { if h == nil {
return "<nil>" return "<nil>"
} }
return fmt.Sprintf("ver: %v, tclass: %#x, flowlbl: %#x, payloadlen: %v, nxthdr: %v, hoplim: %v, src: %v, dst: %v", h.Version, h.TrafficClass, h.FlowLabel, h.PayloadLen, h.NextHeader, h.HopLimit, h.Src, h.Dst) return fmt.Sprintf("ver=%d tclass=%#x flowlbl=%#x payloadlen=%d nxthdr=%d hoplim=%d src=%v dst=%v", h.Version, h.TrafficClass, h.FlowLabel, h.PayloadLen, h.NextHeader, h.HopLimit, h.Src, h.Dst)
} }
// ParseHeader parses b as an IPv6 base header. // ParseHeader parses b as an IPv6 base header.
......
...@@ -7,6 +7,7 @@ package ipv6_test ...@@ -7,6 +7,7 @@ package ipv6_test
import ( import (
"net" "net"
"reflect" "reflect"
"strings"
"testing" "testing"
"golang.org/x/net/internal/iana" "golang.org/x/net/internal/iana"
...@@ -47,4 +48,8 @@ func TestParseHeader(t *testing.T) { ...@@ -47,4 +48,8 @@ func TestParseHeader(t *testing.T) {
if !reflect.DeepEqual(h, testHeader) { if !reflect.DeepEqual(h, testHeader) {
t.Fatalf("got %#v; want %#v", h, testHeader) t.Fatalf("got %#v; want %#v", h, testHeader)
} }
s := h.String()
if strings.Contains(s, ",") {
t.Fatalf("should be space-separated values: %s", s)
}
} }
...@@ -110,12 +110,10 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) { ...@@ -110,12 +110,10 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
rb := make([]byte, 128) rb := make([]byte, 128)
if n, cm, _, err := p.ReadFrom(rb); err != nil { if n, _, _, err := p.ReadFrom(rb); err != nil {
t.Fatal(err) t.Fatal(err)
} else if !bytes.Equal(rb[:n], wb) { } else if !bytes.Equal(rb[:n], wb) {
t.Fatalf("got %v; want %v", rb[:n], wb) t.Fatalf("got %v; want %v", rb[:n], wb)
} else {
t.Logf("rcvd cmsg: %v", cm)
} }
} }
} }
...@@ -243,7 +241,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) { ...@@ -243,7 +241,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
t.Fatalf("got %v; want %v", n, len(wb)) t.Fatalf("got %v; want %v", n, len(wb))
} }
rb := make([]byte, 128) rb := make([]byte, 128)
if n, cm, _, err := p.ReadFrom(rb); err != nil { if n, _, _, err := p.ReadFrom(rb); err != nil {
switch runtime.GOOS { switch runtime.GOOS {
case "darwin": // older darwin kernels have some limitation on receiving icmp packet through raw socket case "darwin": // older darwin kernels have some limitation on receiving icmp packet through raw socket
t.Logf("not supported on %s", runtime.GOOS) t.Logf("not supported on %s", runtime.GOOS)
...@@ -251,7 +249,6 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) { ...@@ -251,7 +249,6 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
} }
t.Fatal(err) t.Fatal(err)
} else { } else {
t.Logf("rcvd cmsg: %v", cm)
if m, err := icmp.ParseMessage(iana.ProtocolIPv6ICMP, rb[:n]); err != nil { if m, err := icmp.ParseMessage(iana.ProtocolIPv6ICMP, rb[:n]); err != nil {
t.Fatal(err) t.Fatal(err)
} else if m.Type != ipv6.ICMPTypeEchoReply || m.Code != 0 { } else if m.Type != ipv6.ICMPTypeEchoReply || m.Code != 0 {
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"bytes" "bytes"
"net" "net"
"runtime" "runtime"
"strings"
"sync" "sync"
"testing" "testing"
...@@ -143,7 +144,10 @@ func TestPacketConnConcurrentReadWriteUnicastUDP(t *testing.T) { ...@@ -143,7 +144,10 @@ func TestPacketConnConcurrentReadWriteUnicastUDP(t *testing.T) {
t.Errorf("got %v; want %v", rb[:n], wb) t.Errorf("got %v; want %v", rb[:n], wb)
return return
} else { } else {
t.Logf("rcvd cmsg: %v", cm) s := cm.String()
if strings.Contains(s, ",") {
t.Errorf("should be space-separated values: %s", s)
}
} }
} }
writer := func(toggle bool) { writer := func(toggle bool) {
......
...@@ -71,12 +71,10 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) { ...@@ -71,12 +71,10 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
if err := p.SetReadDeadline(time.Now().Add(100 * time.Millisecond)); err != nil { if err := p.SetReadDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if n, cm, _, err := p.ReadFrom(rb); err != nil { if n, _, _, err := p.ReadFrom(rb); err != nil {
t.Fatal(err) t.Fatal(err)
} else if !bytes.Equal(rb[:n], wb) { } else if !bytes.Equal(rb[:n], wb) {
t.Fatalf("got %v; want %v", rb[:n], wb) t.Fatalf("got %v; want %v", rb[:n], wb)
} else {
t.Logf("rcvd cmsg: %v", cm)
} }
} }
} }
...@@ -166,7 +164,7 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) { ...@@ -166,7 +164,7 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
if err := p.SetReadDeadline(time.Now().Add(100 * time.Millisecond)); err != nil { if err := p.SetReadDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if n, cm, _, err := p.ReadFrom(rb); err != nil { if n, _, _, err := p.ReadFrom(rb); err != nil {
switch runtime.GOOS { switch runtime.GOOS {
case "darwin": // older darwin kernels have some limitation on receiving icmp packet through raw socket case "darwin": // older darwin kernels have some limitation on receiving icmp packet through raw socket
t.Logf("not supported on %s", runtime.GOOS) t.Logf("not supported on %s", runtime.GOOS)
...@@ -174,7 +172,6 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) { ...@@ -174,7 +172,6 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
} }
t.Fatal(err) t.Fatal(err)
} else { } else {
t.Logf("rcvd cmsg: %v", cm)
if m, err := icmp.ParseMessage(iana.ProtocolIPv6ICMP, rb[:n]); err != nil { if m, err := icmp.ParseMessage(iana.ProtocolIPv6ICMP, rb[:n]); err != nil {
t.Fatal(err) t.Fatal(err)
} else if m.Type != ipv6.ICMPTypeEchoReply || m.Code != 0 { } else if m.Type != ipv6.ICMPTypeEchoReply || m.Code != 0 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment