[PATCH libosmocore 2/8] smscb: add unit test for smscb_entity
Alex Badea
vamposdecampos at gmail.com
Sat Jan 5 20:26:26 CET 2013
Since we've enabled logging, we now ignore stderr.
Signed-off-by: Alex Badea <vamposdecampos at gmail.com>
---
tests/smscb/smscb_test.c | 71 +++++++++++++++++++++++++++++++++++++++++++++
tests/smscb/smscb_test.ok | 3 ++
tests/testsuite.at | 2 +-
3 files changed, 75 insertions(+), 1 deletions(-)
diff --git a/tests/smscb/smscb_test.c b/tests/smscb/smscb_test.c
index e10e12d..de88b0a 100644
--- a/tests/smscb/smscb_test.c
+++ b/tests/smscb/smscb_test.c
@@ -19,8 +19,76 @@
*/
#include <osmocom/gsm/protocol/gsm_03_41.h>
+#include <osmocom/gsm/smscb.h>
+#include <osmocom/gsm/rsl.h>
+#include <osmocom/gsm/tlv.h>
+#include <osmocom/core/logging.h>
+#include <osmocom/core/msgb.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define ASSERT(exp) \
+ if (!(exp)) { \
+ printf("Assert failed %s %s:%d\n", #exp, __FILE__, __LINE__); \
+ abort(); \
+ }
+
+
+static struct log_info info = {};
+
+static uint8_t smscb_null_l1_msg[] = {
+ 0x2f, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b,
+ 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b,
+ 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b,
+};
+
+static int l3_cb(struct msgb *msg, struct smscb_entity *se, void *ctx)
+{
+ struct abis_rsl_cchan_hdr *ch;
+ struct tlv_parsed tv;
+ struct rsl_ie_cb_cmd_type *cmd_type;
+ struct gsm341_ms_message *cbmsg;
+ unsigned int cbmsglen;
+
+ printf("smscb l3 cb\n");
+
+ ch = msgb_l2(msg);
+ ASSERT(ch != NULL);
+ ASSERT(ch->c.msg_discr == ABIS_RSL_MDISC_COM_CHAN | ABIS_RSL_MDISC_TRANSP);
+ ASSERT(ch->c.msg_type == RSL_MT_SMS_BC_CMD);
+
+ rsl_tlv_parse(&tv, ch->data, msgb_l2len(msg) - sizeof(*ch));
+ ASSERT(TLVP_PRESENT(&tv, RSL_IE_CB_CMD_TYPE));
+ ASSERT(TLVP_PRESENT(&tv, RSL_IE_SMSCB_MSG));
+
+ cmd_type = (struct rsl_ie_cb_cmd_type *) TLVP_VAL(&tv, RSL_IE_CB_CMD_TYPE);
+ cbmsg = (struct gsm341_ms_message *) TLVP_VAL(&tv, RSL_IE_SMSCB_MSG);
+ cbmsglen = TLVP_LEN(&tv, RSL_IE_SMSCB_MSG);
+
+ printf("cmd_type: %u\n", cmd_type->command);
+ printf("cbmsg:\t%s\n", osmo_hexdump((uint8_t *) cbmsg, cbmsglen));
+}
+
+static int smscb_send(struct smscb_entity *se, const void *data, size_t len)
+{
+ struct msgb *msg = msgb_alloc_headroom(4096, 128, "data");
+ msg->l2h = msgb_put(msg, len);
+ memcpy(msg->l2h, data, len);
+ return smscb_ph_data_ind(se, msg);
+}
+
+static void test_reassembly(void)
+{
+ struct smscb_entity se;
+
+ smscb_init(&se);
+ smscb_set_l3(&se, l3_cb, NULL);
+ smscb_send(&se, smscb_null_l1_msg, sizeof(smscb_null_l1_msg));
+ smscb_exit(&se);
+}
+
static uint8_t smscb_msg[] = { 0x40, 0x10, 0x05, 0x0d, 0x01, 0x11 };
@@ -37,5 +105,8 @@ int main(int argc, char **argv)
printf("(pge) page total: %d current: %d\n",
msg->page.total, msg->page.current);
+ osmo_init_logging(&info);
+ test_reassembly();
+
return 0;
}
diff --git a/tests/smscb/smscb_test.ok b/tests/smscb/smscb_test.ok
index 347037f..5954fc6 100644
--- a/tests/smscb/smscb_test.ok
+++ b/tests/smscb/smscb_test.ok
@@ -2,3 +2,6 @@
(msg) msg_id: 1293
(dcs) group: 1 language: 0
(pge) page total: 1 current: 1
+smscb l3 cb
+cmd_type: 15
+cbmsg:
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 1cfae03..0f5b721 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -46,7 +46,7 @@ AT_CLEANUP
AT_SETUP([smscb])
AT_KEYWORDS([smscb])
cat $abs_srcdir/smscb/smscb_test.ok > expout
-AT_CHECK([$abs_top_builddir/tests/smscb/smscb_test], [], [expout])
+AT_CHECK([$abs_top_builddir/tests/smscb/smscb_test], [], [expout], [ignore])
AT_CLEANUP
AT_SETUP([timer])
--
1.7.0.4
More information about the baseband-devel
mailing list