Changeset 8:3e143f047f78 in freeDiameter for freeDiameter/tests/testqueues.c
- Timestamp:
- Sep 18, 2009, 6:54:07 PM (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/tests/testqueues.c
r1 r8 38 38 /* Structure for testing threshold function */ 39 39 static struct thrh_test { 40 struct mqueue *queue; /* pointer to the queue */40 struct fifo * queue; /* pointer to the queue */ 41 41 int h_calls; /* number of calls of h_cb */ 42 42 int l_calls; /* number of calls of l_cb */ … … 44 44 45 45 /* Callbacks for threasholds test */ 46 void thrh_cb_h(struct mqueue*queue, void **data)46 void thrh_cb_h(struct fifo *queue, void **data) 47 47 { 48 48 if (thrh_td.h_calls == thrh_td.l_calls) { … … 57 57 thrh_td.h_calls ++; 58 58 } 59 void thrh_cb_l(struct mqueue*queue, void **data)59 void thrh_cb_l(struct fifo *queue, void **data) 60 60 { 61 61 CHECK( 1, data ? 1 : 0 ); … … 76 76 /* Structure that is passed to the test function */ 77 77 struct test_data { 78 struct mqueue* queue; /* pointer to the queue */78 struct fifo * queue; /* pointer to the queue */ 79 79 pthread_barrier_t * bar; /* if not NULL, barrier to synchronize before getting messages */ 80 80 struct timespec * ts; /* if not NULL, use a timedget instead of a get */ … … 100 100 for (i=0; i< td->nbr; i++) { 101 101 if (td->ts != NULL) { 102 CHECK( 0, fd_ mq_timedget(td->queue, &msg, td->ts) );102 CHECK( 0, fd_fifo_timedget(td->queue, &msg, td->ts) ); 103 103 } else { 104 CHECK( 0, fd_ mq_get(td->queue, &msg) );104 CHECK( 0, fd_fifo_get(td->queue, &msg) ); 105 105 } 106 106 } … … 128 128 struct dict_object * dwr_model = NULL; 129 129 130 CHECK( 0, fd_dict_search ( fd_g_ dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request", &acr_model, ENOENT ) );131 CHECK( 0, fd_dict_search ( fd_g_ dict, DICT_COMMAND, CMD_BY_NAME, "Capabilities-Exchange-Request", &cer_model, ENOENT ) );132 CHECK( 0, fd_dict_search ( fd_g_ dict, DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request", &dwr_model, ENOENT ) );130 CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request", &acr_model, ENOENT ) ); 131 CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Capabilities-Exchange-Request", &cer_model, ENOENT ) ); 132 CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request", &dwr_model, ENOENT ) ); 133 133 CHECK( 0, fd_msg_new ( acr_model, 0, &msg1 ) ); 134 134 CHECK( 0, fd_msg_new ( cer_model, 0, &msg2 ) ); … … 138 138 /* Basic operation */ 139 139 { 140 struct mqueue* queue = NULL;140 struct fifo * queue = NULL; 141 141 int count; 142 142 struct msg * msg = NULL; 143 143 144 144 /* Create the queue */ 145 CHECK( 0, fd_ mq_new(&queue) );145 CHECK( 0, fd_fifo_new(&queue) ); 146 146 147 147 /* Check the count is 0 */ 148 CHECK( 0, fd_ mq_length(queue, &count) );148 CHECK( 0, fd_fifo_length(queue, &count) ); 149 149 CHECK( 0, count); 150 150 151 151 /* Now enqueue */ 152 152 msg = msg1; 153 CHECK( 0, fd_ mq_post(queue, &msg) );153 CHECK( 0, fd_fifo_post(queue, &msg) ); 154 154 msg = msg2; 155 CHECK( 0, fd_ mq_post(queue, &msg) );155 CHECK( 0, fd_fifo_post(queue, &msg) ); 156 156 msg = msg3; 157 CHECK( 0, fd_ mq_post(queue, &msg) );157 CHECK( 0, fd_fifo_post(queue, &msg) ); 158 158 159 159 /* Check the count is 3 */ 160 CHECK( 0, fd_ mq_length(queue, &count) );160 CHECK( 0, fd_fifo_length(queue, &count) ); 161 161 CHECK( 3, count); 162 162 163 /* Retrieve the first message using fd_ mq_get */164 CHECK( 0, fd_ mq_get(queue, &msg) );163 /* Retrieve the first message using fd_fifo_get */ 164 CHECK( 0, fd_fifo_get(queue, &msg) ); 165 165 CHECK( msg1, msg); 166 CHECK( 0, fd_ mq_length(queue, &count) );166 CHECK( 0, fd_fifo_length(queue, &count) ); 167 167 CHECK( 2, count); 168 168 169 /* Retrieve the second message using fd_ mq_timedget */169 /* Retrieve the second message using fd_fifo_timedget */ 170 170 CHECK(0, clock_gettime(CLOCK_REALTIME, &ts)); 171 171 ts.tv_sec += 1; /* Set the timeout to 1 second */ 172 CHECK( 0, fd_ mq_timedget(queue, &msg, &ts) );172 CHECK( 0, fd_fifo_timedget(queue, &msg, &ts) ); 173 173 CHECK( msg2, msg); 174 CHECK( 0, fd_ mq_length(queue, &count) );174 CHECK( 0, fd_fifo_length(queue, &count) ); 175 175 CHECK( 1, count); 176 176 177 177 /* Retrieve the third message using meq_tryget */ 178 CHECK( 0, fd_ mq_tryget(queue, &msg) );178 CHECK( 0, fd_fifo_tryget(queue, &msg) ); 179 179 CHECK( msg3, msg); 180 CHECK( 0, fd_ mq_length(queue, &count) );180 CHECK( 0, fd_fifo_length(queue, &count) ); 181 181 CHECK( 0, count); 182 182 183 183 /* Check that another meq_tryget does not block */ 184 CHECK( EWOULDBLOCK, fd_ mq_tryget(queue, &msg) );185 CHECK( 0, fd_ mq_length(queue, &count) );184 CHECK( EWOULDBLOCK, fd_fifo_tryget(queue, &msg) ); 185 CHECK( 0, fd_fifo_length(queue, &count) ); 186 186 CHECK( 0, count); 187 187 188 188 /* We're done for basic tests */ 189 CHECK( 0, fd_ mq_del(&queue) );189 CHECK( 0, fd_fifo_del(&queue) ); 190 190 } 191 191 … … 194 194 #define NBR_MSG 200 195 195 #define NBR_THREADS 60 196 struct mqueue*queue = NULL;196 struct fifo *queue = NULL; 197 197 pthread_barrier_t bar; 198 198 struct test_data td_1; … … 205 205 206 206 /* Create the queue */ 207 CHECK( 0, fd_ mq_new(&queue) );207 CHECK( 0, fd_fifo_new(&queue) ); 208 208 209 209 /* Create the barrier */ … … 215 215 216 216 /* Create the messages */ 217 CHECK( 0, fd_dict_search ( fd_g_ dict, DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request", &dwr_model, ENOENT ) );217 CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request", &dwr_model, ENOENT ) ); 218 218 for (i = 0; i < NBR_MSG * NBR_THREADS * 2; i++) { 219 219 CHECK( 0, fd_msg_new ( dwr_model, 0, &msgs[i] ) ); … … 248 248 for (i=0; i < NBR_MSG * NBR_THREADS * 2; i++) { 249 249 msg = msgs[i]; 250 CHECK( 0, fd_ mq_post(queue, &msg) );250 CHECK( 0, fd_fifo_post(queue, &msg) ); 251 251 } 252 252 … … 257 257 258 258 /* Check the count of the queue is back to 0 */ 259 CHECK( 0, fd_ mq_length(queue, &count) );259 CHECK( 0, fd_fifo_length(queue, &count) ); 260 260 CHECK( 0, count); 261 261 262 262 /* Destroy this queue and the messages */ 263 CHECK( 0, fd_ mq_del(&queue) );263 CHECK( 0, fd_fifo_del(&queue) ); 264 264 for (i=0; i < NBR_MSG * NBR_THREADS * 2; i++) { 265 265 CHECK( 0, fd_msg_free( msgs[i] ) ); … … 269 269 /* Test thread cancelation */ 270 270 { 271 struct mqueue*queue = NULL;271 struct fifo *queue = NULL; 272 272 pthread_barrier_t bar; 273 273 struct test_data td; … … 275 275 276 276 /* Create the queue */ 277 CHECK( 0, fd_ mq_new(&queue) );277 CHECK( 0, fd_fifo_new(&queue) ); 278 278 279 279 /* Create the barrier */ … … 332 332 333 333 /* Destroy the queue */ 334 CHECK( 0, fd_ mq_del(&queue) );334 CHECK( 0, fd_fifo_del(&queue) ); 335 335 } 336 336 337 337 /* Test the threashold function */ 338 338 { 339 struct mqueue* queue = NULL;339 struct fifo * queue = NULL; 340 340 int i; 341 341 struct msg * msg = NULL; 342 342 343 343 /* Create the queue */ 344 CHECK( 0, fd_ mq_new(&queue) );344 CHECK( 0, fd_fifo_new(&queue) ); 345 345 346 346 /* Prepare the test data */ … … 349 349 350 350 /* Set the thresholds for the queue */ 351 CHECK( 0, fd_ mq_setthrhd ( queue, NULL, 6, thrh_cb_h, 4, thrh_cb_l ) );351 CHECK( 0, fd_fifo_setthrhd ( queue, NULL, 6, thrh_cb_h, 4, thrh_cb_l ) ); 352 352 353 353 /* Post 5 messages, no cb must be called. */ 354 354 for (i=0; i<5; i++) { 355 355 msg = msg1; 356 CHECK( 0, fd_ mq_post(queue, &msg) );356 CHECK( 0, fd_fifo_post(queue, &msg) ); 357 357 } /* 5 msg in queue */ 358 358 CHECK( 0, thrh_td.h_calls ); … … 361 361 /* Get all these messages, and check again */ 362 362 for (i=0; i<5; i++) { 363 CHECK( 0, fd_ mq_get(queue, &msg) );363 CHECK( 0, fd_fifo_get(queue, &msg) ); 364 364 } /* 0 msg in queue */ 365 365 CHECK( 0, thrh_td.h_calls ); … … 369 369 for (i=0; i<6; i++) { 370 370 msg = msg1; 371 CHECK( 0, fd_ mq_post(queue, &msg) );371 CHECK( 0, fd_fifo_post(queue, &msg) ); 372 372 } /* 6 msg in queue */ 373 373 CHECK( 1, thrh_td.h_calls ); … … 376 376 /* Remove 2 messages, to reach the low threshold */ 377 377 for (i=0; i<2; i++) { 378 CHECK( 0, fd_ mq_get(queue, &msg) );378 CHECK( 0, fd_fifo_get(queue, &msg) ); 379 379 } /* 4 msg in queue */ 380 380 CHECK( 1, thrh_td.h_calls ); … … 384 384 for (i=0; i<2; i++) { 385 385 msg = msg1; 386 CHECK( 0, fd_ mq_post(queue, &msg) );386 CHECK( 0, fd_fifo_post(queue, &msg) ); 387 387 } /* 6 msg in queue */ 388 388 CHECK( 2, thrh_td.h_calls ); … … 392 392 for (i=0; i<6; i++) { 393 393 msg = msg1; 394 CHECK( 0, fd_ mq_post(queue, &msg) );394 CHECK( 0, fd_fifo_post(queue, &msg) ); 395 395 } /* 12 msg in queue */ 396 396 CHECK( 3, thrh_td.h_calls ); … … 398 398 for (i=0; i<5; i++) { 399 399 msg = msg1; 400 CHECK( 0, fd_ mq_post(queue, &msg) );400 CHECK( 0, fd_fifo_post(queue, &msg) ); 401 401 } /* 17 msg in queue */ 402 402 CHECK( 3, thrh_td.h_calls ); … … 405 405 /* Now the queue goes back to 0 messages */ 406 406 for (i=0; i<17; i++) { 407 CHECK( 0, fd_ mq_get(queue, &msg) );407 CHECK( 0, fd_fifo_get(queue, &msg) ); 408 408 } /* 0 msg in queue */ 409 409 CHECK( 3, thrh_td.h_calls ); … … 411 411 412 412 /* We're done for this test */ 413 CHECK( 0, fd_ mq_del(&queue) );413 CHECK( 0, fd_fifo_del(&queue) ); 414 414 } 415 415
Note: See TracChangeset
for help on using the changeset viewer.