add q931 decoder unit tests

This commit is contained in:
Harald Welte 2022-10-16 19:32:18 +02:00
parent 9d8a83ad8c
commit c50f373aff
5 changed files with 129 additions and 0 deletions

View File

@ -120,4 +120,5 @@ AC_OUTPUT(
doc/examples/Makefile
src/Makefile
tests/Makefile
tests/q931/Makefile
)

View File

@ -1,4 +1,5 @@
SUBDIRS = \
q931 \
$(NULL)
# The `:;' works around a Bash 3.2 bug when the output is not writeable.

31
tests/q931/Makefile.am Normal file
View File

@ -0,0 +1,31 @@
AM_CPPFLAGS = \
$(all_includes) \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src \
$(NULL)
AM_CFLAGS = \
-Wall \
-ggdb3 \
$(LIBOSMOCORE_CFLAGS) \
$(LIBOSMOGSM_CFLAGS) \
$(NULL)
EXTRA_DIST = \
q931_test.ok \
$(NULL)
noinst_PROGRAMS = \
q931_test \
$(NULL)
q931_test_SOURCES = \
q931_test.c \
$(NULL)
q931_test_LDADD = \
$(top_builddir)/src/q931.o \
$(top_builddir)/src/q931_decode.o \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(NULL)

88
tests/q931/q931_test.c Normal file
View File

@ -0,0 +1,88 @@
#include <osmocom/gsm/tlv.h>
#include "q931.h"
static void test_setup(void)
{
const uint8_t msg[] = {
0x08, 0x02, 0x00, 0x23, 0x05, 0x04, 0x03, 0x90,
0x90, 0xa3, 0x18, 0x03, 0xa1, 0x83, 0x81, 0x6c,
0x0d, 0x41, 0x80, 0x30, 0x33, 0x30, 0x31, 0x32,
0x33, 0x34, 0x32, 0x31, 0x31, 0x31
};
struct q931_msg_parsed q931;
int rc;
memset(&q931, 0, sizeof(q931));
rc = q931_msg_parse(&q931, msg, sizeof(msg));
OSMO_ASSERT(rc == 0);
OSMO_ASSERT(q931.msg_type == Q931_MSGT_SETUP);
OSMO_ASSERT(q931.call_ref == 0x0023);
OSMO_ASSERT(TLVP_PRES_LEN(&q931.ies, Q931_IEI_BEARER_CAP, 3));
OSMO_ASSERT(TLVP_PRES_LEN(&q931.ies, Q931_IEI_CHANNEL_ID, 3));
OSMO_ASSERT(TLVP_PRES_LEN(&q931.ies, Q931_IEI_CALLING_PARTY_NUM, 13));
}
static void test_setup_ack(void)
{
const uint8_t msg[] = {
0x08, 0x02, 0x80, 0x24, 0x0d, 0x18, 0x03,
0xa9, 0x83, 0x81
};
struct q931_msg_parsed q931;
int rc;
memset(&q931, 0, sizeof(q931));
rc = q931_msg_parse(&q931, msg, sizeof(msg));
OSMO_ASSERT(rc == 0);
OSMO_ASSERT(q931.msg_type == Q931_MSGT_SETUP_ACK);
OSMO_ASSERT(q931.call_ref == 0x80000024);
OSMO_ASSERT(TLVP_PRES_LEN(&q931.ies, Q931_IEI_CHANNEL_ID, 3));
}
static void test_information(void)
{
const uint8_t msg[] = {
0x08, 0x02, 0x00, 0x24, 0x7b, 0x70, 0x05,
0x81, 0x33, 0x30, 0x33, 0x38
};
struct q931_msg_parsed q931;
int rc;
memset(&q931, 0, sizeof(q931));
rc = q931_msg_parse(&q931, msg, sizeof(msg));
OSMO_ASSERT(rc == 0);
OSMO_ASSERT(q931.msg_type == Q931_MSGT_INFORMATION);
OSMO_ASSERT(q931.call_ref == 0x00000024);
OSMO_ASSERT(TLVP_PRES_LEN(&q931.ies, Q931_IEI_CALLED_PARTY_NUM, 5));
}
static void test_alerting(void)
{
const uint8_t msg[] = {
0x08, 0x02, 0x80, 0x24, 0x01, 0x1e, 0x02,
0x81, 0x88
};
struct q931_msg_parsed q931;
int rc;
memset(&q931, 0, sizeof(q931));
rc = q931_msg_parse(&q931, msg, sizeof(msg));
OSMO_ASSERT(rc == 0);
OSMO_ASSERT(q931.msg_type == Q931_MSGT_ALERTING);
OSMO_ASSERT(q931.call_ref == 0x80000024);
OSMO_ASSERT(TLVP_PRES_LEN(&q931.ies, Q931_IEI_PROGRESS_IND, 2));
}
int main(int argc, char **argv)
{
test_setup();
test_setup_ack();
test_information();
test_alerting();
}

8
tests/testsuite.at Normal file
View File

@ -0,0 +1,8 @@
AT_INIT
AT_BANNER([Regression tests.])
AT_SETUP([q931])
AT_KEYWORDS([q931])
cat $abs_srcdir/q931/q931_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/q931/q931_test], [], [expout], [ignore])
AT_CLEANUP