Navigation


Changeset 8:3e143f047f78 in freeDiameter for freeDiameter/tests/testqueues.c


Ignore:
Timestamp:
Sep 18, 2009, 6:54:07 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Backup for the week-end

File:
1 moved

Legend:

Unmodified
Added
Removed
  • freeDiameter/tests/testqueues.c

    r1 r8  
    3838/* Structure for testing threshold function */
    3939static struct thrh_test {
    40         struct mqueue * queue; /* pointer to the queue */
     40        struct fifo *  queue; /* pointer to the queue */
    4141        int             h_calls; /* number of calls of h_cb */
    4242        int             l_calls; /* number of calls of l_cb */
     
    4444
    4545/* Callbacks for threasholds test */
    46 void thrh_cb_h(struct mqueue *queue, void **data)
     46void thrh_cb_h(struct fifo *queue, void **data)
    4747{
    4848        if (thrh_td.h_calls == thrh_td.l_calls) {
     
    5757        thrh_td.h_calls ++;
    5858}
    59 void thrh_cb_l(struct mqueue *queue, void **data)
     59void thrh_cb_l(struct fifo *queue, void **data)
    6060{
    6161        CHECK( 1, data ? 1 : 0 );
     
    7676/* Structure that is passed to the test function */
    7777struct test_data {
    78         struct mqueue     * queue; /* pointer to the queue */
     78        struct fifo     * queue; /* pointer to the queue */
    7979        pthread_barrier_t * bar;   /* if not NULL, barrier to synchronize before getting messages */
    8080        struct timespec   * ts;    /* if not NULL, use a timedget instead of a get */
     
    100100        for (i=0; i< td->nbr; i++) {
    101101                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) );
    103103                } else {
    104                         CHECK( 0, fd_mq_get(td->queue, &msg) );
     104                        CHECK( 0, fd_fifo_get(td->queue, &msg) );
    105105                }
    106106        }
     
    128128                struct dict_object * dwr_model = NULL;
    129129
    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 ) );
    133133                CHECK( 0, fd_msg_new ( acr_model, 0, &msg1 ) );
    134134                CHECK( 0, fd_msg_new ( cer_model, 0, &msg2 ) );
     
    138138        /* Basic operation */
    139139        {
    140                 struct mqueue * queue = NULL;
     140                struct fifo * queue = NULL;
    141141                int count;
    142142                struct msg * msg  = NULL;
    143143               
    144144                /* Create the queue */
    145                 CHECK( 0, fd_mq_new(&queue) );
     145                CHECK( 0, fd_fifo_new(&queue) );
    146146               
    147147                /* Check the count is 0 */
    148                 CHECK( 0, fd_mq_length(queue, &count) );
     148                CHECK( 0, fd_fifo_length(queue, &count) );
    149149                CHECK( 0, count);
    150150               
    151151                /* Now enqueue */
    152152                msg = msg1;
    153                 CHECK( 0, fd_mq_post(queue, &msg) );
     153                CHECK( 0, fd_fifo_post(queue, &msg) );
    154154                msg = msg2;
    155                 CHECK( 0, fd_mq_post(queue, &msg) );
     155                CHECK( 0, fd_fifo_post(queue, &msg) );
    156156                msg = msg3;
    157                 CHECK( 0, fd_mq_post(queue, &msg) );
     157                CHECK( 0, fd_fifo_post(queue, &msg) );
    158158               
    159159                /* Check the count is 3 */
    160                 CHECK( 0, fd_mq_length(queue, &count) );
     160                CHECK( 0, fd_fifo_length(queue, &count) );
    161161                CHECK( 3, count);
    162162               
    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) );
    165165                CHECK( msg1, msg);
    166                 CHECK( 0, fd_mq_length(queue, &count) );
     166                CHECK( 0, fd_fifo_length(queue, &count) );
    167167                CHECK( 2, count);
    168168               
    169                 /* Retrieve the second message using fd_mq_timedget */
     169                /* Retrieve the second message using fd_fifo_timedget */
    170170                CHECK(0, clock_gettime(CLOCK_REALTIME, &ts));
    171171                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) );
    173173                CHECK( msg2, msg);
    174                 CHECK( 0, fd_mq_length(queue, &count) );
     174                CHECK( 0, fd_fifo_length(queue, &count) );
    175175                CHECK( 1, count);
    176176               
    177177                /* Retrieve the third message using meq_tryget */
    178                 CHECK( 0, fd_mq_tryget(queue, &msg) );
     178                CHECK( 0, fd_fifo_tryget(queue, &msg) );
    179179                CHECK( msg3, msg);
    180                 CHECK( 0, fd_mq_length(queue, &count) );
     180                CHECK( 0, fd_fifo_length(queue, &count) );
    181181                CHECK( 0, count);
    182182               
    183183                /* 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) );
    186186                CHECK( 0, count);
    187187               
    188188                /* We're done for basic tests */
    189                 CHECK( 0, fd_mq_del(&queue) );
     189                CHECK( 0, fd_fifo_del(&queue) );
    190190        }
    191191       
     
    194194#define NBR_MSG         200
    195195#define NBR_THREADS     60
    196                 struct mqueue           *queue = NULL;
     196                struct fifo             *queue = NULL;
    197197                pthread_barrier_t        bar;
    198198                struct test_data         td_1;
     
    205205               
    206206                /* Create the queue */
    207                 CHECK( 0, fd_mq_new(&queue) );
     207                CHECK( 0, fd_fifo_new(&queue) );
    208208               
    209209                /* Create the barrier */
     
    215215               
    216216                /* 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 ) );
    218218                for (i = 0; i < NBR_MSG * NBR_THREADS * 2; i++) {
    219219                        CHECK( 0, fd_msg_new ( dwr_model, 0, &msgs[i] ) );
     
    248248                for (i=0; i < NBR_MSG * NBR_THREADS * 2; i++) {
    249249                        msg = msgs[i];
    250                         CHECK( 0, fd_mq_post(queue, &msg) );
     250                        CHECK( 0, fd_fifo_post(queue, &msg) );
    251251                }
    252252               
     
    257257               
    258258                /* 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) );
    260260                CHECK( 0, count);
    261261               
    262262                /* Destroy this queue and the messages */
    263                 CHECK( 0, fd_mq_del(&queue) );
     263                CHECK( 0, fd_fifo_del(&queue) );
    264264                for (i=0; i < NBR_MSG * NBR_THREADS * 2; i++) {
    265265                        CHECK( 0, fd_msg_free(  msgs[i] ) );
     
    269269        /* Test thread cancelation */
    270270        {
    271                 struct mqueue           *queue = NULL;
     271                struct fifo             *queue = NULL;
    272272                pthread_barrier_t        bar;
    273273                struct test_data         td;
     
    275275               
    276276                /* Create the queue */
    277                 CHECK( 0, fd_mq_new(&queue) );
     277                CHECK( 0, fd_fifo_new(&queue) );
    278278               
    279279                /* Create the barrier */
     
    332332               
    333333                /* Destroy the queue */
    334                 CHECK( 0, fd_mq_del(&queue) );
     334                CHECK( 0, fd_fifo_del(&queue) );
    335335        }
    336336       
    337337        /* Test the threashold function */
    338338        {
    339                 struct mqueue * queue = NULL;
     339                struct fifo * queue = NULL;
    340340                int i;
    341341                struct msg * msg  = NULL;
    342342               
    343343                /* Create the queue */
    344                 CHECK( 0, fd_mq_new(&queue) );
     344                CHECK( 0, fd_fifo_new(&queue) );
    345345               
    346346                /* Prepare the test data */
     
    349349               
    350350                /* 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 ) );
    352352               
    353353                /* Post 5 messages, no cb must be called. */
    354354                for (i=0; i<5; i++) {
    355355                        msg = msg1;
    356                         CHECK( 0, fd_mq_post(queue, &msg) );
     356                        CHECK( 0, fd_fifo_post(queue, &msg) );
    357357                } /* 5 msg in queue */
    358358                CHECK( 0, thrh_td.h_calls );
     
    361361                /* Get all these messages, and check again */
    362362                for (i=0; i<5; i++) {
    363                         CHECK( 0, fd_mq_get(queue, &msg) );
     363                        CHECK( 0, fd_fifo_get(queue, &msg) );
    364364                } /* 0 msg in queue */
    365365                CHECK( 0, thrh_td.h_calls );
     
    369369                for (i=0; i<6; i++) {
    370370                        msg = msg1;
    371                         CHECK( 0, fd_mq_post(queue, &msg) );
     371                        CHECK( 0, fd_fifo_post(queue, &msg) );
    372372                } /* 6 msg in queue */
    373373                CHECK( 1, thrh_td.h_calls );
     
    376376                /* Remove 2 messages, to reach the low threshold */
    377377                for (i=0; i<2; i++) {
    378                         CHECK( 0, fd_mq_get(queue, &msg) );
     378                        CHECK( 0, fd_fifo_get(queue, &msg) );
    379379                } /* 4 msg in queue */
    380380                CHECK( 1, thrh_td.h_calls );
     
    384384                for (i=0; i<2; i++) {
    385385                        msg = msg1;
    386                         CHECK( 0, fd_mq_post(queue, &msg) );
     386                        CHECK( 0, fd_fifo_post(queue, &msg) );
    387387                } /* 6 msg in queue */
    388388                CHECK( 2, thrh_td.h_calls );
     
    392392                for (i=0; i<6; i++) {
    393393                        msg = msg1;
    394                         CHECK( 0, fd_mq_post(queue, &msg) );
     394                        CHECK( 0, fd_fifo_post(queue, &msg) );
    395395                } /* 12 msg in queue */
    396396                CHECK( 3, thrh_td.h_calls );
     
    398398                for (i=0; i<5; i++) {
    399399                        msg = msg1;
    400                         CHECK( 0, fd_mq_post(queue, &msg) );
     400                        CHECK( 0, fd_fifo_post(queue, &msg) );
    401401                } /* 17 msg in queue */
    402402                CHECK( 3, thrh_td.h_calls );
     
    405405                /* Now the queue goes back to 0 messages */
    406406                for (i=0; i<17; i++) {
    407                         CHECK( 0, fd_mq_get(queue, &msg) );
     407                        CHECK( 0, fd_fifo_get(queue, &msg) );
    408408                } /* 0 msg in queue */
    409409                CHECK( 3, thrh_td.h_calls );
     
    411411               
    412412                /* We're done for this test */
    413                 CHECK( 0, fd_mq_del(&queue) );
     413                CHECK( 0, fd_fifo_del(&queue) );
    414414        }
    415415       
Note: See TracChangeset for help on using the changeset viewer.