summaryrefslogtreecommitdiffstats
path: root/tests/gsm0808
diff options
context:
space:
mode:
Diffstat (limited to 'tests/gsm0808')
-rw-r--r--tests/gsm0808/gsm0808_test.c85
-rw-r--r--tests/gsm0808/gsm0808_test.ok92
2 files changed, 169 insertions, 8 deletions
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index af90d00c..c448f439 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -2206,29 +2206,96 @@ static bool test_cell_id_list_matching_discrs(bool test_match,
return true;
}
+const enum CELL_IDENT cell_ident_discrs[] = {
+ CELL_IDENT_LAC, CELL_IDENT_CI, CELL_IDENT_LAC_AND_CI, CELL_IDENT_LAI_AND_LAC,
+ CELL_IDENT_WHOLE_GLOBAL,
+};
+
+
static void test_cell_id_list_matching(bool test_match)
{
int i, j;
bool ok = true;
- const enum CELL_IDENT discrs[] = {
- CELL_IDENT_LAC, CELL_IDENT_CI, CELL_IDENT_LAC_AND_CI, CELL_IDENT_LAI_AND_LAC,
- CELL_IDENT_WHOLE_GLOBAL,
- };
-
printf("\n%s(%s)\n", __func__, test_match ? "test match" : "test mismatch");
/* Autogenerate Cell ID lists from above dataset, which should match / not match. */
- for (i = 0; i < ARRAY_SIZE(discrs); i++) {
- for (j = 0; j < ARRAY_SIZE(discrs); j++)
+ for (i = 0; i < ARRAY_SIZE(cell_ident_discrs); i++) {
+ for (j = 0; j < ARRAY_SIZE(cell_ident_discrs); j++)
if (!test_cell_id_list_matching_discrs(test_match,
- discrs[i], discrs[j]))
+ cell_ident_discrs[i], cell_ident_discrs[j]))
ok = false;
}
OSMO_ASSERT(ok);
}
+
+static const struct gsm0808_cell_id test_gsm0808_cell_id_to_from_cgi_data[] = {
+ lac_23,
+ lac_42,
+ ci_5,
+ ci_6,
+ lac_ci_23_5,
+ lac_ci_42_6,
+ lai_23_042_23,
+ lai_23_042_42,
+ lai_23_99_23,
+ lai_23_42_23,
+ cgi_23_042_23_5,
+ cgi_23_042_42_6,
+ cgi_23_99_23_5,
+ { .id_discr = CELL_IDENT_NO_CELL },
+ { .id_discr = 423 },
+};
+
+static void test_gsm0808_cell_id_to_from_cgi()
+{
+ int i;
+ int j;
+
+ printf("\n%s()\n", __func__);
+
+ for (i = 0; i < ARRAY_SIZE(test_gsm0808_cell_id_to_from_cgi_data); i++) {
+ const struct gsm0808_cell_id *from_cid = &test_gsm0808_cell_id_to_from_cgi_data[i];
+ struct osmo_cell_global_id cgi = {
+ .lai = {
+ .plmn = {
+ .mcc = 777,
+ .mnc = 7,
+ .mnc_3_digits = true,
+ },
+ .lac = 7777,
+ },
+ .cell_identity = 7777,
+ };
+ struct gsm0808_cell_id cid = {};
+ int rc;
+
+ rc = gsm0808_cell_id_to_cgi(&cgi, from_cid);
+ printf("cid %s -> cgi %s", gsm0808_cell_id_name(from_cid), osmo_cgi_name(&cgi));
+
+ if (rc & OSMO_CGI_PART_PLMN)
+ printf(" PLMN");
+ if (rc & OSMO_CGI_PART_LAC)
+ printf(" LAC");
+ if (rc & OSMO_CGI_PART_CI)
+ printf(" CI");
+
+ gsm0808_cell_id_from_cgi(&cid, from_cid->id_discr, &cgi);
+ printf(" -> cid %s\n", gsm0808_cell_id_name(&cid));
+ if (!gsm0808_cell_ids_match(from_cid, &cid, true))
+ printf(" MISMATCH!\n");
+
+ for (j = 0; j < ARRAY_SIZE(cell_ident_discrs); j++) {
+ enum CELL_IDENT discr = cell_ident_discrs[j];
+
+ gsm0808_cell_id_from_cgi(&cid, discr, &cgi);
+ printf(" --> gsm0808_cell_id{%s} = %s\n", gsm0808_cell_id_discr_name(discr), gsm0808_cell_id_name(&cid));
+ }
+ }
+}
+
int main(int argc, char **argv)
{
void *ctx = talloc_named_const(NULL, 0, "gsm0808 test");
@@ -2300,6 +2367,8 @@ int main(int argc, char **argv)
test_cell_id_list_matching(true);
test_cell_id_list_matching(false);
+ test_gsm0808_cell_id_to_from_cgi();
+
printf("Done\n");
return EXIT_SUCCESS;
}
diff --git a/tests/gsm0808/gsm0808_test.ok b/tests/gsm0808/gsm0808_test.ok
index e7df007a..60353262 100644
--- a/tests/gsm0808/gsm0808_test.ok
+++ b/tests/gsm0808/gsm0808_test.ok
@@ -629,4 +629,96 @@ CGI:023-042-23-5 and CI[1]:{6}: mismatch
CGI:023-042-23-5 and LAC-CI[1]:{42-6}: mismatch
CGI:023-042-23-5 and LAI[3]:{023-042-42, 023-99-23, 023-42-23}: mismatch
CGI:023-042-23-5 and CGI[2]:{023-042-42-6, 023-99-23-5}: mismatch
+
+test_gsm0808_cell_id_to_from_cgi()
+cid LAC:23 -> cgi 777-007-23-7777 LAC -> cid LAC:23
+ --> gsm0808_cell_id{LAC} = LAC:23
+ --> gsm0808_cell_id{CI} = CI:7777
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:23-7777
+ --> gsm0808_cell_id{LAI} = LAI:777-007-23
+ --> gsm0808_cell_id{CGI} = CGI:777-007-23-7777
+cid LAC:42 -> cgi 777-007-42-7777 LAC -> cid LAC:42
+ --> gsm0808_cell_id{LAC} = LAC:42
+ --> gsm0808_cell_id{CI} = CI:7777
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:42-7777
+ --> gsm0808_cell_id{LAI} = LAI:777-007-42
+ --> gsm0808_cell_id{CGI} = CGI:777-007-42-7777
+cid CI:5 -> cgi 777-007-7777-5 CI -> cid CI:5
+ --> gsm0808_cell_id{LAC} = LAC:7777
+ --> gsm0808_cell_id{CI} = CI:5
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:7777-5
+ --> gsm0808_cell_id{LAI} = LAI:777-007-7777
+ --> gsm0808_cell_id{CGI} = CGI:777-007-7777-5
+cid CI:6 -> cgi 777-007-7777-6 CI -> cid CI:6
+ --> gsm0808_cell_id{LAC} = LAC:7777
+ --> gsm0808_cell_id{CI} = CI:6
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:7777-6
+ --> gsm0808_cell_id{LAI} = LAI:777-007-7777
+ --> gsm0808_cell_id{CGI} = CGI:777-007-7777-6
+cid LAC-CI:23-5 -> cgi 777-007-23-5 LAC CI -> cid LAC-CI:23-5
+ --> gsm0808_cell_id{LAC} = LAC:23
+ --> gsm0808_cell_id{CI} = CI:5
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:23-5
+ --> gsm0808_cell_id{LAI} = LAI:777-007-23
+ --> gsm0808_cell_id{CGI} = CGI:777-007-23-5
+cid LAC-CI:42-6 -> cgi 777-007-42-6 LAC CI -> cid LAC-CI:42-6
+ --> gsm0808_cell_id{LAC} = LAC:42
+ --> gsm0808_cell_id{CI} = CI:6
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:42-6
+ --> gsm0808_cell_id{LAI} = LAI:777-007-42
+ --> gsm0808_cell_id{CGI} = CGI:777-007-42-6
+cid LAI:023-042-23 -> cgi 023-042-23-7777 PLMN LAC -> cid LAI:023-042-23
+ --> gsm0808_cell_id{LAC} = LAC:23
+ --> gsm0808_cell_id{CI} = CI:7777
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:23-7777
+ --> gsm0808_cell_id{LAI} = LAI:023-042-23
+ --> gsm0808_cell_id{CGI} = CGI:023-042-23-7777
+cid LAI:023-042-42 -> cgi 023-042-42-7777 PLMN LAC -> cid LAI:023-042-42
+ --> gsm0808_cell_id{LAC} = LAC:42
+ --> gsm0808_cell_id{CI} = CI:7777
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:42-7777
+ --> gsm0808_cell_id{LAI} = LAI:023-042-42
+ --> gsm0808_cell_id{CGI} = CGI:023-042-42-7777
+cid LAI:023-99-23 -> cgi 023-99-23-7777 PLMN LAC -> cid LAI:023-99-23
+ --> gsm0808_cell_id{LAC} = LAC:23
+ --> gsm0808_cell_id{CI} = CI:7777
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:23-7777
+ --> gsm0808_cell_id{LAI} = LAI:023-99-23
+ --> gsm0808_cell_id{CGI} = CGI:023-99-23-7777
+cid LAI:023-42-23 -> cgi 023-42-23-7777 PLMN LAC -> cid LAI:023-42-23
+ --> gsm0808_cell_id{LAC} = LAC:23
+ --> gsm0808_cell_id{CI} = CI:7777
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:23-7777
+ --> gsm0808_cell_id{LAI} = LAI:023-42-23
+ --> gsm0808_cell_id{CGI} = CGI:023-42-23-7777
+cid CGI:023-042-23-5 -> cgi 023-042-23-5 PLMN LAC CI -> cid CGI:023-042-23-5
+ --> gsm0808_cell_id{LAC} = LAC:23
+ --> gsm0808_cell_id{CI} = CI:5
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:23-5
+ --> gsm0808_cell_id{LAI} = LAI:023-042-23
+ --> gsm0808_cell_id{CGI} = CGI:023-042-23-5
+cid CGI:023-042-42-6 -> cgi 023-042-42-6 PLMN LAC CI -> cid CGI:023-042-42-6
+ --> gsm0808_cell_id{LAC} = LAC:42
+ --> gsm0808_cell_id{CI} = CI:6
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:42-6
+ --> gsm0808_cell_id{LAI} = LAI:023-042-42
+ --> gsm0808_cell_id{CGI} = CGI:023-042-42-6
+cid CGI:023-99-23-5 -> cgi 023-99-23-5 PLMN LAC CI -> cid CGI:023-99-23-5
+ --> gsm0808_cell_id{LAC} = LAC:23
+ --> gsm0808_cell_id{CI} = CI:5
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:23-5
+ --> gsm0808_cell_id{LAI} = LAI:023-99-23
+ --> gsm0808_cell_id{CGI} = CGI:023-99-23-5
+cid NO-CELL:NO-CELL -> cgi 777-007-7777-7777 -> cid NO-CELL:NO-CELL
+ --> gsm0808_cell_id{LAC} = LAC:7777
+ --> gsm0808_cell_id{CI} = CI:7777
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:7777-7777
+ --> gsm0808_cell_id{LAI} = LAI:777-007-7777
+ --> gsm0808_cell_id{CGI} = CGI:777-007-7777-7777
+cid unknown 0x1a7:unknown 0x1a7 -> cgi 777-007-7777-7777 -> cid unknown 0x1a7:unknown 0x1a7
+ --> gsm0808_cell_id{LAC} = LAC:7777
+ --> gsm0808_cell_id{CI} = CI:7777
+ --> gsm0808_cell_id{LAC-CI} = LAC-CI:7777-7777
+ --> gsm0808_cell_id{LAI} = LAI:777-007-7777
+ --> gsm0808_cell_id{CGI} = CGI:777-007-7777-7777
Done