From d74824bf5db421db71f0aad6aab8e943defddbf9 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Tue, 18 Sep 2012 15:47:36 +0400 Subject: [PATCH] tests: Log error messages to stderr instead of stdout * tests/initsecondarythread.c (main): Print error messages using fprintf(stderr) instead of printf(). * tests/subthread_create.c (entry, main): Likewise. * tests/thread_leak_test.c (main): Likewise. * tests/trace_test.c (mktree): Likewise. * tests/thread_leak_test.c (main): Call exit(2) if thread creation or joining failed. --- tests/initsecondarythread.c | 8 ++++---- tests/subthread_create.c | 8 +++++--- tests/thread_leak_test.c | 6 ++++-- tests/trace_test.c | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/initsecondarythread.c b/tests/initsecondarythread.c index 70063ebd..4a13ca95 100644 --- a/tests/initsecondarythread.c +++ b/tests/initsecondarythread.c @@ -76,21 +76,21 @@ int main(void) # endif # ifdef GC_PTHREADS if ((code = pthread_create (&t, NULL, thread, NULL)) != 0) { - printf("Thread creation failed %d\n", code); + fprintf(stderr, "Thread creation failed %d\n", code); return 1; } if ((code = pthread_join (t, NULL)) != 0) { - printf("Thread join failed %d\n", code); + fprintf(stderr, "Thread join failed %d\n", code); return 1; } # else t = CreateThread(NULL, 0, thread, 0, 0, &thread_id); if (t == NULL) { - printf("Thread creation failed %d\n", (int)GetLastError()); + fprintf(stderr, "Thread creation failed %d\n", (int)GetLastError()); return 1; } if (WaitForSingleObject(t, INFINITE) != WAIT_OBJECT_0) { - printf("Thread join failed %d\n", (int)GetLastError()); + fprintf(stderr, "Thread join failed %d\n", (int)GetLastError()); CloseHandle(t); return 1; } diff --git a/tests/subthread_create.c b/tests/subthread_create.c index 9352f339..9a7095b6 100644 --- a/tests/subthread_create.c +++ b/tests/subthread_create.c @@ -70,7 +70,7 @@ volatile AO_t thread_ended_cnt = 0; DWORD thread_id; th = CreateThread(NULL, 0, entry, (LPVOID)my_depth, 0, &thread_id); if (th == NULL) { - printf("Thread #%d creation failed: %d\n", thread_num, + fprintf(stderr, "Thread #%d creation failed: %d\n", thread_num, (int)GetLastError()); exit(2); } @@ -104,7 +104,8 @@ int main(void) DWORD thread_id; th[i] = CreateThread(NULL, 0, entry, 0, 0, &thread_id); if (th[i] == NULL) { - printf("Thread creation failed: %d\n", (int)GetLastError()); + fprintf(stderr, "Thread creation failed: %d\n", + (int)GetLastError()); exit(1); } # endif @@ -120,7 +121,8 @@ int main(void) } # else if (WaitForSingleObject(th[i], INFINITE) != WAIT_OBJECT_0) { - printf("Failed to join thread: %d\n", (int)GetLastError()); + fprintf(stderr, "Failed to join thread: %d\n", + (int)GetLastError()); CloseHandle(th[i]); exit(1); } diff --git a/tests/thread_leak_test.c b/tests/thread_leak_test.c index 8b7f82d6..845de00e 100644 --- a/tests/thread_leak_test.c +++ b/tests/thread_leak_test.c @@ -63,7 +63,8 @@ int main(void) { code = t[i] != NULL ? 0 : (int)GetLastError(); # endif if (code != 0) { - printf("Thread creation failed %d\n", code); + fprintf(stderr, "Thread creation failed %d\n", code); + exit(2); } } @@ -75,7 +76,8 @@ int main(void) { (int)GetLastError(); # endif if (code != 0) { - printf("Thread join failed %d\n", code); + fprintf(stderr, "Thread join failed %d\n", code); + exit(2); } } diff --git a/tests/trace_test.c b/tests/trace_test.c index 923e0f88..79c353f7 100644 --- a/tests/trace_test.c +++ b/tests/trace_test.c @@ -18,7 +18,7 @@ struct treenode * mktree(int i) { if (0 == i) return 0; if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode)); if (r == NULL) { - printf("Out of memory\n"); + fprintf(stderr, "Out of memory\n"); exit(1); } r -> x = mktree(i-1); -- 2.40.0