bitXXgen: add bitgen_test.c
The autogenerated bitXXgen.h headers for osmo_load16le_ext() thru
osmo_store64_be() are not actually tested at all. Add a test.
The test output shows that the osmo_load*be_ext for a shorter len do not return
nicely matching results. A practical example showing the difficulty in storing
and loading 24bit integer values as/from big-endian:
uint8_t buf[4];
memset(buf, 0, sizeof(buf));
osmo_store32be_ext(0x00112233, buf, 3); // stores 11 22 33
printf("%s\n", osmo_hexdump(buf, 4));
uint32_t r = osmo_load32be_ext(buf, 3); // returns 0x11223300, not 0x00112233
printf("0x%x\n", r);
output is:
11 22 33 00
0x11223300
In contrast, the little-endian variant properly aligns the loaded bytes on the
least significant octet:
uint8_t buf[4];
memset(buf, 0, sizeof(buf));
osmo_store32le_ext(0x00112233, buf, 3); // stores 33 22 11
printf("%s\n", osmo_hexdump(buf, 4));
uint32_t r = osmo_load32le_ext(buf, 3); // returns 0x00112233 as expected
printf("0x%x\n", r);
output for le is:
33 22 11 00
0x112233
Change-Id: I5542ace54376a206aa8574812d4c742c86c293b4
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 56d0ac5..7a0b4b1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -37,6 +37,7 @@
gsm0502/gsm0502_test \
dtx/dtx_gsm0503_test \
i460_mux/i460_mux_test \
+ bitgen/bitgen_test \
$(NULL)
if ENABLE_MSGFILE
@@ -277,6 +278,9 @@
i460_mux_i460_mux_test_SOURCES = i460_mux/i460_mux_test.c
i460_mux_i460_mux_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la
+bitgen_bitgen_test_SOURCES = bitgen/bitgen_test.c
+bitgen_bitgen_test_LDADD = $(LDADD)
+
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
$(srcdir)/package.m4: $(top_srcdir)/configure.ac
:;{ \
@@ -356,6 +360,7 @@
dtx/dtx_gsm0503_test.ok \
exec/exec_test.ok exec/exec_test.err \
i460_mux/i460_mux_test.ok \
+ bitgen/bitgen_test.ok \
$(NULL)
if ENABLE_LIBSCTP