...

Source file src/github.com/tklauser/go-sysconf/sysconf_linux_test.go

Documentation: github.com/tklauser/go-sysconf

     1  // Copyright 2018 Tobias Klauser. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package sysconf
     6  
     7  import (
     8  	"os"
     9  	"testing"
    10  )
    11  
    12  // TestGetNproc tests that sysfs and /proc/stat report the same number of online
    13  // CPUs.
    14  func TestGetNproc(t *testing.T) {
    15  	if _, err := os.Stat("/sys/devices/system/cpu/online"); err != nil {
    16  		t.Skipf("sysfs not mounted, skipping")
    17  	}
    18  
    19  	nprocSysfs, err := getNprocsSysfs()
    20  	if err != nil {
    21  		t.Fatalf("getNprocsSysfs: %v", err)
    22  	}
    23  
    24  	nprocProcStat, err := getNprocsProcStat()
    25  	if err != nil {
    26  		t.Fatalf("getNprocsProcStat: %v", err)
    27  	}
    28  
    29  	if nprocSysfs != nprocProcStat {
    30  		t.Errorf("Number of online CPUs not matching. getNprocsSysfs returned %v, getNprocsProcStat returned %v",
    31  			nprocSysfs, nprocProcStat)
    32  	}
    33  }
    34  

View as plain text