aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-08-20 17:49:03 +0200
committerJacob Erlbeck <jerlbeck@sysmocom.de>2015-08-24 12:23:50 +0200
commit444bc82081be0fd371805017a4c97b01cb41c15d (patch)
tree754b011500c5c8f412fb47b78a27d528a3a492a1 /tests
parent23c4b3f15899c0849fe63726fea404b9b215f103 (diff)
tbf: Use C++/talloc magic to support TBF constructors/destructors
The TBF object are currently created by using talloc_zero/talloc_free directly from plain functions. Therefore C++ constructors and destructors are not called. So the only initialisation that is done is setting every member to 0. Non POD members do not have their constructors called either, which makes it impossible to use the current LListHead class for real members when the LListHead::m_back member has to be set. This commit changes the TBF allocation functions to call the corresponding C++ constructor after the call to talloc_zero and to register the C++ destructor with the talloc context, so that is is called before talloc_free actually frees the memory. With this change, non-POD members and custom constructors/desctructors can be used with gprs_rlcmac_tbf, gprs_rlcmac_dl_tbf, and gprs_rlcmac_ul_tbf. Note that this change is only a single step of the plan to turn the TBF classes into real C++ classes. Sponsored-by: On-Waves ehf
Diffstat (limited to 'tests')
-rw-r--r--tests/ms/MsTest.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/tests/ms/MsTest.cpp b/tests/ms/MsTest.cpp
index 5a25d76..7255da3 100644
--- a/tests/ms/MsTest.cpp
+++ b/tests/ms/MsTest.cpp
@@ -55,9 +55,9 @@ static void test_ms_state()
OSMO_ASSERT(ms->is_idle());
dl_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf);
- dl_tbf->direction = GPRS_RLCMAC_DL_TBF;
+ new (dl_tbf) gprs_rlcmac_dl_tbf();
ul_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
- ul_tbf->direction = GPRS_RLCMAC_UL_TBF;
+ new (ul_tbf) gprs_rlcmac_ul_tbf();
ms->attach_tbf(ul_tbf);
OSMO_ASSERT(!ms->is_idle());
@@ -116,9 +116,9 @@ static void test_ms_callback()
OSMO_ASSERT(ms->is_idle());
dl_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf);
- dl_tbf->direction = GPRS_RLCMAC_DL_TBF;
+ new (dl_tbf) gprs_rlcmac_dl_tbf();
ul_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
- ul_tbf->direction = GPRS_RLCMAC_UL_TBF;
+ new (ul_tbf) gprs_rlcmac_ul_tbf();
OSMO_ASSERT(last_cb == UNKNOWN);
@@ -186,11 +186,11 @@ static void test_ms_replace_tbf()
was_idle = false;
dl_tbf[0] = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf);
- dl_tbf[0]->direction = GPRS_RLCMAC_DL_TBF;
+ new (dl_tbf[0]) gprs_rlcmac_dl_tbf();
dl_tbf[1] = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf);
- dl_tbf[1]->direction = GPRS_RLCMAC_DL_TBF;
+ new (dl_tbf[1]) gprs_rlcmac_dl_tbf();
ul_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
- ul_tbf->direction = GPRS_RLCMAC_UL_TBF;
+ new (ul_tbf) gprs_rlcmac_ul_tbf();
ms->attach_tbf(dl_tbf[0]);
OSMO_ASSERT(!ms->is_idle());
@@ -343,7 +343,7 @@ static void test_ms_storage()
printf("=== start %s ===\n", __func__);
ul_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
- ul_tbf->direction = GPRS_RLCMAC_UL_TBF;
+ new (ul_tbf) gprs_rlcmac_ul_tbf();
ms = store.get_ms(tlli + 0);
OSMO_ASSERT(ms == NULL);
@@ -434,9 +434,9 @@ static void test_ms_timeout()
OSMO_ASSERT(ms->is_idle());
dl_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf);
- dl_tbf->direction = GPRS_RLCMAC_DL_TBF;
+ new (dl_tbf) gprs_rlcmac_dl_tbf();
ul_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
- ul_tbf->direction = GPRS_RLCMAC_UL_TBF;
+ new (ul_tbf) gprs_rlcmac_ul_tbf();
OSMO_ASSERT(last_cb == UNKNOWN);
@@ -492,7 +492,7 @@ static void test_ms_cs_selection()
OSMO_ASSERT(ms->is_idle());
dl_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf);
- dl_tbf->direction = GPRS_RLCMAC_DL_TBF;
+ new (dl_tbf) gprs_rlcmac_dl_tbf();
dl_tbf->set_ms(ms);
OSMO_ASSERT(!ms->is_idle());