github.com/aloncn/graphics-go@v0.0.1/src/runtime/runtime_linux_test.go (about)

     1  // Copyright 2012 The Go Authors.  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 runtime_test
     6  
     7  import (
     8  	. "runtime"
     9  	"syscall"
    10  	"testing"
    11  	"unsafe"
    12  )
    13  
    14  var pid, tid int
    15  
    16  func init() {
    17  	// Record pid and tid of init thread for use during test.
    18  	// The call to LockOSThread is just to exercise it;
    19  	// we can't test that it does anything.
    20  	// Instead we're testing that the conditions are good
    21  	// for how it is used in init (must be on main thread).
    22  	pid, tid = syscall.Getpid(), syscall.Gettid()
    23  	LockOSThread()
    24  }
    25  
    26  func TestLockOSThread(t *testing.T) {
    27  	if pid != tid {
    28  		t.Fatalf("pid=%d but tid=%d", pid, tid)
    29  	}
    30  }
    31  
    32  // Test that error values are negative. Use address 1 (a misaligned
    33  // pointer) to get -EINVAL.
    34  func TestMincoreErrorSign(t *testing.T) {
    35  	var dst byte
    36  	v := Mincore(unsafe.Pointer(uintptr(1)), 1, &dst)
    37  
    38  	const EINVAL = 0x16
    39  	if v != -EINVAL {
    40  		t.Errorf("mincore = %v, want %v", v, -EINVAL)
    41  	}
    42  }