aboutsummaryrefslogtreecommitdiffstats
path: root/tests/ms/MsTest.cpp
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-05-28 15:43:53 +0200
committerJacob Erlbeck <jerlbeck@sysmocom.de>2015-05-28 16:38:16 +0200
commitd9e102472a97c767cba1bd5687db30028436d623 (patch)
tree63e8d6c08fddf98cb0c2391c0f0ed1068c54dcd5 /tests/ms/MsTest.cpp
parent1db67e0a35a479ef20b871c459ea3f3e0155b620 (diff)
ms: Add timer
Currently the MS object is immediately idle when all TBFs are detached and if no guard is being used. Since the plan is to use the MS objects to pass information from one TBF to the next one even across the gap of some seconds of inactivity, a mechanism is needed to keep the MS objects around for some time. This commit extends the GprsMs class by a timer that keeps the MS objects in non-idle state for some time after all TBFs have been detached. The set_timeout method must be used with a non-zero value to activate this feature. Sponsored-by: On-Waves ehf
Diffstat (limited to 'tests/ms/MsTest.cpp')
-rw-r--r--tests/ms/MsTest.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/ms/MsTest.cpp b/tests/ms/MsTest.cpp
index 9c8ec2c3..bb9e21bf 100644
--- a/tests/ms/MsTest.cpp
+++ b/tests/ms/MsTest.cpp
@@ -36,6 +36,7 @@ extern "C" {
}
#include <errno.h>
+#include <unistd.h>
void *tall_pcu_ctx;
int16_t spoof_mnc = 0, spoof_mcc = 0;
@@ -399,6 +400,74 @@ static void test_ms_storage()
printf("=== end %s ===\n", __func__);
}
+static void test_ms_timeout()
+{
+ uint32_t tlli = 0xffeeddbb;
+ gprs_rlcmac_dl_tbf *dl_tbf;
+ gprs_rlcmac_ul_tbf *ul_tbf;
+ GprsMs *ms;
+ static enum {UNKNOWN, IS_IDLE, IS_ACTIVE} last_cb = UNKNOWN;
+
+ struct MyCallback: public GprsMs::Callback {
+ virtual void ms_idle(class GprsMs *ms) {
+ OSMO_ASSERT(ms->is_idle());
+ printf(" ms_idle() was called\n");
+ last_cb = IS_IDLE;
+ }
+ virtual void ms_active(class GprsMs *ms) {
+ OSMO_ASSERT(!ms->is_idle());
+ printf(" ms_active() was called\n");
+ last_cb = IS_ACTIVE;
+ }
+ } cb;
+
+ printf("=== start %s ===\n", __func__);
+
+ ms = new GprsMs(tlli);
+ ms->set_callback(&cb);
+ ms->set_timeout(1);
+
+ OSMO_ASSERT(ms->is_idle());
+
+ dl_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf);
+ dl_tbf->direction = GPRS_RLCMAC_DL_TBF;
+ ul_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
+ ul_tbf->direction = GPRS_RLCMAC_UL_TBF;
+
+ OSMO_ASSERT(last_cb == UNKNOWN);
+
+ ms->attach_tbf(ul_tbf);
+ OSMO_ASSERT(!ms->is_idle());
+ OSMO_ASSERT(last_cb == IS_ACTIVE);
+
+ last_cb = UNKNOWN;
+
+ ms->attach_tbf(dl_tbf);
+ OSMO_ASSERT(!ms->is_idle());
+ OSMO_ASSERT(last_cb == UNKNOWN);
+
+ ms->detach_tbf(ul_tbf);
+ OSMO_ASSERT(!ms->is_idle());
+ OSMO_ASSERT(last_cb == UNKNOWN);
+
+ ms->detach_tbf(dl_tbf);
+ OSMO_ASSERT(!ms->is_idle());
+ OSMO_ASSERT(last_cb == UNKNOWN);
+
+ usleep(1100000);
+ osmo_timers_update();
+
+ OSMO_ASSERT(ms->is_idle());
+ OSMO_ASSERT(last_cb == IS_IDLE);
+
+ last_cb = UNKNOWN;
+ delete ms;
+ talloc_free(dl_tbf);
+ talloc_free(ul_tbf);
+
+ printf("=== end %s ===\n", __func__);
+}
+
static const struct log_info_cat default_categories[] = {
{"DPCU", "", "GPRS Packet Control Unit (PCU)", LOGL_INFO, 1},
};
@@ -437,6 +506,7 @@ int main(int argc, char **argv)
test_ms_replace_tbf();
test_ms_change_tlli();
test_ms_storage();
+ test_ms_timeout();
if (getenv("TALLOC_REPORT_FULL"))
talloc_report_full(tall_pcu_ctx, stderr);