]> granicus.if.org Git - check/commitdiff
change expected exit values of tests to consistently be signed chars
authorbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Sat, 25 Jan 2014 18:18:08 +0000 (18:18 +0000)
committerbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Sat, 25 Jan 2014 18:18:08 +0000 (18:18 +0000)
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

src/check.c
src/check_impl.h
src/check_run.c

index 862da376ab6ea1895ecf7ca61f226920b9cae7a1..4da6c37a0ee1365cd29b7989523930e07bdbdea9 100644 (file)
 #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);
 }
index cef3e7547bc16c981c27377c88606f45e293f56e..2f7d987b88688b7e7cd379c2b9d2a913f59f212f 100644 (file)
@@ -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 {
index 032e86e4e98cf8ead2d72ed4cc6d9d903ee4f232..d6795c17c2e4c1365d7f9c1bd6b4b737993b9c94 100644 (file)
@@ -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) {