Commit Graph

13 Commits

Author SHA1 Message Date
Pau Espin c5c955caae tests: bitrev_test: Fix dynamic-stack-buffer-overflow
Fixes following AddressSanitizer report:
==1983==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffc245f47e6 at pc 0x7f3e2deea68c bp 0x7ffc245f4750 sp 0x7ffc245f4740
WRITE of size 1 at 0x7ffc245f47e6 thread T0
    #0 0x7f3e2deea68b in osmo_nibble_shift_right libosmocore/src/bits.c:92
    #1 0x55c01902e1ab in sh_chk libosmocore/tests/bits/bitrev_test.c:215
    #2 0x55c01902ed8f in main libosmocore/tests/bits/bitrev_test.c:305
    #3 0x7f3e2c93006a in __libc_start_main (/usr/lib/libc.so.6+0x2306a)
    #4 0x55c01902c059 in _start (libosmocore/tests/bits/.libs/lt-bitrev_test+0x5059)

This patch can be seen as a follow-up of commit
4fd6023b03, which already fixed the
left-shift case in the same way.

Change-Id: I6e86d0164b7e982bf7b7449d5b3abfb3e1e5da46
2018-05-16 17:10:33 +02:00
Max 9818664315 Add tests for bitvec_write_field()
This function is actively used by OsmoPCU but have not been covered by
tests so far. The test code is based on
Minh-Quang Nguyen <minh-quang.nguyen@nutaq.com> submission with some
modifications.

The test's FIXME will be addressed in follow-up patches.

Change-Id: I2ee544256b8675bc62a42493aab66a8eeee54f90
Related: OS#1526
2017-10-24 08:21:59 +00:00
Holger Hans Peter Freyther bf173a3df5 bitcomp: Remove the t4 decoding from libosmocore
As outlined by mail on the 13th of July the tree based approach to
decoding in the PCU is faster by order of magnitude. Instead of having a
slow implementation in the library and a quick one in the PCU, let's
only have a quick one in the PCU and at some point in the future move it
to libosmocore.

Execute the plan and remove t4_decode.

Change-Id: I021424444625a097560d086c217c81eac4a5ee44
2016-11-10 17:07:45 +00:00
Neels Hofmeyr 8319a6799f bitrev_test: don't omit last byte from test result check
The osmo_hexdump of the output in sh_chk() omitted the last byte of the
returned bytes from the osmo_nibble_shift_*() functions.

Determine the number of bytes from nibbles divided by two plus one for any odd
nibble number. Output this number of bytes of output data.

Memset the output buffer to get well-defined bytes for unwritten places.

Also assert that we have enough buffer length for all nibbles.

Change-Id: I011f42bca555caec0dfe8688ff1f28303fa04fad
2016-09-26 00:35:30 +00:00
Max 4fd6023b03 Fix ASAN failure in bitrev_test
Previously while testing osmo_nibble_shift_left_unal() following error was
triggered by AddressSanitizer upon offs == 12 and the last sh_chk line, i.e.
shift left of 12 nibbles from in2:

==3890== ERROR: AddressSanitizer: stack-buffer-overflow on address 0xbff5b5b6 at pc 0xb6186862 bp 0xbff5b4a8 sp 0xbff5b49c
READ of size 1 at 0xbff5b5b6 thread T0
    #0 0xb6186861 (/home/msuraev/source/gsm/libosmocore/src/.libs/libosmocore.so.7.0.0+0xc861)
    #1 0x8049d8b (/home/msuraev/source/gsm/libosmocore/tests/bits/.libs/lt-bitrev_test+0x8049d8b)
    #2 0x804a9d1 (/home/msuraev/source/gsm/libosmocore/tests/bits/.libs/lt-bitrev_test+0x804a9d1)
    #3 0xb5fe3af2 (/lib/i386-linux-gnu/libc-2.19.so+0x19af2)
    #4 0x8048a30 (/home/msuraev/source/gsm/libosmocore/tests/bits/.libs/lt-bitrev_test+0x8048a30)
Address 0xbff5b5b6 is located at offset 38 in frame <main> of T0's stack:
  This frame has 3 object(s):
    [32, 38) 'in2'
    [96, 104) 'out'
    [160, 168) 'in1'

The reason is incorrect range in test cycle. Fix it and adjust test
output accordingly.

Tweaked-by: Neels Hofmeyr <nhofmeyr@sysmocom.de>
Fixes: OW#1589 ("undefined behavior in libosmocore triggered by tests")
Change-Id: I5eb3f600290c05b4ab9ac2450a28d616e6b415fd
2016-09-26 00:35:30 +00:00
Max e0a7d9e2c2 Add octet-aligned/unaligned shift functions
The actual code is from OsmoBTS' tch.c by Harald Welte. Add unit tests,
doxygen annotation and extra memory safety check. Those functions are
used in several BTS implementations but seems generic enough to be
generally useful.

Change-Id: I2b1901c4161e8035f059585901dca593b661556d
2016-06-20 19:02:56 +02:00
Max 5c18e26bc2 Add T4 bit map compression routines
Add bit map encoder and decoder functions: decoder is fully functional
while encoder is good enough for testing - no backtracking to find
the best possible compression is implemented. If somebody is willing to
implement MS side of EDGE than this has to be expanded.
Add corresponding tests.
N. B: the encoding is implemented according to ETSI TS 44.060 which is
slightly different from T4 used for fax according to CCITT G31D (RFC 804).

Ticket: OW#2407
Sponsored-by: On-Waves ehf

Signed-off-by: Max <msuraev@sysmocom.de>
2016-02-18 19:45:44 +01:00
Sylvain Munaut 26ea7068e7 tests/bits: Make sure all 'inline' are also static
Not doing so seems to break the BSD build

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2014-06-16 15:57:36 +02:00
Max 5377701746 core: Add generic LE/BE load/store uint type convertors and use them in msgb
Submitted-by: Max <max.suraev@fairwaves.co>
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2014-06-16 14:33:27 +02:00
Diego Elio Pettenò ea0e1eca2b build: simplify test handling and speed up build.
Instead of using a ./configure parameter to decide whehter to build
tests or not, use the check_PROGRAMS variable so that the tests are
only built when running `make check`.

To avoid slowing down the test phase itself, collapse the declaration
of the test targets in the tests/Makefile.am file, this way they can
be built and linked in parallel before the testsuite is executed.

Signed-off-by: Diego Elio Pettenò <flameeyes@flameeyes.eu>
2012-06-30 22:01:42 +02:00
Holger Hans Peter Freyther f6c1d4cd81 tests: Fix the make distcheck of libosmocore with the tests 2011-11-14 14:37:46 +01:00
Holger Hans Peter Freyther f9eda7489b tests: Use GNU autotest to execute our tests and compare textual output
The output of make check is looking like this now:

Regression tests.

  1: bits                                            ok
  2: msgfile                                         ok
  3: sms                                             ok
  4: smscb                                           ok
  5: timer                                           FAILED (testsuite.at:38)
  6: ussd                                            FAILED (testsuite.at:44)
2011-11-14 13:35:41 +01:00
Harald Welte 712691d8d8 add functions for bit-reversal
Sometimes we need stuff like reversing every bit in each byte (but not
the byte-order).
2011-09-01 14:47:31 +02:00