2 #include <executor_test.h>
3 #define WVTEST_CONFIGURED
5 #include <forb/executor.h>
6 #include <forb/object.h>
10 static CORBA_long add(executor_test obj, CORBA_long val, CORBA_Environment *ev)
12 int to_add = (intptr_t)forb_object_instance_data(obj);
16 static CORBA_long add_indirect(executor_test obj, executor_test indirect_obj, CORBA_long val, CORBA_Environment *ev)
18 return executor_test_add(indirect_obj, val, ev);
21 static const struct forb_executor_test_impl executor_test_impl = {
23 .add_indirect = add_indirect,
27 void *executor_thread(void *arg)
29 forb_executor_t *executor = arg;
30 forb_executor_run(executor);
34 // WVTEST_MAIN("remote (inter-server) invocation")
36 // forb_orb orb1, orb2;
37 // fosa_thread_id_t tid;
38 // executor_test testobj, remote_obj;
39 // forb_executor_t executor;
41 // struct forb_env env;
43 // /* Create the first FORB server */
44 // WVPASS(orb1 = forb_init(NULL, NULL,
45 // &(struct forb_init_attr){.orb_id = "server1"}));
47 // /* This object adds 1 to the argument of add() */
48 // WVPASS(testobj = forb_executor_test_new(orb1, &executor_test_impl, (void*)1));
49 // WVPASSEQ(forb_executor_init(&executor), 0);
50 // WVPASSEQ(forb_executor_register_object(&executor, testobj), 0);
52 // /* Execute executor in a separate thread */
53 // fosa_thread_create(&tid, NULL, executor_thread, &executor);
55 // /* Create the second FORB server in the same process */
56 // WVPASS(orb2 = forb_init(NULL, NULL,
57 // &(struct forb_init_attr){.orb_id = "server2"}));
59 // str = forb_object_to_string(testobj);
60 // remote_obj = forb_string_to_object(orb2, str);
61 // //FIXME: the remote forb orb2 does not have any specified argument needeed for the add function
63 // WVPASS(forb_object_is_local(testobj));
64 // WVFAIL(forb_object_is_local(remote_obj));
66 // /* Remote invocation of the object */
67 // WVPASSEQ(executor_test_add(remote_obj, 1, &env), 2);
68 // WVFAIL(forb_exception_occurred(&env));
71 WVTEST_MAIN("inter_thread_invocation")
74 fosa_thread_id_t tid1, tid2;
75 executor_test testobj1, testobj2;
76 forb_executor_t executor1, executor2;
79 ul_log_domain_arg2levels("all.7");
81 /* Create the first FORB server */
82 WVPASS(orb = forb_init(NULL, NULL,
83 &(struct forb_init_attr){.orb_id = "server"}));
85 /* This object adds 1 to the argument of add() */
86 WVPASS(testobj1 = forb_executor_test_new(orb, &executor_test_impl, (void*)1));
87 WVPASSEQ(forb_executor_init(&executor1), 0);
88 WVPASSEQ(forb_executor_register_object(&executor1, testobj1), 0);
90 /* This object adds 2 to the argument of add() */
91 WVPASS(testobj2 = forb_executor_test_new(orb, &executor_test_impl, (void*)2));
92 WVPASSEQ(forb_executor_init(&executor2), 0);
93 WVPASSEQ(forb_executor_register_object(&executor2, testobj2), 0);
95 /* Execute executors in separate threads */
96 fosa_thread_create(&tid1, NULL, executor_thread, &executor1);
97 fosa_thread_create(&tid2, NULL, executor_thread, &executor2);
99 WVPASS(forb_object_is_local(testobj1));
100 WVPASS(forb_object_is_local(testobj2));
102 /* Inter-thread invocation: application->executor */
103 WVPASSEQ(executor_test_add(testobj1, 2, &env), 3);
104 WVFAIL(forb_exception_occurred(&env));
106 /* Inter-thread invocation: (application->)executor->executor */
107 WVPASSEQ(executor_test_add_indirect(testobj1, testobj2, 1, &env), 3);
108 WVFAIL(forb_exception_occurred(&env));
110 /* Direct invocation in the same executor: (application->)executor->executor */
111 WVPASSEQ(executor_test_add_indirect(testobj1, testobj1, 1, &env), 2);
112 WVFAIL(forb_exception_occurred(&env));