File: cpu_plan9_test.go

package info (click to toggle)
golang-github-shirou-gopsutil 4.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 1,824 kB
  • sloc: makefile: 76; ansic: 19; sh: 11
file content (46 lines) | stat: -rw-r--r-- 929 bytes parent folder | download | duplicates (2)
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
// SPDX-License-Identifier: BSD-3-Clause
//go:build plan9

package cpu

import (
	"path/filepath"
	"testing"

	"github.com/google/go-cmp/cmp"
	"github.com/google/go-cmp/cmp/cmpopts"
)

var timesTests = []struct {
	mockedRootFS string
	stats        []TimesStat
}{
	{
		"2cores",
		[]TimesStat{
			{
				CPU:    "Core i7/Xeon",
				User:   2780.0 / 1000.0,
				System: 30020.0 / 1000.0,
				Idle:   (1412961713341830*2)/1000000000.0 - 2.78 - 30.02,
			},
		},
	},
}

func TestTimesPlan9(t *testing.T) {
	for _, tt := range timesTests {
		t.Run(tt.mockedRootFS, func(t *testing.T) {
			t.Setenv("HOST_ROOT", filepath.Join("testdata/plan9", tt.mockedRootFS))
			stats, err := Times(false)
			skipIfNotImplementedErr(t, err)
			if err != nil {
				t.Errorf("error %v", err)
			}
			eps := cmpopts.EquateApprox(0, 0.00000001)
			if !cmp.Equal(stats, tt.stats, eps) {
				t.Errorf("got: %+v\nwant: %+v", stats, tt.stats)
			}
		})
	}
}