aboutsummaryrefslogtreecommitdiffstats
path: root/csource/csource.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-05-29 14:33:50 +0200
committerGitHub <noreply@github.com>2017-05-29 14:33:50 +0200
commitbaf825803c72cdc02bed92a5f84ec43482aa35d3 (patch)
treec9594f9450bb91ce03a5f671f53755c193077ef3 /csource/csource.go
parent145e067777cb0d21644412548e67dcb934f1da5e (diff)
parenteaf1f711fc42235d0b9a73c6877d14b1b5244194 (diff)
Merge pull request #196 from dvyukov/executor-fault-inject3
fault injection and faster tests
Diffstat (limited to 'csource/csource.go')
-rw-r--r--csource/csource.go27
1 files changed, 19 insertions, 8 deletions
diff --git a/csource/csource.go b/csource/csource.go
index 959538dbb..ab585ebec 100644
--- a/csource/csource.go
+++ b/csource/csource.go
@@ -22,12 +22,15 @@ import (
)
type Options struct {
- Threaded bool
- Collide bool
- Repeat bool
- Procs int
- Sandbox string
- Repro bool // generate code for use with repro package
+ Threaded bool
+ Collide bool
+ Repeat bool
+ Procs int
+ Sandbox string
+ Fault bool // inject fault into FaultCall/FaultNth
+ FaultCall int
+ FaultNth int
+ Repro bool // generate code for use with repro package
}
func Write(p *prog.Prog, opts Options) ([]byte, error) {
@@ -65,7 +68,7 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
fmt.Fprint(w, hdr)
fmt.Fprint(w, "\n")
- calls, nvar := generateCalls(exec)
+ calls, nvar := generateCalls(exec, opts)
fmt.Fprintf(w, "long r[%v];\n", nvar)
if !opts.Repeat {
@@ -161,7 +164,7 @@ func generateTestFunc(w io.Writer, opts Options, calls []string, name string) {
}
}
-func generateCalls(exec []byte) ([]string, int) {
+func generateCalls(exec []byte, opts Options) ([]string, int) {
read := func() uintptr {
if len(exec) < 8 {
panic("exec program overflow")
@@ -265,6 +268,11 @@ loop:
default:
// Normal syscall.
newCall()
+ if opts.Fault && opts.FaultCall == len(calls) {
+ fmt.Fprintf(w, "\twrite_file(\"/sys/kernel/debug/failslab/ignore-gfp-wait\", \"N\");\n")
+ fmt.Fprintf(w, "\twrite_file(\"/sys/kernel/debug/fail_futex/ignore-private\", \"N\");\n")
+ fmt.Fprintf(w, "\tinject_fault(%v);\n", opts.FaultNth)
+ }
meta := sys.Calls[instr]
fmt.Fprintf(w, "\tr[%v] = execute_syscall(__NR_%v", n, meta.CallName)
nargs := read()
@@ -311,6 +319,9 @@ func preprocessCommonHeader(opts Options, handled map[string]int) (string, error
if opts.Repeat {
defines = append(defines, "SYZ_REPEAT")
}
+ if opts.Fault {
+ defines = append(defines, "SYZ_FAULT_INJECTION")
+ }
for name, _ := range handled {
defines = append(defines, "__NR_"+name)
}