From 9b6accbcac289e52a80e8584ad569b3b90a1195c Mon Sep 17 00:00:00 2001 From: cpickett Date: Wed, 31 Dec 2008 02:51:26 +0000 Subject: [PATCH] * convert check_thread_stress to run actual fork and pthread tests - implementation again due to Daniel Gollub git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@499 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- tests/check_thread_stress.c | 84 +++++++++++++------------------------ 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/tests/check_thread_stress.c b/tests/check_thread_stress.c index 53f585f..4ad4aea 100644 --- a/tests/check_thread_stress.c +++ b/tests/check_thread_stress.c @@ -6,6 +6,10 @@ #include #include +#ifdef HAVE_UNISTD_H +#include /* fork() */ +#endif + #ifdef HAVE_PTHREAD #include #endif @@ -14,10 +18,10 @@ Suite *s; TCase *tc; SRunner *sr; -static void *sendinfo_thread(void *userdata CK_ATTRIBUTE_UNUSED) +static void *sendinfo(void *userdata CK_ATTRIBUTE_UNUSED) { unsigned int i; - for (i=0; i < 100; i++) { + for (i=0; i < 999; i++) { fail_unless(1,"Shouldn't see this message"); } @@ -25,82 +29,50 @@ static void *sendinfo_thread(void *userdata CK_ATTRIBUTE_UNUSED) } -static void *sendinfo_fail_thread(void *userdata CK_ATTRIBUTE_UNUSED) -{ - unsigned int i; - for (i=0; i < 100; i++) { - fail("This test fails"); - } - - return NULL; -} - -START_TEST(test_pass) +START_TEST(test_stress_threads) { #ifdef HAVE_PTHREAD pthread_t a, b; - pthread_create(&a, NULL, sendinfo_thread, (void *) 0xa); - pthread_create(&b, NULL, sendinfo_thread, (void *) 0xb); + pthread_create(&a, NULL, sendinfo, (void *) 0xa); + pthread_create(&b, NULL, sendinfo, (void *) 0xb); pthread_join(a, NULL); pthread_join(b, NULL); #else - sendinfo_thread((void *) 0xa); - sendinfo_thread((void *) 0xb); + sendinfo((void *) 0xa); + sendinfo((void *) 0xb); #endif } END_TEST -START_TEST(test_fail) +START_TEST(test_stress_forks) { -#ifdef HAVE_PTHREAD - pthread_t a, b; - pthread_create(&a, NULL, sendinfo_fail_thread, (void *) 0xa); - pthread_create(&b, NULL, sendinfo_fail_thread, (void *) 0xb); - - pthread_join(a, NULL); - pthread_join(b, NULL); -#else - sendinfo_fail_thread((void *) 0xa); - sendinfo_fail_thread((void *) 0xb); -#endif + pid_t cpid = fork(); + if (cpid == 0) { /* Child */ + sendinfo((void *) 0x1); + } else { + sendinfo((void *) 0x2); + } } END_TEST -static void run (int num_iters) + +int main(void) { - int i; - s = suite_create ("Stress"); - tc = tcase_create ("Stress"); + int nf; + s = suite_create ("ForkThreadStress"); + tc = tcase_create ("ForkThreadStress"); sr = srunner_create (s); suite_add_tcase(s, tc); - for (i = 0; i < num_iters; i++) { - tcase_add_test (tc, test_pass); - tcase_add_test (tc, test_fail); - } + tcase_add_loop_test (tc, test_stress_threads, 0, 100); + tcase_add_loop_test (tc, test_stress_forks, 0, 100); srunner_run_all(sr, CK_SILENT); - if (srunner_ntests_failed (sr) != num_iters) { - printf ("Error: expected %d failures, got %d\n", - num_iters, srunner_ntests_failed(sr)); - return; - } + + nf = srunner_ntests_failed (sr); srunner_free(sr); -} - -int main(void) -{ - int i; - time_t t1; - int iters[] = {1, 100, 1000, -1}; - - for (i = 0; iters[i] != -1; i++) { - t1 = time(NULL); - run(iters[i]); - printf ("%d, %d\n", iters[i], (int) difftime(time(NULL), t1)); - } - return 0; + return nf ? EXIT_FAILURE : EXIT_SUCCESS; } -- 2.49.0