[MERGED] osmo-bts[master]: Add new unit-test for transmit power computation code

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Feb 8 08:12:51 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: Add new unit-test for transmit power computation code
......................................................................


Add new unit-test for transmit power computation code

This tests the computations of the tx_power.c code using sysmoBTS 1002,
1020, 1100 and 2050 values, as well as the power ramping code.

Change-Id: I1cc88d4c6edff326e2e67d4f869aa02c9b2b1ac5
---
M .gitignore
M configure.ac
M tests/Makefile.am
M tests/testsuite.at
A tests/tx_power/Makefile.am
A tests/tx_power/tx_power_test.c
A tests/tx_power/tx_power_test.err
A tests/tx_power/tx_power_test.ok
8 files changed, 318 insertions(+), 1 deletion(-)

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



diff --git a/.gitignore b/.gitignore
index 224b77c..b449f92 100644
--- a/.gitignore
+++ b/.gitignore
@@ -48,6 +48,7 @@
 tests/misc/misc_test
 tests/bursts/bursts_test
 tests/handover/handover_test
+tests/tx_power/tx_power_test
 tests/testsuite
 tests/testsuite.log
 
diff --git a/configure.ac b/configure.ac
index 3fd6b8a..001e10e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -144,4 +144,5 @@
     tests/misc/Makefile
     tests/bursts/Makefile
     tests/handover/Makefile
+    tests/tx_power/Makefile
     Makefile)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 54ff029..6635ae7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = paging cipher agch misc bursts handover
+SUBDIRS = paging cipher agch misc bursts handover tx_power
 
 if ENABLE_SYSMOBTS
 SUBDIRS += sysmobts
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 171fade..bfc9bad 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -36,3 +36,10 @@
 cat $abs_srcdir/handover/handover_test.ok > expout
 AT_CHECK([$abs_top_builddir/tests/handover/handover_test], [], [expout], [ignore])
 AT_CLEANUP
