...

Source file src/github.com/prometheus/procfs/net_softnet_test.go

Documentation: github.com/prometheus/procfs

     1  // Copyright 2019 The Prometheus Authors
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package procfs
    15  
    16  import (
    17  	"testing"
    18  
    19  	"github.com/google/go-cmp/cmp"
    20  )
    21  
    22  func TestNetSoftnet(t *testing.T) {
    23  	fs, err := NewFS(procTestFixtures)
    24  	if err != nil {
    25  		t.Fatal(err)
    26  	}
    27  
    28  	want := []SoftnetStat{
    29  		{
    30  			Processed:         0x00358fe3,
    31  			Dropped:           0x00006283,
    32  			TimeSqueezed:      0x00000000,
    33  			CPUCollision:      0x00000000,
    34  			ReceivedRps:       0x000855fc,
    35  			FlowLimitCount:    0x00000076,
    36  			SoftnetBacklogLen: 0x00000000,
    37  			Index:             0x00000000,
    38  			Width:             13,
    39  		},
    40  		{
    41  			Processed:         0x00953d1a,
    42  			Dropped:           0x00000446,
    43  			TimeSqueezed:      0x000000b1,
    44  			CPUCollision:      0x00000000,
    45  			ReceivedRps:       0x008eeb9a,
    46  			FlowLimitCount:    0x0000002b,
    47  			SoftnetBacklogLen: 0x000000dc,
    48  			Index:             0x00000001,
    49  			Width:             13,
    50  		},
    51  		{
    52  			Processed:      0x00015c73,
    53  			Dropped:        0x00020e76,
    54  			TimeSqueezed:   0xf0000769,
    55  			CPUCollision:   0x00000004,
    56  			ReceivedRps:    0x00000003,
    57  			FlowLimitCount: 0x00000002,
    58  			Index:          0x00000002,
    59  			Width:          11,
    60  		},
    61  		{
    62  			Processed:    0x01663fb2,
    63  			Dropped:      0x00000000,
    64  			TimeSqueezed: 0x0109a4,
    65  			CPUCollision: 0x00020e76,
    66  			Index:        0x00000003,
    67  			Width:        9,
    68  		},
    69  		{
    70  			Processed:    0x00008e78,
    71  			Dropped:      0x00000001,
    72  			TimeSqueezed: 0x00000011,
    73  			CPUCollision: 0x00000020,
    74  			ReceivedRps:  0x00000010,
    75  			Index:        0x00000004,
    76  			Width:        10,
    77  		},
    78  	}
    79  
    80  	got, err := fs.NetSoftnetStat()
    81  	if err != nil {
    82  		t.Fatal(err)
    83  	}
    84  
    85  	if diff := cmp.Diff(want, got); diff != "" {
    86  		t.Fatalf("unexpected softnet stats(-want +got):\n%s", diff)
    87  	}
    88  }
    89  
    90  func TestBadSoftnet(t *testing.T) {
    91  	softNetProcFile = "net/softnet_stat.broken"
    92  	fs, err := NewFS(procTestFixtures)
    93  	if err != nil {
    94  		t.Fatal(err)
    95  	}
    96  
    97  	_, err = fs.NetSoftnetStat()
    98  	if err == nil {
    99  		t.Fatal("expected error, got nil")
   100  	}
   101  }
   102  

View as plain text