Skip to content

Commit

Permalink
pkg/csource: make all usleeps random
Browse files Browse the repository at this point in the history
We can't know the exact values of those sleeps in advance, they can be
different for different bugs. Making them random increases the chance that
the C repro executes with the right timings at some point.
  • Loading branch information
xairy committed Jul 24, 2017
1 parent 65a2d5f commit e83310d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 6 deletions.
2 changes: 0 additions & 2 deletions executor/common.h
Expand Up @@ -13,8 +13,6 @@
#include <unistd.h>
#if defined(SYZ_EXECUTOR) || defined(SYZ_THREADED) || defined(SYZ_COLLIDE)
#include <pthread.h>
#endif
#if defined(SYZ_EXECUTOR) || defined(SYZ_COLLIDE)
#include <stdlib.h>
#endif
#if defined(SYZ_EXECUTOR) || defined(SYZ_HANDLE_SEGV)
Expand Down
2 changes: 0 additions & 2 deletions pkg/csource/common.go
Expand Up @@ -14,8 +14,6 @@ var commonHeader = `
#include <unistd.h>
#if defined(SYZ_EXECUTOR) || defined(SYZ_THREADED) || defined(SYZ_COLLIDE)
#include <pthread.h>
#endif
#if defined(SYZ_EXECUTOR) || defined(SYZ_COLLIDE)
#include <stdlib.h>
#endif
#if defined(SYZ_EXECUTOR) || defined(SYZ_HANDLE_SEGV)
Expand Down
4 changes: 2 additions & 2 deletions pkg/csource/csource.go
Expand Up @@ -219,7 +219,7 @@ func generateTestFunc(w io.Writer, opts Options, calls []string, name string) {
}
fmt.Fprintf(w, "\tfor (i = 0; i < %v; i++) {\n", len(calls))
fmt.Fprintf(w, "\t\tpthread_create(&th[i], 0, thr, (void*)i);\n")
fmt.Fprintf(w, "\t\tusleep(10000);\n")
fmt.Fprintf(w, "\t\tusleep(rand()%%10000);\n")
fmt.Fprintf(w, "\t}\n")
if opts.Collide {
fmt.Fprintf(w, "\tfor (i = 0; i < %v; i++) {\n", len(calls))
Expand All @@ -228,7 +228,7 @@ func generateTestFunc(w io.Writer, opts Options, calls []string, name string) {
fmt.Fprintf(w, "\t\t\tusleep(rand()%%10000);\n")
fmt.Fprintf(w, "\t}\n")
}
fmt.Fprintf(w, "\tusleep(100000);\n")
fmt.Fprintf(w, "\tusleep(rand()%%100000);\n")
fmt.Fprintf(w, "}\n\n")
}
}
Expand Down

0 comments on commit e83310d

Please sign in to comment.