File: sysconf_linux_test.go

package info (click to toggle)
golang-github-tklauser-go-sysconf 0.3.11-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 540 kB
  • sloc: makefile: 2
file content (33 lines) | stat: -rw-r--r-- 823 bytes parent folder | download | duplicates (4)
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
// Copyright 2018 Tobias Klauser. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package sysconf

import (
	"os"
	"testing"
)

// TestGetNproc tests that sysfs and /proc/stat report the same number of online
// CPUs.
func TestGetNproc(t *testing.T) {
	if _, err := os.Stat("/sys/devices/system/cpu/online"); err != nil {
		t.Skipf("sysfs not mounted, skipping")
	}

	nprocSysfs, err := getNprocsSysfs()
	if err != nil {
		t.Fatalf("getNprocsSysfs: %v", err)
	}

	nprocProcStat, err := getNprocsProcStat()
	if err != nil {
		t.Fatalf("getNprocsProcStat: %v", err)
	}

	if nprocSysfs != nprocProcStat {
		t.Errorf("Number of online CPUs not matching. getNprocsSysfs returned %v, getNprocsProcStat returned %v",
			nprocSysfs, nprocProcStat)
	}
}