...

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

Documentation: github.com/prometheus/procfs/sysfs

     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  //go:build linux
    15  // +build linux
    16  
    17  package sysfs
    18  
    19  import (
    20  	"path/filepath"
    21  	"testing"
    22  )
    23  
    24  func TestGetRaplZones(t *testing.T) {
    25  	fs, err := NewFS(sysTestFixtures)
    26  	if err != nil {
    27  		t.Fatal(err)
    28  	}
    29  
    30  	zones, err := GetRaplZones(fs)
    31  	if err != nil || zones == nil {
    32  		t.Fatal(err)
    33  	}
    34  }
    35  
    36  func TestNoRaplFiles(t *testing.T) {
    37  	// use a bad (but existing) fs path
    38  	fs, err := NewFS(filepath.Join(sysTestFixtures, "class"))
    39  	if err != nil {
    40  		t.Fatal(err)
    41  	}
    42  	zones, err := GetRaplZones(fs)
    43  	// expect failure
    44  	if err == nil || zones != nil {
    45  		t.Fatal(err)
    46  	}
    47  }
    48  
    49  func TestNewRaplValues(t *testing.T) {
    50  	fs, err := NewFS(sysTestFixtures)
    51  	if err != nil {
    52  		t.Fatal(err)
    53  	}
    54  
    55  	zones, err := GetRaplZones(fs)
    56  	if err != nil || zones == nil {
    57  		t.Fatal(err)
    58  	}
    59  
    60  	if len(zones) != 3 {
    61  		t.Fatal("wrong number of RAPL values")
    62  	}
    63  	microjoules, err := zones[0].GetEnergyMicrojoules()
    64  	if err != nil {
    65  		t.Fatal("couldn't read microjoules")
    66  	}
    67  	if microjoules != 240422366267 {
    68  		t.Fatal("wrong microjoule number")
    69  	}
    70  	if zones[2].Index != 10 {
    71  		t.Fatal("wrong index number")
    72  	}
    73  }
    74  

View as plain text