From ce00b1e73630c810a55481c3ed535a63b443b5fc Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Tue, 8 Feb 2011 18:01:37 +0100 Subject: [PATCH] forb: Add test for various invocation methods This tests the following: 1) remote invocation (currently broken) 2) local invocation from application to the executor 3) local invocation from an executor to another one 4) direct invocation from an executor to the same one --- src/tests/executor/Makefile | 14 ++++ src/tests/executor/Makefile.omk | 8 ++ src/tests/executor/executor_test.c | 108 +++++++++++++++++++++++++++ src/tests/executor/executor_test.idl | 6 ++ 4 files changed, 136 insertions(+) create mode 100644 src/tests/executor/Makefile create mode 100644 src/tests/executor/Makefile.omk create mode 100644 src/tests/executor/executor_test.c create mode 100644 src/tests/executor/executor_test.idl diff --git a/src/tests/executor/Makefile b/src/tests/executor/Makefile new file mode 100644 index 0000000..d538d21 --- /dev/null +++ b/src/tests/executor/Makefile @@ -0,0 +1,14 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory: `pwd`\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + diff --git a/src/tests/executor/Makefile.omk b/src/tests/executor/Makefile.omk new file mode 100644 index 0000000..8e52340 --- /dev/null +++ b/src/tests/executor/Makefile.omk @@ -0,0 +1,8 @@ +wvtest_PROGRAMS = executor_test +executor_test_SOURCES = executor_test.c +executor_test_SERVER_IDL = executor_test.idl +executor_test_CLIENT_IDL = executor_test.idl + +INCLUDES += -I. + +lib_LOADLIBES = forb ulut fosa rt wvtest diff --git a/src/tests/executor/executor_test.c b/src/tests/executor/executor_test.c new file mode 100644 index 0000000..77b80ee --- /dev/null +++ b/src/tests/executor/executor_test.c @@ -0,0 +1,108 @@ +#include +#include +#define WVTEST_CONFIGURED +#include +#include +#include + +static CORBA_long add(executor_test obj, CORBA_long val, CORBA_Environment *ev) +{ + int to_add = (intptr_t)forb_object_instance_data(obj); + return val + to_add; +} + +static CORBA_long add_indirect(executor_test obj, executor_test indirect_obj, CORBA_long val, CORBA_Environment *ev) +{ + return executor_test_add(indirect_obj, val, ev); +} + +static const struct forb_executor_test_impl executor_test_impl = { + .add = add, + .add_indirect = add_indirect, +}; + + +void *executor_thread(void *arg) +{ + forb_executor_t *executor = arg; + forb_executor_run(executor); + return NULL; +} + +WVTEST_MAIN("remote (inter-server) invocation") +{ + forb_orb orb1, orb2; + fosa_thread_id_t tid; + executor_test testobj, remote_obj; + forb_executor_t executor; + char *str; + struct forb_env env; + + /* Create the first FORB server */ + WVPASS(orb1 = forb_init(NULL, NULL, + &(struct forb_init_attr){.orb_id = "server1"})); + + /* This object adds 1 to the argument of add() */ + WVPASS(testobj = forb_executor_test_new(orb1, &executor_test_impl, (void*)1)); + WVPASSEQ(forb_executor_init(&executor), 0); + WVPASSEQ(forb_executor_register_object(&executor, testobj), 0); + + /* Execute executor in a separate thread */ + fosa_thread_create(&tid, NULL, executor_thread, &executor); + + /* Create the second FORB server in the same process */ + WVPASS(orb2 = forb_init(NULL, NULL, + &(struct forb_init_attr){.orb_id = "server2"})); + + str = forb_object_to_string(testobj); + remote_obj = forb_string_to_object(orb2, str); + + WVPASS(forb_object_is_local(testobj)); + WVFAIL(forb_object_is_local(remote_obj)); + + /* Remote invocation of the object */ + WVPASSEQ(executor_test_add(remote_obj, 1, &env), 2); + WVFAIL(forb_exception_occurred(&env)); +} + +WVTEST_MAIN("inter_thread_invocation") +{ + forb_orb orb; + fosa_thread_id_t tid1, tid2; + executor_test testobj1, testobj2; + forb_executor_t executor1, executor2; + struct forb_env env; + + /* Create the first FORB server */ + WVPASS(orb = forb_init(NULL, NULL, + &(struct forb_init_attr){.orb_id = "server"})); + + /* This object adds 1 to the argument of add() */ + WVPASS(testobj1 = forb_executor_test_new(orb, &executor_test_impl, (void*)1)); + WVPASSEQ(forb_executor_init(&executor1), 0); + WVPASSEQ(forb_executor_register_object(&executor1, testobj1), 0); + + /* This object adds 2 to the argument of add() */ + WVPASS(testobj2 = forb_executor_test_new(orb, &executor_test_impl, (void*)2)); + WVPASSEQ(forb_executor_init(&executor2), 0); + WVPASSEQ(forb_executor_register_object(&executor2, testobj2), 0); + + /* Execute executors in separate threads */ + fosa_thread_create(&tid1, NULL, executor_thread, &executor1); + fosa_thread_create(&tid2, NULL, executor_thread, &executor2); + + WVPASS(forb_object_is_local(testobj1)); + WVPASS(forb_object_is_local(testobj2)); + + /* Inter-thread invocation: application->executor */ + WVPASSEQ(executor_test_add(testobj1, 1, &env), 2); + WVFAIL(forb_exception_occurred(&env)); + + /* Inter-thread invocation: (application->)executor->executor */ + WVPASSEQ(executor_test_add_indirect(testobj1, testobj2, 1, &env), 3); + WVFAIL(forb_exception_occurred(&env)); + + /* Direct invocation in the same executor: (application->)executor->executor */ + WVPASSEQ(executor_test_add_indirect(testobj1, testobj1, 1, &env), 2); + WVFAIL(forb_exception_occurred(&env)); +} diff --git a/src/tests/executor/executor_test.idl b/src/tests/executor/executor_test.idl new file mode 100644 index 0000000..7aaf9d9 --- /dev/null +++ b/src/tests/executor/executor_test.idl @@ -0,0 +1,6 @@ +interface executor_test { + // Adds some number the value @a val + long add(in long val); + // Adds some number the value @a val by calling @a add method of indirect_obj + long add_indirect(in executor_test indirect_obj, in long val); +}; -- 2.39.2