aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-03-04 23:45:05 +0100
committerNeels Hofmeyr <neels@hofmeyr.de>2018-03-05 00:59:44 +0100
commita05360c9e1cd1a81d0a4d418ab27c4b6626a2ece (patch)
tree0a5e38151e8f6b4e804f650e484ef4cc156f62d0 /tests
parent302f8659b42a53ab22226d852e7c62a65b9a3038 (diff)
add test for gsm48_ra_id_by_bts()
Diffstat (limited to 'tests')
-rw-r--r--tests/gsm0408/gsm0408_test.c114
-rw-r--r--tests/gsm0408/gsm0408_test.ok7
2 files changed, 121 insertions, 0 deletions
diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index 14cd81c5b..d1d50f135 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -32,6 +32,7 @@
#include <osmocom/bsc/abis_rsl.h>
#include <osmocom/core/application.h>
+#include <osmocom/core/byteswap.h>
#include <osmocom/gsm/sysinfo.h>
#include <osmocom/gsm/gsm48.h>
@@ -707,6 +708,117 @@ static void test_si_ba_ind(struct gsm_network *net)
OSMO_ASSERT(si5ter->bcch_frequency_list[0] & 0x10);
}
+struct test_gsm48_ra_id_by_bts {
+ struct osmo_plmn_id plmn;
+ uint16_t lac;
+ uint8_t rac;
+ struct gsm48_ra_id expect;
+};
+static const struct test_gsm48_ra_id_by_bts test_gsm48_ra_id_by_bts_data[] = {
+ {
+ .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false },
+ .lac = 3,
+ .rac = 4,
+ .expect = {
+ .digits = { 0x00, 0xf1, 0x20 },
+ .lac = 0x0300, /* network byte order of 3 */
+ .rac = 4,
+ },
+ },
+ {
+ .plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true },
+ .lac = 3,
+ .rac = 4,
+ .expect = {
+ .digits = { 0x00, 0xf1, 0x20 }, /* FAIL: should be { 0x00, 0x21, 0x00 }, */
+ .lac = 0x0300, /* network byte order of 3 */
+ .rac = 4,
+ },
+ },
+ {
+ .plmn = { .mcc = 0, .mnc = 0, .mnc_3_digits = false },
+ .lac = 0,
+ .rac = 0,
+ .expect = {
+ .digits = { 0x00, 0xf0, 0x00 },
+ },
+ },
+ {
+ .plmn = { .mcc = 0, .mnc = 0, .mnc_3_digits = true },
+ .lac = 0,
+ .rac = 0,
+ .expect = {
+ .digits = { 0x00, 0xf0, 0x00 }, /* FAIL: should be { 0, 0, 0 } */
+ },
+ },
+ {
+ .plmn = { .mcc = 999, .mnc = 999, .mnc_3_digits = false },
+ .lac = 65535,
+ .rac = 255,
+ .expect = {
+ .digits = { 0x99, 0x99, 0x99 },
+ .lac = 0xffff,
+ .rac = 0xff,
+ },
+ },
+ {
+ .plmn = { .mcc = 909, .mnc = 90, .mnc_3_digits = false },
+ .lac = 0xabcd,
+ .rac = 0xab,
+ .expect = {
+ .digits = { 0x09, 0xf9, 0x09 },
+ .lac = 0xcdab,
+ .rac = 0xab,
+ },
+ },
+ {
+ .plmn = { .mcc = 909, .mnc = 90, .mnc_3_digits = true },
+ .lac = 0xabcd,
+ .rac = 0xab,
+ .expect = {
+ .digits = { 0x09, 0xf9, 0x09 }, /* FAIL: should be { 0x09, 0x09, 0x90 }, */
+ .lac = 0xcdab,
+ .rac = 0xab,
+ },
+ },
+};
+
+static void test_gsm48_ra_id_by_bts()
+{
+ int i;
+ bool pass = true;
+
+ for (i = 0; i < ARRAY_SIZE(test_gsm48_ra_id_by_bts_data); i++) {
+ struct gsm_network net;
+ struct gsm_bts bts;
+ const struct test_gsm48_ra_id_by_bts *t = &test_gsm48_ra_id_by_bts_data[i];
+ struct gsm48_ra_id result = {};
+ bool ok;
+
+ net.country_code = t->plmn.mcc;
+ net.network_code = t->plmn.mnc;
+ bts.network = &net;
+ bts.location_area_code = t->lac;
+ bts.gprs.rac = t->rac;
+
+ gsm48_ra_id_by_bts((uint8_t*)&result, &bts);
+
+ ok = (t->expect.digits[0] == result.digits[0])
+ && (t->expect.digits[1] == result.digits[1])
+ && (t->expect.digits[2] == result.digits[2])
+ && (t->expect.lac == result.lac)
+ && (t->expect.rac == result.rac);
+ printf("%s[%d]: digits='%02x%02x%02x' lac=0x%04x=htons(%u) rac=0x%02x=%u %s\n",
+ __func__, i,
+ result.digits[0], result.digits[1], result.digits[2],
+ result.lac, osmo_ntohs(result.lac), result.rac, result.rac,
+ ok ? "pass" : "FAIL");
+ pass = pass && ok;
+ }
+
+ OSMO_ASSERT(pass);
+}
+
static const struct log_info_cat log_categories[] = {
};
@@ -744,6 +856,8 @@ int main(int argc, char **argv)
test_si_ba_ind(net);
+ test_gsm48_ra_id_by_bts();
+
printf("Done.\n");
return EXIT_SUCCESS;
diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok
index b85141a27..686018bcd 100644
--- a/tests/gsm0408/gsm0408_test.ok
+++ b/tests/gsm0408/gsm0408_test.ok
@@ -214,4 +214,11 @@ SI2ter: 59 06 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2b 2b 2b 2b
SI5: 06 1d 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
SI5bis: 06 05 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
SI5ter: 06 06 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+test_gsm48_ra_id_by_bts[0]: digits='00f120' lac=0x0300=htons(3) rac=0x04=4 pass
+test_gsm48_ra_id_by_bts[1]: digits='00f120' lac=0x0300=htons(3) rac=0x04=4 pass
+test_gsm48_ra_id_by_bts[2]: digits='00f000' lac=0x0000=htons(0) rac=0x00=0 pass
+test_gsm48_ra_id_by_bts[3]: digits='00f000' lac=0x0000=htons(0) rac=0x00=0 pass
+test_gsm48_ra_id_by_bts[4]: digits='999999' lac=0xffff=htons(65535) rac=0xff=255 pass
+test_gsm48_ra_id_by_bts[5]: digits='09f909' lac=0xcdab=htons(43981) rac=0xab=171 pass
+test_gsm48_ra_id_by_bts[6]: digits='09f909' lac=0xcdab=htons(43981) rac=0xab=171 pass
Done.