aboutsummaryrefslogtreecommitdiffstats
path: root/tests/misc/misc_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/misc/misc_test.c')
-rw-r--r--tests/misc/misc_test.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/misc/misc_test.c b/tests/misc/misc_test.c
index 91fd73a1..f1b7ce3c 100644
--- a/tests/misc/misc_test.c
+++ b/tests/misc/misc_test.c
@@ -21,10 +21,81 @@
*/
#include <osmo-bts/bts.h>
+#include <osmo-bts/msg_utils.h>
+#include <osmo-bts/logging.h>
+
+#include <osmocom/gsm/protocol/ipaccess.h>
#include <stdlib.h>
#include <stdio.h>
+static const uint8_t ipa_rsl_connect[] = {
+ 0x00, 0x1c, 0xff, 0x10, 0x80, 0x00, 0x0a, 0x0d,
+ 0x63, 0x6f, 0x6d, 0x2e, 0x69, 0x70, 0x61, 0x63,
+ 0x63, 0x65, 0x73, 0x73, 0x00, 0xe0, 0x04, 0x00,
+ 0x00, 0xff, 0x85, 0x00, 0x81, 0x0b, 0xbb
+};
+
+static void test_msg_utils_ipa(void)
+{
+ struct msgb *msg;
+ int rc, size;
+
+ printf("Testing IPA structure\n");
+
+ msg = msgb_alloc(sizeof(ipa_rsl_connect), "IPA test");
+ msg->l1h = msgb_put(msg, sizeof(ipa_rsl_connect));
+ memcpy(msg->l1h, ipa_rsl_connect, sizeof(ipa_rsl_connect));
+ rc = msg_verify_ipa_structure(msg);
+ OSMO_ASSERT(rc == 0);
+ msgb_free(msg);
+
+ /* test truncated messages and they should fail */
+ for (size = sizeof(ipa_rsl_connect) - 1; size >= 0; --size) {
+ msg = msgb_alloc(sizeof(ipa_rsl_connect) - 1, "IPA test");
+ msg->l1h = msgb_put(msg, size);
+ memcpy(msg->l1h, ipa_rsl_connect, size);
+ rc = msg_verify_ipa_structure(msg);
+ OSMO_ASSERT(rc == -1);
+ msgb_free(msg);
+ }
+
+ /* change the type of the message */
+ msg = msgb_alloc(sizeof(ipa_rsl_connect), "IPA test");
+ msg->l1h = msgb_put(msg, sizeof(ipa_rsl_connect));
+ memcpy(msg->l1h, ipa_rsl_connect, sizeof(ipa_rsl_connect));
+ msg->l1h[2] = 0x23;
+ rc = msg_verify_ipa_structure(msg);
+ OSMO_ASSERT(rc == -1);
+ msgb_free(msg);
+}
+
+static void test_msg_utils_oml(void)
+{
+ static const size_t hh_size = sizeof(struct ipaccess_head);
+ struct msgb *msg;
+ int rc, size;
+
+ printf("Testing OML structure\n");
+
+ msg = msgb_alloc(sizeof(ipa_rsl_connect) - hh_size, "IPA test");
+ msg->l2h = msgb_put(msg, sizeof(ipa_rsl_connect) - hh_size);
+ memcpy(msg->l2h, ipa_rsl_connect + hh_size, sizeof(ipa_rsl_connect) - hh_size);
+ rc = msg_verify_oml_structure(msg);
+ OSMO_ASSERT(rc == OML_MSG_TYPE_IPA);
+ msgb_free(msg);
+
+ /* test truncated messages and they should fail */
+ for (size = sizeof(ipa_rsl_connect) - hh_size - 1; size >=0; --size) {
+ msg = msgb_alloc(size, "IPA test");
+ msg->l2h = msgb_put(msg, size);
+ memcpy(msg->l2h, ipa_rsl_connect + hh_size, size);
+ rc = msg_verify_oml_structure(msg);
+ OSMO_ASSERT(rc == -1);
+ msgb_free(msg);
+ }
+}
+
static void test_sacch_get(void)
{
struct gsm_lchan lchan;
@@ -53,6 +124,10 @@ static void test_sacch_get(void)
int main(int argc, char **argv)
{
+ bts_log_init(NULL);
+
test_sacch_get();
+ test_msg_utils_ipa();
+ test_msg_utils_oml();
return EXIT_SUCCESS;
}