Change cap node to use a temporary setup.

This commit is contained in:
Renan DelValle 2020-01-04 18:09:41 -08:00
parent cf4ffe61c0
commit b3de44bac6
No known key found for this signature in database
GPG key ID: 3895800E03F17676

View file

@ -4,6 +4,7 @@ import (
"io/ioutil" "io/ioutil"
"math" "math"
"os" "os"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
@ -15,11 +16,20 @@ import (
// that mimic the powercap subsystem and create test to operate on it. // that mimic the powercap subsystem and create test to operate on it.
func TestCapNode(t *testing.T) { func TestCapNode(t *testing.T) {
err := capNode("/sys/devices/virtual/powercap/intel-rapl", 95) RAPLdir, err := ioutil.TempDir("", "intel-rapl")
assert.NoError(t, err)
defer os.RemoveAll(RAPLdir)
if err != nil { zonePath := filepath.Join(RAPLdir, raplPrefixCPU+":0")
t.Fail() err = os.Mkdir(zonePath, 755)
} assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(zonePath, maxPowerFileShortWindow), []byte("1500000"), 0444)
assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(zonePath, powerLimitFileShortWindow), []byte("1500000"), 0644)
assert.NoError(t, err)
err = capNode(RAPLdir, 95)
assert.NoError(t, err)
} }
func TestMaxPower(t *testing.T) { func TestMaxPower(t *testing.T) {
@ -42,7 +52,6 @@ func TestMaxPower(t *testing.T) {
} }
func TestCapZone(t *testing.T) { func TestCapZone(t *testing.T) {
const maxPower float64 = 1500000 const maxPower float64 = 1500000
const percentage float64 = .50 const percentage float64 = .50