File: rusage_test.go

package info (click to toggle)
golang-github-containers-buildah 1.39.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,724 kB
  • sloc: sh: 2,398; makefile: 236; perl: 187; asm: 16; awk: 12; ansic: 1
file content (48 lines) | stat: -rw-r--r-- 1,044 bytes parent folder | download | duplicates (3)
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?")
}