diff options
Diffstat (limited to 'hicn-light/src')
-rw-r--r-- | hicn-light/src/hicn/base/bitmap.h | 9 | ||||
-rw-r--r-- | hicn-light/src/hicn/base/pool.c | 2 | ||||
-rw-r--r-- | hicn-light/src/hicn/test/test-bitmap.cc | 11 | ||||
-rw-r--r-- | hicn-light/src/hicn/test/test-ctrl.cc | 32 |
4 files changed, 50 insertions, 4 deletions
diff --git a/hicn-light/src/hicn/base/bitmap.h b/hicn-light/src/hicn/base/bitmap.h index ed3fac2fd..060fd5be0 100644 --- a/hicn-light/src/hicn/base/bitmap.h +++ b/hicn-light/src/hicn/base/bitmap.h @@ -114,12 +114,15 @@ static inline int bitmap_get(const bitmap_t* bitmap, off_t i) { * * @return bool */ -static inline int _bitmap_set(bitmap_t** bitmap, off_t i) { - if (bitmap_ensure_pos(bitmap, i) < 0) return -1; +static inline int _bitmap_set(bitmap_t** bitmap_ptr, off_t i) { + if (bitmap_ensure_pos(bitmap_ptr, i) < 0) return -1; + + bitmap_t* bitmap = *bitmap_ptr; size_t offset = i / BITMAP_WIDTH(bitmap); size_t pos = i % BITMAP_WIDTH(bitmap); size_t shift = BITMAP_WIDTH(bitmap) - pos - 1; - (*bitmap)[offset] |= (bitmap_t)1 << shift; + + bitmap[offset] |= (bitmap_t)1 << shift; return 0; } diff --git a/hicn-light/src/hicn/base/pool.c b/hicn-light/src/hicn/base/pool.c index ba2a14c5f..e5fb7d6ac 100644 --- a/hicn-light/src/hicn/base/pool.c +++ b/hicn-light/src/hicn/base/pool.c @@ -60,7 +60,7 @@ void _pool_init(void** pool_ptr, size_t elt_size, size_t init_size, ph->free_indices = free_indices; /* Free bitmap */ - uint_fast32_t* fb = ph->free_bitmap; + bitmap_t* fb = ph->free_bitmap; bitmap_init(fb, init_size, max_size); bitmap_set_to(fb, init_size); ph->free_bitmap = fb; diff --git a/hicn-light/src/hicn/test/test-bitmap.cc b/hicn-light/src/hicn/test/test-bitmap.cc index f1bf1ae5a..f9cd4024f 100644 --- a/hicn-light/src/hicn/test/test-bitmap.cc +++ b/hicn-light/src/hicn/test/test-bitmap.cc @@ -103,6 +103,17 @@ TEST_F(BitmapTest, BitmapSet) { EXPECT_FALSE(bitmap_is_set(bitmap, 19)); EXPECT_TRUE(bitmap_is_unset(bitmap, 19)); + // Test edge cases (i.e. start and end of block) + off_t start_position = 0; + bitmap_set(bitmap, start_position); + EXPECT_TRUE(bitmap_is_set(bitmap, start_position)); + EXPECT_FALSE(bitmap_is_unset(bitmap, start_position)); + + off_t end_position = BITMAP_WIDTH(bitmap) - 1; + bitmap_set(bitmap, end_position); + EXPECT_TRUE(bitmap_is_set(bitmap, end_position)); + EXPECT_FALSE(bitmap_is_unset(bitmap, end_position)); + bitmap_free(bitmap); } diff --git a/hicn-light/src/hicn/test/test-ctrl.cc b/hicn-light/src/hicn/test/test-ctrl.cc index 77b16a8af..e24b47f27 100644 --- a/hicn-light/src/hicn/test/test-ctrl.cc +++ b/hicn-light/src/hicn/test/test-ctrl.cc @@ -161,4 +161,36 @@ TEST_F(CtrlTest, AddRouteInvalidCost) { result = hc_route_create_conf(s_, &command_.object.route); success = hc_result_get_success(s_, result); EXPECT_FALSE(success); +} + +TEST_F(CtrlTest, RouteNameOrID) { + hc_route_t route = { + .face_id = (face_id_t)INVALID_FACE_ID, + .family = AF_INET6, + .remote_addr = IPV6_LOOPBACK, + .len = 64, + .cost = 1, + }; + + // At least one between name (symbolic or ID) and face_id + // should be set to make the route valid + + // Valid name (symbolic) + snprintf(route.name, SYMBOLIC_NAME_LEN, "%s", "test"); + EXPECT_EQ(hc_route_validate(&route), 0); + + // Valid name (ID) + snprintf(route.name, SYMBOLIC_NAME_LEN, "%s", "conn0"); + EXPECT_EQ(hc_route_validate(&route), 0); + + // Valid face_id + route.face_id = 1; + snprintf(route.name, SYMBOLIC_NAME_LEN, "%s", ""); + EXPECT_EQ(hc_route_validate(&route), 0); + + // Invalid name stating with number + // (face_id is only checked if empty name) + route.face_id = 1; + snprintf(route.name, SYMBOLIC_NAME_LEN, "%s", "1test"); + EXPECT_EQ(hc_route_validate(&route), -1); }
\ No newline at end of file |