runtime: add geust memory dump

When guest panic, dump guest kernel memory to host filesystem.
And also includes:
- hypervisor config
- hypervisor version
- and state of sandbox

Fixes: #1012

Signed-off-by: bin liu <bin@hyper.sh>
This commit is contained in:
bin liu
2020-10-21 14:09:14 +08:00
parent 5b065eb599
commit 40418f6d88
16 changed files with 345 additions and 46 deletions

View File

@@ -6,7 +6,10 @@
package utils
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"testing"
"github.com/stretchr/testify/assert"
@@ -45,3 +48,71 @@ func TestGzipAccepted(t *testing.T) {
assert.Equal(tc.result, b)
}
}
func TestEnsureDir(t *testing.T) {
const testMode = 0755
tmpdir, err := ioutil.TempDir("", "TestEnsureDir")
assert := assert.New(t)
assert.NoError(err)
defer os.RemoveAll(tmpdir)
testCases := []struct {
before func()
path string
err bool
msg string
}{
{
before: nil,
path: "a/b/c",
err: true,
msg: "Not an absolute path",
},
{
before: nil,
path: fmt.Sprintf("%s/abc/def", tmpdir),
err: false,
msg: "",
},
{
before: nil,
path: fmt.Sprintf("%s/abc", tmpdir),
err: false,
msg: "",
},
{
before: func() {
err := os.MkdirAll(fmt.Sprintf("%s/abc/def", tmpdir), testMode)
assert.NoError(err)
},
path: fmt.Sprintf("%s/abc/def", tmpdir),
err: false,
msg: "",
},
{
before: func() {
// create a regular file
err := os.MkdirAll(fmt.Sprintf("%s/abc", tmpdir), testMode)
assert.NoError(err)
_, err = os.Create(fmt.Sprintf("%s/abc/file.txt", tmpdir))
assert.NoError(err)
},
path: fmt.Sprintf("%s/abc/file.txt", tmpdir),
err: true,
msg: "Not a directory",
},
}
for _, tc := range testCases {
if tc.before != nil {
tc.before()
}
err := EnsureDir(tc.path, testMode)
if tc.err {
assert.Contains(err.Error(), tc.msg, "error msg should contains: %s, but got %s", tc.msg, err.Error())
} else {
assert.Equal(err, nil, "failed for path: %s, except no error, but got %+v", tc.path, err)
}
}
}