From f76d76ba6192d2bcf2bc2330088ca053ee1e985d Mon Sep 17 00:00:00 2001 From: boure Date: Mon, 2 Jun 2008 15:02:24 +0000 Subject: managing conn list working & tested git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2191 017c9cb6-072f-447c-8318-d5b54f68fe89 --- cesar/cp2/conn/doc/conn.odt | Bin 103201 -> 103249 bytes cesar/cp2/conn/link.h | 30 ++++- cesar/cp2/conn/src/conn.c | 18 +++ cesar/cp2/conn/src/conn_mgr.c | 16 ++- cesar/cp2/conn/src/link.c | 79 +++++++++--- cesar/cp2/conn/test/src/conn_test.c | 242 ++++++++++++++++++++++-------------- 6 files changed, 274 insertions(+), 111 deletions(-) diff --git a/cesar/cp2/conn/doc/conn.odt b/cesar/cp2/conn/doc/conn.odt index 5de8edcc43..81b736f9fc 100644 Binary files a/cesar/cp2/conn/doc/conn.odt and b/cesar/cp2/conn/doc/conn.odt differ diff --git a/cesar/cp2/conn/link.h b/cesar/cp2/conn/link.h index e59d72f781..fa83bda3a4 100644 --- a/cesar/cp2/conn/link.h +++ b/cesar/cp2/conn/link.h @@ -64,7 +64,11 @@ struct cp_link_ble_interval_t */ u16 et; - + /** + * Pointer on the next interval + */ + struct cp_link_ble_interval_t *next; + }; typedef struct cp_link_ble_interval_t cp_link_ble_interval_t; @@ -258,8 +262,12 @@ struct cp_link_t /** * forward BLE */ - // cp_link_ble_interval_t *ble; - blk_t *ble; + cp_link_ble_interval_t *ble; + + /** + * Number of ble + */ + u16 nb_ble; /** * expiration date of the connection used by the garbadge collector @@ -303,7 +311,7 @@ typedef struct cp_link_t cp_link_t; * */ cp_link_t* -cp_link_init (cp_link_ble_interval_t *table_ble, u16 nb_ble); +cp_link_init (void); /** * Clear the Memory taken buy a specific link. @@ -313,4 +321,18 @@ cp_link_init (cp_link_ble_interval_t *table_ble, u16 nb_ble); void cp_link_uninit (cp_link_t *link); +/** + * BLE memory allocation + * \param first first BLE of a link + * \param new new element to add to the heap + * + * link the BLE + */ +void +push_ble(cp_link_t *link, u8 ble, u16 et); + +void +release_ble(cp_link_t *link); + + #endif /* cp_link_h */ diff --git a/cesar/cp2/conn/src/conn.c b/cesar/cp2/conn/src/conn.c index e534ce76d4..93f6957552 100644 --- a/cesar/cp2/conn/src/conn.c +++ b/cesar/cp2/conn/src/conn.c @@ -91,3 +91,21 @@ cp_conn_add_conn(cp_t *ctx, u8 cid, cp_link_t *flink, cp_link_t *rlink) } +void +cp_conn_del_conn(cp_t *ctx, u8 cid) +{ + cp_conn_t *conn = NULL; + + conn = cp_conn_get_conn(ctx, cid); + + cp_link_uninit(conn->flink); + cp_link_uninit(conn->rlink); + blk_release(conn->flink); + blk_release(conn->rlink); + + list_remove(&ctx->conn_mgr.conns, &conn->node); + blk_release(conn); + + blk_print_memory(); + +} diff --git a/cesar/cp2/conn/src/conn_mgr.c b/cesar/cp2/conn/src/conn_mgr.c index fc165e0ece..c78364870e 100644 --- a/cesar/cp2/conn/src/conn_mgr.c +++ b/cesar/cp2/conn/src/conn_mgr.c @@ -28,13 +28,27 @@ void cp_conn_mgr_init(cp_t *ctx) { + dbg_assert(ctx); + list_init(&ctx->conn_mgr.conns); - dbg_assert(list_empty(&ctx->conn_mgr.conns)); } void cp_conn_mgr_uninit(cp_t *ctx) { + list_node_t *del_conn_node; + list_node_t *tmp_conn_node; + + dbg_assert(ctx); + + del_conn_node = list_begin(&ctx->conn_mgr.conns); + + while(!list_empty(&ctx->conn_mgr.conns)) + { + tmp_conn_node = list_next(del_conn_node); + cp_conn_del_conn(ctx, PARENT_OF(cp_conn_t, node, del_conn_node)->cid); + del_conn_node = tmp_conn_node; + } } /** * Process a CM_CONN_NEW_REQ MME diff --git a/cesar/cp2/conn/src/link.c b/cesar/cp2/conn/src/link.c index 1c9292637c..b8be55f399 100644 --- a/cesar/cp2/conn/src/link.c +++ b/cesar/cp2/conn/src/link.c @@ -28,32 +28,18 @@ * fill the elements concerning the link */ cp_link_t* -cp_link_init (cp_link_ble_interval_t *table_ble, u16 nb_ble) +cp_link_init (void) { cp_link_t *link; - blk_t *tmp_blk, *last_blk; - - int i; link = blk_alloc(); link->cinfo = blk_alloc(); - - link->ble = blk_alloc_desc_range(10, &last_blk); + link->ble = NULL; blk_print_memory(); - - tmp_blk = link->ble; - - for(i=0;idata = &table_ble[i]; - tmp_blk = tmp_blk->next; - } return link; } - - /** * del a connection regarding to its CID. * \param ctx conn context. @@ -63,4 +49,65 @@ cp_link_init (cp_link_ble_interval_t *table_ble, u16 nb_ble) void cp_link_uninit (cp_link_t *link) { + + blk_release(link->cinfo); + + blk_print_memory(); + + release_ble (link); + + blk_print_memory(); +} + +/** + * BLE memory allocation + * \param first first BLE of a link + * \param new new element to add to the heap + * + * link the BLE + */ +void +push_ble(cp_link_t *link, u8 ble, u16 et) +{ + + cp_link_ble_interval_t *new; + cp_link_ble_interval_t *tmp; + + dbg_assert(link); + + new = blk_alloc(); + new->ble = ble; + new->et = et; + new->next = NULL; + + tmp = link->ble; + + if (!tmp) + link->ble = new; + else + { + while(tmp->next) + tmp = tmp->next; + + tmp->next = new; + } +} + +void +release_ble(cp_link_t *link) +{ + cp_link_ble_interval_t *ble; + cp_link_ble_interval_t *tmp_ble; + + dbg_assert(link); + + ble = link->ble; + + while(ble) + { + tmp_ble = ble->next; + + blk_release(ble); + ble = tmp_ble; + } } diff --git a/cesar/cp2/conn/test/src/conn_test.c b/cesar/cp2/conn/test/src/conn_test.c index 6fa849be67..88dcf87d12 100644 --- a/cesar/cp2/conn/test/src/conn_test.c +++ b/cesar/cp2/conn/test/src/conn_test.c @@ -22,179 +22,241 @@ #include "lib/test.h" void -test_case_conn_init(test_t test) +test_case_conn_init(test_t test, cp_t *cp) { test_case_begin(test, "conn init"); + + cp_conn_mgr_init(cp); + test_begin(test, "conn init") { - + test_fail_if(!list_empty(&cp->conn_mgr.conns), + "the conn list should be empty"); + } test_end; } void -test_case_conn_uninit(test_t test) +test_case_conn_uninit(test_t test, cp_t *cp) { test_case_begin(test, "conn uninit"); + + cp_conn_mgr_uninit(cp); + test_begin(test, "conn uninit") { - + test_fail_if(!list_empty(&cp->conn_mgr.conns), + "the conn list should be empty"); + + test_fail_if(!blk_check_memory, + "Memory pb in the Conn module"); } test_end; } void -test_case_conn_add_conn (test_t test) +test_case_conn_add_conn (test_t test, cp_t *cp) { - cp_t cp; - int i; - u8 conn_cid = 8; - cp_conn_t *conn = NULL; - cp_link_t *rlink; - cp_link_ble_interval_t rlink_ble[10]; - u16 nb_rlink_ble = 10; - - cp_link_ble_interval_t *test_ble[10]; - blk_t *tmp_blk; - - cp_link_t *flink; - cp_link_ble_interval_t flink_ble[10]; - u16 nb_flink_ble = 10; - + + int i,j; + u8 conn_cid[3]; + cp_conn_t *conn[3] ; + + cp_link_t *rlink[3]; + cp_link_t *flink[3]; + + cp_link_ble_interval_t *tmp_ble; + cp_link_ble_interval_t *test_ble[3][10]; + list_node_t *actual_node; - for(i=0;iflink->ble; + /* init forward ble*/ + for(j=0;j<3;j++) + { + for(i=0;i<10;i++) + { + push_ble(flink[j],(i+1)*20, + ((i+1)*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10)); + push_ble(rlink[j],(i+1)*10, + (i+1)*(CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10)); + } + } + /*Get back the connection for the tests*/ + actual_node = list_begin(&cp->conn_mgr.conns); - for(i = 0; i<10; i++) + for(i=0;i<3;i++) { - test_ble[i] = ((cp_link_ble_interval_t*)(tmp_blk->data)); - tmp_blk = tmp_blk->next; + conn[i] = PARENT_OF(cp_conn_t,node,actual_node); + actual_node = list_next(actual_node); } - test_begin(test, "Add conn") + /*Get back the ble for the tests*/ + actual_node = list_begin(&cp->conn_mgr.conns); + + for(j = 0;j<3;j++) { - test_fail_if(conn->cid != 8, - "wrong CID of the added conn"); - test_fail_if(test_ble[3]->et != (4*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10), - "Wrong end time init in the added Conn"); - test_fail_if(test_ble[0]->ble != 20, - "Wrong BLE init in the added Conn"); - test_fail_if(test_ble[8]->ble != 180, - "Wrong BLE init in the added Conn"); - test_fail_if(test_ble[6]->et != (7*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10), - "Wrong end time init in the added Conn"); + tmp_ble = conn[j]->flink->ble; + + for(i = 0; i<10; i++) + { + test_ble[j][i] = tmp_ble; + tmp_ble = tmp_ble->next; + } + } + + + test_begin(test,"get connection") + { + test_fail_if(test_ble[0][0]->ble != 20, + "wrong ble init of the conn"); + test_fail_if(test_ble[1][1]->ble != 40, + "wrong ble init of the conn"); + test_fail_if(test_ble[2][2]->ble != 60, + "wrong ble init of the conn"); + + test_fail_if(test_ble[0][2]->et != (3*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10), + "wrong init end time of the conn"); + test_fail_if(test_ble[1][6]->et != (7*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10), + "wrong init end time of the conn"); + test_fail_if(test_ble[2][9]->et != (10*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10), + "wrong init end time of the conn"); } test_end; } + void -test_case_conn_get_conn (test_t test) +test_case_conn_del_conn(test_t test) { + cp_t cp; - int i,j; - u8 conn_cid = 8; + int i; + u8 conn_cid[3]; cp_conn_t *conn[3] ; - cp_link_t *rlink[3]; - cp_link_ble_interval_t rlink_ble[10]; - u16 nb_rlink_ble = 10; - cp_link_ble_interval_t *test_ble[3][10]; - blk_t *tmp_blk; + list_node_t *actual_node; - cp_link_t *flink[3]; - cp_link_ble_interval_t flink_ble[10]; - u16 nb_flink_ble = 10; + test_case_conn_init(test, &cp); - list_node_t *actual_node; + test_case_begin(test, "\nget connection"); - for(i=0;iflink->ble; + tmp_ble = conn[j]->flink->ble; for(i = 0; i<10; i++) { - test_ble[j][i] = ((cp_link_ble_interval_t*)(tmp_blk->data)); - tmp_blk = tmp_blk->next; + test_ble[j][i] =tmp_ble; + tmp_ble = tmp_ble->next; } } test_begin(test,"get connection") { + test_fail_if(conn[0]->cid != 10, + "wrong cid 0"); + test_fail_if(conn[1]->cid != 11, + "wrong cid 1"); + test_fail_if(conn[2]->cid != 12, + "wrong cid 2"); + + test_fail_if(test_ble[0][0]->ble != 20, + "wrong ble init of the conn"); + test_fail_if(test_ble[1][1]->ble != 40, + "wrong ble init of the conn"); + test_fail_if(test_ble[2][2]->ble != 60, + "wrong ble init of the conn"); + + test_fail_if(test_ble[0][2]->et != (3*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10), + "wrong init end time of the conn"); + test_fail_if(test_ble[1][6]->et != (7*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10), + "wrong init end time of the conn"); + test_fail_if(test_ble[2][9]->et != (10*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10), + "wrong init end time of the conn"); } test_end; + + test_case_conn_uninit(test, &cp); } + int main (void){ test_t test; test_init(test, 0, NULL); - // test_case_conn_init (test); - // test_case_conn_uninit (test); - // test_case_conn_add_conn (test); + test_case_conn_del_conn(test); test_case_conn_get_conn (test); -- cgit v1.2.3