diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-03-23 02:00:00 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2018-03-23 12:25:04 +0000 |
commit | c1991df2c496835bd2bdfda6c79c5100dea56a8d (patch) | |
tree | 89d28474c0d03f93b318586378d3ecfae7e82ab9 /tests | |
parent | 7e27b14ef29da0d8f834d8aba03551c34341ba90 (diff) |
gsm0808_test: cosmetic: re-arrange struct init; print hexdump on failure
I am going to ehance the test to actually include leading-zero MNC, but first I
would like to simplify how the test source struct is initialized, before I edit
around in it.
Also, when the memcmp() fails, print hexdumps of expected and actual result for
comparison. I needed it to figure out a test failure, might as well keep it.
Change-Id: I77cd4b9142510c6914298b720d9c19ab68f9ebef
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gsm0808/gsm0808_test.c | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c index c3c86dc1..c25344a2 100644 --- a/tests/gsm0808/gsm0808_test.c +++ b/tests/gsm0808/gsm0808_test.c @@ -1005,37 +1005,45 @@ static void test_gsm0808_enc_dec_cell_id_list_multi_global() 0x92, 0x72, 0x54, 0x24, 0x43, 0x00, 0x2, 0x92, 0x83, 0x54, 0x25, 0x44, 0x00, 0x77 }; - struct osmo_cell_global_id id; uint8_t rc_enc; int rc_dec, i; - memset(&enc_cil, 0, sizeof(enc_cil)); - - enc_cil.id_discr = CELL_IDENT_WHOLE_GLOBAL; - - id.lai.plmn.mcc = 0x123; - osmo_mnc_from_str("456", &id.lai.plmn.mnc, &id.lai.plmn.mnc_3_digits); - id.lai.lac = 0x2342; - id.cell_identity = 1; - memcpy(&enc_cil.id_list[0].global, &id, sizeof(id)); - - id.lai.plmn.mcc = 0x124; - osmo_mnc_from_str("457", &id.lai.plmn.mnc, &id.lai.plmn.mnc_3_digits); - id.lai.lac = 0x2443; - id.cell_identity = 2; - memcpy(&enc_cil.id_list[1].global, &id, sizeof(id)); - - id.lai.plmn.mcc = 0x125; - osmo_mnc_from_str("458", &id.lai.plmn.mnc, &id.lai.plmn.mnc_3_digits); - id.lai.lac = 0x2544; - id.cell_identity = 119; - memcpy(&enc_cil.id_list[2].global, &id, sizeof(id)); - - enc_cil.id_list_len = 3; + enc_cil = (struct gsm0808_cell_id_list2){ + .id_discr = CELL_IDENT_WHOLE_GLOBAL, + .id_list_len = 3, + .id_list = { + { + .global = { + .lai = { .plmn = { .mcc = 0x123, .mnc = 456 }, + .lac = 0x2342 }, + .cell_identity = 1, + } + }, + { + .global = { + .lai = { .plmn = { .mcc = 0x124, .mnc = 457 }, + .lac = 0x2443 }, + .cell_identity = 2, + } + }, + { + .global = { + .lai = { .plmn = { .mcc = 0x125, .mnc = 458 }, + .lac = 0x2544 }, + .cell_identity = 119, + } + }, + } + }; msg = msgb_alloc(1024, "output buffer"); rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil); OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected)); + if (memcmp(cil_enc_expected, msg->data, msg->len)) { + printf(" got: %s\n", osmo_hexdump(msg->data, msg->len)); + printf("expect: %s\n", osmo_hexdump(cil_enc_expected, sizeof(cil_enc_expected))); + OSMO_ASSERT(false); + } OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0); rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2); |