pkg/runtest: fixes for fuchsia

Add simple fuchsia program, the one that is run during image testing.
Fix csource errno printing for fuchsia.
Fix creation of executable files (chmod is not implemented on fuchsia).
Check that we get signal/coverage from all syscalls.
This commit is contained in:
Dmitry Vyukov 2018-09-06 10:54:14 +02:00
parent 873745f2ff
commit 596466b38c
4 changed files with 35 additions and 9 deletions

View File

@ -247,7 +247,13 @@ func (ctx *context) emitCall(w *bytes.Buffer, call prog.ExecCall, ci int, haveCo
}
fmt.Fprintf(w, ");\n")
if trace {
fmt.Fprintf(w, "\tprintf(\"### call=%v errno=%%u\\n\", res == -1 ? errno : 0);\n", ci)
cast := ""
if !native && !strings.HasPrefix(callName, "syz_") {
// Potentially we casted a function returning int to a function returning long.
// So instead of long -1 we can get 0x00000000ffffffff. Sign extend it to long.
cast = "(long)(int)"
}
fmt.Fprintf(w, "\tprintf(\"### call=%v errno=%%u\\n\", %vres == -1 ? errno : 0);\n", ci, cast)
}
}

View File

@ -196,10 +196,8 @@ func WriteFile(filename string, data []byte) error {
}
func WriteExecFile(filename string, data []byte) error {
if err := ioutil.WriteFile(filename, data, DefaultExecPerm); err != nil {
return err
}
return os.Chmod(filename, DefaultExecPerm)
os.Remove(filename)
return ioutil.WriteFile(filename, data, DefaultExecPerm)
}
// TempFile creates a unique temp filename.

View File

@ -100,7 +100,7 @@ func (ctx *Context) Run() error {
result = "OK"
}
}
ctx.log("%-36v: %v", req.name, result)
ctx.log("%-38v: %v", req.name, result)
}
if err := <-errc; err != nil {
return err
@ -318,7 +318,7 @@ func (ctx *Context) createSyzTest(p *prog.Prog, sandbox string, threaded, cov bo
}
if cov {
cfg.Flags |= ipc.FlagSignal
opts.Flags |= ipc.FlagCollectCover | ipc.FlagDedupCover
opts.Flags |= ipc.FlagCollectCover
}
if ctx.Features[host.FeatureNetworkInjection].Enabled {
cfg.Flags |= ipc.FlagEnableTun
@ -373,7 +373,8 @@ func (ctx *Context) createCTest(p *prog.Prog, sandbox string, threaded bool, tim
}
func checkResult(req *RunRequest) error {
if req.Bin != "" {
isC := req.Bin != ""
if isC {
var err error
if req.Info, err = parseBinOutput(req); err != nil {
return err
@ -383,6 +384,7 @@ func checkResult(req *RunRequest) error {
return fmt.Errorf("should repeat %v times, but repeated %v",
req.Repeat, len(req.Info))
}
calls := make(map[string]bool)
for run, info := range req.Info {
for i, inf := range info {
want := req.results[i]
@ -391,7 +393,7 @@ func checkResult(req *RunRequest) error {
ipc.CallBlocked: "blocked",
ipc.CallFinished: "finished",
} {
if flag == ipc.CallBlocked && req.Bin != "" {
if isC && flag == ipc.CallBlocked {
// C code does not detect when a call was blocked.
continue
}
@ -407,6 +409,25 @@ func checkResult(req *RunRequest) error {
return fmt.Errorf("run %v: wrong call %v result %v, want %v",
run, i, inf.Errno, want.Errno)
}
if isC {
continue
}
if req.Cfg.Flags&ipc.FlagSignal != 0 {
// Signal is always deduplicated, so we may not get any signal
// on a second invocation of the same syscall.
callName := req.P.Calls[i].Meta.CallName
if len(inf.Signal) < 2 && !calls[callName] {
return fmt.Errorf("run %v: call %v: no signal", run, i)
}
if len(inf.Cover) == 0 {
return fmt.Errorf("run %v: call %v: no cover", run, i)
}
calls[callName] = true
} else {
if len(inf.Signal) == 0 {
return fmt.Errorf("run %v: call %v: no fallback signal", run, i)
}
}
}
}
return nil

1
sys/fuchsia/test/simple Normal file
View File

@ -0,0 +1 @@
syz_mmap(&(0x7f0000000000/0x1000), 0x1000)