aboutsummaryrefslogtreecommitdiffstats
path: root/tests/tx_power/tx_power_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tx_power/tx_power_test.c')
-rw-r--r--tests/tx_power/tx_power_test.c86
1 files changed, 64 insertions, 22 deletions
diff --git a/tests/tx_power/tx_power_test.c b/tests/tx_power/tx_power_test.c
index ad3f68ce..e0f88bc9 100644
--- a/tests/tx_power/tx_power_test.c
+++ b/tests/tx_power/tx_power_test.c
@@ -12,7 +12,7 @@
* 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.
+ * GNU Affero 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/>.
@@ -20,6 +20,7 @@
*/
#include <stdint.h>
+#include <errno.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/talloc.h>
@@ -27,9 +28,11 @@
#include <osmo-bts/gsm_data.h>
#include <osmo-bts/bts.h>
+#include <osmo-bts/bts_sm.h>
#include <osmo-bts/logging.h>
#include <osmo-bts/tx_power.h>
+static bool power_ramp_finished = false;
static const struct trx_power_params tpp_1002 = {
.trx_p_max_out_mdBm = to_mdB(23),
@@ -120,9 +123,9 @@ static void test_sbts1002(struct gsm_bts_trx *trx)
/* 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));
+ OSMO_ASSERT(get_p_target_mdBm(trx, 2) == 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));
+ OSMO_ASSERT(get_p_trxout_target_mdBm(trx, 4) == to_mdB(17));
}
static void test_sbts1020(struct gsm_bts_trx *trx)
@@ -138,9 +141,9 @@ static void test_sbts1020(struct gsm_bts_trx *trx)
/* 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));
+ OSMO_ASSERT(get_p_target_mdBm(trx, 2) == 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));
+ OSMO_ASSERT(get_p_trxout_target_mdBm(trx, 4) == to_mdB(17));
}
@@ -157,9 +160,9 @@ static void test_sbts1100(struct gsm_bts_trx *trx)
/* 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));
+ OSMO_ASSERT(get_p_target_mdBm(trx, 2) == 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));
+ OSMO_ASSERT(get_p_trxout_target_mdBm(trx, 4) == to_mdB(17));
}
static void test_sbts2050(struct gsm_bts_trx *trx)
@@ -175,31 +178,63 @@ static void test_sbts2050(struct gsm_bts_trx *trx)
/* 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));
+ OSMO_ASSERT(get_p_target_mdBm(trx, 2) == 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));
+ OSMO_ASSERT(get_p_trxout_target_mdBm(trx, 4) == 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)
+static void test_ramp_compl_cb(struct gsm_bts_trx *trx)
+{
+ power_ramp_finished = true;
+ printf("power_ramp finished\n");
+}
+
+static int test_power_ramp(struct gsm_bts_trx *trx, int dBm)
{
printf("Testing tx_power ramping for sysmoBTS 1020\n");
+ int rc;
+
trx->power_params = tpp_1020;
+ trx->power_params.ramp.step_interval_sec = 0; /* speedup test */
trx->max_power_red = 0;
- power_ramp_start(trx, to_mdB(dBm), 0);
+ power_ramp_finished = false;
+ if ((rc = power_ramp_start(trx, to_mdB(dBm), 0, test_ramp_compl_cb)))
+ return rc;
+ while (!power_ramp_finished)
+ osmo_select_main(0);
+ return 0;
+}
+
+
+static int test_power_ramp_from_minus10(struct gsm_bts_trx *trx, int dBm)
+{
+ printf("Testing tx_power ramping for osmo-bts-trx after lock\n");
+ int rc;
+
+ trx->power_params = tpp_1002;
+ trx->power_params.trx_p_max_out_mdBm = to_mdB(20);
+ trx->power_params.p_total_tgt_mdBm = to_mdB(-10);
+ trx->power_params.p_total_cur_mdBm = to_mdB(-10);
+ trx->power_params.ramp.max_initial_pout_mdBm = to_mdB(0);
+ trx->power_params.ramp.step_interval_sec = 0; /* speedup test */
+ trx->max_power_red = 10;
+
+ power_ramp_finished = false;
+ if ((rc = power_ramp_start(trx, to_mdB(dBm), 0, test_ramp_compl_cb)))
+ return rc;
+ while (!power_ramp_finished)
+ osmo_select_main(0);
+ return 0;
}
int main(int argc, char **argv)
@@ -213,9 +248,17 @@ int main(int argc, char **argv)
osmo_init_logging2(tall_bts_ctx, &bts_log_info);
osmo_stderr_target->categories[DL1C].loglevel = LOGL_DEBUG;
- log_set_print_filename(osmo_stderr_target, 0);
+ log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
+ log_set_use_color(osmo_stderr_target, 0);
+ log_set_print_category(osmo_stderr_target, 0);
+ log_set_print_category_hex(osmo_stderr_target, 0);
- bts = gsm_bts_alloc(tall_bts_ctx, 0);
+ g_bts_sm = gsm_bts_sm_alloc(tall_bts_ctx);
+ if (!g_bts_sm) {
+ fprintf(stderr, "Failed to create BTS Site Manager structure\n");
+ exit(1);
+ }
+ bts = gsm_bts_alloc(g_bts_sm, 0);
if (!bts) {
fprintf(stderr, "Failed to create BTS structure\n");
exit(1);
@@ -237,11 +280,10 @@ int main(int argc, char **argv)
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 */
+ OSMO_ASSERT(test_power_ramp(trx, 40) == -ERANGE);
+ /* test actual ramping to full 33 dBm */
test_power_ramp(trx, 33);
+ /* Test ramp up from -10dBm (locked) to 10dBm */
+ test_power_ramp_from_minus10(trx, 10);
- while (1) {
- osmo_select_main(0);
- }
}