From 8e4090902540da8c6e8fa640a0fc325c29c3efcb Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 22 Dec 2017 18:52:10 +0100 Subject: 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 --- pkg/csource/csource.go | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'pkg/csource/csource.go') 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") } } -- cgit mrf-deployment