Renaming variable in test.
This commit is contained in:
parent
74b488750d
commit
bcd25c805a
2 changed files with 9 additions and 11 deletions
|
@ -61,8 +61,7 @@ func capNode(base string, percentage int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// maxPower returns the value in float of the maximum watts a power zone
|
// maxPower returns the value in float of the maximum watts a power zone can use.
|
||||||
// can use.
|
|
||||||
func maxPower(maxFile string) (uint64, error) {
|
func maxPower(maxFile string) (uint64, error) {
|
||||||
maxPower, err := ioutil.ReadFile(maxFile)
|
maxPower, err := ioutil.ReadFile(maxFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -35,12 +35,12 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
initialWatts := strconv.FormatUint(maxWattage, 10)
|
initialWatts := strconv.FormatUint(maxWattage, 10)
|
||||||
|
|
||||||
err = ioutil.WriteFile(filepath.Join(zonePath, maxPowerFileShortWindow), []byte(initialWatts), 0444)
|
err = ioutil.WriteFile(filepath.Join(zonePath, maxPowerFileLongWindow), []byte(initialWatts), 0444)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(filepath.Join(zonePath, powerLimitFileShortWindow), []byte(initialWatts), 0644)
|
err = ioutil.WriteFile(filepath.Join(zonePath, powerLimitFileLongWindow), []byte(initialWatts), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -48,30 +48,29 @@ func TestMain(m *testing.M) {
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(rdelvalle): Create filesystem only once and allow tests to use it
|
|
||||||
func TestCapNode(t *testing.T) {
|
func TestCapNode(t *testing.T) {
|
||||||
err := capNode(raplDir, 95)
|
err := capNode(raplDir, 95)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
t.Run("badPercentage", func(t *testing.T) {
|
t.Run("bad-percentage", func(t *testing.T) {
|
||||||
err := capNode(raplDir, 1000)
|
err := capNode(raplDir, 1000)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("zeroPercent", func(t *testing.T) {
|
t.Run("zero-percent", func(t *testing.T) {
|
||||||
err := capNode(raplDir, 0)
|
err := capNode(raplDir, 0)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMaxPower(t *testing.T) {
|
func TestMaxPower(t *testing.T) {
|
||||||
maxFile := filepath.Join(raplDir, raplPrefixCPU+":0", maxPowerFileShortWindow)
|
maxFile := filepath.Join(raplDir, raplPrefixCPU+":0", maxPowerFileLongWindow)
|
||||||
|
|
||||||
maxWatts, err := maxPower(maxFile)
|
maxWatts, err := maxPower(maxFile)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, maxWattage, maxWatts)
|
assert.Equal(t, maxWattage, maxWatts)
|
||||||
|
|
||||||
t.Run("nameDoesNotExist", func(t *testing.T) {
|
t.Run("name-does-not-exist", func(t *testing.T) {
|
||||||
_, err := maxPower("madeupname")
|
_, err := maxPower("madeupname")
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
|
@ -81,7 +80,7 @@ func TestCapZone(t *testing.T) {
|
||||||
const percentage float64 = .50
|
const percentage float64 = .50
|
||||||
|
|
||||||
powercap := uint64(math.Ceil(float64(maxWattage) * percentage))
|
powercap := uint64(math.Ceil(float64(maxWattage) * percentage))
|
||||||
limitFile := filepath.Join(raplDir, raplPrefixCPU+":0", powerLimitFileShortWindow)
|
limitFile := filepath.Join(raplDir, raplPrefixCPU+":0", powerLimitFileLongWindow)
|
||||||
err := capZone(limitFile, powercap)
|
err := capZone(limitFile, powercap)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
@ -92,7 +91,7 @@ func TestCapZone(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, powercap, newCap)
|
assert.Equal(t, powercap, newCap)
|
||||||
|
|
||||||
t.Run("nameDoesNotExist", func(t *testing.T) {
|
t.Run("name-does-not-exist", func(t *testing.T) {
|
||||||
err := capZone("madeupname", powercap)
|
err := capZone("madeupname", powercap)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
Reference in a new issue