]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
Prepared test cases for executors (thread specific data) benesp16
authorPetr Beneš <petr@petr-nb.(none)>
Tue, 25 Jan 2011 16:13:36 +0000 (17:13 +0100)
committerPetr Beneš <petr@petr-nb.(none)>
Tue, 25 Jan 2011 16:13:36 +0000 (17:13 +0100)
tests/executor_id.c as a simple test
tests/executor_calls.c as a manually created stub

src/tests/Makefile.omk
src/tests/executor_calls.c [new file with mode: 0644]
src/tests/executor_id.c [new file with mode: 0644]

index a81f8844dfe8240bc5d76f02ed25066feec568ee..d3fa45dc36e6ea34f7ad2d39882fafa22b268db1 100644 (file)
@@ -1,7 +1,7 @@
 SUBDIRS = $(ALL_OMK_SUBDIRS)
 
 test_PROGRAMS += hello_inproc hello_remote test_proto_inet discovery   \
-               syncobj regobjref
+               syncobj regobjref executor_id #executor_calls
 ifeq ($(CONFIG_FORB_PROTO_UNIX),y)
 test_PROGRAMS += test_proto_unix
 endif
@@ -44,3 +44,7 @@ test_proto_inet_SOURCES = test_proto_inet.c
 discovery_SOURCES = discovery.c
 
 syncobj_SOURCES = test_syncobj.c
