Commit Graph

223 Commits

Author SHA1 Message Date
Neels Hofmeyr 9795cf1b12 fix: DLGSUP logging category "unusable"
All DL* categories are typically negative, but DLGSUP isn't, and it's also not
in libosmocore's internal_cat array.
See: 3b6fb0880c

This means that a program using DLGSUP has to include DLGSUP in its own logging
cat array (typically not needed for DL* categories), which means for osmo-nitb
that DLGSUP (11) replaces DMGCP (also 11), and DMGCP becomes unusable.

Fix this: make DLGSUP -11 and include in internal_cat.

In gsup_test.c, no longer add DLGSUP to the logging categories array.

External follow-ups are otherwise needed only in osmo-hlr.git and some pending
patches for openbsc (Id3938267fa062e1a997d3704cd678874306f86ee).

Change-Id: Id974c7be158e4d60421a98110f5c807aefd31119
2016-12-11 03:42:58 +01:00
Harald Welte a24be85dc4 Fix msgb_test on 64 bit architectures
truncating the unsigned long pointer msg->data to 'int' and then passin
git into msgb_resize_area() is unsafe as depending on the 32rd address
bit it will be eiether negative or positive.  That will in turn change
the expected "Sub area is not fully contained in the msg data\n" error
message into "Negative sizes are not allowed\n" which is not what the
autotest case expects.

Change-Id: I87ce13c265704d4ba8724e7dc7ed874c1128e0fa
2016-12-09 17:59:58 +01:00
Holger Hans Peter Freyther c7f52c4c84 wqueue: Reject messges if queue is considered full
The write queue was always meant to not queue more than the
max_length messages but the implementation never rejected a
message.

Begin to log and enforce the queue size limit, add a testcase
to verify the code and initialize except_cb as part of a fix
for that new test case.

Real applications might now run into the queue limit and drop
messages where they just queued them before. It is unfortunate
but I still think it is good to implement the routine as it was
intended. We need to review osmo_wqueue_enqueue once more to
see that no msgb is leaked.

Change-Id: I1e6aef30f3e73d4bcf2967bc49f0783aa65395ae
2016-12-09 11:37:37 +01:00
Neels Hofmeyr 96831049d9 build: make check: disable sim_test when built with --disable-pcsc
Numerous issues caused sim_test to be attempted even though libosmosim was not
built:

In configure.ac, the ENABLE_PCSC variable lacked an AC_SUBST() to be exported.

Furthermore in configure.ac, no value 'yes'/'no' was assigned to the
ENABLE_PCSC variable, only to the enable_pcsc value.

In testsuite.at, encapsulating the sim_test in 'if ENABLE_PCSC' seems to have
no effect, regardless (not even when using a variable that should be defined
accurately).

So fix with these steps, similarly to how we do it in openbsc:

In AC_ARG_ENABLE, directly use 'ENABLE_PCSC' to assign 'yes'/'no'.
Export the same using AC_SUBST().
Add tests/atlocal.in to translate ENABLE_PCSC to enable_sim_test (also add
atlocal to AC_OUTPUT and distclean).
Use enable_sim_test in testuite.at, as seen in openbsc: use AT_CHECK() to
indicate skipping the test if enable_sim_test isn't 'yes'.

Change-Id: I9e8740c7d2dfbd272e22fee85972ef3fda7184a8
2016-11-16 16:40:44 +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
Max 3de97e1926 Add logging and testing for FSM deallocation
osmo_fsm_inst_alloc() logs allocation but osmo_fsm_inst_free() is
silent. Fix this by adding log message for deallocation to make FSM
lifecycle tracking easier. Also make sure it's covered by test suite.

Change-Id: I7e5b55a1fff8e36cf61c7fb61d3e79c1f00e29d2
2016-11-08 19:35:19 +00:00
Max e9e5f8e4e9 Add null-pointer check to osmo_amr_rtp_dec()
Check that RTP payload we're about to decode is not NULL and return
proper error code instead of segfaulting. Add corresponding test case.

Change-Id: Ib6cda9900a41ed16bbfbde9df3de9d38e0a7469b
2016-11-07 15:19:47 +01:00
Max 8b25a3f5c3 Add osmo_fsm_unregister() to header
Previously function was defined but not exposed so there were a way to
register FSM but no way to unregister it.

