From: Rhys Kidd Date: Tue, 2 Jun 2015 09:21:28 +0000 (+0000) Subject: Add regression test for bz#228343. X-Git-Tag: svn/VALGRIND_3_11_0~330 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6b0c3b8990349e31e4a69644578bca663e5a980;p=thirdparty%2Fvalgrind.git Add regression test for bz#228343. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15302 --- diff --git a/none/tests/darwin/Makefile.am b/none/tests/darwin/Makefile.am index 5cce00cdfd..1473e80089 100644 --- a/none/tests/darwin/Makefile.am +++ b/none/tests/darwin/Makefile.am @@ -6,12 +6,14 @@ dist_noinst_SCRIPTS = filter_stderr EXTRA_DIST = \ access_extended.stderr.exp access_extended.vgtest \ apple-main-arg.stderr.exp apple-main-arg.vgtest \ + bug228343.stderr.exp bug228343.stdout.exp bug228343.vgtest \ bug254164.stderr.exp bug254164.vgtest \ rlimit.stderr.exp rlimit.vgtest check_PROGRAMS = \ access_extended \ apple-main-arg \ + bug228343 \ bug254164 \ rlimit diff --git a/none/tests/darwin/bug228343.c b/none/tests/darwin/bug228343.c new file mode 100644 index 0000000000..6d9c063288 --- /dev/null +++ b/none/tests/darwin/bug228343.c @@ -0,0 +1,58 @@ +// https://bugs.kde.org/show_bug.cgi?id=228343 + +#include +#include +#include +#include +#include +#include + +OSSpinLock sl = OS_SPINLOCK_INIT; +typedef void *(*worker_t)(void*); +typedef void (*Sigaction)(int, siginfo_t *, void *); + +int GLOB=0; + +static void EnableSigprof(Sigaction SignalHandler) { + struct sigaction sa; + sa.sa_sigaction = SignalHandler; + sa.sa_flags = SA_RESTART | SA_SIGINFO; + sigemptyset(&sa.sa_mask); + if (sigaction(SIGPROF, &sa, NULL) != 0) { + perror("sigaction"); + abort(); + } + struct itimerval timer; + timer.it_interval.tv_sec = 0; + timer.it_interval.tv_usec = 1000000 / 10000; + timer.it_value = timer.it_interval; + if (setitimer(ITIMER_PROF, &timer, 0) != 0) { + perror("setitimer"); + abort(); + } +} + +void *Worker() { + for (long int i = 0; i < 100000000; i++) { + void *x = malloc((i % 64) + 1); + free (x); + } +} + +void SignalHandlerWithSpinlock(int sig, siginfo_t *siginfo, void *context) { + OSSpinLockLock(&sl); + GLOB++; + OSSpinLockUnlock(&sl); +} + +int main() { + EnableSigprof(SignalHandlerWithSpinlock); + pthread_t w_1; + pthread_t w_2; + pthread_create(&w_1, NULL, Worker, NULL); + pthread_create(&w_2, NULL, Worker, NULL); + pthread_join(w_1, NULL); + pthread_join(w_2, NULL); + printf("\tGLOB=%d\n", GLOB); + return 0; +} diff --git a/none/tests/darwin/bug228343.stderr.exp b/none/tests/darwin/bug228343.stderr.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/none/tests/darwin/bug228343.stdout.exp b/none/tests/darwin/bug228343.stdout.exp new file mode 100644 index 0000000000..f2b5cc1d57 --- /dev/null +++ b/none/tests/darwin/bug228343.stdout.exp @@ -0,0 +1 @@ + GLOB=0 diff --git a/none/tests/darwin/bug228343.vgtest b/none/tests/darwin/bug228343.vgtest new file mode 100644 index 0000000000..1d4c0d3676 --- /dev/null +++ b/none/tests/darwin/bug228343.vgtest @@ -0,0 +1,2 @@ +prog: bug228343 +vgopts: -q --tool=none