Change in osmo-bts[master]: measurement: add unit tests for ts45008_83_is_sub()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Aug 29 17:04:33 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/10696 )

Change subject: measurement: add unit tests for ts45008_83_is_sub()
......................................................................

measurement: add unit tests for ts45008_83_is_sub()

The function ts45008_83_is_sub() is an integral part of the measurement
calculation as it automatically tags incoming measurements as SUB
measurements. This is important in the context of DTX. Unfortunately
there is no unit test for this function yet.

- Add unit test for ts45008_83_is_sub()

Change-Id: Ia26774859f4bf31baee075896905079368bddd42
Related: OS#3502
---
M include/osmo-bts/measurement.h
M src/common/measurement.c
M tests/meas/meas_test.c
M tests/meas/meas_test.ok
4 files changed, 163 insertions(+), 2 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/include/osmo-bts/measurement.h b/include/osmo-bts/measurement.h
index 5c3def0..b4fc35b 100644
--- a/include/osmo-bts/measurement.h
+++ b/include/osmo-bts/measurement.h
@@ -12,6 +12,8 @@
 
 void lchan_meas_reset(struct gsm_lchan *lchan);
 
+bool ts45008_83_is_sub(struct gsm_lchan *lchan, uint32_t fn, bool is_amr_sid_update);
+
 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);
diff --git a/src/common/measurement.c b/src/common/measurement.c
index b0ef869..bc27287 100644
--- a/src/common/measurement.c
+++ b/src/common/measurement.c
@@ -27,8 +27,9 @@
 	return false;
 }
 
-/* Decide if a given frame number is part of the "-SUB" measurements (true) or not (false) */
-static bool ts45008_83_is_sub(struct gsm_lchan *lchan, uint32_t fn, bool is_amr_sid_update)
+/* Decide if a given frame number is part of the "-SUB" measurements (true) or not (false)
+ * (this function is only used internally, it is public to call it from unit-tests) */
+bool ts45008_83_is_sub(struct gsm_lchan *lchan, uint32_t fn, bool is_amr_sid_update)
 {
 	uint32_t fn104 = fn % 104;
 
diff --git a/tests/meas/meas_test.c b/tests/meas/meas_test.c
index 0166771..4009ddb 100644
--- a/tests/meas/meas_test.c
+++ b/tests/meas/meas_test.c
@@ -719,6 +719,138 @@
 	}
 }
 
