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.
18 // Record pid and tid of init thread for use during test.
19 // The call to LockOSThread is just to exercise it;
20 // we can't test that it does anything.
21 // Instead we're testing that the conditions are good
22 // for how it is used in init (must be on main thread).
23 pid, tid = syscall.Getpid(), syscall.Gettid()
26 sysNanosleep = func(d time.Duration) {
27 // Invoke a blocking syscall directly; calling time.Sleep()
28 // would deschedule the goroutine instead.
29 ts := syscall.NsecToTimespec(d.Nanoseconds())
31 if err := syscall.Nanosleep(&ts, &ts); err != syscall.EINTR {
38 func TestLockOSThread(t *testing.T) {
40 t.Fatalf("pid=%d but tid=%d", pid, tid)
44 // Test that error values are negative.
45 // Use a misaligned pointer to get -EINVAL.
46 func TestMincoreErrorSign(t *testing.T) {
48 v := Mincore(unsafe.Add(unsafe.Pointer(new(int32)), 1), 1, &dst)
52 t.Errorf("mincore = %v, want %v", v, -EINVAL)
56 func TestKernelStructSize(t *testing.T) {
57 // Check that the Go definitions of structures exchanged with the kernel are
58 // the same size as what the kernel defines.
59 if have, want := unsafe.Sizeof(Siginfo{}), uintptr(SiginfoMaxSize); have != want {
60 t.Errorf("Go's siginfo struct is %d bytes long; kernel expects %d", have, want)
62 if have, want := unsafe.Sizeof(Sigevent{}), uintptr(SigeventMaxSize); have != want {
63 t.Errorf("Go's sigevent struct is %d bytes long; kernel expects %d", have, want)