Change-Id: I2e749d896009784b77d6d5952fcc38e1c131db2b
2016-11-02 08:56:29 +00:00
Neels Hofmeyr 8a3409c4b7 gsm0408_test: initialize msgb talloc ctx
Change-Id: Ib26214add1932e93651c248cc09fbc68339b4dce
2016-09-27 11:46:38 +02: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
Neels Hofmeyr dbc6817792 timer_test: set 8 as default steps, use the default in testsuite.at
Change-Id: I5070578e9fe2bdacaad000eaafb8dc5f549d6f3e
2016-09-22 07:18:39 +02:00
Neels Hofmeyr d0858c2ae9 timer_test: print more details to stdout to check
The test is now fully deterministic, so include all detail in stdout, to check
for.

Change-Id: Iecf6387f1d25253fcf1260777673853030c1d326
2016-09-22 07:18:39 +02:00
Neels Hofmeyr 255dac16a4 timer_test: redirect some output from stderr to stdout
This way we can check the output in timer_test.ok.

Change-Id: Ia3bba1c650be3558d370e0f59d4ee7f36ef97506
2016-09-22 07:18:39 +02:00
Neels Hofmeyr d73c1cc7c2 timer_test: remove all random elements
Change-Id: I9833031407e99f5d7a1144c26b68a7e320b2020d
2016-09-22 07:18:39 +02:00
Neels Hofmeyr 7b4d727ec5 timer_test: do not use real time: deterministic and faster
Use osmo_gettimeofday_override* to decouple the timer test from real time. No
longer call osmo_select_main(), since select() actually waits for real time.

This reduces the timer_test to the osmo_timer_* logic and excludes the real
time and osmo_timers_nearest() accuracy testing with actual waiting involved.
This may be seen as a loss, but is more fit for a test suite.

The main point here is to get deterministic results in jenkins, so that we
don't have to retrigger jobs based on timing failures; added bonus is that the
test runs much faster now.

Change-Id: Ic5649512df86dd17070daa2f314159eafaf8feb8
2016-09-22 07:18:39 +02:00
Neels Hofmeyr 8e2f7e87f4 add osmo_gettimeofday as a shim around gettimeofday
This allows feeding a custom time for unit tests by overriding
osmo_gettimeofday.

Change-Id: Ic7a81a6eb51f27fe452962b91f2eae2070d87089
2016-09-22 07:18:39 +02:00
Neels Hofmeyr 13a8fb84f0 timer_test: remove unused precision values and confusing log
Change-Id: I1570b7096c757d63d23e0950feeeb7230f8a5c9f
2016-09-22 07:18:39 +02:00
Neels Hofmeyr 9c9a04705f timer_test: also report early finishes, report timing on error
When a timer was late, show the timing details.

Also count whether timers fired early, for completeness' sake.

Change-Id: Id3942637d77a28b5092ffffcc3e6d9d67c2b8e68
2016-09-22 07:18:39 +02:00
Neels Hofmeyr 633a0e76a2 fix timer_test: don't forget to set tv_usec on the stop time
The timer_test schedules timers and records the desired stop time. Also store
the usec value of the desired stop time, because scheduling at e.g. sec N usec
999999 but recording sec N usec 0, and then receiving a timer at sec N+1 usec 0
is only 1 usec late, but records as 1000000 usecs late. This might have been
the main cause of the timer test not working well on the osmocom build server.

Change-Id: I13bb60f7d341a397f95d13d9c63c40188b6cd5a0
2016-09-22 07:18:39 +02:00
Neels Hofmeyr d95f01d204 build: tests: don't link system installed libosmogsm.
Add src/gsm/libosmogsm.la explicitly to some test linkages, because otherwise
the linker would pick the libosmogsm already installed on the system instead of
the one that was just built in the source tree.

I noticed because a libosmogsm needing some more symbols from libosmocodec was
still installed, while the patch that cause it was already removed. Thus I
caught all(?) test binaries that linked libosmogsm from $PREFIX.

Change-Id: Ie61d60e1506f16de20add70fd0f44ebfa7a00a75
2016-09-10 12:03:39 +00:00
Holger Hans Peter Freyther 4a62dbbfa9 ussd: Decode interrogateSS that doesn't have test
Keith of Rhizomatica has an issue of a unrejected interrogateSS.
Start with just decoding the message and printing the empty test
and the code.

What is kind of missing is the classification between invoke,
returnResult and returnResultLast that we need to add in the
long run.

Change-Id: Iadfa156707a96f2a34f3948c7cc9a74435f17114
2016-07-12 17:45:34 +02:00
Max 4f169500df Add GEA3 & GEA4 ciphers
Corresponding test code include both official test vectors from the
specs and data from over-the-air tests.

This obsoletes libosmo-crypt-a53 as it was last missing piece
unimplemented in libosmogsm.

Change-Id: I939e4f6b91b4a7c591ef3761fe2d46ed1c2fb2d3
Related: OS#1582
2016-07-11 19:15:24 +00:00
Max eb59f241ec tests: test actual support status for auth. algo
Check if library actually support Milenage, COMP128 v2 and v3 algorithms
instead of just printing enum values or nothing.