+static bool test_ts45008_83_is_sub_is_sacch(uint32_t fn)
+{
+	if (fn % 104 == 12)
+		return true;
+	if (fn % 104 == 25)
+		return true;
+	if (fn % 104 == 38)
+		return true;
+	if (fn % 104 == 51)
+		return true;
+	if (fn % 104 == 64)
+		return true;
+	if (fn % 104 == 77)
+		return true;
+	if (fn % 104 == 90)
+		return true;
+	if (fn % 104 == 103)
+		return true;
+
+	return false;
+}
+
+static bool test_ts45008_83_is_sub_is_sub(uint32_t fn, uint8_t ss)
+{
+	fn = fn % 104;
+
+	if (fn >= 52 && fn <= 59)
+		return true;
+
+	if (ss == 0) {
+		if (fn == 0)
+			return true;
+		if (fn == 2)
+			return true;
+		if (fn == 4)
+			return true;
+		if (fn == 6)
+			return true;
+		if (fn == 52)
+			return true;
+		if (fn == 54)
+			return true;
+		if (fn == 56)
+			return true;
+		if (fn == 58)
+			return true;
+	} else if (ss == 1) {
+		if (fn == 14)
+			return true;
+		if (fn == 16)
+			return true;
+		if (fn == 18)
+			return true;
+		if (fn == 20)
+			return true;
+		if (fn == 66)
+			return true;
+		if (fn == 68)
+			return true;
+		if (fn == 70)
+			return true;
+		if (fn == 72)
+			return true;
+	} else
+		OSMO_ASSERT(false);
+
+	return false;
+}
+
+static void test_ts45008_83_is_sub_single(uint8_t ts, uint8_t ss, bool fr)
+{
+	struct gsm_lchan *lchan;
+	bool rc;
+	unsigned int i;
+
+	lchan = &trx->ts[ts].lchan[ss];
+
+	printf("Checking: ");
+
+	if (fr) {
+		printf("TCH/F");
+		lchan->type = GSM_LCHAN_TCH_F;
+		lchan->ts->pchan = GSM_PCHAN_TCH_F;
+		lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
+	} else {
+		printf("TCH/H");
+		lchan->type = GSM_LCHAN_TCH_H;
+		lchan->ts->pchan = GSM_PCHAN_TCH_H;
+		lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
+	}
+
+	printf(" TS=%u ", ts);
+	printf("SS=%u", ss);
+
+	/* Walk trough the first 100 intervals and check for unexpected
+	 * results (false positive and false negative) */
+	for (i = 0; i < 104 * 100; i++) {
+		rc = ts45008_83_is_sub(lchan, i, false);
+		if (rc) {
+			if (!test_ts45008_83_is_sub_is_sacch(i)
+			    && !test_ts45008_83_is_sub_is_sub(i, ss)) {
+				printf("==> Unexpected SUB frame at fn=%u", i);
+				OSMO_ASSERT(false);
+			}
+		} else {
+			if (test_ts45008_83_is_sub_is_sacch(i)
+			    && test_ts45008_83_is_sub_is_sub(i, ss)) {
+				printf("==> Unexpected non-SUB frame at fn=%u",
+				       i);
+				OSMO_ASSERT(false);
+			}
+		}
+	}
+	printf("\n");
+}
+
+static void test_ts45008_83_is_sub(void)
+{
+	unsigned int i;
+
+	printf("\n\n");
+	printf("===========================================================\n");
+	printf("Testing ts45008_83_is_sub()\n");
+
+	for (i = 0; i < 7; i++)
+		test_ts45008_83_is_sub_single(i, 0, true);
+	for (i = 0; i < 7; i++)
+		test_ts45008_83_is_sub_single(i, 0, false);
+	for (i = 0; i < 7; i++)
+		test_ts45008_83_is_sub_single(i, 1, false);
+}
+
 int main(int argc, char **argv)
 {
 	void *tall_bts_ctx;
@@ -785,6 +917,7 @@
 	test_lchan_meas_process_measurement(true, false);
 	test_lchan_meas_process_measurement(false, true);
 	test_lchan_meas_process_measurement(true, true);
+	test_ts45008_83_is_sub();
 
 	printf("Success\n");
 
diff --git a/tests/meas/meas_test.ok b/tests/meas/meas_test.ok
index d8f8174..ac32acf 100644
--- a/tests/meas/meas_test.ok
+++ b/tests/meas/meas_test.ok
@@ -1055,4 +1055,29 @@
 (leaving out measurement sample for SACCH block)
 (leaving out measurement sample for SACCH block)
 (leaving out measurement sample for SACCH block)
+
+
+===========================================================
+Testing ts45008_83_is_sub()
+Checking: TCH/F TS=0 SS=0
+Checking: TCH/F TS=1 SS=0
+Checking: TCH/F TS=2 SS=0
+Checking: TCH/F TS=3 SS=0
+Checking: TCH/F TS=4 SS=0
+Checking: TCH/F TS=5 SS=0
+Checking: TCH/F TS=6 SS=0
+Checking: TCH/H TS=0 SS=0
+Checking: TCH/H TS=1 SS=0
+Checking: TCH/H TS=2 SS=0
+Checking: TCH/H TS=3 SS=0
+Checking: TCH/H TS=4 SS=0
+Checking: TCH/H TS=5 SS=0
+Checking: TCH/H TS=6 SS=0
+Checking: TCH/H TS=0 SS=1
+Checking: TCH/H TS=1 SS=1
+Checking: TCH/H TS=2 SS=1
+Checking: TCH/H TS=3 SS=1
+Checking: TCH/H TS=4 SS=1
+Checking: TCH/H TS=5 SS=1
+Checking: TCH/H TS=6 SS=1
 Success

-- 
To view, visit https://gerrit.osmocom.org/10696
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia26774859f4bf31baee075896905079368bddd42
Gerrit-Change-Number: 10696
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180829/e2d13526/attachment.htm>


More information about the gerrit-log mailing list