2 #include <executor_test.h>
3 #define WVTEST_CONFIGURED
5 #include <forb/executor.h>
6 #include <forb/object.h>
8 static CORBA_long add(executor_test obj, CORBA_long val, CORBA_Environment *ev)
10 int to_add = (intptr_t)forb_object_instance_data(obj);
14 static CORBA_long add_indirect(executor_test obj, executor_test indirect_obj, CORBA_long val, CORBA_Environment *ev)
16 return executor_test_add(indirect_obj, val, ev);
19 static const struct forb_executor_test_impl executor_test_impl = {
21 .add_indirect = add_indirect,
25 void *executor_thread(void *arg)
27 forb_executor_t *executor = arg;
28 forb_executor_run(executor);
32 WVTEST_MAIN("remote (inter-server) invocation")
36 executor_test testobj, remote_obj;
37 forb_executor_t executor;
41 /* Create the first FORB server */
42 WVPASS(orb1 = forb_init(NULL, NULL,
43 &(struct forb_init_attr){.orb_id = "server1"}));
45 /* This object adds 1 to the argument of add() */
46 WVPASS(testobj = forb_executor_test_new(orb1, &executor_test_impl, (void*)1));
47 WVPASSEQ(forb_executor_init(&executor), 0);
48 WVPASSEQ(forb_executor_register_object(&executor, testobj), 0);
50 /* Execute executor in a separate thread */
51 fosa_thread_create(&tid, NULL, executor_thread, &executor);
53 /* Create the second FORB server in the same process */
54 WVPASS(orb2 = forb_init(NULL, NULL,
55 &(struct forb_init_attr){.orb_id = "server2"}));
57 str = forb_object_to_string(testobj);
58 remote_obj = forb_string_to_object(orb2, str);
60 WVPASS(forb_object_is_local(testobj));
61 WVFAIL(forb_object_is_local(remote_obj));
63 /* Remote invocation of the object */
64 WVPASSEQ(executor_test_add(remote_obj, 1, &env), 2);
65 WVFAIL(forb_exception_occurred(&env));
68 WVTEST_MAIN("inter_thread_invocation")
71 fosa_thread_id_t tid1, tid2;
72 executor_test testobj1, testobj2;
73 forb_executor_t executor1, executor2;
76 /* Create the first FORB server */
77 WVPASS(orb = forb_init(NULL, NULL,
78 &(struct forb_init_attr){.orb_id = "server"}));
80 /* This object adds 1 to the argument of add() */
81 WVPASS(testobj1 = forb_executor_test_new(orb, &executor_test_impl, (void*)1));
82 WVPASSEQ(forb_executor_init(&executor1), 0);
83 WVPASSEQ(forb_executor_register_object(&executor1, testobj1), 0);
85 /* This object adds 2 to the argument of add() */
86 WVPASS(testobj2 = forb_executor_test_new(orb, &executor_test_impl, (void*)2));
87 WVPASSEQ(forb_executor_init(&executor2), 0);
88 WVPASSEQ(forb_executor_register_object(&executor2, testobj2), 0);
90 /* Execute executors in separate threads */
91 fosa_thread_create(&tid1, NULL, executor_thread, &executor1);
92 fosa_thread_create(&tid2, NULL, executor_thread, &executor2);
94 WVPASS(forb_object_is_local(testobj1));
95 WVPASS(forb_object_is_local(testobj2));
97 /* Inter-thread invocation: application->executor */
98 WVPASSEQ(executor_test_add(testobj1, 1, &env), 2);
99 WVFAIL(forb_exception_occurred(&env));
101 /* Inter-thread invocation: (application->)executor->executor */
102 WVPASSEQ(executor_test_add_indirect(testobj1, testobj2, 1, &env), 3);
103 WVFAIL(forb_exception_occurred(&env));
105 /* Direct invocation in the same executor: (application->)executor->executor */
106 WVPASSEQ(executor_test_add_indirect(testobj1, testobj1, 1, &env), 2);
107 WVFAIL(forb_exception_occurred(&env));