1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
package rusage
import (
"flag"
"os"
"testing"
"github.com/containers/storage/pkg/reexec"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
)
const (
noopCommand = "noop"
)
func noopMain() {
}
func init() {
reexec.Register(noopCommand, noopMain)
}
func TestMain(m *testing.M) {
if reexec.Init() {
return
}
flag.Parse()
if testing.Verbose() {
logrus.SetLevel(logrus.DebugLevel)
}
os.Exit(m.Run())
}
func TestRusage(t *testing.T) {
if !Supported() {
t.Skip("not supported on this platform")
}
before, err := Get()
require.Nil(t, err, "unexpected error from GetRusage before running child: %v", err)
cmd := reexec.Command(noopCommand)
err = cmd.Run()
require.Nil(t, err, "unexpected error running child process: %v", err)
after, err := Get()
require.Nil(t, err, "unexpected error from GetRusage after running child: %v", err)
t.Logf("rusage from child: %#v", FormatDiff(after.Subtract(before)))
require.NotZero(t, after.Subtract(before), "running a child process didn't use any resources?")
}
|