Commit Graph

192 Commits

Author SHA1 Message Date
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
Jacob Erlbeck 8114294bf2 gsm: Add APN conversion functions
These functions are currently part of openbsc but also needed by
other projects.

The function have been renamed as follows:

  gprs_apn_to_str -> osmo_apn_to_str
  gprs_str_to_apn -> osmo_apn_from_str

Sponsored-by: On-Waves ehf
2016-01-15 14:46:19 +01:00
Jacob Erlbeck cc6ac4cdc4 ns: Force a defined state when sending NS RESET
Currently the state is assumed to remain the same while the reset
procedure is active. While this works correctly in general, a single
unexpected BLOCK_ACK or UNBLOCK_ACK can change the state but will not
stop the reset procedure. The leads to repeated RESET messages, where
the corresponding RESET_ACK is ignored. This is a stable state which
can only be left by manual intervention or by reception of a RESET
message from the peer.

This commit changes the RESET timeout handler to set the state to
BLOCKED/RESET when sending the new NS RESET message.

Note that this should ensure a clean restart even if the state has been
screwed up. It does not fix the handling of BLOCK_ACK or UNBLOCK_ACK
in abnormal cases.

Addresses:
 gprs_ns.c:349 NSEI=8895 Tx NS RESET (NSVCI=8895, cause=O&M intervention)
 gprs_ns.c:878 NSVCI=8895 Rx NS RESET ACK (NSEI=8895, NSVCI=8895)
 gprs_ns.c:887 NS RESET ACK Discarding unexpected message for NS-VCI 8895 from SGSN NSEI=8895

Ticket: OW#1551
Sponsored-by: On-Waves ehf
2015-12-17 14:16:50 +01:00
Harald Welte 90e614f7cc remove our internal copy of talloc, use system libtalloc
Shipping our own private copy of talloc was a good idea in 2008,
when it was not readily available on most target platforms.  Today,
the situation is quite different, as it is a standard library on
major Linux distributions.
2015-12-05 23:38:18 +01:00
Jacob Erlbeck f13de868be stats/test: Add memory leak check
Adds a rudimentary leak check for the counters and stat items.

Sponsored-by: On-Waves ehf
2015-11-26 12:52:24 +01:00
Jacob Erlbeck 46b703d083 stats/test: Add test for reporting
This tests uses a dedicated test reported to check several aspects of
the value reporting.
  - addition/removal of stats reporter
  - addition/removal of counters/items
  - setting of max_class
  - initial value flush
  - updating single counters/items
  - reporter retrieval
  - enable/disable

Sponsored-by: On-Waves ehf
2015-11-26 12:52:24 +01:00
Jacob Erlbeck be37fb7db4 stats/test: Add tests to check VTY configuration
This commit adds tests to verify the stats related VTY configuration
commands.

Sponsored-by: On-Waves ehf
2015-08-22 01:34:05 +00:00
Jacob Erlbeck ca6602f476 vty/test: Refactor vty creation/deletion into separate functions
Currently this is part of the only test function that uses the
vty directly.

In preperation for more such test cases, this commit moves this code
into separate functions.

Sponsored-by: On-Waves ehf
2015-08-22 01:31:31 +00:00
Jacob Erlbeck ee2657f6af test: Remove unneeded linking to libosmovty.la
The addition of libosmovty.la to several test cases as done in
commit 738d9e2210 (stats: Add vty_out_stat_item_group)
is not needed.

This commit removes them.

Sponsored-by: On-Waves ehf
2015-08-22 01:31:23 +00:00
Jacob Erlbeck fc9533d6c4 stats: Add osmo_ name prefix to identifiers
Since the the stat_item and stats functions and data types are meant
to be exported, they get an osmo_ prefix.

Sponsored-by: On-Waves ehf

[hfreyther: Prepended the enum values too. This was requested by
Jacob]
2015-11-02 15:39:01 +01:00
Jacob Erlbeck adc900e0e3 stats/vty: Add stats configuration
This commit provides stats configuration similar to the log
configuration.

The following vty commands are added to the config node:
  stats reporter statsd          Create/Modify a statsd reporter
  no stats reporter statsd       Remove a statsd reporter

