From 70418eb819eb1d02c2c56a13159d95baab85d3a8 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 11 Feb 2016 16:36:38 +0000 Subject: [PATCH] runtime: add test for mincore's return value sign on Linux Updates #14297 Change-Id: I6b5f5020af5efaaa71280bdeb2ff99785ee9b959 Reviewed-on: https://go-review.googlesource.com/19457 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/export_test.go | 2 ++ src/runtime/runtime_linux_test.go | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index 5400c1d14e..b09022b53c 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -28,6 +28,8 @@ var Exitsyscall = exitsyscall var LockedOSThread = lockedOSThread var Xadduintptr = atomic.Xadduintptr +var Mincore = mincore + var FuncPC = funcPC var Fastlog2 = fastlog2 diff --git a/src/runtime/runtime_linux_test.go b/src/runtime/runtime_linux_test.go index 5344ed2051..58c797f1dd 100644 --- a/src/runtime/runtime_linux_test.go +++ b/src/runtime/runtime_linux_test.go @@ -8,6 +8,7 @@ import ( . "runtime" "syscall" "testing" + "unsafe" ) var pid, tid int @@ -27,3 +28,15 @@ func TestLockOSThread(t *testing.T) { t.Fatalf("pid=%d but tid=%d", pid, tid) } } + +// Test that error values are negative. Use address 1 (a misaligned +// pointer) to get -EINVAL. +func TestMincoreErrorSign(t *testing.T) { + var dst byte + v := Mincore(unsafe.Pointer(uintptr(1)), 1, &dst) + + const EINVAL = 0x16 + if v != -EINVAL { + t.Errorf("mincore = %v, want %v", v, -EINVAL) + } +} -- 2.50.0