Skip to content

Test_parseTCPStats fails on big-endian archs #2507

@dswarbrick

Description

@dswarbrick

Test_parseTCPStats fails on s390x and presumably other big-endian archs (e.g. mips, mips64, ppc64):

=== RUN   Test_parseTCPStats
    tcpstat_linux_test.go:80: want tcpstat number of bytes in tx queue 42, got 704643072
    tcpstat_linux_test.go:83: want tcpstat number of bytes in rx queue 22, got 369098752
--- FAIL: Test_parseTCPStats (0.00s)

This is due to a wrong assumption about the endianness of s390x etc. in the test:

func Test_parseTCPStats(t *testing.T) {
    encode := func(m InetDiagMsg) []byte {
        var buf bytes.Buffer
        err := binary.Write(&buf, binary.LittleEndian, m)
        if err != nil {
            panic(err)
        }   
        return buf.Bytes()
    }
...

Most, but not all modern CPUs are little-endian. s390x is big-endian.

This is a regression in v1.4.0 due to #2322. Other functionality related to that PR may also be buggy on s390x, in addition to the failing test.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions