syzkaller/vm/vm.go
Dmitry Vyukov 293e915415 vm: fix crash message extraction regexp
First, "cut here" is not interesting as it always follows
by a more descriptive message.
Unreferenced object is interesting.
Also, strip \r at the end.
Add a test.
2015-12-24 19:55:19 +01:00

62 lines
1.6 KiB
Go

// Copyright 2015 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package vm
import (
"errors"
"fmt"
"regexp"
"time"
)
// Instance represents a Linux VM or a remote physical machine.
type Instance interface {
// Copy copies a hostSrc file to vmDst file (think of scp).
Copy(hostSrc, vmDst string) error
// Run runs cmd inside of the VM (think of ssh cmd).
// outc receives combined cmd and kernel console output.
// errc receives either command Wait return error or vm.TimeoutErr.
Run(timeout time.Duration, command string) (outc <-chan []byte, errc <-chan error, err error)
// HostAddr returns ip address of the host as seen by the VM.
HostAddr() string
// Close stops and destroys the VM.
Close()
}
type Config struct {
Name string
Index int
Workdir string
Bin string
Kernel string
Cmdline string
Image string
Sshkey string
Cpu int
Mem int
Debug bool
}
type ctorFunc func(cfg *Config) (Instance, error)
var ctors = make(map[string]ctorFunc)
func Register(typ string, ctor ctorFunc) {
ctors[typ] = ctor
}
// Create creates and boots a new VM instance.
func Create(typ string, cfg *Config) (Instance, error) {
ctor := ctors[typ]
if ctor == nil {
return nil, fmt.Errorf("unknown instance type '%v'", typ)
}
return ctor(cfg)
}
var (
CrashRe = regexp.MustCompile("Kernel panic[^\r\n]*|BUG:[^\r\n]*|kernel BUG[^\r\n]*|WARNING:[^\r\n]*|INFO:[^\r\n]*|unable to handle|general protection fault|UBSAN:[^\r\n]*|unreferenced object[^\r\n]*")
TimeoutErr = errors.New("timeout")
)