mirror of
https://github.com/moby/moby.git
synced 2025-04-18 20:44:11 +03:00
This fix address issues where the scanner was unable to properly parse longer outputs from /proc/stat. This could happen on an ARM machine with large amount of CPU cores (and interrupts). By switching to reader we have more control over data parsing and dump unnecessary data Signed-off-by: Patrik Leifert <patrikleifert@hotmail.com>
31 lines
617 B
Go
31 lines
617 B
Go
//go:build !windows
|
|
|
|
package daemon
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestGetSystemCPUUsageParsing(t *testing.T) {
|
|
dummyFilePath := filepath.Join("testdata", "stat")
|
|
expectedCpuUsage := uint64(65647090000000)
|
|
expectedCpuNum := uint32(128)
|
|
|
|
origStatPath := procStatPath
|
|
procStatPath = dummyFilePath
|
|
defer func() { procStatPath = origStatPath }()
|
|
|
|
_, err := os.Stat(dummyFilePath)
|
|
assert.NilError(t, err)
|
|
|
|
cpuUsage, cpuNum, err := getSystemCPUUsage()
|
|
|
|
assert.Equal(t, cpuUsage, expectedCpuUsage)
|
|
assert.Equal(t, cpuNum, expectedCpuNum)
|
|
assert.NilError(t, err)
|
|
}
|