...

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

Documentation: github.com/prometheus/procfs

     1  // Copyright 2022 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  	"reflect"
    18  	"testing"
    19  )
    20  
    21  func TestProcInterrupts(t *testing.T) {
    22  	p, err := getProcFixtures(t).Proc(26231)
    23  	if err != nil {
    24  		t.Fatal(err)
    25  	}
    26  
    27  	interrupts, err := p.Interrupts()
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  
    32  	if want, have := 47, len(interrupts); want != have {
    33  		t.Errorf("want length %d, have %d", want, have)
    34  	}
    35  
    36  	for _, test := range []struct {
    37  		name string
    38  		irq  string
    39  		want Interrupt
    40  	}{
    41  		{
    42  			name: "first line",
    43  			irq:  "0",
    44  			want: Interrupt{
    45  				Info:    "IO-APIC",
    46  				Devices: "2-edge timer",
    47  				Values:  []string{"49", "0", "0", "0"},
    48  			},
    49  		},
    50  		{
    51  			name: "last line",
    52  			irq:  "PIW",
    53  			want: Interrupt{
    54  				Info:    "Posted-interrupt wakeup event",
    55  				Devices: "",
    56  				Values:  []string{"0", "0", "0", "0"},
    57  			},
    58  		},
    59  		{
    60  			name: "empty devices",
    61  			irq:  "LOC",
    62  			want: Interrupt{
    63  				Info:    "Local timer interrupts",
    64  				Devices: "",
    65  				Values:  []string{"10196", "7429", "8542", "8229"},
    66  			},
    67  		},
    68  		{
    69  			name: "single value",
    70  			irq:  "ERR",
    71  			want: Interrupt{
    72  				Info:    "",
    73  				Devices: "",
    74  				Values:  []string{"0"},
    75  			},
    76  		},
    77  	} {
    78  		t.Run(test.name, func(t *testing.T) {
    79  			if value, ok := interrupts[test.irq]; ok {
    80  				if value.Info != test.want.Info {
    81  					t.Errorf("info: want %s, have %s", test.want.Info, value.Info)
    82  				}
    83  				if value.Devices != test.want.Devices {
    84  					t.Errorf("devices: want %s, have %s", test.want.Devices, value.Devices)
    85  				}
    86  				if !reflect.DeepEqual(value.Values, test.want.Values) {
    87  					t.Errorf("values: want %v, have %v", test.want.Values, value.Values)
    88  				}
    89  			} else {
    90  				t.Errorf("IRQ %s not found", test.irq)
    91  			}
    92  		})
    93  	}
    94  }
    95  

View as plain text