+
+executor_id_SOURCES = executor_id.c
+
+executor_calls_SOURCES = executor_calls.c
\ No newline at end of file
diff --git a/src/tests/executor_calls.c b/src/tests/executor_calls.c
new file mode 100644 (file)
index 0000000..896c2d9
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * This file was generated by forb-idl but now it is a test
+ */
+
+#include <string.h>
+#include <forb/forb-internal.h>
+#include <forb/request.h>
+#include <forb/iop.h>
+#include <forb/cdr.h>
+#include <forb/object.h>
+
+#include "myinterface.h"
+
+#define ex_on_fail(command, ex) if (!(command)) do { ev->major = (ex); goto exception; } while(0)
+#define FORB_REQEST_HDR_SIZE (forb_iop_MESSAGE_HEADER_SIZE + forb_iop_REQUEST_HEADER_SIZE)
+
+#define _myinterface_impl(obj) ((struct forb_myinterface_impl*)(obj)->implementation)
+
+CORBA_long myinterface_add(myinterface _obj, const CORBA_long a, const CORBA_long b, CORBA_Environment *ev)
+{
+  CORBA_long _forb_retval;
+  executor *exec_current;
+  if (ev) ev->major = FORB_EX_NONE;
+  /* local object */
+  if (forb_object_is_local(_obj)) {
+    if (!_obj->interface ||
+        strncmp(_obj->interface->name, "myinterface", 11) != 0) {
+      ev->major = FORB_EX_BAD_OPERATION;
+      return _forb_retval;
+    }
+    if (!forb_get_current_executor(exec_current) && (forb_object_get_executor(_obj) == exec_current))
+      /* direct invocation */
+      _forb_retval = _myinterface_impl(_obj)->add(_obj, a, b, ev);
+    } else {
+      /* TODO inter-thread invocation*/
+    }
+  } else {
+    /* remote object - the same as before */
+    forb_request_t req;
+    ex_on_fail(forb_request_init(&req, _obj) == 0, FORB_EX_INTERNAL);
+    forb_iop_prepare_request(&req, "myinterface", FORB_METHOD_INDEX(myinterface_add), ev);
+    if (forb_exception_occurred(ev)) goto exception;
+    ex_on_fail(CORBA_long_serialize(&req.cdr_request, &a), FORB_EX_IMP_LIMIT);
+    ex_on_fail(CORBA_long_serialize(&req.cdr_request, &b), FORB_EX_IMP_LIMIT);
+    forb_request_send(&req, ev);
+    if (forb_exception_occurred(ev)) goto exception;
+    forb_request_wait_for_reply(&req);
+    if (forb_exception_occurred(ev)) goto exception;
+    CORBA_long_deserialize(req.cdr_reply, &_forb_retval);
+    forb_request_signal_processed(&req);
+exception:
+    forb_request_destroy(&req);
+  }
+  return _forb_retval;
+}
+
diff --git a/src/tests/executor_id.c b/src/tests/executor_id.c
new file mode 100644 (file)
index 0000000..1aace5b
--- /dev/null
@@ -0,0 +1,100 @@
+/**************************************************************************/
+/* ---------------------------------------------------------------------- */
+/* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                */
+/*                                                                       */
+/*   Universidad de Cantabria,              SPAIN                        */
+/*   University of York,                    UK                           */
+/*   Scuola Superiore Sant'Anna,            ITALY                        */
+/*   Kaiserslautern University,             GERMANY                      */
+/*   Univ. Politécnica  Valencia,           SPAIN                       */
+/*   Czech Technical University in Prague,  CZECH REPUBLIC               */
+/*   ENEA                                   SWEDEN                       */
+/*   Thales Communication S.A.              FRANCE                       */
+/*   Visual Tools S.A.                      SPAIN                        */
+/*   Rapita Systems Ltd                     UK                           */
+/*   Evidence                               ITALY                        */
+/*                                                                       */
+/*   See http://www.frescor.org for a link to partners' websites         */
+/*                                                                       */
+/*          FRESCOR project (FP6/2005/IST/5-034026) is funded            */
+/*       in part by the European Union Sixth Framework Programme         */
+/*       The European Union is not liable of any use that may be         */
+/*       made of this code.                                              */
+/*                                                                       */
+/*                                                                       */
+/*  This file is part of FORB (Frescor Object Request Broker)            */
+/*                                                                       */
+/* FORB is free software; you can redistribute it and/or modify it       */
+/* under terms of the GNU General Public License as published by the     */
+/* Free Software Foundation; either version 2, or (at your option) any   */
+/* later version.  FORB is distributed in the hope that it will be       */
+/* useful, but WITHOUT ANY WARRANTY; without even the implied warranty   */
+/* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   */
+/* General Public License for more details. You should have received a   */
+/* copy of the GNU General Public License along with FORB; see file      */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
+/* Cambridge, MA 02139, USA.                                             */
+/*                                                                       */
+/* As a special exception, including FORB header files in a file,        */
+/* instantiating FORB generics or templates, or linking other files      */
+/* with FORB objects to produce an executable application, does not      */
+/* by itself cause the resulting executable application to be covered    */
+/* by the GNU General Public License. This exception does not            */
+/* however invalidate any other reasons why the executable file might be  */
+/* covered by the GNU Public License.                                    */
+/**************************************************************************/
+
+/**
+ * @file   discovery.c
+ * @author Petr Benes <benesp16@fel.cvut.cz>
+ * @date   Sun Oct 12 19:05:27 2008
+ * 
+ * @brief  Test for running executor identification.
+ * 
+ */
+
+#include <stdbool.h>
+#include <forb.h>
+#include <forb/object.h>
+#include <forb/forb-internal.h>
+#include <forb/config.h>
+#include <unistd.h>
+#include "../proto.h"
+#include "../discovery.h"
+#include <error.h>
+#include <fosa.h>
+#include <stdio.h>
+
+#if !CONFIG_FORB_PROTO_UNIX && !CONFIG_FORB_PROTO_INET_DEFAULT
+#error This test should only work if there is some local protocol enabled.
+#endif
+
+int main(int argc, char *argv[])
+{
+       forb_orb orb;
+       forb_executor_t *executor;
+       //forb_executor_t *my_executor;
+
+       orb = forb_init(&argc, &argv, NULL);
+       if (!orb) {
+               error(1, errno, "Test: Orb was not created\n");
+       }
+       else {
+               printf("Test: Orb initialized\n");
+       }
+
+       // ------------------------------------------------------
+       if (forb_get_current_executor(&executor)) {
+               printf("Test: Error while getting current executor\n");
+               if (executor == NULL)
+               printf("Test: Executor: NULL\n");
+       }
+       else
+               printf("Test: Executor: %p\n", executor);
+       
+       printf("Test: ORB executor: %p\n", orb->executor);
+       
+       forb_executor_run(orb->executor);
+       
+       return 0;
+}