From 981e0924e785b3563e289b5ec0032a57355f8de7 Mon Sep 17 00:00:00 2001 From: brarcher Date: Sun, 22 Sep 2013 17:22:45 +0000 Subject: [PATCH] Replace _POSIX_VERSION with more specific checks _POSIX_VERSION was used to conditionally compile several posix-only features. Replacing these with checks for exactly what is needed. git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@761 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- configure.ac | 4 ++++ src/check.c | 4 ++-- src/check_run.c | 44 ++++++++++++++++++------------------- tests/check_check_main.c | 4 ++-- tests/check_check_pack.c | 12 +++++----- tests/check_check_sub.c | 12 +++++----- tests/check_thread_stress.c | 16 +++++++------- 7 files changed, 50 insertions(+), 46 deletions(-) diff --git a/configure.ac b/configure.ac index 9f71098..134aa39 100644 --- a/configure.ac +++ b/configure.ac @@ -186,6 +186,10 @@ AC_CHECK_DECLS([alarm, clock_gettime, timer_create, timer_settime, timer_delete, AC_CHECK_FUNCS([setitimer]) +# Checks for functions not available in Windows +AC_CHECK_FUNCS([fork]) +AC_CHECK_FUNCS([sigaction]) + # Check if the system's snprintf (and its variations) are C99 compliant. # If they are not, use the version in libcompat. HW_FUNC_VSNPRINTF diff --git a/src/check.c b/src/check.c index c6e88da..8fc4bf1 100644 --- a/src/check.c +++ b/src/check.c @@ -258,9 +258,9 @@ void _ck_assert_msg (int result, const char *file, va_end(ap); send_failure_info (buf); if (cur_fork_status() == CK_FORK) { -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK exit(1); -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ } else { longjmp(error_jmp_buffer, 1); } diff --git a/src/check_run.c b/src/check_run.c index b9b4778..944a41e 100644 --- a/src/check_run.c +++ b/src/check_run.c @@ -75,7 +75,7 @@ static TestResult *receive_result_info_nofork (const char *tcname, static void set_nofork_info (TestResult *tr); static char *pass_msg (void); -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK static TestResult *tcase_run_tfun_fork (SRunner *sr, TCase *tc, TF *tf, int i); static TestResult *receive_result_info_fork (const char *tcname, const char *tname, @@ -104,7 +104,7 @@ static void CK_ATTRIBUTE_UNUSED sig_handler(int sig_nr) break; } } -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ #define MSG_LEN 100 @@ -177,11 +177,11 @@ static void srunner_iterate_tcase_tfuns (SRunner *sr, TCase *tc) log_test_start (sr, tc, tfun); switch (srunner_fork_status(sr)) { case CK_FORK: -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK tr = tcase_run_tfun_fork (sr, tc, tfun, i); -#else /* _POSIX_VERSION */ +#else /* HAVE_FORK */ eprintf("This version does not support fork", __FILE__, __LINE__); -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ break; case CK_NOFORK: tr = tcase_run_tfun_nofork (sr, tc, tfun, i); @@ -371,7 +371,7 @@ static char *pass_msg (void) return strdup("Passed"); } -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK static TestResult *tcase_run_tfun_fork (SRunner *sr, TCase *tc, TF *tfun, int i) { pid_t pid_w; @@ -570,7 +570,7 @@ static int waserror (int status, int signal_expected) return ((was_sig && (signal_received != signal_expected)) || (was_exit && exit_status != 0)); } -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ enum fork_status srunner_fork_status (SRunner *sr) { @@ -581,12 +581,12 @@ enum fork_status srunner_fork_status (SRunner *sr) if (strcmp (env,"no") == 0) return CK_NOFORK; else { -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK return CK_FORK; -#else /* _POSIX_VERSION */ +#else /* HAVE_FORK */ eprintf("This version does not support fork", __FILE__, __LINE__); return CK_NOFORK; -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ } } else return sr->fstat; @@ -607,10 +607,10 @@ void srunner_run_all (SRunner *sr, enum print_output print_mode) void srunner_run (SRunner *sr, const char *sname, const char *tcname, enum print_output print_mode) { -#ifdef _POSIX_VERSION +#ifdef HAVE_SIGACTION struct sigaction old_action; struct sigaction new_action; -#endif /* _POSIX_VERSION */ +#endif /* HAVE_SIGACTION */ /* Get the selected test suite and test case from the environment. */ @@ -624,22 +624,22 @@ void srunner_run (SRunner *sr, const char *sname, const char *tcname, enum print eprintf ("Bad print_mode argument to srunner_run_all: %d", __FILE__, __LINE__, print_mode); } -#ifdef _POSIX_VERSION +#ifdef HAVE_SIGACTION memset(&new_action, 0, sizeof new_action); new_action.sa_handler = sig_handler; sigaction(SIGALRM, &new_action, &old_action); -#endif /* _POSIX_VERSION */ +#endif /* HAVE_SIGACTION */ srunner_run_init (sr, print_mode); srunner_iterate_suites (sr, sname, tcname, print_mode); srunner_run_end (sr, print_mode); -#ifdef _POSIX_VERSION +#ifdef HAVE_SIGACTION sigaction(SIGALRM, &old_action, NULL); -#endif /* _POSIX_VERSION */ +#endif /* HAVE_SIGACTION */ } pid_t check_fork (void) { -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK pid_t pid = fork(); /* Set the process to a process group to be able to kill it easily. */ if(pid >= 0) @@ -647,15 +647,15 @@ pid_t check_fork (void) setpgid(pid, group_pid); } return pid; -#else /* _POSIX_VERSION */ +#else /* HAVE_FORK */ eprintf("This version does not support fork", __FILE__, __LINE__); return 0; -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ } void check_waitpid_and_exit (pid_t pid CK_ATTRIBUTE_UNUSED) { -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK pid_t pid_w; int status; @@ -668,7 +668,7 @@ void check_waitpid_and_exit (pid_t pid CK_ATTRIBUTE_UNUSED) } } exit(EXIT_SUCCESS); -#else /* _POSIX_VERSION */ +#else /* HAVE_FORK */ eprintf("This version does not support fork", __FILE__, __LINE__); -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ } diff --git a/tests/check_check_main.c b/tests/check_check_main.c index b0b66cc..db99fdc 100644 --- a/tests/check_check_main.c +++ b/tests/check_check_main.c @@ -10,11 +10,11 @@ int main (void) int n; SRunner *sr; -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK fork_setup(); setup_fixture(); setup(); -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ sr = srunner_create (make_master_suite()); srunner_add_suite(sr, make_list_suite()); diff --git a/tests/check_check_pack.c b/tests/check_check_pack.c index fe97424..f35035b 100644 --- a/tests/check_check_pack.c +++ b/tests/check_check_pack.c @@ -189,7 +189,7 @@ START_TEST(test_pack_loc_limit) END_TEST /* the ppack probably means 'pipe' pack */ -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK START_TEST(test_ppack) { int filedes[2]; @@ -383,7 +383,7 @@ START_TEST(test_ppack_big) free (fmsg.msg); } END_TEST -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ Suite *make_pack_suite(void) { @@ -401,20 +401,20 @@ Suite *make_pack_suite(void) tcase_add_test (tc_core, test_pack_loc); tcase_add_test (tc_core, test_pack_ctx); tcase_add_test (tc_core, test_pack_len); -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK tcase_add_test (tc_core, test_ppack); tcase_add_test (tc_core, test_ppack_noctx); tcase_add_test (tc_core, test_ppack_onlyctx); tcase_add_test (tc_core, test_ppack_multictx); tcase_add_test (tc_core, test_ppack_nofail); -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ suite_add_tcase (s, tc_limit); tcase_add_test (tc_limit, test_pack_ctx_limit); tcase_add_test (tc_limit, test_pack_fail_limit); tcase_add_test (tc_limit, test_pack_loc_limit); -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK tcase_add_test (tc_limit, test_ppack_big); -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ return s; } diff --git a/tests/check_check_sub.c b/tests/check_check_sub.c index 2f34ae4..12b8fdb 100644 --- a/tests/check_check_sub.c +++ b/tests/check_check_sub.c @@ -20,9 +20,9 @@ START_TEST(test_mark_lno) { mark_point(); #define LINENO_mark_lno _STR(__LINE__) -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK exit(EXIT_FAILURE); /* should fail with mark_point above as line */ -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ } END_TEST @@ -516,7 +516,7 @@ START_TEST(test_null_2) } END_TEST -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK START_TEST(test_fork1p_pass) { pid_t pid; @@ -620,7 +620,7 @@ START_TEST(test_fork2_fail) check_waitpid_and_exit(pid); } END_TEST -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ START_TEST(test_srunner) { @@ -1121,14 +1121,14 @@ Suite *make_sub_suite(void) tcase_add_test (tc_limit, test_null); tcase_add_test (tc_limit, test_null_2); -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK tcase_add_test (tc_messaging_and_fork, test_fork1p_pass); tcase_add_test (tc_messaging_and_fork, test_fork1p_fail); tcase_add_test (tc_messaging_and_fork, test_fork1c_pass); tcase_add_test (tc_messaging_and_fork, test_fork1c_fail); tcase_add_test (tc_messaging_and_fork, test_fork2_pass); tcase_add_test (tc_messaging_and_fork, test_fork2_fail); -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ return s; } diff --git a/tests/check_thread_stress.c b/tests/check_thread_stress.c index 37df7d6..b06ed16 100644 --- a/tests/check_thread_stress.c +++ b/tests/check_thread_stress.c @@ -8,7 +8,7 @@ Suite *s; TCase *tc; SRunner *sr; -#if defined (HAVE_PTHREAD) || defined (_POSIX_VERSION) +#if defined (HAVE_PTHREAD) || defined (HAVE_FORK) static void * sendinfo (void *userdata CK_ATTRIBUTE_UNUSED) { @@ -19,7 +19,7 @@ sendinfo (void *userdata CK_ATTRIBUTE_UNUSED) } return NULL; } -#endif /* HAVE_PTHREAD || _POSIX_VERSION */ +#endif /* HAVE_PTHREAD || HAVE_FORK */ #ifdef HAVE_PTHREAD START_TEST (test_stress_threads) @@ -34,7 +34,7 @@ START_TEST (test_stress_threads) END_TEST #endif /* HAVE_PTHREAD */ -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK START_TEST (test_stress_forks) { pid_t cpid = fork (); @@ -51,7 +51,7 @@ START_TEST (test_stress_forks) } } END_TEST -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ int main (void) @@ -66,18 +66,18 @@ main (void) tcase_add_loop_test (tc, test_stress_threads, 0, 100); #endif /* HAVE_PTHREAD */ -#ifdef _POSIX_VERSION +#ifdef HAVE_FORK tcase_add_loop_test (tc, test_stress_forks, 0, 100); -#endif /* _POSIX_VERSION */ +#endif /* HAVE_FORK */ srunner_run_all (sr, CK_VERBOSE); nf = srunner_ntests_failed (sr); srunner_free (sr); /* hack to give us XFAIL on non-posix platforms */ -#ifndef _POSIX_VERSION +#ifndef HAVE_FORK nf++; -#endif /* !_POSIX_VERSION */ +#endif /* !HAVE_FORK */ return nf ? EXIT_FAILURE : EXIT_SUCCESS; } -- 2.40.0