Change-Id: I2b98481f56a8381058d4b29db5e8a36eb193eee9
2016-06-29 16:33:40 +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
Harald Welte 136e73764e Add Finite State Machine abstraction code
This code is supposed to formalize some of the state machine handling in
Osmocom code.

Change-Id: I0b0965a912598c1f6b84042a99fea9d522642466
Reviewed-on: https://gerrit.osmocom.org/163
Tested-by: Jenkins Builder
Reviewed-by: Harald Welte <laforge@gnumonks.org>
2016-06-16 21:43:45 +00:00
Max ec8f192fec Add functions to detect HR/FR SID frames
Add functions which check if given FR or HR frame (packed in RTP)
contains SID (SIlence Descriptor) and corresponding tests.

Related: OS#22
Change-Id: I4051e3c0d4fb9ee93d7e9e0ef4abaf9f18e227ca
Reviewed-on: https://gerrit.osmocom.org/160
Tested-by: Jenkins Builder
Reviewed-by: Harald Welte <laforge@gnumonks.org>
2016-06-01 10:44:06 +00:00
Max 92db150488 Add helper functions for AMR codec
* add functions to encode/decode various codec paramters from RTP payload with
  AMR frame according to RFC 4867
* those functions are extended version based on code from osmo-bts'
  amr.c by Andreas Eversberg
* add corresponding enum types and strings for logging
* add regression tests

It's useful both to replace manual parsing in osmo-bts with fuctions
covered by test suite and as a debugging helpers for issues related to
AMR.

Change-Id: Ia217679a07d3fbc970f435e20f6eac33d34bd597
Related: OS#1562
Reviewed-on: https://gerrit.osmocom.org/118
Tested-by: Jenkins Builder
Reviewed-by: Holger Freyther <holger@freyther.de>
2016-05-31 10:11:51 +00:00
Harald Welte 3b6fb0880c import gprs_gsup_message.[ch] from openbsc as gsup.[ch]
Move those routines from OpenBSC to libosmogsm, so they can be
re-used from other programs.  I think it was a mistake to add them only
inside the openbsc repository in the first place.  We need to pay more
attention to this in the future.
2016-05-06 11:21:06 +02:00
Harald Welte fbd02fa8cc tlv: Import osmo_shift_* and osmo_match_shift_* from openbsc
These routines have nothing to do with specifically the BSC, so import
them to the TLV parser we keep in libosmogsm.
2016-05-05 18:49:27 +02:00
Harald Welte 84da22f964 Add code generator for convolutional codes
Add python utility to generate .c code with convolutional
encoder/decoder based on polynomial description of the code. If argument
given it'll be interpreted as intended output directory, otherwise
current working directory is used.

Codes for *CCH, CS2/3 and TCH/AFS are generated. Corresponding manual
implementations are removed from tests. This introduce build-time
dependency on python.

The main work for this patch was generously contributed by Sylvain
Munaut.

Fixes: OS#1629
2016-04-29 13:17:22 +02:00
Max d8fb14226f Add ubit <-> sbit convertors
Move functions for conversion between soft and unpacked bits to main
library as they are generally useful.
2016-04-12 10:10:44 -04:00
Holger Hans Peter Freyther 92c4ec293d sim: Fix compiler warning and by this fixing the test result 2016-03-21 11:29:16 +01:00
Harald Welte 676e534462 sim: Add simplistic unit test for APDU class tables 2016-03-17 16:55:11 +01:00
Max d4793212b5 Add function to add bits from array to bitvec
Add function which adds specified number of bits from each element of
array to the bit vector prefixing each addition with one and finishing
entire sequence with adding 0. This is very common patter for various
repetitive data structures described with CSN.1 in 3GPP standards.

Corresponding test vectors and doxygen headers are added too.
2016-03-17 14:07:19 +01:00
Holger Hans Peter Freyther 79599acd66 logging: Move the filter check up as well
There doesn't seem to be a reason not to check the filter. Update
and extend the test. Currently the filter function will be called
once for the log check and once for the output of it.
2016-02-29 14:30:14 +01:00
Jacob Erlbeck 64e0eb56fd log/test: Extend test case for log_check_level
This commit adds OSMO_ASSERTs for mandatory conditions related to
log_check_level, and fprintfs for optional conditions, since it is
always safe for log_check_level to return != 0.

