aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2017-12-22 14:20:05 +0100
committerMax <msuraev@sysmocom.de>2017-12-22 14:20:05 +0100
commit20c7c46bceac4969e420f2b0dd89448327914971 (patch)
tree6f864d1be95478bc00ff45715d1363c8c320b22a
parent406a1f0acf63d88c197d1d29221294f9e27f774d (diff)
Add tests for pcu_lsb()
This utility functions is used by TBF allocation routines and only tested indirectly through allocation test. Let's add proper exhaustive test which checks all uint8_t values. This also requires adding missing include to pcu_utils.h Change-Id: If08a7f0d31f0e5ad8a5efa5885880aed19c329ab
-rw-r--r--src/pcu_utils.h4
-rw-r--r--tests/types/TypesTest.cpp18
-rw-r--r--tests/types/TypesTest.ok257
3 files changed, 279 insertions, 0 deletions
diff --git a/src/pcu_utils.h b/src/pcu_utils.h
index 3a64a47..767771c 100644
--- a/src/pcu_utils.h
+++ b/src/pcu_utils.h
@@ -16,6 +16,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+extern "C" {
+#include <osmocom/gsm/gsm_utils.h>
+}
+
inline int msecs_to_frames(int msecs) {
return (msecs * (1024 * 1000 / 4615)) / 1024;
}
diff --git a/tests/types/TypesTest.cpp b/tests/types/TypesTest.cpp
index 7d09108..ff78c87 100644
--- a/tests/types/TypesTest.cpp
+++ b/tests/types/TypesTest.cpp
@@ -21,6 +21,7 @@
*/
#include "bts.h"
#include "tbf.h"
+#include "pcu_utils.h"
#include "gprs_debug.h"
#include "encoding.h"
#include "decoding.h"
@@ -30,6 +31,7 @@ extern "C" {
#include <osmocom/core/msgb.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/utils.h>
+#include <osmocom/core/bits.h>
}
#define OSMO_ASSERT_STR_EQ(a, b) \
@@ -463,6 +465,20 @@ void test_immediate_assign_rej()
}
+static void test_lsb()
+{
+ uint8_t u = 0;
+
+ printf("Testing LBS utility...\n");
+
+ do {
+ uint8_t x = pcu_lsb(u); /* equivalent of (1 << ffs(u)) / 2 */
+ printf("%2X " OSMO_BIT_SPEC ": {%d} %3d\n",
+ u, OSMO_BIT_PRINT(u), pcu_bitcount(u), x);
+ u++;
+ } while (u);
+}
+
int main(int argc, char **argv)
{
osmo_init_logging(&gprs_log_info);
@@ -476,6 +492,8 @@ int main(int argc, char **argv)
test_rlc_v_n();
test_rlc_dl_ul_basic();
test_immediate_assign_rej();
+ test_lsb();
+
return EXIT_SUCCESS;
}
diff --git a/tests/types/TypesTest.ok b/tests/types/TypesTest.ok
index fe5162c..4bdd917 100644
--- a/tests/types/TypesTest.ok
+++ b/tests/types/TypesTest.ok
@@ -8,3 +8,260 @@ show_rbb: RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
show_rbb: IIRRIIIR
assignment reject: 06 3a 10 7f 06 36 14 7f 06 36 14 7f 06 36 14 7f 06 36 14 c0 2b 2b
assignment reject: 06 3a 10 70 06 36 14 70 06 36 14 70 06 36 14 70 06 36 14 0b 2b 2b
+Testing LBS utility...
+ 0 ........: {0} 0
+ 1 .......1: {1} 1
+ 2 ......1.: {1} 2
+ 3 ......11: {2} 1
+ 4 .....1..: {1} 4
+ 5 .....1.1: {2} 1
+ 6 .....11.: {2} 2
+ 7 .....111: {3} 1
+ 8 ....1...: {1} 8
+ 9 ....1..1: {2} 1
+ A ....1.1.: {2} 2
+ B ....1.11: {3} 1
+ C ....11..: {2} 4
+ D ....11.1: {3} 1
+ E ....111.: {3} 2
+ F ....1111: {4} 1
+10 ...1....: {1} 16
+11 ...1...1: {2} 1
+12 ...1..1.: {2} 2
+13 ...1..11: {3} 1
+14 ...1.1..: {2} 4
+15 ...1.1.1: {3} 1
+16 ...1.11.: {3} 2
+17 ...1.111: {4} 1
+18 ...11...: {2} 8
+19 ...11..1: {3} 1
+1A ...11.1.: {3} 2
+1B ...11.11: {4} 1
+1C ...111..: {3} 4
+1D ...111.1: {4} 1
+1E ...1111.: {4} 2
+1F ...11111: {5} 1
+20 ..1.....: {1} 32
+21 ..1....1: {2} 1
+22 ..1...1.: {2} 2
+23 ..1...11: {3} 1
+24 ..1..1..: {2} 4
+25 ..1..1.1: {3} 1
+26 ..1..11.: {3} 2
+27 ..1..111: {4} 1
+28 ..1.1...: {2} 8
+29 ..1.1..1: {3} 1
+2A ..1.1.1.: {3} 2
+2B ..1.1.11: {4} 1
+2C ..1.11..: {3} 4
+2D ..1.11.1: {4} 1
+2E ..1.111.: {4} 2
+2F ..1.1111: {5} 1
+30 ..11....: {2} 16
+31 ..11...1: {3} 1
+32 ..11..1.: {3} 2
+33 ..11..11: {4} 1
+34 ..11.1..: {3} 4
+35 ..11.1.1: {4} 1
+36 ..11.11.: {4} 2
+37 ..11.111: {5} 1
+38 ..111...: {3} 8
+39 ..111..1: {4} 1
+3A ..111.1.: {4} 2
+3B ..111.11: {5} 1
+3C ..1111..: {4} 4
+3D ..1111.1: {5} 1
+3E ..11111.: {5} 2
+3F ..111111: {6} 1
+40 .1......: {1} 64
+41 .1.....1: {2} 1
+42 .1....1.: {2} 2
+43 .1....11: {3} 1
+44 .1...1..: {2} 4
+45 .1...1.1: {3} 1
+46 .1...11.: {3} 2
+47 .1...111: {4} 1
+48 .1..1...: {2} 8
+49 .1..1..1: {3} 1
+4A .1..1.1.: {3} 2
+4B .1..1.11: {4} 1
+4C .1..11..: {3} 4
+4D .1..11.1: {4} 1
+4E .1..111.: {4} 2
+4F .1..1111: {5} 1
+50 .1.1....: {2} 16
+51 .1.1...1: {3} 1
+52 .1.1..1.: {3} 2
+53 .1.1..11: {4} 1
+54 .1.1.1..: {3} 4
+55 .1.1.1.1: {4} 1
+56 .1.1.11.: {4} 2
+57 .1.1.111: {5} 1
+58 .1.11...: {3} 8
+59 .1.11..1: {4} 1
+5A .1.11.1.: {4} 2
+5B .1.11.11: {5} 1
+5C .1.111..: {4} 4
+5D .1.111.1: {5} 1
+5E .1.1111.: {5} 2
+5F .1.11111: {6} 1
+60 .11.....: {2} 32
+61 .11....1: {3} 1
+62 .11...1.: {3} 2
+63 .11...11: {4} 1
+64 .11..1..: {3} 4
+65 .11..1.1: {4} 1
+66 .11..11.: {4} 2
+67 .11..111: {5} 1
+68 .11.1...: {3} 8
+69 .11.1..1: {4} 1
+6A .11.1.1.: {4} 2
+6B .11.1.11: {5} 1
+6C .11.11..: {4} 4
+6D .11.11.1: {5} 1
+6E .11.111.: {5} 2
+6F .11.1111: {6} 1
+70 .111....: {3} 16
+71 .111...1: {4} 1
+72 .111..1.: {4} 2
+73 .111..11: {5} 1
+74 .111.1..: {4} 4
+75 .111.1.1: {5} 1
+76 .111.11.: {5} 2
+77 .111.111: {6} 1
+78 .1111...: {4} 8
+79 .1111..1: {5} 1
+7A .1111.1.: {5} 2
+7B .1111.11: {6} 1
+7C .11111..: {5} 4
+7D .11111.1: {6} 1
+7E .111111.: {6} 2
+7F .1111111: {7} 1
+80 1.......: {1} 128
+81 1......1: {2} 1
+82 1.....1.: {2} 2
+83 1.....11: {3} 1
+84 1....1..: {2} 4
+85 1....1.1: {3} 1
+86 1....11.: {3} 2
+87 1....111: {4} 1
+88 1...1...: {2} 8
+89 1...1..1: {3} 1
+8A 1...1.1.: {3} 2
+8B 1...1.11: {4} 1
+8C 1...11..: {3} 4
+8D 1...11.1: {4} 1
+8E 1...111.: {4} 2
+8F 1...1111: {5} 1
+90 1..1....: {2} 16
+91 1..1...1: {3} 1
+92 1..1..1.: {3} 2
+93 1..1..11: {4} 1
+94 1..1.1..: {3} 4
+95 1..1.1.1: {4} 1
+96 1..1.11.: {4} 2
+97 1..1.111: {5} 1
+98 1..11...: {3} 8
+99 1..11..1: {4} 1
+9A 1..11.1.: {4} 2
+9B 1..11.11: {5} 1
+9C 1..111..: {4} 4
+9D 1..111.1: {5} 1
+9E 1..1111.: {5} 2
+9F 1..11111: {6} 1
+A0 1.1.....: {2} 32
+A1 1.1....1: {3} 1
+A2 1.1...1.: {3} 2
+A3 1.1...11: {4} 1
+A4 1.1..1..: {3} 4
+A5 1.1..1.1: {4} 1
+A6 1.1..11.: {4} 2
+A7 1.1..111: {5} 1
+A8 1.1.1...: {3} 8
+A9 1.1.1..1: {4} 1
+AA 1.1.1.1.: {4} 2
+AB 1.1.1.11: {5} 1
+AC 1.1.11..: {4} 4
+AD 1.1.11.1: {5} 1
+AE 1.1.111.: {5} 2
+AF 1.1.1111: {6} 1
+B0 1.11....: {3} 16
+B1 1.11...1: {4} 1
+B2 1.11..1.: {4} 2
+B3 1.11..11: {5} 1
+B4 1.11.1..: {4} 4
+B5 1.11.1.1: {5} 1
+B6 1.11.11.: {5} 2
+B7 1.11.111: {6} 1
+B8 1.111...: {4} 8
+B9 1.111..1: {5} 1
+BA 1.111.1.: {5} 2
+BB 1.111.11: {6} 1
+BC 1.1111..: {5} 4
+BD 1.1111.1: {6} 1
+BE 1.11111.: {6} 2
+BF 1.111111: {7} 1
+C0 11......: {2} 64
+C1 11.....1: {3} 1
+C2 11....1.: {3} 2
+C3 11....11: {4} 1
+C4 11...1..: {3} 4
+C5 11...1.1: {4} 1
+C6 11...11.: {4} 2
+C7 11...111: {5} 1
+C8 11..1...: {3} 8
+C9 11..1..1: {4} 1
+CA 11..1.1.: {4} 2
+CB 11..1.11: {5} 1
+CC 11..11..: {4} 4
+CD 11..11.1: {5} 1
+CE 11..111.: {5} 2
+CF 11..1111: {6} 1
+D0 11.1....: {3} 16
+D1 11.1...1: {4} 1
+D2 11.1..1.: {4} 2
+D3 11.1..11: {5} 1
+D4 11.1.1..: {4} 4
+D5 11.1.1.1: {5} 1
+D6 11.1.11.: {5} 2
+D7 11.1.111: {6} 1
+D8 11.11...: {4} 8
+D9 11.11..1: {5} 1
+DA 11.11.1.: {5} 2
+DB 11.11.11: {6} 1
+DC 11.111..: {5} 4
+DD 11.111.1: {6} 1
+DE 11.1111.: {6} 2
+DF 11.11111: {7} 1
+E0 111.....: {3} 32
+E1 111....1: {4} 1
+E2 111...1.: {4} 2
+E3 111...11: {5} 1
+E4 111..1..: {4} 4
+E5 111..1.1: {5} 1
+E6 111..11.: {5} 2
+E7 111..111: {6} 1
+E8 111.1...: {4} 8
+E9 111.1..1: {5} 1
+EA 111.1.1.: {5} 2
+EB 111.1.11: {6} 1
+EC 111.11..: {5} 4
+ED 111.11.1: {6} 1
+EE 111.111.: {6} 2
+EF 111.1111: {7} 1
+F0 1111....: {4} 16
+F1 1111...1: {5} 1
+F2 1111..1.: {5} 2
+F3 1111..11: {6} 1
+F4 1111.1..: {5} 4
+F5 1111.1.1: {6} 1
+F6 1111.11.: {6} 2
+F7 1111.111: {7} 1
+F8 11111...: {5} 8
+F9 11111..1: {6} 1
+FA 11111.1.: {6} 2
+FB 11111.11: {7} 1
+FC 111111..: {6} 4
+FD 111111.1: {7} 1
+FE 1111111.: {7} 2
+FF 11111111: {8} 1