aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/csource/csource.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-12-22 18:52:10 +0100
committerDmitry Vyukov <dvyukov@google.com>2017-12-22 18:55:38 +0100
commit8e4090902540da8c6e8fa640a0fc325c29c3efcb (patch)
tree42af582b4a6b448bc34329346046c67f07f26984 /pkg/csource/csource.go
parent26cd53f078db858a6ccca338e13e7f4d1d291c22 (diff)
pkg/csource: mimic the way syscalls are scheduled in executor
Currently csource uses completely different, simpler way of scheduling syscalls onto threads (thread per call with random sleeps). Mimic the way calls are scheduled in executor. Fixes #312
Diffstat (limited to 'pkg/csource/csource.go')
-rw-r--r--pkg/csource/csource.go28
1 files changed, 6 insertions, 22 deletions
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go
index 38814c3b2..14f381451 100644
--- a/pkg/csource/csource.go
+++ b/pkg/csource/csource.go
@@ -193,21 +193,17 @@ func (ctx *context) generateTestFunc(calls []string, nvar uint64, name string) {
}
ctx.printf("}\n\n")
} else {
- ctx.printf("void *thr(void *arg)\n{\n")
- ctx.printf("\tswitch ((long)arg) {\n")
+ ctx.printf("void execute_call(int call)\n{\n")
+ ctx.printf("\tswitch (call) {\n")
for i, c := range calls {
ctx.printf("\tcase %v:\n", i)
ctx.printf("%s", strings.Replace(c, "\t", "\t\t", -1))
ctx.printf("\t\tbreak;\n")
}
ctx.printf("\t}\n")
- ctx.printf("\treturn 0;\n}\n\n")
+ ctx.printf("}\n\n")
ctx.printf("void %v()\n{\n", name)
- ctx.printf("\tlong i;\n")
- ctx.printf("\tpthread_t th[%v];\n", 2*len(calls))
- ctx.printf("\tpthread_attr_t attr;\n")
- ctx.printf("\n")
if opts.Debug {
// Use debug to avoid: error: ‘debug’ defined but not used.
ctx.printf("\tdebug(\"%v\\n\");\n", name)
@@ -218,23 +214,11 @@ func (ctx *context) generateTestFunc(calls []string, nvar uint64, name string) {
if nvar != 0 {
ctx.printf("\tmemset(r, -1, sizeof(r));\n")
}
+ ctx.printf("\texecute(%v);\n", len(calls))
if opts.Collide {
- ctx.printf("\tsrand(getpid());\n")
- }
- ctx.printf("\tpthread_attr_init(&attr);\n")
- ctx.printf("\tpthread_attr_setstacksize(&attr, 128 << 10);\n")
- ctx.printf("\tfor (i = 0; i < %v; i++) {\n", len(calls))
- ctx.printf("\t\tpthread_create(&th[i], &attr, thr, (void*)i);\n")
- ctx.printf("\t\tusleep(rand()%%10000);\n")
- ctx.printf("\t}\n")
- if opts.Collide {
- ctx.printf("\tfor (i = 0; i < %v; i++) {\n", len(calls))
- ctx.printf("\t\tpthread_create(&th[%v+i], &attr, thr, (void*)i);\n", len(calls))
- ctx.printf("\t\tif (rand()%%2)\n")
- ctx.printf("\t\t\tusleep(rand()%%10000);\n")
- ctx.printf("\t}\n")
+ ctx.printf("\tcollide = 1;\n")
+ ctx.printf("\texecute(%v);\n", len(calls))
}
- ctx.printf("\tusleep(rand()%%100000);\n")
ctx.printf("}\n\n")
}
}