This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Vadim Yanitskiy gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/1627 tests/conv: separate test logic To be able to add some more tests, related to convolutional coding, without duplication of code, the test logic was separated from the conv_test.c into conv.c and conv.h. Change-Id: Idbdc7e19cb9b9a36cd1fccd621cd858e87530d98 --- M tests/Makefile.am A tests/conv/conv.c A tests/conv/conv.h M tests/conv/conv_test.c 4 files changed, 169 insertions(+), 153 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/27/1627/1 diff --git a/tests/Makefile.am b/tests/Makefile.am index b9eb8f2..889eb8d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -54,7 +54,7 @@ bits_bitcomp_test_SOURCES = bits/bitcomp_test.c bits_bitcomp_test_LDADD = $(top_builddir)/src/libosmocore.la -conv_conv_test_SOURCES = conv/conv_test.c +conv_conv_test_SOURCES = conv/conv_test.c conv/conv.c conv_conv_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libgsmint.la gsm0808_gsm0808_test_SOURCES = gsm0808/gsm0808_test.c @@ -179,6 +179,7 @@ write_queue/wqueue_test.ok DISTCLEANFILES = atconfig atlocal +noinst_HEADERS = conv/conv.h TESTSUITE = $(srcdir)/testsuite diff --git a/tests/conv/conv.c b/tests/conv/conv.c new file mode 100644 index 0000000..7dac155 --- /dev/null +++ b/tests/conv/conv.c @@ -0,0 +1,143 @@ +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <time.h> + +#include <osmocom/core/bits.h> +#include <osmocom/core/conv.h> +#include <osmocom/core/utils.h> + +#include "conv.h" + +static void fill_random(ubit_t *b, int n) +{ + int i; + + for (i = 0; i < n; i++) + b[i] = random() & 1; +} + +int do_check(const struct conv_test_vector *test) +{ + ubit_t *bu0, *bu1; + sbit_t *bs; + int len, j; + + bu0 = malloc(sizeof(ubit_t) * MAX_LEN_BITS); + bu1 = malloc(sizeof(ubit_t) * MAX_LEN_BITS); + bs = malloc(sizeof(sbit_t) * MAX_LEN_BITS); + + srandom(time(NULL)); + + /* Test name */ + printf("[+] Testing: %s\n", test->name); + + /* Check length */ + len = osmo_conv_get_input_length(test->code, 0); + printf("[.] Input length : ret = %3d exp = %3d -> %s\n", + len, test->in_len, len == test->in_len ? "OK" : "Bad !"); + + if (len != test->in_len) { + fprintf(stderr, "[!] Failure for input length computation\n"); + return -1; + } + + len = osmo_conv_get_output_length(test->code, 0); + printf("[.] Output length : ret = %3d exp = %3d -> %s\n", + len, test->out_len, len == test->out_len ? "OK" : "Bad !"); + + if (len != test->out_len) { + fprintf(stderr, "[!] Failure for output length computation\n"); + return -1; + } + + /* Check pre-computed vector */ + if (test->has_vec) { + printf("[.] Pre computed vector checks:\n"); + + printf("[..] Encoding: "); + + osmo_pbit2ubit(bu0, test->vec_in, test->in_len); + + len = osmo_conv_encode(test->code, bu0, bu1); + if (len != test->out_len) { + printf("ERROR !\n"); + fprintf(stderr, "[!] Failed encoding length check\n"); + return -1; + } + + osmo_pbit2ubit(bu0, test->vec_out, test->out_len); + + if (memcmp(bu0, bu1, test->out_len)) { + printf("ERROR !\n"); + fprintf(stderr, "[!] Failed encoding: Results don't match\n"); + return -1; + }; + + printf("OK\n"); + + + printf("[..] Decoding: "); + + osmo_ubit2sbit(bs, bu0, len); + + len = osmo_conv_decode(test->code, bs, bu1); + if (len != 0) { + printf("ERROR !\n"); + fprintf(stderr, "[!] Failed decoding: non-zero path (%d)\n", len); + return -1; + } + + osmo_pbit2ubit(bu0, test->vec_in, test->in_len); + + if (memcmp(bu0, bu1, test->in_len)) { + printf("ERROR !\n"); + fprintf(stderr, "[!] Failed decoding: Results don't match\n"); + return -1; + } + + printf("OK\n"); + } + + /* Check random vector */ + printf("[.] Random vector checks:\n"); + + for (j = 0; j < 3; j++) { + printf("[..] Encoding / Decoding cycle : "); + + fill_random(bu0, test->in_len); + + len = osmo_conv_encode(test->code, bu0, bu1); + if (len != test->out_len) { + printf("ERROR !\n"); + fprintf(stderr, "[!] Failed encoding length check\n"); + return -1; + } + + osmo_ubit2sbit(bs, bu1, len); + + len = osmo_conv_decode(test->code, bs, bu1); + if (len != 0) { + printf("ERROR !\n"); + fprintf(stderr, "[!] Failed decoding: non-zero path (%d)\n", len); + return -1; + } + + if (memcmp(bu0, bu1, test->in_len)) { + printf("ERROR !\n"); + fprintf(stderr, "[!] Failed decoding: Results don't match\n"); + return -1; + } + + printf("OK\n"); + } + + /* Spacing */ + printf("\n"); + + free(bs); + free(bu1); + free(bu0); + + return 0; +} diff --git a/tests/conv/conv.h b/tests/conv/conv.h new file mode 100644 index 0000000..676c5af --- /dev/null +++ b/tests/conv/conv.h @@ -0,0 +1,16 @@ +#pragma once + +#define MAX_LEN_BITS 512 +#define MAX_LEN_BYTES (512/8) + +struct conv_test_vector { + const char *name; + const struct osmo_conv_code *code; + int in_len; + int out_len; + int has_vec; + pbit_t vec_in[MAX_LEN_BYTES]; + pbit_t vec_out[MAX_LEN_BYTES]; +}; + +int do_check(const struct conv_test_vector *test); diff --git a/tests/conv/conv_test.c b/tests/conv/conv_test.c index 3064f9c..131b459 100644 --- a/tests/conv/conv_test.c +++ b/tests/conv/conv_test.c @@ -1,16 +1,10 @@ #include <stdio.h> #include <stdlib.h> -#include <string.h> -#include <time.h> -#include <osmocom/core/bits.h> #include <osmocom/core/conv.h> -#include <osmocom/core/utils.h> #include <osmocom/gsm/gsm0503.h> -#define MAX_LEN_BITS 512 -#define MAX_LEN_BYTES (512/8) - +#include "conv.h" /* ------------------------------------------------------------------------ */ /* Test codes */ @@ -172,38 +166,15 @@ }; /* ------------------------------------------------------------------------ */ -/* Test vectors */ -/* ------------------------------------------------------------------------ */ - -struct conv_test_vector { - const char *name; - const struct osmo_conv_code *code; - int in_len; - int out_len; - int has_vec; - pbit_t vec_in[MAX_LEN_BYTES]; - pbit_t vec_out[MAX_LEN_BYTES]; -}; - -/* ------------------------------------------------------------------------ */ /* Main */ /* ------------------------------------------------------------------------ */ -static void -fill_random(ubit_t *b, int n) -{ - int i; - for (i=0; i<n; i++) - b[i] = random() & 1; -} - int main(int argc, char *argv[]) { - const struct conv_test_vector *tst; - ubit_t *bu0, *bu1; - sbit_t *bs; + const struct conv_test_vector *test; + int rc; -/* Random code -> Non recursive code, direct truncation, non-punctured */ + /* Random code -> Non recursive code, direct truncation, non-punctured */ const struct osmo_conv_code conv_trunc = { .N = 2, .K = 5, @@ -300,126 +271,11 @@ { /* end */ }, }; - srandom(time(NULL)); - - bu0 = malloc(sizeof(ubit_t) * MAX_LEN_BITS); - bu1 = malloc(sizeof(ubit_t) * MAX_LEN_BITS); - bs = malloc(sizeof(sbit_t) * MAX_LEN_BITS); - - for (tst=tests; tst->name; tst++) - { - int i,l; - - /* Test name */ - printf("[+] Testing: %s\n", tst->name); - - /* Check length */ - l = osmo_conv_get_input_length(tst->code, 0); - printf("[.] Input length : ret = %3d exp = %3d -> %s\n", - l, tst->in_len, l == tst->in_len ? "OK" : "Bad !"); - - if (l != tst->in_len) { - fprintf(stderr, "[!] Failure for input length computation\n"); - return -1; - } - - l = osmo_conv_get_output_length(tst->code, 0); - printf("[.] Output length : ret = %3d exp = %3d -> %s\n", - l, tst->out_len, l == tst->out_len ? "OK" : "Bad !"); - - if (l != tst->out_len) { - fprintf(stderr, "[!] Failure for output length computation\n"); - return -1; - } - - /* Check pre-computed vector */ - if (tst->has_vec) { - printf("[.] Pre computed vector checks:\n"); - - printf("[..] Encoding: "); - - osmo_pbit2ubit(bu0, tst->vec_in, tst->in_len); - - l = osmo_conv_encode(tst->code, bu0, bu1); - if (l != tst->out_len) { - printf("ERROR !\n"); - fprintf(stderr, "[!] Failed encoding length check\n"); - return -1; - } - - osmo_pbit2ubit(bu0, tst->vec_out, tst->out_len); - - if (memcmp(bu0, bu1, tst->out_len)) { - printf("ERROR !\n"); - fprintf(stderr, "[!] Failed encoding: Results don't match\n"); - return -1; - }; - - printf("OK\n"); - - - printf("[..] Decoding: "); - - osmo_ubit2sbit(bs, bu0, l); - - l = osmo_conv_decode(tst->code, bs, bu1); - if (l != 0) { - printf("ERROR !\n"); - fprintf(stderr, "[!] Failed decoding: non-zero path (%d)\n", l); - return -1; - } - - osmo_pbit2ubit(bu0, tst->vec_in, tst->in_len); - - if (memcmp(bu0, bu1, tst->in_len)) { - printf("ERROR !\n"); - fprintf(stderr, "[!] Failed decoding: Results don't match\n"); - return -1; - } - - printf("OK\n"); - } - - /* Check random vector */ - printf("[.] Random vector checks:\n"); - - for (i=0; i<3; i++) { - printf("[..] Encoding / Decoding cycle : "); - - fill_random(bu0, tst->in_len); - - l = osmo_conv_encode(tst->code, bu0, bu1); - if (l != tst->out_len) { - printf("ERROR !\n"); - fprintf(stderr, "[!] Failed encoding length check\n"); - return -1; - } - - osmo_ubit2sbit(bs, bu1, l); - - l = osmo_conv_decode(tst->code, bs, bu1); - if (l != 0) { - printf("ERROR !\n"); - fprintf(stderr, "[!] Failed decoding: non-zero path (%d)\n", l); - return -1; - } - - if (memcmp(bu0, bu1, tst->in_len)) { - printf("ERROR !\n"); - fprintf(stderr, "[!] Failed decoding: Results don't match\n"); - return -1; - } - - printf("OK\n"); - } - - /* Spacing */ - printf("\n"); + for (test = tests; test->name; test++) { + rc = do_check(test); + if (rc) + return rc; } - - free(bs); - free(bu1); - free(bu0); return 0; } -- To view, visit https://gerrit.osmocom.org/1627 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idbdc7e19cb9b9a36cd1fccd621cd858e87530d98 Gerrit-PatchSet: 1 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>