aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/base
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/base')
-rw-r--r--hicn-light/src/hicn/base/bitmap.h6
-rw-r--r--hicn-light/src/hicn/base/pool.c6
-rw-r--r--hicn-light/src/hicn/base/test/CMakeLists.txt4
-rw-r--r--hicn-light/src/hicn/base/test/test-bitmap.cc14
-rw-r--r--hicn-light/src/hicn/base/test/test-pool.cc21
-rw-r--r--hicn-light/src/hicn/base/test/test-vector.cc6
-rw-r--r--hicn-light/src/hicn/base/vector.h2
7 files changed, 39 insertions, 20 deletions
diff --git a/hicn-light/src/hicn/base/bitmap.h b/hicn-light/src/hicn/base/bitmap.h
index 4a78af567..ebc3dddbb 100644
--- a/hicn-light/src/hicn/base/bitmap.h
+++ b/hicn-light/src/hicn/base/bitmap.h
@@ -43,8 +43,8 @@ typedef uint_fast32_t bitmap_t;
* @param[in] max_size Bitmap max_size
*/
#define bitmap_init(bitmap, init_size, max_size) \
- vector_init(bitmap, next_pow2(init_size / BITMAP_WIDTH(bitmap)), \
- max_size == 0 ? 0 : next_pow2(max_size / BITMAP_WIDTH(bitmap)))
+ vector_init(bitmap, next_pow2((init_size) / BITMAP_WIDTH(bitmap)), \
+ max_size == 0 ? 0 : next_pow2((max_size) / BITMAP_WIDTH(bitmap)))
/*
* @brief Ensures a bitmap is sufficiently large to hold an element at the
@@ -156,7 +156,7 @@ bitmap_set_range(bitmap_t * bitmap, off_t from, off_t to)
*/
if ((pos_to != BITMAP_WIDTH(bitmap) - 1) && (offset_to != offset_from)) {
size_t to_start = MAX(from, offset_to * BITMAP_WIDTH(bitmap));
- for (size_t k = to_start; k < to; k++) {
+ for (size_t k = to_start; k < (size_t) to; k++) {
if (bitmap_set(bitmap, k) < 0)
goto END;
}
diff --git a/hicn-light/src/hicn/base/pool.c b/hicn-light/src/hicn/base/pool.c
index 31abb13f1..cb650b9e5 100644
--- a/hicn-light/src/hicn/base/pool.c
+++ b/hicn-light/src/hicn/base/pool.c
@@ -16,7 +16,7 @@
/**
* \file pool.c
* \brief Implementation of fixed-size pool allocator.
- *
+ *
* NOTE:
* - Ideally, we should have a single realloc per resize, that would encompass
* both the free indices vector and bitmap, by nesting data structures. Because
@@ -81,6 +81,10 @@ ERR_MAX_SIZE:
void
_pool_free(void ** pool_ptr)
{
+ pool_hdr_t * ph = pool_hdr(*pool_ptr);
+ vector_free(ph->free_indices);
+ bitmap_free(ph->free_bitmap);
+
free(pool_hdr(*pool_ptr));
*pool_ptr = NULL;
}
diff --git a/hicn-light/src/hicn/base/test/CMakeLists.txt b/hicn-light/src/hicn/base/test/CMakeLists.txt
index 351e7bd34..cdf6ed11b 100644
--- a/hicn-light/src/hicn/base/test/CMakeLists.txt
+++ b/hicn-light/src/hicn/base/test/CMakeLists.txt
@@ -15,9 +15,9 @@ foreach(test ${TESTS})
build_executable(${test}
NO_INSTALL
SOURCES ${test}.cc
- LINK_LIBRARIES ${LIBHICN_LIGHT_SHARED} ${GTEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+ LINK_LIBRARIES ${LIBHICN_LIGHT_SHARED} ${LIBHICNCTRL_SHARED} ${GTEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
INCLUDE_DIRS ${HICN_LIGHT_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
- DEPENDS gtest ${LIBHICN_LIGHT_SHARED}
+ DEPENDS gtest ${LIBHICNCTRL_SHARED} ${LIBHICN_LIGHT_SHARED}
COMPONENT ${HICN_LIGHT}
DEFINITIONS "${COMPILER_DEFINITIONS}"
)
diff --git a/hicn-light/src/hicn/base/test/test-bitmap.cc b/hicn-light/src/hicn/base/test/test-bitmap.cc
index 1a62edba3..d1b335ace 100644
--- a/hicn-light/src/hicn/base/test/test-bitmap.cc
+++ b/hicn-light/src/hicn/base/test/test-bitmap.cc
@@ -57,32 +57,32 @@ TEST_F(BitmapTest, BitmapAllocation)
* Bitmap should have been allocated with a size rounded to the next power
* of 2
*/
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1);
+ EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1UL);
/* By default, no element should be set */
EXPECT_FALSE(bitmap_is_set(bitmap, 0));
EXPECT_TRUE(bitmap_is_unset(bitmap, 0));
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1);
+ EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1UL);
EXPECT_FALSE(bitmap_is_set(bitmap, size_not_pow2 - 1));
EXPECT_TRUE(bitmap_is_unset(bitmap, size_not_pow2 - 1));
/* Bitmap should not have been reallocated */
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1);
+ EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1UL);
/* After setting a bit after the end, bitmap should have been reallocated */
bitmap_set(bitmap, sizeof(bitmap[0]) * 8 - 1);
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1);
+ EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1UL);
/* After setting a bit after the end, bitmap should have been reallocated */
rc = bitmap_set(bitmap, sizeof(bitmap[0]) * 8);
EXPECT_GE(rc, 0);
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 2);
+ EXPECT_EQ(bitmap_get_alloc_size(bitmap), 2UL);
rc = bitmap_set(bitmap, sizeof(bitmap[0]) * 8 + 1);
EXPECT_GE(rc, 0);
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 2);
+ EXPECT_EQ(bitmap_get_alloc_size(bitmap), 2UL);
bitmap_free(bitmap);
@@ -90,7 +90,7 @@ TEST_F(BitmapTest, BitmapAllocation)
/* Limiting test for allocation size */
bitmap_init(bitmap, size_pow2, 0);
- EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1);
+ EXPECT_EQ(bitmap_get_alloc_size(bitmap), 1UL);
bitmap_free(bitmap);
}
diff --git a/hicn-light/src/hicn/base/test/test-pool.cc b/hicn-light/src/hicn/base/test/test-pool.cc
index 1146ef2b7..f87ff65dd 100644
--- a/hicn-light/src/hicn/base/test/test-pool.cc
+++ b/hicn-light/src/hicn/base/test/test-pool.cc
@@ -56,7 +56,7 @@ TEST_F(PoolTest, PoolAllocation)
/* Check that free indices and bitmaps are correctly initialize */
off_t * fi = pool_get_free_indices(pool);
EXPECT_EQ(vector_len(fi), pool_size);
- EXPECT_EQ(fi[0], pool_size - 1);
+ EXPECT_EQ(fi[0], (long) (pool_size - 1));
EXPECT_EQ(fi[pool_size - 1], 0);
/* The allocated size of the underlying vector should be the next power of two */
@@ -89,12 +89,12 @@ TEST_F(PoolTest, PoolAllocation)
rc = pool_get(pool, elt);
EXPECT_GE(rc, 0);
- EXPECT_EQ(vector_len(fi), 1);
+ EXPECT_EQ(vector_len(fi), 1UL);
EXPECT_TRUE(bitmap_is_unset(fb, pool_size - 2));
rc = pool_get(pool, elt);
EXPECT_GE(rc, 0);
- EXPECT_EQ(vector_len(fi), 0);
+ EXPECT_EQ(vector_len(fi), 0UL);
EXPECT_TRUE(bitmap_is_unset(fb, pool_size - 1));
/*
@@ -155,6 +155,21 @@ TEST_F(PoolTest, PoolPut)
pool_free(pool);
}
+// TODO: this test fails, there is a problem when N = n*64
+// (i.e. when a bitmap reallocation occurs)
+TEST_F(PoolTest, PoolGetForceBitmapRealloc)
+{
+ const int N = 64;
+ int *elts[N];
+ int *elt = NULL;
+ pool_init(pool, N, 0);
+
+ for (int i = 0; i < N; i++)
+ pool_get(pool, elts[i]);
+ pool_get(pool, elt);
+
+ pool_free(pool);
+}
int main(int argc, char **argv)
{
diff --git a/hicn-light/src/hicn/base/test/test-vector.cc b/hicn-light/src/hicn/base/test/test-vector.cc
index 59571b053..aaec7a92c 100644
--- a/hicn-light/src/hicn/base/test/test-vector.cc
+++ b/hicn-light/src/hicn/base/test/test-vector.cc
@@ -49,15 +49,15 @@ TEST_F(VectorTest, VectorAllocate)
vector_init(vector, DEFAULT_SIZE, 0);
/* Allocated size should be the next power of two */
- EXPECT_EQ(vector_get_alloc_size(vector), 16);
+ EXPECT_EQ(vector_get_alloc_size(vector), 16UL);
/* Setting elements within the allocated size should not trigger a resize */
vector_ensure_pos(vector, 15);
- EXPECT_EQ(vector_get_alloc_size(vector), 16);
+ EXPECT_EQ(vector_get_alloc_size(vector), 16UL);
/* Setting elements after should through */
vector_ensure_pos(vector, 16);
- EXPECT_EQ(vector_get_alloc_size(vector), 32);
+ EXPECT_EQ(vector_get_alloc_size(vector), 32UL);
/* Check that free indices and bitmaps are correctly updated */
diff --git a/hicn-light/src/hicn/base/vector.h b/hicn-light/src/hicn/base/vector.h
index ff12e6ee6..b369086fc 100644
--- a/hicn-light/src/hicn/base/vector.h
+++ b/hicn-light/src/hicn/base/vector.h
@@ -129,7 +129,7 @@ int
_vector_ensure_pos(void ** vector_ptr, size_t elt_size, off_t pos)
{
vector_hdr_t * vh = vector_hdr(*vector_ptr);
- if (pos >= vh->alloc_size)
+ if (pos >= (off_t) vh->alloc_size)
return _vector_resize(vector_ptr, elt_size, pos + 1);
return 0;
}