github.com/hongwozai/go-src-1.4.3@v0.0.0-20191127132709-dc3fce3dbccb/src/runtime/debug/heapdump_test.go (about)

     1  // Copyright 2014 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 debug
     6  
     7  import (
     8  	"io/ioutil"
     9  	"os"
    10  	"runtime"
    11  	"testing"
    12  )
    13  
    14  func TestWriteHeapDumpNonempty(t *testing.T) {
    15  	if runtime.GOOS == "nacl" {
    16  		t.Skip("WriteHeapDump is not available on NaCl.")
    17  	}
    18  	f, err := ioutil.TempFile("", "heapdumptest")
    19  	if err != nil {
    20  		t.Fatalf("TempFile failed: %v", err)
    21  	}
    22  	defer os.Remove(f.Name())
    23  	defer f.Close()
    24  	WriteHeapDump(f.Fd())
    25  	fi, err := f.Stat()
    26  	if err != nil {
    27  		t.Fatalf("Stat failed: %v", err)
    28  	}
    29  	const minSize = 1
    30  	if size := fi.Size(); size < minSize {
    31  		t.Fatalf("Heap dump size %d bytes, expected at least %d bytes", size, minSize)
    32  	}
    33  }