To actually configure a reporter, the config-stats node is entered
when the "stats reporter" command has succeeded. The following new
vty commands are available there:
  local-ip ADDR          Set the IP address to which we bind locally
  no local-ip            Do not bind to a certain IP address
  remote-ip ADDR         Set the remote IP address to which we connect
  remote-port <1-65535>  Set the remote port to which we connect
  prefix PREFIX          Set the item/counter name prefix
  no prefix              Do not use a prefix
  enable                 Enable the reporter
  disable                Disable the reporter

Sponsored-by: On-Waves ehf
2015-10-29 01:10:06 +01:00
Jacob Erlbeck b27b352e93 stats: Use a global index for stat item values
Currently each stat item has a separate index value which basically
counts each single value added to the item and which can be used by
a reporter to get all new values that have not been reported yet.
The drawback is, that such an index must be stored for each stat
item.

This commit introduces a global index which is incremented for each
new stat item value. This index is then stored together with the item
value. So a single stored index per reporter is sufficient to make
sure that only new values are reported.

Sponsored-by: On-Waves ehf
2015-10-28 23:51:24 +01:00
Jacob Erlbeck 738d9e2210 stats: Add vty_out_stat_item_group
This functions dumps a whole stat item group to the VTY.

Sponsored-by: On-Waves ehf
2015-10-28 23:51:12 +01:00
Jacob Erlbeck 9732cb4a92 stats: Add stat_item for value monitoring
This commit adds instrumentation function to gather measurement
and statistical values similar to counter groups.

Multiple values can be stored per item, which can be retrieved in
FIFO order. Getting values from the item does not modify its state to
allow for multiple independant backends (e.g. VTY and statd).

When a new value is set, the oldest value gets silently overwritten.
Lost values are skipped when getting values from the item.

Sponsored-by: On-Waves ehf
2015-10-28 23:51:04 +01:00
Jan Engelhardt c2ddc4f555 build: have a disable-static build succeed
When using configure --disable-static, no libosmogsm.a will be
created, and the tests fail to link because symbols like _a5_3 and
_a5_4 are not exported through the only remaining libosmogsm.so.

A method to overcome this is an intermediate private non-distributed
library, examples of which are present in e.g. libabc, kmod and
systemd.

With this, disable-static can now be the default and practical compile
time be halved.
2015-09-16 18:08:48 +02:00
Sylvain Munaut 0d72785568 tests: Don't reference file in src/ to test hidden func. Use static link.
Taken from:
https://qiaomuf.wordpress.com/2011/03/27/handling-unit-test-with-c-visibilityhidden/

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2015-08-19 11:14:23 +02:00
Jacob Erlbeck 2c58197e5d bssgp/test: Add missing START/END printfs
Sponsored-by: On-Waves ehf
2015-06-19 20:53:31 +02:00
Holger Hans Peter Freyther f558ed4bb9 ipa: Properly parse LV stream of a ID_GET request
For some reason the structure is closer to be a LV (length
and value). The value is actually a tag but it is counted
inside the length. Introduce an overload of the parse function
to provide an offset for the length. This will be taken from
the returned length.
2015-06-02 15:52:06 +02:00
Holger Hans Peter Freyther 0d86c21f6a build: Fix the building of tests as well
In file included from ../../include/osmocom/core/msgb.h:25:0,
                 from ../../tests/sms/sms_test.c:31:
../../include/osmocom/core/bits.h:6:35: fatal error: osmocom/core/bit16gen.h: No such file or directory
 #include <osmocom/core/bit16gen.h>
2015-05-17 19:55:53 +02:00
Jacob Erlbeck 9385d1e01b bssgp: Fix bssgp_tx_fc_bvc parameter type
Currently large values for Bmax default MS get sliced since a uint16_t is
used as the type of the corresponding parameter of bssgp_tx_fc_bvc.
GSM 48.018, 11.3.2 which in turn refers to 11.3.5 specifies a maximum
of 6MB (0xffff * 100).

This commit changes the type to uint32_t to cover the full value
range.

