From: brarcher Date: Sat, 25 Jan 2014 18:18:08 +0000 (+0000) Subject: change expected exit values of tests to consistently be signed chars X-Git-Tag: 0.10.0~156 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92e472c06a155345047a076157b1f923769a8dc4;p=check change expected exit values of tests to consistently be signed chars when a forked process finishes, waitpid() will return the status as an int. Several macros determine what the status means. WEXITSTATUS() is defined as returning the low-order 8 bits of the status argument that the child process passed to _exit() or exit(), or the value the child process returned from main(). It makes sense for the value to be stored as either a signed or unsigned char. As the decision is arbitrary (e.g. it only matters internally to check), signed is used to keep consistent with the _tcase_add_test function. git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@1061 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/src/check.c b/src/check.c index 862da37..4da6c37 100644 --- a/src/check.c +++ b/src/check.c @@ -36,6 +36,14 @@ #define DEFAULT_TIMEOUT 4 #endif +/* + * When a process exits either normally, with exit(), or + * by an uncaught signal, The lower 0x377 bits are passed + * to the parent. Of those, only the lower 8 bits are + * returned by the WEXITSTATUS() macro. + */ +#define WEXITSTATUS_MASK 0xFF + int check_major_version = CHECK_MAJOR_VERSION; int check_minor_version = CHECK_MINOR_VERSION; int check_micro_version = CHECK_MICRO_VERSION; @@ -166,7 +174,7 @@ void _tcase_add_test (TCase *tc, TFun fn, const char *name, int _signal, int all tf->loop_start = start; tf->loop_end = end; tf->signal = _signal; /* 0 means no signal expected */ - tf->allowed_exit_value = allowed_exit_value; /* 0 is default successful exit */ + tf->allowed_exit_value = (WEXITSTATUS_MASK & allowed_exit_value); /* 0 is default successful exit */ tf->name = name; check_list_add_end (tc->tflst, tf); } diff --git a/src/check_impl.h b/src/check_impl.h index cef3e75..2f7d987 100644 --- a/src/check_impl.h +++ b/src/check_impl.h @@ -40,7 +40,7 @@ typedef struct TF { int loop_end; const char *name; int signal; - unsigned char allowed_exit_value; + signed char allowed_exit_value; } TF; struct Suite { diff --git a/src/check_run.c b/src/check_run.c index 032e86e..d6795c1 100644 --- a/src/check_run.c +++ b/src/check_run.c @@ -81,9 +81,9 @@ static TestResult *receive_result_info_fork (const char *tcname, const char *tname, int iter, int status, int expected_signal, - unsigned char allowed_exit_value); + signed char allowed_exit_value); static void set_fork_info (TestResult *tr, int status, int expected_signal, - unsigned char allowed_exit_value); + signed char allowed_exit_value); static char *signal_msg (int sig); static char *signal_error_msg (int signal_received, int signal_expected); static char *exit_msg (int exitstatus); @@ -441,7 +441,7 @@ static TestResult *receive_result_info_fork (const char *tcname, const char *tname, int iter, int status, int expected_signal, - unsigned char allowed_exit_value) + signed char allowed_exit_value) { TestResult *tr; @@ -458,11 +458,11 @@ static TestResult *receive_result_info_fork (const char *tcname, return tr; } -static void set_fork_info (TestResult *tr, int status, int signal_expected, unsigned char allowed_exit_value) +static void set_fork_info (TestResult *tr, int status, int signal_expected, signed char allowed_exit_value) { int was_sig = WIFSIGNALED(status); int was_exit = WIFEXITED(status); - int exit_status = WEXITSTATUS(status); + signed char exit_status = WEXITSTATUS(status); int signal_received = WTERMSIG(status); if (was_sig) {