From 510158256b7ca8d3c3764c0481a6fee652ed2eb2 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Tue, 28 Aug 2018 18:57:42 +0200 Subject: [PATCH] measurement: add unit tests for is_meas_complete() We do not test is_meas_complete() individually yet, but it is an integral part of the measurement processings since this function decides where a measurement interval ends. - Add unit tests that test TCH/F, TCH/H, SDCCH/4 and STDCH/8 Change-Id: I8f89d9e7092cd65ba4d5c5649140692dcc20bdd6 Related: OS#2987 --- include/osmo-bts/measurement.h | 2 + src/common/measurement.c | 6 +- tests/meas/meas_test.c | 177 +++++++++++++++++++++++++++++++++ tests/meas/meas_test.ok | 4 + 4 files changed, 187 insertions(+), 2 deletions(-) diff --git a/include/osmo-bts/measurement.h b/include/osmo-bts/measurement.h index 57eeef5b8..5c3def0e7 100644 --- a/include/osmo-bts/measurement.h +++ b/include/osmo-bts/measurement.h @@ -12,6 +12,8 @@ void lchan_meas_process_measurement(struct gsm_lchan *lchan, struct bts_ul_meas void lchan_meas_reset(struct gsm_lchan *lchan); +int is_meas_complete(struct gsm_lchan *lchan, uint32_t fn); + bool is_meas_overdue(struct gsm_lchan *lchan, uint32_t *fn_missed_end, uint32_t fn); #endif diff --git a/src/common/measurement.c b/src/common/measurement.c index cb45e6e32..158849d50 100644 --- a/src/common/measurement.c +++ b/src/common/measurement.c @@ -244,8 +244,10 @@ static uint8_t translate_tch_meas_rep_fn104_inv(uint8_t fn_mod) return 0; } -/* determine if a measurement period ends at the given frame number */ -static int is_meas_complete(struct gsm_lchan *lchan, uint32_t fn) +/* determine if a measurement period ends at the given frame number + * (this function is only used internally, it is public to call it from + * unit-tests) */ +int is_meas_complete(struct gsm_lchan *lchan, uint32_t fn) { unsigned int fn_mod = -1; const uint8_t *tbl; diff --git a/tests/meas/meas_test.c b/tests/meas/meas_test.c index ec89df989..016677183 100644 --- a/tests/meas/meas_test.c +++ b/tests/meas/meas_test.c @@ -484,6 +484,182 @@ static void test_is_meas_overdue(void) OSMO_ASSERT(fn_missed_end == LCHAN_FN_DUMMY); } +static void test_is_meas_complete_single(struct gsm_lchan *lchan, + uint32_t fn_end, uint8_t intv_len) +{ + unsigned int i; + unsigned int k; + int rc; + uint32_t offset; + + /* Walk through multiple measurement intervals and make sure that the + * interval end is detected only in the expected location */ + for (k = 0; k < 100; k++) { + offset = intv_len * k; + for (i = 0; i < intv_len; i++) { + rc = is_meas_complete(lchan, i + offset); + if (rc) + OSMO_ASSERT(i + offset == fn_end + offset); + } + } +} + +static void test_is_meas_complete(void) +{ + struct gsm_lchan *lchan; + printf("\n\n"); + printf("===========================================================\n"); + printf("Testing is_meas_complete()\n"); + + /* Test interval end detection on TCH/F TS0-TS7 */ + lchan = &trx->ts[0].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_F; + test_is_meas_complete_single(lchan, 12, 104); + + lchan = &trx->ts[1].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_F; + test_is_meas_complete_single(lchan, 25, 104); + + lchan = &trx->ts[2].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_F; + test_is_meas_complete_single(lchan, 38, 104); + + lchan = &trx->ts[3].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_F; + test_is_meas_complete_single(lchan, 51, 104); + + lchan = &trx->ts[4].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_F; + test_is_meas_complete_single(lchan, 64, 104); + + lchan = &trx->ts[5].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_F; + test_is_meas_complete_single(lchan, 77, 104); + + lchan = &trx->ts[6].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_F; + test_is_meas_complete_single(lchan, 90, 104); + + lchan = &trx->ts[7].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_F; + test_is_meas_complete_single(lchan, 103, 104); + + /* Test interval end detection on TCH/H TS0-TS7 */ + lchan = &trx->ts[0].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 12, 104); + + lchan = &trx->ts[1].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 12, 104); + + lchan = &trx->ts[0].lchan[1]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 25, 104); + + lchan = &trx->ts[1].lchan[1]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 25, 104); + + lchan = &trx->ts[2].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 38, 104); + + lchan = &trx->ts[3].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 38, 104); + + lchan = &trx->ts[2].lchan[1]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 51, 104); + + lchan = &trx->ts[3].lchan[1]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 51, 104); + + lchan = &trx->ts[4].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 64, 104); + + lchan = &trx->ts[5].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 64, 104); + + lchan = &trx->ts[4].lchan[1]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 77, 104); + + lchan = &trx->ts[5].lchan[1]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 77, 104); + + lchan = &trx->ts[6].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 90, 104); + + lchan = &trx->ts[7].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 90, 104); + + lchan = &trx->ts[6].lchan[1]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 103, 104); + + lchan = &trx->ts[7].lchan[1]; + lchan->ts->pchan = GSM_PCHAN_TCH_H; + test_is_meas_complete_single(lchan, 103, 104); + + /* Test interval end detection on SDCCH/8 SS0-SS7 */ + lchan = &trx->ts[0].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_SDCCH8_SACCH8C; + test_is_meas_complete_single(lchan, 66, 102); + + lchan = &trx->ts[0].lchan[1]; + lchan->ts->pchan = GSM_PCHAN_SDCCH8_SACCH8C; + test_is_meas_complete_single(lchan, 70, 102); + + lchan = &trx->ts[0].lchan[2]; + lchan->ts->pchan = GSM_PCHAN_SDCCH8_SACCH8C; + test_is_meas_complete_single(lchan, 74, 102); + + lchan = &trx->ts[0].lchan[3]; + lchan->ts->pchan = GSM_PCHAN_SDCCH8_SACCH8C; + test_is_meas_complete_single(lchan, 78, 102); + + lchan = &trx->ts[0].lchan[4]; + lchan->ts->pchan = GSM_PCHAN_SDCCH8_SACCH8C; + test_is_meas_complete_single(lchan, 98, 102); + + lchan = &trx->ts[0].lchan[5]; + lchan->ts->pchan = GSM_PCHAN_SDCCH8_SACCH8C; + test_is_meas_complete_single(lchan, 0, 102); + + lchan = &trx->ts[0].lchan[6]; + lchan->ts->pchan = GSM_PCHAN_SDCCH8_SACCH8C; + test_is_meas_complete_single(lchan, 4, 102); + + lchan = &trx->ts[0].lchan[7]; + lchan->ts->pchan = GSM_PCHAN_SDCCH8_SACCH8C; + test_is_meas_complete_single(lchan, 8, 102); + + /* Test interval end detection on SDCCH/4 SS0-SS3 */ + lchan = &trx->ts[0].lchan[0]; + lchan->ts->pchan = GSM_PCHAN_CCCH_SDCCH4; + test_is_meas_complete_single(lchan, 88, 102); + + lchan = &trx->ts[0].lchan[1]; + lchan->ts->pchan = GSM_PCHAN_CCCH_SDCCH4; + test_is_meas_complete_single(lchan, 92, 102); + + lchan = &trx->ts[0].lchan[2]; + lchan->ts->pchan = GSM_PCHAN_CCCH_SDCCH4; + test_is_meas_complete_single(lchan, 6, 102); + + lchan = &trx->ts[0].lchan[3]; + lchan->ts->pchan = GSM_PCHAN_CCCH_SDCCH4; + test_is_meas_complete_single(lchan, 10, 102); +} + /* This tests the robustness of lchan_meas_process_measurement(). This is the * function that is called from l1_sap.c each time a measurement indication is * received. The process must still go on when measurement indications (blocks) @@ -604,6 +780,7 @@ int main(int argc, char **argv) printf("***************************************************\n"); test_is_meas_overdue(); + test_is_meas_complete(); test_lchan_meas_process_measurement(false, false); test_lchan_meas_process_measurement(true, false); test_lchan_meas_process_measurement(false, true); diff --git a/tests/meas/meas_test.ok b/tests/meas/meas_test.ok index 77b652eac..d8f817445 100644 --- a/tests/meas/meas_test.ok +++ b/tests/meas/meas_test.ok @@ -583,6 +583,10 @@ meas.ul_res.full.rx_qual | 0 | 0 Testing is_meas_overdue() and is_meas_complete() +=========================================================== +Testing is_meas_complete() + + =========================================================== Testing lchan_meas_process_measurement() (leaving out measurement sample for SACCH block)