summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/gb/bssgp_fc_test.c167
-rw-r--r--tests/gb/bssgp_fc_tests.err51
-rw-r--r--tests/gb/bssgp_fc_tests.ok150
-rwxr-xr-xtests/gb/bssgp_fc_tests.sh15
-rw-r--r--tests/testsuite.at7
6 files changed, 395 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ce5fefbf..b489b3b2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -3,7 +3,8 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include
check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \
smscb/smscb_test bits/bitrev_test a5/a5_test \
conv/conv_test auth/milenage_test lapd/lapd_test \
- gsm0808/gsm0808_test gsm0408/gsm0408_test
+ gsm0808/gsm0808_test gsm0408/gsm0408_test \
+ gb/bssgp_fc_test
if ENABLE_MSGFILE
check_PROGRAMS += msgfile/msgfile_test
endif
@@ -44,6 +45,9 @@ timer_timer_test_LDADD = $(top_builddir)/src/libosmocore.la
ussd_ussd_test_SOURCES = ussd/ussd_test.c
ussd_ussd_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
+gb_bssgp_fc_test_SOURCES = gb/bssgp_fc_test.c
+gb_bssgp_fc_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la
+
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
$(srcdir)/package.m4: $(top_srcdir)/configure.ac
:;{ \
diff --git a/tests/gb/bssgp_fc_test.c b/tests/gb/bssgp_fc_test.c
new file mode 100644
index 00000000..c5e864d4
--- /dev/null
+++ b/tests/gb/bssgp_fc_test.c
@@ -0,0 +1,167 @@
+/* test routines for BSSGP flow control implementation in libosmogb
+ * (C) 2012 by Harald Welte <laforge@gnumonks.org>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <getopt.h>
+
+#include <osmocom/core/utils.h>
+#include <osmocom/core/logging.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/gprs/gprs_bssgp.h>
+
+static unsigned long in_ctr = 1;
+static struct timeval tv_start;
+
+int get_centisec_diff(void)
+{
+ struct timeval tv;
+ struct timeval now;
+ gettimeofday(&now, NULL);
+
+ timersub(&now, &tv_start, &tv);
+
+ return tv.tv_sec * 100 + tv.tv_usec/10000;
+}
+
+/* round to deciseconds to make sure test output is always consistent */
+int round_decisec(int csec_in)
+{
+ int tmp = csec_in / 10;
+
+ return tmp * 10;
+}
+
+static int fc_out_cb(struct bssgp_flow_control *fc, struct msgb *msg,
+ uint32_t llc_pdu_len, void *priv)
+{
+ unsigned int csecs = get_centisec_diff();
+ csecs = round_decisec(csecs);
+
+ printf("%u: FC OUT Nr %lu\n", csecs, (unsigned long) msg);
+}
+
+static int fc_in(struct bssgp_flow_control *fc, unsigned int pdu_len)
+{
+ unsigned int csecs = get_centisec_diff();
+ csecs = round_decisec(csecs);
+
+ printf("%u: FC IN Nr %lu\n", csecs, in_ctr);
+ bssgp_fc_in(fc, (struct msgb *) in_ctr, pdu_len, NULL);
+ in_ctr++;
+}
+
+
+static void test_fc(uint32_t bucket_size_max, uint32_t bucket_leak_rate,
+ uint32_t max_queue_depth, uint32_t pdu_len,
+ uint32_t pdu_count)
+{
+ struct bssgp_flow_control *fc = talloc_zero(NULL, struct bssgp_flow_control);
+ int i;
+
+ bssgp_fc_init(fc, bucket_size_max, bucket_leak_rate, max_queue_depth,
+ fc_out_cb);
+
+ gettimeofday(&tv_start, NULL);
+
+ for (i = 0; i < pdu_count; i++) {
+ fc_in(fc, pdu_len);
+ osmo_timers_check();
+ osmo_timers_prepare();
+ osmo_timers_update();
+ }
+
+ while (1) {
+ usleep(100000);
+ osmo_timers_check();
+ osmo_timers_prepare();
+ osmo_timers_update();
+
+ if (llist_empty(&fc->queue))
+ break;
+ }
+}
+
+static void help(void)
+{
+ printf(" -h --help This help message\n");
+ printf(" -s --bucket-size-max N Maximum size of bucket in octets\n");
+ printf(" -r --bucket-leak-rate N Bucket leak rate in octets/sec\n");
+ printf(" -d --max-queue-depth N Maximum length of pending PDU queue (msgs)\n");
+ printf(" -l --pdu-length N Length of each PDU in octets\n");
+}
+
+int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
+{
+ return -1;
+}
+
+static struct log_info info = {};
+
+int main(int argc, char **argv)
+{
+ uint32_t bucket_size_max = 100; /* octets */
+ uint32_t bucket_leak_rate = 100; /* octets / second */
+ uint32_t max_queue_depth = 5; /* messages */
+ uint32_t pdu_length = 10; /* octets */
+ uint32_t pdu_count = 20; /* messages */
+ int c;
+
+ static const struct option long_options[] = {
+ { "bucket-size-max", 1, 0, 's' },
+ { "bucket-leak-rate", 1, 0, 'r' },
+ { "max-queue-depth", 1, 0, 'd' },
+ { "pdu-length", 1, 0, 'l' },
+ { "pdu-count", 1, 0, 'c' },
+ { "help", 0, 0, 'h' },
+ { 0, 0, 0, 0 }
+ };
+
+ osmo_init_logging(&info);
+
+ while ((c = getopt_long(argc, argv, "s:r:d:l:c:",
+ long_options, NULL)) != -1) {
+ switch (c) {
+ case 's':
+ bucket_size_max = atoi(optarg);
+ break;
+ case 'r':
+ bucket_leak_rate = atoi(optarg);
+ break;
+ case 'd':
+ max_queue_depth = atoi(optarg);
+ break;
+ case 'l':
+ pdu_length = atoi(optarg);
+ break;
+ case 'c':
+ pdu_count = atoi(optarg);
+ break;
+ case 'h':
+ help();
+ exit(EXIT_SUCCESS);
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ /* bucket leak rate less than 100 not supported! */
+ if (bucket_leak_rate < 100) {
+ fprintf(stderr, "Bucket leak rate < 100 not supported!\n");
+ exit(EXIT_FAILURE);
+ }
+
+ printf("===== BSSGP flow-control test START\n");
+ printf("size-max=%u oct, leak-rate=%u oct/s, "
+ "queue-len=%u msgs, pdu_len=%u oct, pdu_cnt=%u\n\n", bucket_size_max,
+ bucket_leak_rate, max_queue_depth, pdu_length, pdu_count);
+ test_fc(bucket_size_max, bucket_leak_rate, max_queue_depth,
+ pdu_length, pdu_count);
+ printf("===== BSSGP flow-control test END\n\n");
+
+ exit(EXIT_SUCCESS);
+}
diff --git a/tests/gb/bssgp_fc_tests.err b/tests/gb/bssgp_fc_tests.err
new file mode 100644
index 00000000..ae5d6f66
--- /dev/null
+++ b/tests/gb/bssgp_fc_tests.err
@@ -0,0 +1,51 @@
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:699 Single PDU (size=1000) is larger than maximum bucket size (100)!
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+<0000> gprs_bssgp.c:556 BSSGP-FC: fc_timer_cb() but still not able to send PDU of 10 bytes
+ \ No newline at end of file
diff --git a/tests/gb/bssgp_fc_tests.ok b/tests/gb/bssgp_fc_tests.ok
new file mode 100644
index 00000000..fda96f30
--- /dev/null
+++ b/tests/gb/bssgp_fc_tests.ok
@@ -0,0 +1,150 @@
+===== BSSGP flow-control test START
+size-max=100 oct, leak-rate=100 oct/s, queue-len=5 msgs, pdu_len=10 oct, pdu_cnt=20
+
+0: FC IN Nr 1
+0: FC OUT Nr 1
+0: FC IN Nr 2
+0: FC OUT Nr 2
+0: FC IN Nr 3
+0: FC OUT Nr 3
+0: FC IN Nr 4
+0: FC OUT Nr 4
+0: FC IN Nr 5
+0: FC OUT Nr 5
+0: FC IN Nr 6
+0: FC OUT Nr 6
+0: FC IN Nr 7
+0: FC OUT Nr 7
+0: FC IN Nr 8
+0: FC OUT Nr 8
+0: FC IN Nr 9
+0: FC OUT Nr 9
+0: FC IN Nr 10
+0: FC OUT Nr 10
+0: FC IN Nr 11
+0: FC IN Nr 12
+0: FC IN Nr 13
+0: FC IN Nr 14
+0: FC IN Nr 15
+0: FC IN Nr 16
+0: FC IN Nr 17
+0: FC IN Nr 18
+0: FC IN Nr 19
+0: FC IN Nr 20
+10: FC OUT Nr 11
+20: FC OUT Nr 12
+30: FC OUT Nr 13
+40: FC OUT Nr 14
+50: FC OUT Nr 15
+===== BSSGP flow-control test END
+
+===== BSSGP flow-control test START
+size-max=100 oct, leak-rate=100 oct/s, queue-len=100 msgs, pdu_len=10 oct, pdu_cnt=20
+
+0: FC IN Nr 1
+0: FC OUT Nr 1
+0: FC IN Nr 2
+0: FC OUT Nr 2
+0: FC IN Nr 3
+0: FC OUT Nr 3
+0: FC IN Nr 4
+0: FC OUT Nr 4
+0: FC IN Nr 5
+0: FC OUT Nr 5
+0: FC IN Nr 6
+0: FC OUT Nr 6
+0: FC IN Nr 7
+0: FC OUT Nr 7
+0: FC IN Nr 8
+0: FC OUT Nr 8
+0: FC IN Nr 9
+0: FC OUT Nr 9
+0: FC IN Nr 10
+0: FC OUT Nr 10
+0: FC IN Nr 11
+0: FC IN Nr 12
+0: FC IN Nr 13
+0: FC IN Nr 14
+0: FC IN Nr 15
+0: FC IN Nr 16
+0: FC IN Nr 17
+0: FC IN Nr 18
+0: FC IN Nr 19
+0: FC IN Nr 20
+10: FC OUT Nr 11
+20: FC OUT Nr 12
+30: FC OUT Nr 13
+40: FC OUT Nr 14
+50: FC OUT Nr 15
+60: FC OUT Nr 16
+70: FC OUT Nr 17
+80: FC OUT Nr 18
+90: FC OUT Nr 19
+100: FC OUT Nr 20
+===== BSSGP flow-control test END
+
+===== BSSGP flow-control test START
+size-max=100 oct, leak-rate=100 oct/s, queue-len=5 msgs, pdu_len=1000 oct, pdu_cnt=20
+
+0: FC IN Nr 1
+0: FC IN Nr 2
+0: FC IN Nr 3
+0: FC IN Nr 4
+0: FC IN Nr 5
+0: FC IN Nr 6
+0: FC IN Nr 7
+0: FC IN Nr 8
+0: FC IN Nr 9
+0: FC IN Nr 10
+0: FC IN Nr 11
+0: FC IN Nr 12
+0: FC IN Nr 13
+0: FC IN Nr 14
+0: FC IN Nr 15
+0: FC IN Nr 16
+0: FC IN Nr 17
+0: FC IN Nr 18
+0: FC IN Nr 19
+0: FC IN Nr 20
+===== BSSGP flow-control test END
+
+===== BSSGP flow-control test START
+size-max=100 oct, leak-rate=100 oct/s, queue-len=5 msgs, pdu_len=10 oct, pdu_cnt=20
+
+0: FC IN Nr 1
+0: FC OUT Nr 1
+0: FC IN Nr 2
+0: FC OUT Nr 2
+0: FC IN Nr 3
+0: FC OUT Nr 3
+0: FC IN Nr 4
+0: FC OUT Nr 4
+0: FC IN Nr 5
+0: FC OUT Nr 5
+0: FC IN Nr 6
+0: FC OUT Nr 6
+0: FC IN Nr 7
+0: FC OUT Nr 7
+0: FC IN Nr 8
+0: FC OUT Nr 8
+0: FC IN Nr 9
+0: FC OUT Nr 9
+0: FC IN Nr 10
+0: FC OUT Nr 10
+0: FC IN Nr 11
+0: FC IN Nr 12
+0: FC IN Nr 13
+0: FC IN Nr 14
+0: FC IN Nr 15
+0: FC IN Nr 16
+0: FC IN Nr 17
+0: FC IN Nr 18
+0: FC IN Nr 19
+0: FC IN Nr 20
+10: FC OUT Nr 11
+20: FC OUT Nr 12
+30: FC OUT Nr 13
+40: FC OUT Nr 14
+50: FC OUT Nr 15
+===== BSSGP flow-control test END
+
diff --git a/tests/gb/bssgp_fc_tests.sh b/tests/gb/bssgp_fc_tests.sh
new file mode 100755
index 00000000..38659bb9
--- /dev/null
+++ b/tests/gb/bssgp_fc_tests.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+T=$1/bssgp_fc_test
+
+# default test (1 second, insufficient queue depth)
+$T
+
+# default test (1 second, sufficient queue depth)
+$T -d 100
+
+# test with PDU too large for bucket max
+$T -l 1000
+
+# test with 100 byte PDUs (10 second)
+$T -s 100
+
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 21542695..dd22c323 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -9,6 +9,13 @@ cat $abs_srcdir/a5/a5_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/a5/a5_test], [], [expout])
AT_CLEANUP
+AT_SETUP([bssgp-fc])
+AT_KEYWORDS([bssgp-fc])
+cat $abs_srcdir/gb/bssgp_fc_tests.ok > expout
+cat $abs_srcdir/gb/bssgp_fc_tests.err > experr
+AT_CHECK([$abs_top_builddir/tests/gb/bssgp_fc_tests.sh $abs_top_builddir/tests/gb], [], [expout], [experr])
+AT_CLEANUP
+
AT_SETUP([bits])
AT_KEYWORDS([bits])
cat $abs_srcdir/bits/bitrev_test.ok > expout