]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/tests/executor/executor_test.c
2049a5c107502103bb1186ee0e60d9cc67af1a1b
[frescor/forb.git] / src / tests / executor / executor_test.c
1 #include <forb.h>
2 #include <executor_test.h>
3 #define WVTEST_CONFIGURED
4 #include <wvtest.h>
5 #include <forb/executor.h>
6 #include <forb/object.h>
7 #include <forb/iop.h>
8
9 static CORBA_long add(executor_test obj, CORBA_long val, CORBA_Environment *ev)
10 {
11         int to_add = (intptr_t)forb_object_instance_data(obj);
12         return val + to_add;
13 }
14
15 static CORBA_long add_indirect(executor_test obj, executor_test indirect_obj, CORBA_long val, CORBA_Environment *ev)
16 {
17         return executor_test_add(indirect_obj, val, ev);
18 }
19
20 static const struct forb_executor_test_impl executor_test_impl = {
21         .add = add,
22         .add_indirect = add_indirect,
23 };
24
25
26 void *executor_thread(void *arg)
27 {
28         forb_executor_t *executor = arg;
29         forb_executor_run(executor);
30         return NULL;
31 }
32
33 // WVTEST_MAIN("remote (inter-server) invocation")
34 // {
35 //      forb_orb orb1, orb2;
36 //      fosa_thread_id_t tid;
37 //      executor_test testobj, remote_obj;
38 //      forb_executor_t executor;
39 //      char *str;
40 //      struct forb_env env;
41 // 
42 //      /* Create the first FORB server */
43 //      WVPASS(orb1 = forb_init(NULL, NULL,
44 //                              &(struct forb_init_attr){.orb_id = "server1"}));
45 // 
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);
50 // 
51 //      /* Execute executor in a separate thread */
52 //      fosa_thread_create(&tid, NULL, executor_thread, &executor);
53 // 
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"}));
57 // 
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
61 // 
62 //      WVPASS(forb_object_is_local(testobj));
63 //      WVFAIL(forb_object_is_local(remote_obj));
64 // 
65 //      /* Remote invocation of the object */
66 //      WVPASSEQ(executor_test_add(remote_obj, 1, &env), 2);
67 //      WVFAIL(forb_exception_occurred(&env));
68 // }
69
70 WVTEST_MAIN("inter_thread_invocation")
71 {
72         forb_orb orb;
73         fosa_thread_id_t tid1, tid2;
74         executor_test testobj1, testobj2;
75         forb_executor_t executor1, executor2;
76         struct forb_env env;
77
78         /* Create the first FORB server */
79         WVPASS(orb = forb_init(NULL, NULL,
80                                &(struct forb_init_attr){.orb_id = "server"}));
81
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);
86
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);
91
92         /* Execute executors in separate threads */
93         fosa_thread_create(&tid1, NULL, executor_thread, &executor1);
94         fosa_thread_create(&tid2, NULL, executor_thread, &executor2);
95
96         WVPASS(forb_object_is_local(testobj1));
97         WVPASS(forb_object_is_local(testobj2));
98
99         /* Inter-thread invocation: application->executor */
100         WVPASSEQ(executor_test_add(testobj1, 2, &env), 3);
101         WVFAIL(forb_exception_occurred(&env));
102
103         /* Inter-thread invocation: (application->)executor->executor */
104         WVPASSEQ(executor_test_add_indirect(testobj1, testobj2, 1, &env), 3);
105         WVFAIL(forb_exception_occurred(&env));
106
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));
110 }