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