|
From: Jeremy F. <je...@go...> - 2005-01-28 09:09:34
|
CVS commit by fitzhardinge:
Expand thread-exits to test for the case where master_tid is blocked in a syscall.
M +68 -5 thread-exits.c 1.3
M +1 -0 thread-exits.stderr.exp 1.2
M +16 -1 thread-exits.stdout.exp 1.2
--- valgrind/none/tests/thread-exits.c #1.2:1.3
@@ -14,4 +14,11 @@
like the program crashed.
+ The extra complication in this test is making sure that the
+ unwanted signals are discarded while the main thread is blocked in
+ a syscall. So, to check this, main creates a new process, which
+ attempts to grow the stack once all the threads have been created
+ and exited. main() itself is blocked waiting for the child
+ process.
+
Oh, and this test also makes sure that thread resources are cleaned
up properly.
@@ -21,4 +28,13 @@
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/wait.h>
+
+static int grower;
+
+static void handler(int sig)
+{
+}
static void *thr(void *v)
@@ -39,13 +55,19 @@ static void grow(int depth)
}
-int main()
+static void *maker(void *v)
{
int i;
+ sleep(1);
+
/* Create lots of threads */
+ printf("creating threads...\n");
for(i = 0; i < 1300; i++) {
pthread_t t;
int ret;
+ if (i % 100 == 0)
+ printf("%d...\n", i);
+
ret = pthread_create(&t, NULL, thr, NULL);
if (ret) {
@@ -61,9 +83,50 @@ int main()
}
- /* Grow the stack */
+ kill(grower, SIGUSR1);
+
+ return NULL;
+}
+
+int main()
+{
+ pthread_t pth;
+ sigset_t mask;
+ int status;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGCHLD);
+ sigprocmask(SIG_BLOCK, &mask, NULL);
+
+ struct sigaction sa;
+ sa.sa_handler = handler;
+ sa.sa_flags = 0;
+ sigfillset(&sa.sa_mask);
+ sigaction(SIGUSR1, &sa, NULL);
+
+ grower = fork();
+
+ if (grower == -1) {
+ perror("fork");
+ exit(1);
+ }
+
+ if (grower == 0) {
+ pause(); /* child - wait for SIGUSR1 */
grow(10);
+ printf("stack grew OK\n");
+ exit(0);
+ }
- /* If we didn't die with SIGSEGV in grow(), it is a pass */
- printf("PASS\n");
+ pthread_create(&pth, NULL, maker, NULL);
+
+ /* wait for child */
+ if (waitpid(grower, &status, 0) != grower)
+ printf("FAILED\n");
+ else if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+ printf("PASS: child OK\n");
+ else
+ printf("FAILED: exit status=%d\n", status);
+
+ pthread_join(pth, NULL);
return 0;
--- valgrind/none/tests/thread-exits.stderr.exp #1.1:1.2
@@ -1,2 +1,3 @@
+
--- valgrind/none/tests/thread-exits.stdout.exp #1.1:1.2
@@ -1 +1,16 @@
-PASS
+stack grew OK
+creating threads...
+0...
+100...
+200...
+300...
+400...
+500...
+600...
+700...
+800...
+900...
+1000...
+1100...
+1200...
+PASS: child OK
|