]> granicus.if.org Git - check/commitdiff
Ensure that each subprocesses alloc the correct msg queue
authoramalec <amalec@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Sat, 1 Sep 2001 00:12:51 +0000 (00:12 +0000)
committeramalec <amalec@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Sat, 1 Sep 2001 00:12:51 +0000 (00:12 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@89 64e312b2-a51f-0410-8e61-82d0ca0eb02a

check/src/check.c
check/src/check_msg.c
check/src/check_msg.h
check/src/check_run.c

index 99765b1a7165c9c33fb2b5a8450e35517b9180f5..da719027d3ac6592791b4491565e48be1e842c54 100644 (file)
@@ -104,7 +104,7 @@ void tcase_fn_start (char *fname, char *file, int line)
 {
   int msqid;
 
-  msqid = get_msq();
+  msqid = get_send_msq();
   send_last_loc_msg (msqid, file, line);
 }
 
@@ -112,7 +112,7 @@ void _mark_point (char *file, int line)
 {
   int msqid;
 
-  msqid = get_msq();
+  msqid = get_send_msq();
   send_last_loc_msg (msqid, file, line);
 }
 
@@ -120,7 +120,7 @@ void _fail_unless (int result, char *file, int line, char * msg)
 {
   int msqid;
 
-  msqid = get_msq();
+  msqid = get_send_msq();
   if (line > MAXLINE)
     eprintf ("Line number %d too large to use", line);
 
index 37a4082e7a7674468faadbcef166a179a1a50698..8618941092f6a1045266fa73bc16d4e8cc565b5f 100644 (file)
@@ -39,7 +39,8 @@ enum {
 };
 static LastLocMsg *create_last_loc_msg (char *file, int line);
 static FailureMsg *create_failure_msg (char *msg);
-static key_t get_key(void);
+static int get_msq (key_t key);
+static char *ipcerrstr (int ipcerr);
 
 static FailureMsg *create_failure_msg (char *msg)
 {
@@ -102,36 +103,33 @@ void send_last_loc_msg (int msqid, char * file, int line)
   free(rmsg);
 }
 
-static char *ipcerrstr (int ipcerr) 
-{
-  switch (ipcerr) {
-  case EACCES: return "EACCES";
-  case EEXIST: return "EEXIST";
-  case EIDRM: return "EIDRM";
-  case ENOENT: return "ENOENT";
-  case ENOMEM: return "ENOMEM";
-  case ENOSPC: return "ENOSPC";
-  default: return "None";
-  }
-}
-
-
 int init_msq (void) {
   int msqid;
 
-  msqid = msgget(get_key(), 0666 | IPC_CREAT);
+  msqid = msgget(init_key(), 0666 | IPC_CREAT);
   if (msqid == -1)
     eprintf ("Unable to create message queue (%s):", ipcerrstr(errno));
   return msqid;
 }
 
-int get_msq (void) 
+int get_recv_msq (void)
+{
+  return get_msq ((key_t) recv_key());
+}
+
+int get_send_msq (void)
+{
+  return get_msq ((key_t) send_key());
+}
+
+
+static int get_msq (key_t key)
 {
   int msqid;
   
-  msqid = msgget (get_key(), 0666);
+  msqid = msgget (key, 0666);
   if (msqid == -1)
-    eprintf ("Unable to create message queue (%s):", ipcerrstr(errno));
+    eprintf ("Unable to get message queue (%s):", ipcerrstr(errno));
   return msqid;
 }
 
@@ -139,7 +137,7 @@ void delete_msq (void)
 {
   int msqid;
 
-  msqid = get_msq();
+  msqid = get_msq((key_t) init_key());
   if (msgctl (msqid, IPC_RMID, NULL) == -1)
     eprintf ("Failed to free message queue:");
 }
@@ -185,10 +183,33 @@ FailureMsg *receive_failure_msg (int msqid)
   return rmsg;
 }
 
-static key_t get_key (void)
+int init_key(void)
+{
+  return getpid();
+}
+
+int send_key(void)
+{
+  return getppid();
+}
+
+int recv_key(void)
+{
+  return getpid();
+}
+
+static char *ipcerrstr (int ipcerrno)
 {
-  if (is_child())
-    return (key_t) getppid();
-  else
-    return (key_t) getpid();
+  /* Debian sid has broken error reporting for IPC */
+  switch (errno) {
+  case EACCES: return "EACCES";
+  case EEXIST: return "EEXIST";
+  case EIDRM: return "EIDRM";
+  case ENOENT: return "ENOENT";
+  case ENOMEM: return "ENOMEM";
+  case ENOSPC: return "ENOSPC";
+  default: return "Other";
+  }
 }
+
+    
index 19d4235fc7346e617e18a8dcd0943ceb3e3ef2e8..02db392e6af83fcedb7f57c4a761f2d66516e846 100644 (file)
@@ -34,9 +34,6 @@ typedef struct FailureMsg {
   char msg[CMAXMSG];
 } FailureMsg;
 
-int init_msq (void);
-int get_msq (void);
-void delete_msq (void);
 
 void send_failure_msg (int msqid, char *msg);
 void send_last_loc_msg (int msqid, char * file, int line);
@@ -51,4 +48,13 @@ LastLocMsg *receive_last_loc_msg (int msqid);
 char *last_loc_file(LastLocMsg *msg);
 int last_loc_line(LastLocMsg *msg);
 
+int init_msq (void);
+void delete_msq (void);
+
+int get_recv_msq (void);
+int get_send_msq (void);
+int init_key (void);
+int send_key (void);
+int recv_key (void);
+
 #endif /*CHECK_MSG_H */
index 7f105b7a6625181153862bc6a6024c85846a9c06..4fa8cb2d746f6274f8b7901bccf5ab7e66c3161d 100644 (file)
 #include "check_run.h"
 
 
+static void srunner_run_init (SRunner *sr, enum print_verbosity print_mode);
+static void srunner_run_end (SRunner *sr, enum print_verbosity print_mode);
+static void srunner_iterate_suites (SRunner *sr,
+                                   enum print_verbosity print_mode);
 static void srunner_run_tcase (SRunner *sr, TCase *tc);
 static void srunner_add_failure (SRunner *sr, TestResult *tf);
 static TestResult *tfun_run (char *tcname, TF *tf);
@@ -39,7 +43,6 @@ static TestResult *receive_result_info (int msqid, int status, char *tcname);
 static void receive_last_loc_info (int msqid, TestResult *tr);
 static void receive_failure_info (int msqid, int status, TestResult *tr);
 static List *srunner_resultlst (SRunner *sr);
-int _is_child = 0;
 
 static char *signal_msg (int sig);
 static char *exit_msg (int exitstatus);
@@ -85,23 +88,28 @@ void srunner_free (SRunner *sr)
   list_free (sr->resultlst);
 
   free (sr);
-} 
+}
 