Sponsored-by: On-Waves ehf
2016-02-29 14:30:14 +01:00
Max 6a5ef46dd0 Add byte printing macros
It's sometimes handy for debugging to be able to immediately see which
bits are set in a given byte. Generalize macro used for that in bitvec
tests and make it available for the rest of the library.
2016-02-25 22:35:44 +01:00
Jacob Erlbeck f78ec5ce0d gb: Add bssgp_msgb_copy function
This function originates from openbsc/src/gprs but is just specific
to BSSGP/Gb on the same level like bssgp_msgb_alloc.

This commit puts the former gprs_msgb_copy function beside
bssgp_msgb_alloc.

Renamed function:

  gprs_msgb_copy -> bssgp_msgb_copy

Sponsored-by: On-Waves ehf
2016-02-22 10:20:49 +01: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
Max 0a59e9899f Expand bitvec interface
Add bit filling, shifting and other functions necessary for bit
compression implementation. Add corresponding tests.
2016-02-18 19:45:40 +01:00
Holger Hans Peter Freyther 5710804a42 bivec: Fix the output of the testcase
osmo_hexdump_nospc/osmo_hexdump is an old school C routine with a
static internal array. This means that printf will most likely one
of the two strings twice. For Linux/glibc this is the first string
(for whatever reason?) and for FreeBSD it is the last call of the
osmo_hexdump_nospc. We could have noticed by both strings being
of the same length besides the different length input. The second
issue is that we cast a hexstring to uint8_t and dump the string
as hex. So the two strings should not match at all.

Fix it by printing the hex string as plain hex and separating the
two printf calls. Update the test output.
2016-01-30 16:19:33 +01:00
Holger Hans Peter Freyther a9301a1a1f bitvec: Test and fix regression for C++->C conversion
bitvec_read_field/bitvec_write_field in the PCU used a C++ reference
and when porting to C it was decided to pass the parameter by value
and this lost the "back propagation" of the new index. Change the
parameter to be an in/out parameter and this way do not have a silent
semantic break in the osmo-pcu (where we copy the reference in csn.1
by value) and have a true compile failure.

Add Max's simple test for bitvec_unhex function leaving the checking
of bitvec_read_field and the side effect in the datastructure about
the number of bits still open.
2016-01-30 10:54:43 +01:00
Holger Hans Peter Freyther fdb4667609 test: Fix compiler warnings on 64bit systems
Use %td to print ptrdiff_t use %zu to print size_t,
include time.h on FreeBSD. Some more compiler warnings are
left but they require more thinking.
2015-11-09 16:46:03 +00:00
Holger Hans Peter Freyther fb7e683575 kasumi: Fix build with gcc5 that changed behavior of inline
GCC 5 has changed inline semantics (https://gcc.gnu.org/gcc-5/porting_to.html)
and apparently that now fails to link.
2016-01-21 15:50:04 +01:00
Jacob Erlbeck 17b3c3aca1 msgb/test: Add test case for error cases
Include a test for msgb_trim.

Sponsored-by: On-Waves ehf
2016-01-15 18:12:49 +01:00
Jacob Erlbeck 0a053ec506 msgb/test: Add tests for msgb_resize_area and msgb_copy
Sponsored-by: On-Waves ehf
2016-01-15 18:11:20 +01:00
Jacob Erlbeck cbefa08559 msgb/test: Add functions to catch and check exceptions
Currently the msgb error handling cannot be fully tested, since in
many cases osmo_panic will be called. This will in turn call abort().
Using an osmo_panic_handler that just returns will not help, since
many msgb functions rely on MSGB_ABORT to not return at all.

This commit uses an alternative osmo_panic_raise handler that just
calls longjmp to return to the test function.

Since some of this activity is logged to stderr where the strings may
contain variable parts like pointer addresses, stderr checking is
disabled in testsuite.at.

Sponsored-by: On-Waves ehf
2016-01-15 18:10:05 +01:00
Jacob Erlbeck 7cd8a1b063 msgb/test: Add test for msgb message buffers
This tests several API functions of the msgb by checking the
invariant and by dumping resulting message buffers as hex.

Sponsored-by: On-Waves ehf

Conflicts:
	tests/Makefile.am
2016-01-15 18:09:06 +01:00
Jacob Erlbeck 5f349be820 bitvec: Add get/set byte sequences
The new functions bitvec_get_bytes and bitvec_set_bytes copy
byte sequences from bitvecs to uint8_t arrays and vice versa.
While the bytes in the bitvecs do not need to be aligned, the uint8_t
arrays always are. In case the bytes in the bitvec are aligned, the
implementation uses memcpy.

Note that the implementation like the other existing functions assume
MSB first encoding.

[hfreyther: Squash the comment fix into this commit as well]

Sponsored-by: On-Waves ehf
2016-01-15 14:51:32 +01:00