aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--src/llc.cpp3
-rw-r--r--src/llc.h4
-rw-r--r--tests/Makefile.am13
-rw-r--r--tests/testsuite.at7
-rw-r--r--tests/types/TypesTest.cpp93
-rw-r--r--tests/types/TypesTest.err0
-rw-r--r--tests/types/TypesTest.ok1
8 files changed, 117 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 4e4f1c59..554879a2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,7 @@ tests/package.m4
tests/alloc/AllocTest
tests/rlcmac/RLCMACTest
tests/tbf/TbfTest
+tests/types/TypesTest
tests/emu/pcu_emu
tests/testsuite
tests/testsuite.log
diff --git a/src/llc.cpp b/src/llc.cpp
index c0c517f3..ae190b7f 100644
--- a/src/llc.cpp
+++ b/src/llc.cpp
@@ -55,7 +55,7 @@ void gprs_llc::put_frame(const uint8_t *data, size_t len)
void gprs_llc::append_frame(const uint8_t *data, size_t len)
{
/* TODO: bounds check */
- memcpy(frame + m_index, data, len);
+ memcpy(frame + m_length, data, len);
m_length += len;
}
@@ -72,6 +72,7 @@ void gprs_llc::clear(BTS *bts)
void gprs_llc::init()
{
INIT_LLIST_HEAD(&queue);
+ reset();
}
struct msgb *gprs_llc::dequeue()
diff --git a/src/llc.h b/src/llc.h
index f1692f4b..f50419c8 100644
--- a/src/llc.h
+++ b/src/llc.h
@@ -63,7 +63,7 @@ inline uint16_t gprs_llc::chunk_size() const
inline uint16_t gprs_llc::remaining_space() const
{
- return LLC_MAX_LEN - m_index;
+ return LLC_MAX_LEN - m_length;
}
inline uint16_t gprs_llc::frame_length() const
@@ -85,5 +85,5 @@ inline void gprs_llc::consume(uint8_t *data, size_t len)
inline bool gprs_llc::fits_in_current_frame(uint8_t chunk_size) const
{
- return m_index + chunk_size <= LLC_MAX_LEN;
+ return m_length + chunk_size <= LLC_MAX_LEN;
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 415fb4d4..e84f17de 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,6 @@
AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGB_CFLAGS) $(LIBOSMOGSM_CFLAGS) -I$(top_srcdir)/src/
-check_PROGRAMS = rlcmac/RLCMACTest alloc/AllocTest tbf/TbfTest
+check_PROGRAMS = rlcmac/RLCMACTest alloc/AllocTest tbf/TbfTest types/TypesTest
noinst_PROGRAMS = emu/pcu_emu
rlcmac_RLCMACTest_SOURCES = rlcmac/RLCMACTest.cpp
@@ -35,6 +35,14 @@ emu_pcu_emu_LDADD = \
$(LIBOSMOCORE_LIBS) \
$(COMMON_LA)
+types_TypesTest_SOURCES = types/TypesTest.cpp
+types_TypesTest_LDADD = \
+ $(LIBOSMOGB_LIBS) \
+ $(LIBOSMOGSM_LIBS) \
+ $(LIBOSMOCORE_LIBS) \
+ $(COMMON_LA) \
+ $(top_builddir)/src/libgprs.la
+
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
$(srcdir)/package.m4: $(top_srcdir)/configure.ac
@@ -58,7 +66,8 @@ EXTRA_DIST = \
testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \
rlcmac/RLCMACTest.ok rlcmac/RLCMACTest.err \
alloc/AllocTest.ok alloc/AllocTest.err \
- tbf/TbfTest.ok tbf/TbfTest.err
+ tbf/TbfTest.ok tbf/TbfTest.err \
+ types/TypesTest.ok types/TypesTest.err
DISTCLEANFILES = atconfig
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 4d770050..27f66b9f 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -22,3 +22,10 @@ cat $abs_srcdir/tbf/TbfTest.ok > expout
cat $abs_srcdir/tbf/TbfTest.err > experr
AT_CHECK([$abs_top_builddir/tests/tbf/TbfTest], [0], [expout], [experr])
AT_CLEANUP
+
+AT_SETUP([types])
+AT_KEYWORDS([types])
+cat $abs_srcdir/types/TypesTest.ok > expout
+cat $abs_srcdir/types/TypesTest.err > experr
+AT_CHECK([$abs_top_builddir/tests/types/TypesTest], [0], [expout], [experr])
+AT_CLEANUP
diff --git a/tests/types/TypesTest.cpp b/tests/types/TypesTest.cpp
new file mode 100644
index 00000000..235ba974
--- /dev/null
+++ b/tests/types/TypesTest.cpp
@@ -0,0 +1,93 @@
+/*
+ * TypesTest.cpp Test the primitive data types
+ *
+ * Copyright (C) 2013 by Holger Hans Peter Freyther
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include "bts.h"
+#include "tbf.h"
+#include "gprs_debug.h"
+
+extern "C" {
+#include <osmocom/core/application.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/utils.h>
+}
+
+void *tall_pcu_ctx;
+int16_t spoof_mnc = 0, spoof_mcc = 0;
+
+static void test_llc(void)
+{
+ {
+ uint8_t data[LLC_MAX_LEN] = {1, 2, 3, 4, };
+ uint8_t out;
+ gprs_llc llc;
+ llc.init();
+
+ OSMO_ASSERT(llc.chunk_size() == 0);
+ OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN);
+ OSMO_ASSERT(llc.frame_length() == 0);
+
+ llc.put_frame(data, 2);
+ OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN - 2);
+ OSMO_ASSERT(llc.frame_length() == 2);
+ OSMO_ASSERT(llc.chunk_size() == 2);
+ OSMO_ASSERT(llc.frame[0] == 1);
+ OSMO_ASSERT(llc.frame[1] == 2);
+
+ llc.append_frame(&data[3], 1);
+ OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN - 3);
+ OSMO_ASSERT(llc.frame_length() == 3);
+ OSMO_ASSERT(llc.chunk_size() == 3);
+
+ /* consume two bytes */
+ llc.consume(&out, 1);
+ OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN - 3);
+ OSMO_ASSERT(llc.frame_length() == 3);
+ OSMO_ASSERT(llc.chunk_size() == 2);
+
+ /* check that the bytes are as we expected */
+ OSMO_ASSERT(llc.frame[0] == 1);
+ OSMO_ASSERT(llc.frame[1] == 2);
+ OSMO_ASSERT(llc.frame[2] == 4);
+
+ /* now fill the frame */
+ llc.append_frame(data, llc.remaining_space() - 1);
+ OSMO_ASSERT(llc.fits_in_current_frame(1));
+ OSMO_ASSERT(!llc.fits_in_current_frame(2));
+ }
+}
+
+int main(int argc, char **argv)
+{
+ printf("Making some basic type testing.\n");
+ test_llc();
+ return EXIT_SUCCESS;
+}
+
+/*
+ * stubs that should not be reached
+ */
+extern "C" {
+void l1if_pdch_req() { abort(); }
+void l1if_connect_pdch() { abort(); }
+void l1if_close_pdch() { abort(); }
+void l1if_open_pdch() { abort(); }
+}
diff --git a/tests/types/TypesTest.err b/tests/types/TypesTest.err
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/types/TypesTest.err
diff --git a/tests/types/TypesTest.ok b/tests/types/TypesTest.ok
new file mode 100644
index 00000000..9d0cbfbb
--- /dev/null
+++ b/tests/types/TypesTest.ok
@@ -0,0 +1 @@
+Making some basic type testing.