+static void srunner_run_init (SRunner *sr, enum print_verbosity print_mode)
+{
+  srunner_init_logging (sr, print_mode);
+  log_srunner_start (sr);
+}
 
+static void srunner_run_end (SRunner *sr, enum print_verbosity print_mode)
+{
 
-void srunner_run_all (SRunner *sr, int print_mode)
+  log_srunner_end (sr);
+  srunner_end_logging (sr);
+}
+
+static void srunner_iterate_suites (SRunner *sr,
+                                   enum print_verbosity print_mode)
+  
 {
   List *slst;
   List *tcl;
   TCase *tc;
-  if (sr == NULL)
-    return;
-  if (print_mode < 0 || print_mode >= CRLAST)
-    eprintf("Bad print_mode argument to srunner_run_all: %d", print_mode);
-
-  srunner_init_logging (sr, print_mode);
-
-  log_srunner_start (sr);
 
   slst = sr->slst;
   
@@ -117,10 +125,18 @@ void srunner_run_all (SRunner *sr, int print_mode)
       srunner_run_tcase (sr, tc);
     }
   }
+}
 
-  log_srunner_end (sr);
-
-  srunner_end_logging (sr);
+void srunner_run_all (SRunner *sr, int print_mode)
+{
+  if (sr == NULL)
+    return;
+  if (print_mode < 0 || print_mode >= CRLAST)
+    eprintf("Bad print_mode argument to srunner_run_all: %d", print_mode);
+      
+  srunner_run_init (sr, print_mode);
+  srunner_iterate_suites (sr, print_mode);
+  srunner_run_end (sr, print_mode);
 }
 
 static void srunner_add_failure (SRunner *sr, TestResult *tr)
@@ -215,7 +231,7 @@ static TestResult *receive_result_info (int msqid, int status, char *tcname)
 {
   TestResult *tr = emalloc (sizeof(TestResult));
 
-  msqid = get_msq();
+  msqid = get_recv_msq();
   tr->tcname = tcname;
   receive_last_loc_info (msqid, tr);
   receive_failure_info (msqid, status, tr);
@@ -228,13 +244,12 @@ static TestResult *tfun_run (char *tcname, TF *tfun)
   int status = 0;
   int  msqid;
 
-  msqid = get_msq();
+  msqid = get_recv_msq();
 
   pid = fork();
   if (pid == -1)
      eprintf ("Unable to fork:");
   if (pid == 0) {
-    _is_child = 1;
     tfun->fn();
     _exit(EXIT_SUCCESS);
   }
@@ -334,8 +349,3 @@ static int non_pass (int val)
 {
   return val == CRFAILURE || val == CRERROR;
 }
-
-int is_child (void)
-{
-  return _is_child;
-}