diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-09-06 10:54:14 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-09-06 10:56:09 +0200 |
| commit | 596466b38cd4e2de23df479ffd78dece9966d875 (patch) | |
| tree | ade7a76b932f6311f505c4615755a56997411035 /pkg | |
| parent | 873745f2ff183dcbc303a504683ccaa3a472a635 (diff) | |
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.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/csource/csource.go | 8 | ||||
| -rw-r--r-- | pkg/osutil/osutil.go | 6 | ||||
| -rw-r--r-- | pkg/runtest/run.go | 29 |
3 files changed, 34 insertions, 9 deletions
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go index 69be3ff2a..49431f655 100644 --- a/pkg/csource/csource.go +++ b/pkg/csource/csource.go @@ -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) } } diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index d9a543971..d8a1cbe84 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -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. diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go index aa090e371..68cd40ca7 100644 --- a/pkg/runtest/run.go +++ b/pkg/runtest/run.go @@ -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 |
