2 #include <executor_test.h>
3 #define WVTEST_CONFIGURED
5 #include <forb/executor.h>
6 #include <forb/object.h>
9 static CORBA_long add(executor_test obj, CORBA_long val, CORBA_Environment *ev)
11 int to_add = (intptr_t)forb_object_instance_data(obj);
15 static CORBA_long add_indirect(executor_test obj, executor_test indirect_obj, CORBA_long val, CORBA_Environment *ev)
17 return executor_test_add(indirect_obj, val, ev);
20 static const struct forb_executor_test_impl executor_test_impl = {
22 .add_indirect = add_indirect,
26 void *executor_thread(void *arg)
28 forb_executor_t *executor = arg;
29 forb_executor_run(executor);
33 // WVTEST_MAIN("remote (inter-server) invocation")
35 // forb_orb orb1, orb2;
36 // fosa_thread_id_t tid;
37 // executor_test testobj, remote_obj;
38 // forb_executor_t executor;
40 // struct forb_env env;
42 // /* Create the first FORB server */
43 // WVPASS(orb1 = forb_init(NULL, NULL,
44 // &(struct forb_init_attr){.orb_id = "server1"}));
46 // /* This object adds 1 to the argument of add() */
47 // WVPASS(testobj = forb_executor_test_new(orb1, &executor_test_impl, (void*)1));
48 // WVPASSEQ(forb_executor_init(&executor), 0);
49 // WVPASSEQ(forb_executor_register_object(&executor, testobj), 0);
51 // /* Execute executor in a separate thread */
52 // fosa_thread_create(&tid, NULL, executor_thread, &executor);
54 // /* Create the second FORB server in the same process */
55 // WVPASS(orb2 = forb_init(NULL, NULL,
56 // &(struct forb_init_attr){.orb_id = "server2"}));
58 // str = forb_object_to_string(testobj);
59 // remote_obj = forb_string_to_object(orb2, str);
60 // //FIXME: the remote forb orb2 does not have any specified argument needeed for the add function
62 // WVPASS(forb_object_is_local(testobj));
63 // WVFAIL(forb_object_is_local(remote_obj));
65 // /* Remote invocation of the object */
66 // WVPASSEQ(executor_test_add(remote_obj, 1, &env), 2);
67 // WVFAIL(forb_exception_occurred(&env));
70 WVTEST_MAIN("inter_thread_invocation")
73 fosa_thread_id_t tid1, tid2;
74 executor_test testobj1, testobj2;
75 forb_executor_t executor1, executor2;
78 /* Create the first FORB server */
79 WVPASS(orb = forb_init(NULL, NULL,
80 &(struct forb_init_attr){.orb_id = "server"}));
82 /* This object adds 1 to the argument of add() */
83 WVPASS(testobj1 = forb_executor_test_new(orb, &executor_test_impl, (void*)1));
84 WVPASSEQ(forb_executor_init(&executor1), 0);
85 WVPASSEQ(forb_executor_register_object(&executor1, testobj1), 0);
87 /* This object adds 2 to the argument of add() */
88 WVPASS(testobj2 = forb_executor_test_new(orb, &executor_test_impl, (void*)2));
89 WVPASSEQ(forb_executor_init(&executor2), 0);
90 WVPASSEQ(forb_executor_register_object(&executor2, testobj2), 0);
92 /* Execute executors in separate threads */
93 fosa_thread_create(&tid1, NULL, executor_thread, &executor1);
94 fosa_thread_create(&tid2, NULL, executor_thread, &executor2);
96 WVPASS(forb_object_is_local(testobj1));
97 WVPASS(forb_object_is_local(testobj2));
99 /* Inter-thread invocation: application->executor */
100 WVPASSEQ(executor_test_add(testobj1, 2, &env), 3);
101 WVFAIL(forb_exception_occurred(&env));
103 /* Inter-thread invocation: (application->)executor->executor */
104 WVPASSEQ(executor_test_add_indirect(testobj1, testobj2, 1, &env), 3);
105 WVFAIL(forb_exception_occurred(&env));
107 /* Direct invocation in the same executor: (application->)executor->executor */
108 WVPASSEQ(executor_test_add_indirect(testobj1, testobj1, 1, &env), 2);
109 WVFAIL(forb_exception_occurred(&env));