Skip to content

Commit

Permalink
validation/linux_cgroups_*: Generate TAP output
Browse files Browse the repository at this point in the history
The test harness requires TAP output.  Before this commit:

  # RUNTIME=runc tap ./validation/linux_cgroups_pids.t
  ./validation/linux_cgroups_pids.t ..................... 0/1
    Skipped: 1
      ./validation/linux_cgroups_pids.t no tests found

  total ................................................. 0/1

    0 passing (191.66ms)
    1 pending

After this commit:

  # RUNTIME=runc tap ./validation/linux_cgroups_pids.t
  ./validation/linux_cgroups_pids.t ..................... 3/3
  total ................................................. 3/3

    3 passing (185.118ms)

    ok

This commit also DRYs up some relative/absolute tests by factoring out
the shared code into util.ValidateLinuxResources* helpers.

And it adds a missing AddLinuxResourcesNetworkPriorities call;
previously we were testing for a priority that we hadn't actually
configured.

Signed-off-by: W. Trevor King <wking@tremily.us>
  • Loading branch information
wking committed Dec 14, 2017
1 parent c94875e commit 6a23d21
Show file tree
Hide file tree
Showing 15 changed files with 310 additions and 372 deletions.
91 changes: 1 addition & 90 deletions validation/linux_cgroups_blkio.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
"fmt"

rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -23,93 +20,7 @@ func main() {
g.AddLinuxResourcesBlockIOThrottleWriteBpsDevice(major, minor, rate)
g.AddLinuxResourcesBlockIOThrottleReadIOPSDevice(major, minor, rate)
g.AddLinuxResourcesBlockIOThrottleWriteIOPSDevice(major, minor, rate)
err := util.RuntimeOutsideValidate(g, func(config *rspec.Spec, state *rspec.State) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lbd, err := cg.GetBlockIOData(state.Pid, config.Linux.CgroupsPath)
if err != nil {
return err
}
if *lbd.Weight != weight {
return fmt.Errorf("blkio weight is not set correctly, expect: %d, actual: %d", weight, lbd.Weight)
}
if *lbd.LeafWeight != leafWeight {
return fmt.Errorf("blkio leafWeight is not set correctly, expect: %d, actual: %d", weight, lbd.LeafWeight)
}

found := false
for _, wd := range lbd.WeightDevice {
if wd.Major == major && wd.Minor == minor {
found = true
if *wd.Weight != weight {
return fmt.Errorf("blkio weight for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, weight, wd.Weight)
}
if *wd.LeafWeight != leafWeight {
return fmt.Errorf("blkio leafWeight for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, leafWeight, wd.LeafWeight)
}
}
}
if !found {
return fmt.Errorf("blkio weightDevice for %d:%d is not set", major, minor)
}

found = false
for _, trbd := range lbd.ThrottleReadBpsDevice {
if trbd.Major == major && trbd.Minor == minor {
found = true
if trbd.Rate != rate {
return fmt.Errorf("blkio read bps for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, trbd.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio read bps for %d:%d is not set", major, minor)
}

found = false
for _, twbd := range lbd.ThrottleWriteBpsDevice {
if twbd.Major == major && twbd.Minor == minor {
found = true
if twbd.Rate != rate {
return fmt.Errorf("blkio write bps for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, twbd.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio write bps for %d:%d is not set", major, minor)
}

found = false
for _, trid := range lbd.ThrottleReadIOPSDevice {
if trid.Major == major && trid.Minor == minor {
found = true
if trid.Rate != rate {
return fmt.Errorf("blkio read iops for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, trid.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio read iops for %d:%d is not set", major, minor)
}

found = false
for _, twid := range lbd.ThrottleWriteIOPSDevice {
if twid.Major == major && twid.Minor == minor {
found = true
if twid.Rate != rate {
return fmt.Errorf("blkio write iops for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, twid.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio write iops for %d:%d is not set", major, minor)
}

return nil
})

err := util.RuntimeOutsideValidate(g, util.ValidateLinuxResourcesBlockIO)
if err != nil {
util.Fatal(err)
}
Expand Down
36 changes: 1 addition & 35 deletions validation/linux_cgroups_memory.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
"fmt"

rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -20,38 +17,7 @@ func main() {
g.SetLinuxResourcesMemoryKernelTCP(limit)
g.SetLinuxResourcesMemorySwappiness(swappiness)
g.SetLinuxResourcesMemoryDisableOOMKiller(true)
err := util.RuntimeOutsideValidate(g, func(config *rspec.Spec, state *rspec.State) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lm, err := cg.GetMemoryData(state.Pid, config.Linux.CgroupsPath)
if err != nil {
return err
}
if limit != *lm.Limit {
return fmt.Errorf("memory limit is not set correctly, expect: %d, actual: %d", limit, *lm.Limit)
}
if limit != *lm.Reservation {
return fmt.Errorf("memory reservation is not set correctly, expect: %d, actual: %d", limit, *lm.Reservation)
}
if limit != *lm.Swap {
return fmt.Errorf("memory swap is not set correctly, expect: %d, actual: %d", limit, *lm.Reservation)
}
if limit != *lm.Kernel {
return fmt.Errorf("memory kernel is not set correctly, expect: %d, actual: %d", limit, *lm.Kernel)
}
if limit != *lm.KernelTCP {
return fmt.Errorf("memory kernelTCP is not set correctly, expect: %d, actual: %d", limit, *lm.Kernel)
}
if swappiness != *lm.Swappiness {
return fmt.Errorf("memory swappiness is not set correctly, expect: %d, actual: %d", swappiness, *lm.Swappiness)
}
if true != *lm.DisableOOMKiller {
return fmt.Errorf("memory oom is not set correctly, expect: %t, actual: %t", true, *lm.DisableOOMKiller)
}
return nil
})
err := util.RuntimeOutsideValidate(g, util.ValidateLinuxResourcesMemory)
if err != nil {
util.Fatal(err)
}
Expand Down
33 changes: 2 additions & 31 deletions validation/linux_cgroups_network.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
"fmt"

rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -14,34 +11,8 @@ func main() {
g := util.GetDefaultGenerator()
g.SetLinuxCgroupsPath(cgroups.AbsCgroupPath)
g.SetLinuxResourcesNetworkClassID(id)
err := util.RuntimeOutsideValidate(g, func(config *rspec.Spec, state *rspec.State) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lnd, err := cg.GetNetworkData(state.Pid, config.Linux.CgroupsPath)
if err != nil {
return err
}
if *lnd.ClassID != id {
return fmt.Errorf("network ID is not set correctly, expect: %d, actual: %d", id, lnd.ClassID)
}
found := false
for _, lip := range lnd.Priorities {
if lip.Name == ifName {
found = true
if lip.Priority != prio {
return fmt.Errorf("network priority for %s is not set correctly, expect: %d, actual: %d", ifName, prio, lip.Priority)
}
}
}
if !found {
return fmt.Errorf("network priority for %s is not set correctly", ifName)
}

return nil
})

g.AddLinuxResourcesNetworkPriorities(ifName, prio)
err := util.RuntimeOutsideValidate(g, util.ValidateLinuxResourcesNetwork)
if err != nil {
util.Fatal(err)
}
Expand Down
19 changes: 1 addition & 18 deletions validation/linux_cgroups_pids.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
"fmt"

rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -13,21 +10,7 @@ func main() {
g := util.GetDefaultGenerator()
g.SetLinuxCgroupsPath(cgroups.AbsCgroupPath)
g.SetLinuxResourcesPidsLimit(limit)
err := util.RuntimeOutsideValidate(g, func(config *rspec.Spec, state *rspec.State) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lpd, err := cg.GetPidsData(state.Pid, config.Linux.CgroupsPath)
if err != nil {
return err
}
if lpd.Limit != limit {
return fmt.Errorf("pids limit is not set correctly, expect: %d, actual: %d", limit, lpd.Limit)
}
return nil
})

err := util.RuntimeOutsideValidate(g, util.ValidateLinuxResourcesPids)
if err != nil {
util.Fatal(err)
}
Expand Down
90 changes: 1 addition & 89 deletions validation/linux_cgroups_relative_blkio.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
"fmt"

rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
Expand All @@ -23,92 +20,7 @@ func main() {
g.AddLinuxResourcesBlockIOThrottleWriteBpsDevice(major, minor, rate)
g.AddLinuxResourcesBlockIOThrottleReadIOPSDevice(major, minor, rate)
g.AddLinuxResourcesBlockIOThrottleWriteIOPSDevice(major, minor, rate)
err := util.RuntimeOutsideValidate(g, func(config *rspec.Spec, state *rspec.State) error {
cg, err := cgroups.FindCgroup()
if err != nil {
return err
}
lbd, err := cg.GetBlockIOData(state.Pid, config.Linux.CgroupsPath)
if err != nil {
return err
}
if *lbd.Weight != weight {
return fmt.Errorf("blkio weight is not set correctly, expect: %d, actual: %d", weight, lbd.Weight)
}
if *lbd.LeafWeight != leafWeight {
return fmt.Errorf("blkio leafWeight is not set correctly, expect: %d, actual: %d", weight, lbd.LeafWeight)
}

found := false
for _, wd := range lbd.WeightDevice {
if wd.Major == major && wd.Minor == minor {
found = true
if *wd.Weight != weight {
return fmt.Errorf("blkio weight for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, weight, wd.Weight)
}
if *wd.LeafWeight != leafWeight {
return fmt.Errorf("blkio leafWeight for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, leafWeight, wd.LeafWeight)
}
}
}
if !found {
return fmt.Errorf("blkio weightDevice for %d:%d is not set", major, minor)
}

found = false
for _, trbd := range lbd.ThrottleReadBpsDevice {
if trbd.Major == major && trbd.Minor == minor {
found = true
if trbd.Rate != rate {
return fmt.Errorf("blkio read bps for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, trbd.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio read bps for %d:%d is not set", major, minor)
}

found = false
for _, twbd := range lbd.ThrottleWriteBpsDevice {
if twbd.Major == major && twbd.Minor == minor {
found = true
if twbd.Rate != rate {
return fmt.Errorf("blkio write bps for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, twbd.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio write bps for %d:%d is not set", major, minor)
}

found = false
for _, trid := range lbd.ThrottleReadIOPSDevice {
if trid.Major == major && trid.Minor == minor {
found = true
if trid.Rate != rate {
return fmt.Errorf("blkio read iops for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, trid.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio read iops for %d:%d is not set", major, minor)
}

found = false
for _, twid := range lbd.ThrottleWriteIOPSDevice {
if twid.Major == major && twid.Minor == minor {
found = true
if twid.Rate != rate {
return fmt.Errorf("blkio write iops for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, twid.Rate)
}
}
}
if !found {
return fmt.Errorf("blkio write iops for %d:%d is not set", major, minor)
}

return nil
})
err := util.RuntimeOutsideValidate(g, util.ValidateLinuxResourcesBlockIO)

if err != nil {
util.Fatal(err)
Expand Down
Loading

0 comments on commit 6a23d21

Please sign in to comment.