Max has uploaded this change for review. ( https://gerrit.osmocom.org/13132


Change subject: Use msgb_eq_data_print() in tests
......................................................................

Use msgb_eq_data_print() in tests

This allows to see exact byte which differs with expected output in case
of test failure.

Change-Id: If1285649b27843d68dfaa6f6dd3b80deee9aa148
---
M tests/llc/LlcTest.cpp
M tests/rlcmac/RLCMACTest.cpp
M tests/tbf/TbfTest.cpp
3 files changed, 43 insertions(+), 18 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/32/13132/1

diff --git a/tests/llc/LlcTest.cpp b/tests/llc/LlcTest.cpp
index 3083644..13bda3c 100644
--- a/tests/llc/LlcTest.cpp
+++ b/tests/llc/LlcTest.cpp
@@ -61,7 +61,6 @@
        size_t len, const gprs_llc_queue::MetaInfo *exp_info = 0)
 {
        struct msgb *llc_msg;
-       uint8_t *msg_data;
        const gprs_llc_queue::MetaInfo *info_res;

        llc_msg = queue->dequeue(&info_res);
@@ -70,10 +69,8 @@
        fprintf(stderr, "dequeued msg, length %u (expected %zu), data %s\n",
                msgb_length(llc_msg), len, msgb_hexdump(llc_msg));

-       OSMO_ASSERT(msgb_length(llc_msg) == len);
-       msg_data = msgb_data(llc_msg);
-
-       OSMO_ASSERT(memcmp(msg_data, exp_data, len) == 0);
+       if (!msgb_eq_data_print(llc_msg, exp_data, len))
+               fprintf(stderr, "check failed!\n");

        if (exp_info)
                OSMO_ASSERT(memcmp(exp_info, info_res, sizeof(*exp_info)) == 0);
@@ -229,7 +226,7 @@
        log_set_use_color(osmo_stderr_target, 0);
        log_set_print_filename(osmo_stderr_target, 0);
        log_set_log_level(osmo_stderr_target, LOGL_INFO);
-       log_parse_category_mask(osmo_stderr_target, "DPCU,3");
+       log_parse_category_mask(osmo_stderr_target, "DPCU,3:DLGLOBAL,1:");

        vty_init(&pcu_vty_info);
        pcu_vty_init(&gprs_log_info);
diff --git a/tests/rlcmac/RLCMACTest.cpp b/tests/rlcmac/RLCMACTest.cpp
index bf7a605..04d3895 100644
--- a/tests/rlcmac/RLCMACTest.cpp
+++ b/tests/rlcmac/RLCMACTest.cpp
@@ -33,6 +33,7 @@
 #include <osmocom/vty/telnet_interface.h>
 #include <osmocom/vty/logging.h>
 #include <osmocom/core/utils.h>
+#include <osmocom/core/msgb.h>
 #include <osmocom/core/application.h>
 }
 using namespace std;