+
+AT_SETUP([tx_power])
+AT_KEYWORDS([tx_power])
+cat $abs_srcdir/tx_power/tx_power_test.ok > expout
+cat $abs_srcdir/tx_power/tx_power_test.err > experr
+AT_CHECK([$abs_top_builddir/tests/tx_power/tx_power_test], [], [expout], [experr])
+AT_CLEANUP
diff --git a/tests/tx_power/Makefile.am b/tests/tx_power/Makefile.am
new file mode 100644
index 0000000..3d4377a
--- /dev/null
+++ b/tests/tx_power/Makefile.am
@@ -0,0 +1,8 @@
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOCODEC_CFLAGS)$(LIBOSMOTRAU_CFLAGS)
+LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS)
+noinst_PROGRAMS = tx_power_test
+EXTRA_DIST = tx_power_test.ok tx_power_test.err
+
+tx_power_test_SOURCES = tx_power_test.c $(srcdir)/../stubs.c
+tx_power_test_LDADD = $(top_builddir)/src/common/libbts.a $(LDADD)
diff --git a/tests/tx_power/tx_power_test.c b/tests/tx_power/tx_power_test.c
new file mode 100644
index 0000000..d657362
--- /dev/null
+++ b/tests/tx_power/tx_power_test.c
@@ -0,0 +1,239 @@
+/* Test cases for tx_power.c Transmit Power Computation */
+
+/* (C) 2017 by Harald Welte <laforge at gnumonks.org>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdint.h>
+
+#include <osmocom/core/utils.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/application.h>
+
+#include <osmo-bts/gsm_data.h>
+#include <osmo-bts/bts.h>
+#include <osmo-bts/logging.h>
+#include <osmo-bts/tx_power.h>
+
+
+static const struct trx_power_params tpp_1002 = {
+	.trx_p_max_out_mdBm = to_mdB(23),
+	.p_total_tgt_mdBm = to_mdB(23),
+	.p_total_cur_mdBm = 0,
+	.thermal_attenuation_mdB = 0,
+	.user_gain_mdB = 0,
+	.pa = {
+		.nominal_gain_mdB = 0,
+	},
+	.user_pa = {
+		.nominal_gain_mdB = 0,
+	},
+	.ramp = {
+		.step_size_mdB = to_mdB(2),
+		.step_interval_sec = 1,
+	},
+};
+
+static const struct trx_power_params tpp_1020 = {
+	.trx_p_max_out_mdBm = to_mdB(23),
+	.p_total_tgt_mdBm = to_mdB(33),
+	.p_total_cur_mdBm = 0,
+	.thermal_attenuation_mdB = 0,
+	.user_gain_mdB = 0,
+	.pa = {
+		.nominal_gain_mdB = to_mdB(10),
+	},
+	.user_pa = {
+		.nominal_gain_mdB = 0,
+	},
+	.ramp = {
+		.step_size_mdB = to_mdB(2),
+		.step_interval_sec = 1,
+	},
+};
+
+static const struct trx_power_params tpp_1100 = {
+	.trx_p_max_out_mdBm = to_mdB(23),
+	.p_total_tgt_mdBm = to_mdB(40),
+	.p_total_cur_mdBm = 0,
+	.thermal_attenuation_mdB = 0,
+	.user_gain_mdB = 0,
+	.pa = {
+		.nominal_gain_mdB = to_mdB(17),
+	},
+	.user_pa = {
+		.nominal_gain_mdB = 0,
+	},
+	.ramp = {
+		.step_size_mdB = to_mdB(2),
+		.step_interval_sec = 1,
+	},
+};
+
+static const struct trx_power_params tpp_2050 = {
+	.trx_p_max_out_mdBm = to_mdB(37),
+	.p_total_tgt_mdBm = to_mdB(37),
+	.p_total_cur_mdBm = 0,
+	.thermal_attenuation_mdB = 0,
+	.user_gain_mdB = 0,
+	.pa = {
+		.nominal_gain_mdB = 0,
+	},
+	.user_pa = {
+		.nominal_gain_mdB = 0,
+	},
+	.ramp = {
+		.step_size_mdB = to_mdB(2),
+		.step_interval_sec = 1,
+	},
+};
+
+static void test_sbts1002(struct gsm_bts_trx *trx)
+{
+	printf("Testing tx_power calculation for sysmoBTS 1002\n");
+	trx->power_params = tpp_1002;
+	trx->max_power_red = 0;
+	OSMO_ASSERT(get_p_max_out_mdBm(trx) == to_mdB(23));
+	/* at max_power_red = 0, we expect full 23dBm */
+	OSMO_ASSERT(get_p_nominal_mdBm(trx) == to_mdB(23));
+	trx->max_power_red = 2;
+	/* at max_power_red = 2, we expect 21dBm */
+	OSMO_ASSERT(get_p_nominal_mdBm(trx) == to_mdB(21));
+	/* at 1 step (of 2dB), we expect full 23-2-2=19 dBm */
+	OSMO_ASSERT(get_p_target_mdBm(trx, 1) == to_mdB(19));
+	/* at 2 steps (= 4dB), we expect 23-2-4=17*/
+	OSMO_ASSERT(get_p_trxout_target_mdBm(trx, 2) == to_mdB(17));
+}
+
+static void test_sbts1020(struct gsm_bts_trx *trx)
+{
+	printf("Testing tx_power calculation for sysmoBTS 1020\n");
+	trx->power_params = tpp_1020;
+	trx->max_power_red = 0;
+	OSMO_ASSERT(get_p_max_out_mdBm(trx) == to_mdB(33));
+	/* at max_power_red = 0, we expect full 33dBm */
+	OSMO_ASSERT(get_p_nominal_mdBm(trx) == to_mdB(33));
+	trx->max_power_red = 2;
+	/* at max_power_red = 2, we expect 31dBm */
+	OSMO_ASSERT(get_p_nominal_mdBm(trx) == to_mdB(31));
+	/* at 1 step (of 2dB), we expect full 33-2-2=29 dBm */
+	OSMO_ASSERT(get_p_target_mdBm(trx, 1) == to_mdB(29));
+	/* at 2 steps (= 4dB), we expect 33-2-4-10=17*/
+	OSMO_ASSERT(get_p_trxout_target_mdBm(trx, 2) == to_mdB(17));
+}
+
+
+static void test_sbts1100(struct gsm_bts_trx *trx)
+{
+	printf("Testing tx_power calculation for sysmoBTS 1100\n");
+	trx->power_params = tpp_1100;
+	trx->max_power_red = 0;
+	OSMO_ASSERT(get_p_max_out_mdBm(trx) == to_mdB(40));
+	/* at max_power_red = 0, we expect full 33dBm */
+	OSMO_ASSERT(get_p_nominal_mdBm(trx) == to_mdB(40));
+	trx->max_power_red = 2;
+	/* at max_power_red = 2, we expect 38dBm */
+	OSMO_ASSERT(get_p_nominal_mdBm(trx) == to_mdB(38));
+	/* at 1 step (of 2dB), we expect full 40-2-2=36 dBm */
+	OSMO_ASSERT(get_p_target_mdBm(trx, 1) == to_mdB(36));
+	/* at 2 steps (= 4dB), we expect 40-2-4-17=17*/
+	OSMO_ASSERT(get_p_trxout_target_mdBm(trx, 2) == to_mdB(17));
+}
+
+static void test_sbts2050(struct gsm_bts_trx *trx)
+{
+	printf("Testing tx_power calculation for sysmoBTS 2050\n");
+	trx->power_params = tpp_2050;
+	trx->max_power_red = 0;
+	OSMO_ASSERT(get_p_max_out_mdBm(trx) == to_mdB(37));
+	/* at max_power_red = 0, we expect full 37dBm */
+	OSMO_ASSERT(get_p_nominal_mdBm(trx) == to_mdB(37));
+	trx->max_power_red = 2;
+	/* at max_power_red = 2, we expect 35dBm */
+	OSMO_ASSERT(get_p_nominal_mdBm(trx) == to_mdB(35));
+	/* at 1 step (of 2dB), we expect full 37-2-2=33 dBm */
+	OSMO_ASSERT(get_p_target_mdBm(trx, 1) == to_mdB(33));
+	/* at 2 steps (= 4dB), we expect 37-2-4=31dBm */
+	OSMO_ASSERT(get_p_trxout_target_mdBm(trx, 2) == to_mdB(31));
+}
+
+int bts_model_change_power(struct gsm_bts_trx *trx, int p_trxout_mdBm)
+{
+	struct trx_power_params *tpp = &trx->power_params;
+
+	printf("CHANGE_POWER(%d)\n", p_trxout_mdBm);
+
+	if (tpp->ramp.attenuation_mdB == 0)
+		exit(0);
+
+	power_trx_change_compl(trx, p_trxout_mdBm);
+	return 0;
+}
+
+static void test_power_ramp(struct gsm_bts_trx *trx, int dBm)
+{
+	printf("Testing tx_power ramping for sysmoBTS 1020\n");
+	trx->power_params = tpp_1020;
+	trx->max_power_red = 0;
+
+	power_ramp_start(trx, to_mdB(dBm), 0);
+}
+
+int main(int argc, char **argv)
+{
+	static struct gsm_bts *bts;
+	struct gsm_bts_trx *trx;
+	void *tall_bts_ctx;
+
+	tall_bts_ctx = talloc_named_const(NULL, 1, "OsmoBTS context");
+	msgb_talloc_ctx_init(tall_bts_ctx, 0);
+
+	bts_log_init(NULL);
+	osmo_stderr_target->categories[DL1C].loglevel = LOGL_DEBUG;
+	log_set_print_filename(osmo_stderr_target, 0);
+
+	bts = gsm_bts_alloc(tall_bts_ctx);
+	if (!bts) {
+		fprintf(stderr, "Failed to create BTS structure\n");
+		exit(1);
+	}
+	trx = gsm_bts_trx_alloc(bts);
+	if (!trx) {
+		fprintf(stderr, "Failed to TRX structure\n");
+		exit(1);
+	}
+
+	if (bts_init(bts) < 0) {
+		fprintf(stderr, "unable to to open bts\n");
+		exit(1);
+	}
+
+	test_sbts1002(trx);
+	test_sbts1020(trx);
+	test_sbts1100(trx);
+	test_sbts2050(trx);
+
+	/* test error case / excess power (40 dBm is too much) */
+	test_power_ramp(trx, 40);
+	/* test actaul ramping to full 33 dBm */
+	test_power_ramp(trx, 33);
+
+	while (1) {
+		osmo_select_main(0);
+	}
+}
diff --git a/tests/tx_power/tx_power_test.err b/tests/tx_power/tx_power_test.err
new file mode 100644
index 0000000..bf33b42
--- /dev/null
+++ b/tests/tx_power/tx_power_test.err
@@ -0,0 +1,38 @@
+power_ramp_start(cur=0, tgt=40000)
+Asked to ramp power up to 40000 mdBm, which exceeds P_max_out (33000)
+power_ramp_start(cur=0, tgt=33000)
+ramp_timer_cb(cur_pout=2000, tgt_pout=33000, ramp_att=31000, therm_att=0, user_gain=0)
+ramping TRX board output power to -8000 mdBm.
+ramp_timer_cb(cur_pout=4000, tgt_pout=33000, ramp_att=29000, therm_att=0, user_gain=0)
+ramping TRX board output power to -6000 mdBm.
+ramp_timer_cb(cur_pout=6000, tgt_pout=33000, ramp_att=27000, therm_att=0, user_gain=0)
+ramping TRX board output power to -4000 mdBm.
+ramp_timer_cb(cur_pout=8000, tgt_pout=33000, ramp_att=25000, therm_att=0, user_gain=0)
+ramping TRX board output power to -2000 mdBm.
+ramp_timer_cb(cur_pout=10000, tgt_pout=33000, ramp_att=23000, therm_att=0, user_gain=0)
+ramping TRX board output power to 0 mdBm.
+ramp_timer_cb(cur_pout=12000, tgt_pout=33000, ramp_att=21000, therm_att=0, user_gain=0)
+ramping TRX board output power to 2000 mdBm.
+ramp_timer_cb(cur_pout=14000, tgt_pout=33000, ramp_att=19000, therm_att=0, user_gain=0)
+ramping TRX board output power to 4000 mdBm.
+ramp_timer_cb(cur_pout=16000, tgt_pout=33000, ramp_att=17000, therm_att=0, user_gain=0)
+ramping TRX board output power to 6000 mdBm.
+ramp_timer_cb(cur_pout=18000, tgt_pout=33000, ramp_att=15000, therm_att=0, user_gain=0)
+ramping TRX board output power to 8000 mdBm.
+ramp_timer_cb(cur_pout=20000, tgt_pout=33000, ramp_att=13000, therm_att=0, user_gain=0)
+ramping TRX board output power to 10000 mdBm.
+ramp_timer_cb(cur_pout=22000, tgt_pout=33000, ramp_att=11000, therm_att=0, user_gain=0)
+ramping TRX board output power to 12000 mdBm.
+ramp_timer_cb(cur_pout=24000, tgt_pout=33000, ramp_att=9000, therm_att=0, user_gain=0)
+ramping TRX board output power to 14000 mdBm.
+ramp_timer_cb(cur_pout=26000, tgt_pout=33000, ramp_att=7000, therm_att=0, user_gain=0)
+ramping TRX board output power to 16000 mdBm.
+ramp_timer_cb(cur_pout=28000, tgt_pout=33000, ramp_att=5000, therm_att=0, user_gain=0)
+ramping TRX board output power to 18000 mdBm.
+ramp_timer_cb(cur_pout=30000, tgt_pout=33000, ramp_att=3000, therm_att=0, user_gain=0)
+ramping TRX board output power to 20000 mdBm.
+ramp_timer_cb(cur_pout=32000, tgt_pout=33000, ramp_att=1000, therm_att=0, user_gain=0)
+ramping TRX board output power to 22000 mdBm.
+ramp_timer_cb(cur_pout=33000, tgt_pout=33000, ramp_att=0, therm_att=0, user_gain=0)
+ramping TRX board output power to 23000 mdBm.
+
\ No newline at end of file
diff --git a/tests/tx_power/tx_power_test.ok b/tests/tx_power/tx_power_test.ok
new file mode 100644
index 0000000..ceb88ab
--- /dev/null
+++ b/tests/tx_power/tx_power_test.ok
@@ -0,0 +1,23 @@
+Testing tx_power calculation for sysmoBTS 1002
+Testing tx_power calculation for sysmoBTS 1020
+Testing tx_power calculation for sysmoBTS 1100
+Testing tx_power calculation for sysmoBTS 2050
+Testing tx_power ramping for sysmoBTS 1020
+Testing tx_power ramping for sysmoBTS 1020
+CHANGE_POWER(-8000)
+CHANGE_POWER(-6000)
+CHANGE_POWER(-4000)
+CHANGE_POWER(-2000)
+CHANGE_POWER(0)
+CHANGE_POWER(2000)
+CHANGE_POWER(4000)
+CHANGE_POWER(6000)
+CHANGE_POWER(8000)
+CHANGE_POWER(10000)
+CHANGE_POWER(12000)
+CHANGE_POWER(14000)
+CHANGE_POWER(16000)
+CHANGE_POWER(18000)
+CHANGE_POWER(20000)
+CHANGE_POWER(22000)
+CHANGE_POWER(23000)

-- 
To view, visit https://gerrit.osmocom.org/1768
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1cc88d4c6edff326e2e67d4f869aa02c9b2b1ac5
Gerrit-PatchSet: 2
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder


More information about the gerrit-log mailing list