Sponsored-by: On-Waves ehf
2015-05-06 17:55:55 +02:00
Jacob Erlbeck 455d34f476 bssgp/test: Fix bssgp-fc test
The fix in the commit "bssgp: Fix call to llist_entry in
fc_queue_timer_cfg" prevents the flow control code from generating
certain logging messages ("-BSSGP-FC: fc_timer_cb() but still not
able to send PDU of 10 bytes") during the tests. This breaks the test
suite, since the update of the correseponding stderr output file
misses.

This commit updates the bssgp_fc_tests.err file accordingly.

Sponsored-by: On-Waves ehf
2015-05-04 07:44:43 +02:00
Holger Hans Peter Freyther 6b1faf7362 logginrb: Fix compiler warning about fprintf
loggingrb/loggingrb_test.c:76:18: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
        fprintf(stderr, log_target_rb_get(ringbuf_target, 0));
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
loggingrb/loggingrb_test.c:77:18: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
        fprintf(stderr, log_target_rb_get(ringbuf_target, 1));
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2015-04-11 19:33:10 +02:00
Jacob Erlbeck b535e391b0 bssgp: Ensure non-NULL bctx before calling bssgp_rx_ptp (Coverity)
Currently bssgp_rx_ptp might be called with bctx being NULL, when the
NS BVCI is neither BVCI_SIGNALLING nor BVCI_PTM, but the message is
a BVC_RESET or it contains an BVCI IE != BVCI_SIGNALLING where the
BVCI is not known.

This patch ensures that bssgp_rx_ptp will only be called with a
non-NULL bctx. A log message will be issued, if the bctx is NULL when
this was not expected.

Fixes: Coverity CID 1040674
Sponsored-by: On-Waves ehf
2015-04-07 20:10:09 +02:00
Max a11994ddff fix compiler warnings for a5 tests
Signed-off-by: Max <max.suraev@fairwaves.co>
2015-04-07 20:08:38 +02:00
Michael McTernan 4e0543f730 Tests: Fix broken loggingrb testcase.
The loggingrb (ringbuffer) test case was not actually being built or ran, instead still using the normal logging test.

This patch fixes the makefile, then the loggingrb testcase is changed to use the current loggingrb API so that it builds and passes.

Signed-off-by: Michael McTernan <mike.mcternan@wavemobile.com>
2015-04-01 20:50:26 +02:00
Max f8699ca51e gsm: Add A5/3-4 cipher support
Signed-off-by: Max <max.suraev@fairwaves.co>
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2015-03-28 18:07:05 +01:00
Jacob Erlbeck 36153dc61a bssgp: Handle BSSGP STATUS messages
Currently incoming BSSGP STATUS messages are just logged and no other
action is taken. This makes it impossible for higher layers to react
to failures which are indicated by corresponding STATUS messages
unless a timeout is triggered as a result of that failure later on.

This commit adds a bssgp_rx_status() function and calls it on
incoming STATUS messages. That function logs a message, increments the
new BSSGP_CTR_STATUS counter if the bctx context exists and invokes
an NM_STATUS status indication. The latter will allow the application
to handle failures immediately. Since all STATUS messages should be
handled, the function is already called in bssgp_rcvmsg and the
message is no longer handled in (and will not reach) bssgp_rx_sign
and bssgp_rx_ptp.

Ticket: OW#1414
Sponsored-by: On-Waves ehf
2015-03-18 21:54:37 +01:00
Tobias Engel 419684e30c Supplementary Services (de)activation, interrogation added
These patches enhance the Supplementary Service (SS) processing from
only being able to handle USSD to other SS, specifically activation,
deactivation and interrogation of those SS. Registration is not yet
implemented.

include/osmocom/gsm/protocol/gsm_09_02.h has been added with needed
values for SS.

Modified by Harald Welte to keep the old ussd-only functiosn for API/ABI
stability.
2015-01-01 14:19:17 +01:00
Harald Welte c13cf8bbd3 SMS-CB: introduce and use GSM341_7BIT_PADDING 2014-12-30 13:25:44 +01:00
Harald Welte c993a07ceb use the new GSM341 / GSM412 size constants 2014-12-30 13:22:56 +01:00
Daniel Willmann f626123f83 smscb/gsm0341_test: Add \r padding to the message 2014-12-30 12:07:17 +01:00
Harald Welte 65f676dac5 test 2014-12-30 00:43:39 +01:00