@@ -216,6 +217,8 @@

 void testCsnLeftAlignedVarBmpBounds(void *test_ctx)
 {
+       struct msgb *m = msgb_alloc(80, "test");
+       static uint8_t exp[] = { 0x7f, 0xff, 0xff, 0xee, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
        bitvec *vector = bitvec_alloc(23, test_ctx);

        bitvec_unhex(vector, "40200bffd161003e0e519ffffffb800000000000000000");
@@ -225,14 +228,16 @@
                &data.u.Egprs_Packet_Downlink_Ack_Nack.EGPRS_AckNack.Desc;
        decode_gsm_rlcmac_uplink(vector, &data);
 
-       OSMO_ASSERT(!strcmp(osmo_hexdump(urbb->URBB, 13),
-                           "7f ff ff ee 00 00 00 00 00 00 00 00 00 "));
+       memcpy(msgb_put(m, 13), urbb->URBB, 13);
+       if (!msgb_eq_data_print(m, exp, 13))
+               printf("%s failed!\n", __func__);
 }

 int main(int argc, char *argv[])
 {
        void *ctx = talloc_named_const(NULL, 1, "RLCMACTest");
        osmo_init_logging2(ctx, &gprs_log_info);
+       log_parse_category_mask(osmo_stderr_target, "DPCU,3:DLGLOBAL,1:");

        //printSizeofRLCMAC();
        testRlcMacDownlink(ctx);
diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp
index dfed79e..ff73d90 100644
--- a/tests/tbf/TbfTest.cpp
+++ b/tests/tbf/TbfTest.cpp
@@ -527,12 +527,21 @@
        struct msgb *msg;
        int fn = 0;
        uint8_t expected_data = 1;
+       static uint8_t exp[][GSM_MACBLOCK_LEN] = {
+               { 0x07, 0x00, 0x00, 0x4d, 0x01, 0x01, 0x01,
+                 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+               { 0x07, 0x00, 0x02, 0x4d, 0x02, 0x02, 0x02,
+                 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 
0x02, 0x02, 0x02, 0x02, 0x02, 0x02 },
+               { 0x07, 0x01, 0x04, 0x4d, 0x03, 0x03, 0x03,
+                 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 
0x03, 0x03, 0x03, 0x03, 0x03, 0x03 },
+       };

        while (ms->dl_tbf()->have_data()) {
                msg = ms->dl_tbf()->create_dl_acked_block(fn += 4, 7);
                fprintf(stderr, "MSG = %s\n", msgb_hexdump(msg));
-               OSMO_ASSERT(msgb_length(msg) == 23);
-               OSMO_ASSERT(msgb_data(msg)[10] == expected_data);
+               if (!msgb_eq_data_print(msg, exp[expected_data - 1], 
GSM_MACBLOCK_LEN))
+                       printf("%s failed at %u\n", __func__, expected_data);
+
                expected_data += 1;
        }
        OSMO_ASSERT(expected_data-1 == 3);
@@ -732,9 +741,14 @@
 
        struct msgb *msg1 = ul_tbf->create_ul_ack(*fn, ts_no);

-       OSMO_ASSERT(!strcmp(osmo_hexdump(msg1->data, msg1->data_len),
-       "40 24 01 3f 3e 24 46 68 90 87 b0 06 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b "
-       ));
+       static uint8_t exp1[] = { 0x40, 0x24, 0x01, 0x3f, 0x3e, 0x24, 0x46, 
0x68, 0x90, 0x87, 0xb0, 0x06,
+                                 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 
0x2b, 0x2b, 0x2b, 0x2b
+       };
+
+       if (!msgb_eq_data_print(msg1, exp1, GSM_MACBLOCK_LEN)) {
+               printf("%s test failed on 1st segment!\n", __func__);
+               return NULL;
+       }

        egprs3->si = 0;
        egprs3->r = 1;
@@ -754,10 +768,14 @@

        msg1 = ul_tbf->create_ul_ack(*fn, ts_no);

-       OSMO_ASSERT(!strcmp(osmo_hexdump(msg1->data, msg1->data_len),
-       "40 24 01 3f 3e 24 46 68 90 88 b0 06 8b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b "
-       ));
+       static uint8_t exp2[] = { 0x40, 0x24, 0x01, 0x3f, 0x3e, 0x24, 0x46, 
0x68, 0x90, 0x88, 0xb0, 0x06, 0x8b,
+                                 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 
0x2b, 0x2b, 0x2b
+       };

+       if (!msgb_eq_data_print(msg1, exp2, GSM_MACBLOCK_LEN)) {
+               printf("%s test failed on 2nd segment!\n", __func__);
+               return NULL;
+       }
        return ul_tbf;
 }

@@ -3205,6 +3223,10 @@
 {
        BTS the_bts;
        uint32_t tlli = 0xffeeddcc;
+       static uint8_t exp[] = { 0x40, 0x84, 0x7f, 0xf7, 0x6e, 0xe6, 0x41, 0x4b,
+                                0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b,
+                                0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b
+       };

        printf("=== start %s ===\n", __func__);
        setup_bts(&the_bts, 4);
@@ -3217,8 +3239,9 @@
        printf("packet reject: %s\n",
                        osmo_hexdump(msg->data, 23));

-       OSMO_ASSERT(!strcmp(osmo_hexdump(msg->data, 23),
-                           "40 84 7f f7 6e e6 41 4b 2b 2b 2b 2b 2b 2b 2b 2b 2b 
2b 2b 2b 2b 2b 2b "));
+       if (!msgb_eq_data_print(msg, exp, GSM_MACBLOCK_LEN))
+               printf("%s test failed!\n", __func__);
+
        printf("=== end %s ===\n", __func__);

 }

--
To view, visit https://gerrit.osmocom.org/13132
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: If1285649b27843d68dfaa6f6dd3b80deee9aa148
Gerrit-Change-Number: 13132
Gerrit-PatchSet: 1
Gerrit-Owner: Max <[email protected]>

Reply via email to