summaryrefslogtreecommitdiffstats
path: root/tests/prbs/prbs_test.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-06-18 18:16:02 +0300
committerHarald Welte <laforge@gnumonks.org>2017-07-10 23:42:02 +0200
commit1389e86d116509884b0e5ee3421fe7683afcab9b (patch)
tree52ef42f5f49ac3ae52e687cbc7207426fd11e075 /tests/prbs/prbs_test.c
parent548e3712009f68f801be806884d848b47c30dced (diff)
Add pseudo-random bit sequence generator to libosmcoore
These PRBS sequences are specified in ITU-T O.150. They are typically used as test data to be transmitted for BER (bit error rate) testing. Change-Id: I227b6a6e86a251460ecb816afa9a7439d5fb94d1
Diffstat (limited to 'tests/prbs/prbs_test.c')
-rw-r--r--tests/prbs/prbs_test.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/prbs/prbs_test.c b/tests/prbs/prbs_test.c
new file mode 100644
index 00000000..f478635b
--- /dev/null
+++ b/tests/prbs/prbs_test.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <osmocom/core/prbs.h>
+
+static void dump_bits(const ubit_t *bits, unsigned int num_bits)
+{
+ unsigned int i;
+
+ for (i = 0; i < num_bits; i++) {
+ if (bits[i])
+ fputc('1', stdout);
+ else
+ fputc('0', stdout);
+ }
+ fputc('\n',stdout);
+}
+
+static void test_prbs(const struct osmo_prbs *prbs)
+{
+ struct osmo_prbs_state st;
+ unsigned int i;
+
+ printf("Testing PRBS sequence generation '%s'\n", prbs->name);
+ osmo_prbs_state_init(&st, prbs);
+
+ /* 2 lines */
+ for (i = 0; i < 2; i++) {
+ unsigned int seq_len = (1 << prbs->len)-1;
+ ubit_t bits[seq_len];
+ memset(bits, 0, sizeof(bits));
+ osmo_prbs_get_ubits(bits, sizeof(bits), &st);
+ dump_bits(bits, sizeof(bits));
+ }
+
+ printf("\n");
+}
+
+int main(int argc, char **argv)
+{
+ test_prbs(&osmo_prbs7);
+ test_prbs(&osmo_prbs9);
+ test_prbs(&osmo_prbs11);
+ test_prbs(&osmo_prbs15);
+
+ exit(0);
+}