Skip to content

Commit 84e6326

Browse files
author
rhyskidd
committed
Add regression test for bz#228343.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15302 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent bf11884 commit 84e6326

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

none/tests/darwin/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ dist_noinst_SCRIPTS = filter_stderr
66
EXTRA_DIST = \
77
access_extended.stderr.exp access_extended.vgtest \
88
apple-main-arg.stderr.exp apple-main-arg.vgtest \
9+
bug228343.stderr.exp bug228343.stdout.exp bug228343.vgtest \
910
bug254164.stderr.exp bug254164.vgtest \
1011
rlimit.stderr.exp rlimit.vgtest
1112

1213
check_PROGRAMS = \
1314
access_extended \
1415
apple-main-arg \
16+
bug228343 \
1517
bug254164 \
1618
rlimit
1719

none/tests/darwin/bug228343.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// https://bugs.kde.org/show_bug.cgi?id=228343
2+
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <sys/time.h>
6+
#include <signal.h>
7+
#include <libkern/OSAtomic.h>
8+
#include <pthread.h>
9+
10+
OSSpinLock sl = OS_SPINLOCK_INIT;
11+
typedef void *(*worker_t)(void*);
12+
typedef void (*Sigaction)(int, siginfo_t *, void *);
13+
14+
int GLOB=0;
15+
16+
static void EnableSigprof(Sigaction SignalHandler) {
17+
struct sigaction sa;
18+
sa.sa_sigaction = SignalHandler;
19+
sa.sa_flags = SA_RESTART | SA_SIGINFO;
20+
sigemptyset(&sa.sa_mask);
21+
if (sigaction(SIGPROF, &sa, NULL) != 0) {
22+
perror("sigaction");
23+
abort();
24+
}
25+
struct itimerval timer;
26+
timer.it_interval.tv_sec = 0;
27+
timer.it_interval.tv_usec = 1000000 / 10000;
28+
timer.it_value = timer.it_interval;
29+
if (setitimer(ITIMER_PROF, &timer, 0) != 0) {
30+
perror("setitimer");
31+
abort();
32+
}
33+
}
34+
35+
void *Worker() {
36+
for (long int i = 0; i < 100000000; i++) {
37+
void *x = malloc((i % 64) + 1);
38+
free (x);
39+
}
40+
}
41+
42+
void SignalHandlerWithSpinlock(int sig, siginfo_t *siginfo, void *context) {
43+
OSSpinLockLock(&sl);
44+
GLOB++;
45+
OSSpinLockUnlock(&sl);
46+
}
47+
48+
int main() {
49+
EnableSigprof(SignalHandlerWithSpinlock);
50+
pthread_t w_1;
51+
pthread_t w_2;
52+
pthread_create(&w_1, NULL, Worker, NULL);
53+
pthread_create(&w_2, NULL, Worker, NULL);
54+
pthread_join(w_1, NULL);
55+
pthread_join(w_2, NULL);
56+
printf("\tGLOB=%d\n", GLOB);
57+
return 0;
58+
}

none/tests/darwin/bug228343.stderr.exp

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GLOB=0

none/tests/darwin/bug228343.vgtest

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
prog: bug228343
2+
vgopts: -q --tool=none

0 commit comments

Comments
 (0)