...

Source file src/github.com/prometheus/procfs/sysfs/class_sas_phy_test.go

Documentation: github.com/prometheus/procfs/sysfs

     1  // Copyright 2021 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  //go:build linux
    15  // +build linux
    16  
    17  package sysfs
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/google/go-cmp/cmp"
    23  )
    24  
    25  func TestSASPhyClass(t *testing.T) {
    26  	fs, err := NewFS(sysTestFixtures)
    27  	if err != nil {
    28  		t.Fatal(err)
    29  	}
    30  
    31  	got, err := fs.SASPhyClass()
    32  	if err != nil {
    33  		t.Fatal(err)
    34  	}
    35  
    36  	want := SASPhyClass{
    37  		"phy-11:0:2": {
    38  			Name:                       "phy-11:0:2",
    39  			SASAddress:                 "0x5000ccab0200947e",
    40  			SASPort:                    "port-11:0:0",
    41  			DeviceType:                 "edge expander",
    42  			InitiatorPortProtocols:     []string{"smp"},
    43  			InvalidDwordCount:          18,
    44  			LossOfDwordSyncCount:       1,
    45  			MaximumLinkrate:            12,
    46  			MaximumLinkrateHW:          12,
    47  			MinimumLinkrate:            1.5,
    48  			MinimumLinkrateHW:          1.5,
    49  			NegotiatedLinkrate:         6,
    50  			PhyIdentifier:              "2",
    51  			RunningDisparityErrorCount: 18,
    52  			TargetPortProtocols:        []string{"smp"},
    53  		},
    54  		"phy-11:0:4": {
    55  			Name:                       "phy-11:0:4",
    56  			SASAddress:                 "0x5000ccab0200947e",
    57  			SASPort:                    "port-11:0:1",
    58  			DeviceType:                 "edge expander",
    59  			InitiatorPortProtocols:     []string{"smp"},
    60  			InvalidDwordCount:          1,
    61  			MaximumLinkrate:            12,
    62  			MaximumLinkrateHW:          12,
    63  			MinimumLinkrate:            1.5,
    64  			MinimumLinkrateHW:          1.5,
    65  			NegotiatedLinkrate:         12,
    66  			PhyIdentifier:              "4",
    67  			RunningDisparityErrorCount: 1,
    68  			TargetPortProtocols:        []string{"smp"},
    69  		},
    70  		"phy-11:0:6": {
    71  			Name:                       "phy-11:0:6",
    72  			SASAddress:                 "0x5000ccab0200947e",
    73  			SASPort:                    "port-11:0:2",
    74  			DeviceType:                 "edge expander",
    75  			InitiatorPortProtocols:     []string{"smp"},
    76  			InvalidDwordCount:          19,
    77  			LossOfDwordSyncCount:       1,
    78  			MaximumLinkrate:            12,
    79  			MaximumLinkrateHW:          12,
    80  			MinimumLinkrate:            1.5,
    81  			MinimumLinkrateHW:          1.5,
    82  			NegotiatedLinkrate:         6,
    83  			PhyIdentifier:              "6",
    84  			RunningDisparityErrorCount: 20,
    85  			TargetPortProtocols:        []string{"smp"},
    86  		},
    87  		"phy-11:10": {
    88  			Name:                   "phy-11:10",
    89  			SASAddress:             "0x500062b2047b51c4",
    90  			SASPort:                "port-11:0",
    91  			DeviceType:             "end device",
    92  			InitiatorPortProtocols: []string{"smp", "stp", "ssp"},
    93  			MaximumLinkrate:        12,
    94  			MaximumLinkrateHW:      12,
    95  			MinimumLinkrate:        3,
    96  			MinimumLinkrateHW:      1.5,
    97  			NegotiatedLinkrate:     12,
    98  			PhyIdentifier:          "10",
    99  			TargetPortProtocols:    []string{"none"},
   100  		},
   101  		"phy-11:11": {
   102  			Name:                   "phy-11:11",
   103  			SASAddress:             "0x500062b2047b51c4",
   104  			SASPort:                "port-11:0",
   105  			DeviceType:             "end device",
   106  			InitiatorPortProtocols: []string{"smp", "stp", "ssp"},
   107  			MaximumLinkrate:        12,
   108  			MaximumLinkrateHW:      12,
   109  			MinimumLinkrate:        3,
   110  			MinimumLinkrateHW:      1.5,
   111  			NegotiatedLinkrate:     12,
   112  			PhyIdentifier:          "11",
   113  			TargetPortProtocols:    []string{"none"},
   114  		},
   115  		"phy-11:12": {
   116  			Name:                   "phy-11:12",
   117  			SASAddress:             "0x500062b2047b51c4",
   118  			SASPort:                "port-11:1",
   119  			DeviceType:             "end device",
   120  			InitiatorPortProtocols: []string{"smp", "stp", "ssp"},
   121  			MaximumLinkrate:        12,
   122  			MaximumLinkrateHW:      12,
   123  			MinimumLinkrate:        3,
   124  			MinimumLinkrateHW:      1.5,
   125  			NegotiatedLinkrate:     6,
   126  			PhyIdentifier:          "12",
   127  			TargetPortProtocols:    []string{"none"},
   128  		},
   129  		"phy-11:13": {
   130  			Name:                   "phy-11:13",
   131  			SASAddress:             "0x500062b2047b51c4",
   132  			SASPort:                "port-11:1",
   133  			DeviceType:             "end device",
   134  			InitiatorPortProtocols: []string{"smp", "stp", "ssp"},
   135  			MaximumLinkrate:        12,
   136  			MaximumLinkrateHW:      12,
   137  			MinimumLinkrate:        3,
   138  			MinimumLinkrateHW:      1.5,
   139  			NegotiatedLinkrate:     6,
   140  			PhyIdentifier:          "13",
   141  			TargetPortProtocols:    []string{"none"},
   142  		},
   143  		"phy-11:14": {
   144  			Name:                   "phy-11:14",
   145  			SASAddress:             "0x500062b2047b51c4",
   146  			SASPort:                "port-11:1",
   147  			DeviceType:             "end device",
   148  			InitiatorPortProtocols: []string{"smp", "stp", "ssp"},
   149  			MaximumLinkrate:        12,
   150  			MaximumLinkrateHW:      12,
   151  			MinimumLinkrate:        3,
   152  			MinimumLinkrateHW:      1.5,
   153  			NegotiatedLinkrate:     6,
   154  			PhyIdentifier:          "14",
   155  			TargetPortProtocols:    []string{"none"},
   156  		},
   157  		"phy-11:15": {
   158  			Name:                   "phy-11:15",
   159  			SASAddress:             "0x500062b2047b51c4",
   160  			SASPort:                "port-11:1",
   161  			DeviceType:             "end device",
   162  			InitiatorPortProtocols: []string{"smp", "stp", "ssp"},
   163  			MaximumLinkrate:        12,
   164  			MaximumLinkrateHW:      12,
   165  			MinimumLinkrate:        3,
   166  			MinimumLinkrateHW:      1.5,
   167  			NegotiatedLinkrate:     6,
   168  			PhyIdentifier:          "15",
   169  			TargetPortProtocols:    []string{"none"},
   170  		},
   171  		"phy-11:7": {
   172  			Name:                   "phy-11:7",
   173  			SASAddress:             "0x500062b2047b51c4",
   174  			SASPort:                "port-11:2",
   175  			DeviceType:             "end device",
   176  			InitiatorPortProtocols: []string{"smp", "stp", "ssp"},
   177  			MaximumLinkrate:        12,
   178  			MaximumLinkrateHW:      12,
   179  			MinimumLinkrate:        3,
   180  			MinimumLinkrateHW:      1.5,
   181  			NegotiatedLinkrate:     12,
   182  			PhyIdentifier:          "7",
   183  			TargetPortProtocols:    []string{"none"},
   184  		},
   185  		"phy-11:8": {
   186  			Name:                   "phy-11:8",
   187  			SASAddress:             "0x500062b2047b51c4",
   188  			SASPort:                "port-11:0",
   189  			DeviceType:             "end device",
   190  			InitiatorPortProtocols: []string{"smp", "stp", "ssp"},
   191  			MaximumLinkrate:        12,
   192  			MaximumLinkrateHW:      12,
   193  			MinimumLinkrate:        3,
   194  			MinimumLinkrateHW:      1.5,
   195  			NegotiatedLinkrate:     12,
   196  			PhyIdentifier:          "8",
   197  			TargetPortProtocols:    []string{"none"},
   198  		},
   199  		"phy-11:9": {
   200  			Name:                   "phy-11:9",
   201  			SASAddress:             "0x500062b2047b51c4",
   202  			SASPort:                "port-11:0",
   203  			DeviceType:             "end device",
   204  			InitiatorPortProtocols: []string{"smp", "stp", "ssp"},
   205  			MaximumLinkrate:        12,
   206  			MaximumLinkrateHW:      12,
   207  			MinimumLinkrate:        3,
   208  			MinimumLinkrateHW:      1.5,
   209  			NegotiatedLinkrate:     12,
   210  			PhyIdentifier:          "9",
   211  			TargetPortProtocols:    []string{"none"},
   212  		},
   213  	}
   214  
   215  	if diff := cmp.Diff(want, got); diff != "" {
   216  		t.Fatalf("unexpected SASPhy class (-want +got):\n%s", diff)
   217  	}
   218  }
   219  
   220  func TestSASPhyGetByName(t *testing.T) {
   221  	fs, err := NewFS(sysTestFixtures)
   222  	if err != nil {
   223  		t.Fatal(err)
   224  	}
   225  
   226  	pc, err := fs.SASPhyClass()
   227  	if err != nil {
   228  		t.Fatal(err)
   229  	}
   230  
   231  	want := "phy-11:9"
   232  	got := pc.GetByName("phy-11:9").Name
   233  	if diff := cmp.Diff(want, got); diff != "" {
   234  		t.Fatalf("unexpected SASPhy class (-want +got):\n%s", diff)
   235  	}
   236  
   237  	// Doesn't exist.
   238  	got2 := pc.GetByName("phy-12:0")
   239  	if got2 != nil {
   240  		t.Fatalf("unexpected GetByName response: got %v want nil", got2)
   241  	}
   242  }
   243  

View as plain text