| 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 | #include <string.h>
|
|---|
| 4 |
|
|---|
| 5 | #include <orbit/orbit.h>
|
|---|
| 6 |
|
|---|
| 7 | #include "test1.h"
|
|---|
| 8 |
|
|---|
| 9 | static CORBA_ORB orb;
|
|---|
| 10 | static GTimer *timer;
|
|---|
| 11 | static double bogomark = 0.0;
|
|---|
| 12 | static double elapsed_time;
|
|---|
| 13 |
|
|---|
| 14 | static void
|
|---|
| 15 | test_copy (void)
|
|---|
| 16 | {
|
|---|
| 17 | int i, j;
|
|---|
| 18 | #define ELEMS (sizeof (tc) / sizeof (tc[0]))
|
|---|
| 19 | CORBA_TypeCode tc[] = {
|
|---|
| 20 | TC_CORBA_octet,
|
|---|
| 21 | TC_CORBA_sequence_CORBA_octet,
|
|---|
| 22 | TC_CORBA_double,
|
|---|
| 23 | TC_CORBA_string,
|
|---|
| 24 | TC_CORBA_sequence_CORBA_string,
|
|---|
| 25 | TC_GIOP_TargetAddress
|
|---|
| 26 | };
|
|---|
| 27 | gpointer data [ELEMS];
|
|---|
| 28 | const char *test_string = "This is a sample string, for dupping";
|
|---|
| 29 |
|
|---|
| 30 | fprintf (stderr, "Testing copy...\n");
|
|---|
| 31 |
|
|---|
| 32 | for (i = 0; i < ELEMS; i++) {
|
|---|
| 33 | data [i] = ORBit_dynany_new_default (tc [i]);
|
|---|
| 34 |
|
|---|
| 35 | g_timer_reset (timer);
|
|---|
| 36 | for (j = 0; j < 1000; j++) {
|
|---|
| 37 | gpointer foo = ORBit_copy_value (data [i], tc [i]);
|
|---|
| 38 | CORBA_free (foo);
|
|---|
| 39 | }
|
|---|
| 40 | elapsed_time = g_timer_elapsed (timer, NULL);
|
|---|
| 41 | bogomark += elapsed_time;
|
|---|
| 42 | fprintf (stderr, " copy %20s : %g(ms)\n",
|
|---|
| 43 | tc[i]->repo_id == NULL ? "(null)" : tc[i]->repo_id,
|
|---|
| 44 | elapsed_time);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | fprintf (stderr, "Testing strdup ...\n");
|
|---|
| 48 |
|
|---|
| 49 | g_timer_reset (timer);
|
|---|
| 50 | for (i = 0; i < 10000; i++) {
|
|---|
| 51 | char *str = g_strdup (test_string);
|
|---|
| 52 | g_free (str);
|
|---|
| 53 | }
|
|---|
| 54 | elapsed_time = g_timer_elapsed (timer, NULL) / 10.0;
|
|---|
| 55 | bogomark += elapsed_time;
|
|---|
| 56 | fprintf (stderr, " g_strdup : %g(ns)\n", elapsed_time * 1000.0);
|
|---|
| 57 |
|
|---|
| 58 | g_timer_reset (timer);
|
|---|
| 59 | for (i = 0; i < 10000; i++) {
|
|---|
| 60 | char *str = CORBA_string_dup (test_string);
|
|---|
| 61 | CORBA_free (str);
|
|---|
| 62 | }
|
|---|
| 63 | elapsed_time = g_timer_elapsed (timer, NULL) / 10.0;
|
|---|
| 64 | bogomark += elapsed_time;
|
|---|
| 65 | fprintf (stderr, " CORBA_strdup : %g(ns)\n", elapsed_time * 1000.0);
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | static PortableServer_POA
|
|---|
| 69 | create_mult_id_poa (CORBA_Environment *ev)
|
|---|
| 70 | {
|
|---|
| 71 | PortableServer_POA rootpoa;
|
|---|
| 72 | PortableServer_POA retval;
|
|---|
| 73 | CORBA_PolicyList *policies;
|
|---|
| 74 |
|
|---|
| 75 | rootpoa = (PortableServer_POA)
|
|---|
| 76 | CORBA_ORB_resolve_initial_references (orb, "RootPOA", ev);
|
|---|
| 77 | g_assert (ev->_major == CORBA_NO_EXCEPTION);
|
|---|
| 78 |
|
|---|
| 79 | policies = CORBA_PolicyList__alloc ();
|
|---|
| 80 | policies->_maximum = 1;
|
|---|
| 81 | policies->_length = 1;
|
|---|
| 82 | policies->_buffer = CORBA_PolicyList_allocbuf (1);
|
|---|
| 83 | CORBA_sequence_set_release (policies, CORBA_TRUE);
|
|---|
| 84 |
|
|---|
| 85 | policies->_buffer[0] = (CORBA_Policy)
|
|---|
| 86 | PortableServer_POA_create_id_uniqueness_policy (
|
|---|
| 87 | rootpoa,
|
|---|
| 88 | PortableServer_MULTIPLE_ID,
|
|---|
| 89 | ev);
|
|---|
| 90 | g_assert (ev->_major == CORBA_NO_EXCEPTION);
|
|---|
| 91 |
|
|---|
| 92 | retval = PortableServer_POA_create_POA (rootpoa, "Multiple Id POA",
|
|---|
| 93 | NULL, policies, ev);
|
|---|
| 94 | g_assert (ev->_major == CORBA_NO_EXCEPTION);
|
|---|
| 95 |
|
|---|
| 96 | CORBA_Policy_destroy (policies->_buffer[0], ev);
|
|---|
| 97 | CORBA_free (policies);
|
|---|
| 98 |
|
|---|
| 99 | g_assert (ev->_major == CORBA_NO_EXCEPTION);
|
|---|
| 100 |
|
|---|
| 101 | CORBA_Object_release ((CORBA_Object) rootpoa, ev);
|
|---|
| 102 |
|
|---|
| 103 | g_assert (ev->_major == CORBA_NO_EXCEPTION);
|
|---|
| 104 |
|
|---|
| 105 | return retval;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | static PortableServer_ServantBase__epv base_epv = { NULL, NULL, NULL };
|
|---|
| 109 | static POA_Test__epv test_epv = { NULL, NULL };
|
|---|
| 110 | static POA_Test__vepv test_vepv = { &base_epv, &test_epv };
|
|---|
| 111 | static POA_Test test_servant = { NULL, &test_vepv };
|
|---|
| 112 |
|
|---|
| 113 | static void
|
|---|
| 114 | test_activation (void)
|
|---|
| 115 | {
|
|---|
| 116 | CORBA_Environment env;
|
|---|
| 117 | PortableServer_POA poa;
|
|---|
| 118 | GSList *objids = NULL, *l;
|
|---|
| 119 | int i;
|
|---|
| 120 |
|
|---|
| 121 | fprintf (stderr, "Testing object activation...\n");
|
|---|
| 122 |
|
|---|
| 123 | CORBA_exception_init (&env);
|
|---|
| 124 |
|
|---|
| 125 | POA_Test__init (&test_servant, &env);
|
|---|
| 126 |
|
|---|
| 127 | poa = create_mult_id_poa (&env);
|
|---|
| 128 |
|
|---|
| 129 | g_assert (env._major == CORBA_NO_EXCEPTION);
|
|---|
| 130 |
|
|---|
| 131 | g_timer_reset (timer);
|
|---|
| 132 |
|
|---|
| 133 | for (i = 0; i < 1000; i++) {
|
|---|
| 134 | PortableServer_ObjectId *objid;
|
|---|
| 135 |
|
|---|
| 136 | objid = PortableServer_POA_activate_object (poa, &test_servant, &env);
|
|---|
| 137 | g_assert (env._major == CORBA_NO_EXCEPTION);
|
|---|
| 138 |
|
|---|
| 139 | objids = g_slist_append (objids, objid);
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | elapsed_time = g_timer_elapsed (timer, NULL);
|
|---|
| 143 | bogomark += elapsed_time;
|
|---|
| 144 | fprintf (stderr, " activation : %g(ms)\n", elapsed_time);
|
|---|
| 145 |
|
|---|
| 146 | g_timer_reset (timer);
|
|---|
| 147 |
|
|---|
| 148 | for (l = objids; l; l = l->next) {
|
|---|
| 149 | PortableServer_POA_deactivate_object (poa, l->data, &env);
|
|---|
| 150 | g_assert (env._major == CORBA_NO_EXCEPTION);
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | elapsed_time = g_timer_elapsed (timer, NULL);
|
|---|
| 154 | bogomark += elapsed_time;
|
|---|
| 155 | fprintf (stderr, " de-activation : %g(ms)\n", elapsed_time);
|
|---|
| 156 |
|
|---|
| 157 | for (l = objids; l; l = l->next)
|
|---|
| 158 | CORBA_free (l->data);
|
|---|
| 159 | g_slist_free (objids);
|
|---|
| 160 |
|
|---|
| 161 | POA_Test__fini (&test_servant, &env);
|
|---|
| 162 |
|
|---|
| 163 | PortableServer_POA_destroy (poa, CORBA_FALSE, CORBA_FALSE, &env);
|
|---|
| 164 | g_assert (env._major == CORBA_NO_EXCEPTION);
|
|---|
| 165 | CORBA_Object_release ((CORBA_Object) poa, &env);
|
|---|
| 166 | g_assert (env._major == CORBA_NO_EXCEPTION);
|
|---|
| 167 |
|
|---|
| 168 | CORBA_exception_free (&env);
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | int
|
|---|
| 172 | main (int argc, char *argv[])
|
|---|
| 173 | {
|
|---|
| 174 | CORBA_Environment ev;
|
|---|
| 175 |
|
|---|
| 176 | free (malloc (8));
|
|---|
| 177 |
|
|---|
| 178 | CORBA_exception_init (&ev);
|
|---|
| 179 |
|
|---|
| 180 | timer = g_timer_new ();
|
|---|
| 181 | g_timer_start (timer);
|
|---|
| 182 |
|
|---|
| 183 | g_timer_reset (timer);
|
|---|
| 184 | orb = CORBA_ORB_init (&argc, argv, "orbit-local-orb", &ev);
|
|---|
| 185 | g_assert (ev._major == CORBA_NO_EXCEPTION);
|
|---|
| 186 | fprintf (stderr, "ORB: init took %g(ms)\n",
|
|---|
| 187 | (elapsed_time = g_timer_elapsed (timer, NULL)) * 1000.0);
|
|---|
| 188 | bogomark += elapsed_time;
|
|---|
| 189 |
|
|---|
| 190 | test_copy ();
|
|---|
| 191 |
|
|---|
| 192 | test_activation ();
|
|---|
| 193 |
|
|---|
| 194 | g_timer_reset (timer);
|
|---|
| 195 | CORBA_ORB_destroy (orb, &ev);
|
|---|
| 196 | g_assert (ev._major == CORBA_NO_EXCEPTION);
|
|---|
| 197 | fprintf (stderr, "ORB: destroy took %g(ms)\n",
|
|---|
| 198 | (elapsed_time = g_timer_elapsed (timer, NULL)) * 1000.0);
|
|---|
| 199 | bogomark += elapsed_time;
|
|---|
| 200 | g_timer_reset (timer);
|
|---|
| 201 |
|
|---|
| 202 | CORBA_Object_release ((CORBA_Object) orb, &ev);
|
|---|
| 203 | g_assert (ev._major == CORBA_NO_EXCEPTION);
|
|---|
| 204 |
|
|---|
| 205 | g_timer_destroy (timer);
|
|---|
| 206 |
|
|---|
| 207 | fprintf (stderr, "Overall bogomark %g\n", 1000.0 / bogomark);
|
|---|
| 208 |
|
|---|
| 209 | return 0;
|
|---|
| 210 | }
|
|---|