aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2016-11-01 15:16:30 +0100
committerDave Barach <openvpp@barachs.net>2016-11-01 16:19:13 +0000
commit3b906b0d9b93a892831ce4d54d1d7ec3956ce2b4 (patch)
treef1314662dced3e94524e3d5aa203fe8b02cbe84a
parenta0bc391daf1ded0c0d512cade822675d2bd32a36 (diff)
vppinfra: add STATIC_ASSERT macro
Change-Id: Icc4e74ae1627c5b97746ed64955a3dc089e3998f Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r--vlib/vlib/node.c3
-rw-r--r--vnet/vnet/devices/dpdk/init.c13
-rw-r--r--vnet/vnet/ip/lookup.c6
-rw-r--r--vppinfra/vppinfra/error_bootstrap.h2
4 files changed, 17 insertions, 7 deletions
diff --git a/vlib/vlib/node.c b/vlib/vlib/node.c
index fccc37ab7b9..23f7ea0239e 100644
--- a/vlib/vlib/node.c
+++ b/vlib/vlib/node.c
@@ -433,7 +433,8 @@ register_node (vlib_main_t * vm, vlib_node_registration_t * r)
for (i = 0; i < vec_len (rt->errors); i++)
rt->errors[i] = vlib_error_set (n->index, i);
- ASSERT (sizeof (vlib_node_runtime_t) == 2 * CLIB_CACHE_LINE_BYTES);
+ STATIC_ASSERT (sizeof (vlib_node_runtime_t) == 2 * CLIB_CACHE_LINE_BYTES,
+ "Size of vlib_node_runtime_t must be equal to 2 cachelines");
ASSERT (vec_len (n->runtime_data) <= sizeof (vlib_node_runtime_t) -
STRUCT_OFFSET_OF (vlib_node_runtime_t, runtime_data));
diff --git a/vnet/vnet/devices/dpdk/init.c b/vnet/vnet/devices/dpdk/init.c
index c57fcde3543..01bd27db35d 100644
--- a/vnet/vnet/devices/dpdk/init.c
+++ b/vnet/vnet/devices/dpdk/init.c
@@ -1707,10 +1707,15 @@ dpdk_init (vlib_main_t * vm)
vlib_thread_main_t *tm = vlib_get_thread_main ();
/* verify that structs are cacheline aligned */
- ASSERT (offsetof (dpdk_device_t, cacheline0) == 0);
- ASSERT (offsetof (dpdk_device_t, cacheline1) == CLIB_CACHE_LINE_BYTES);
- ASSERT (offsetof (dpdk_worker_t, cacheline0) == 0);
- ASSERT (offsetof (frame_queue_trace_t, cacheline0) == 0);
+ STATIC_ASSERT (offsetof (dpdk_device_t, cacheline0) == 0,
+ "Cache line marker must be 1st element in dpdk_device_t");
+ STATIC_ASSERT (offsetof (dpdk_device_t, cacheline1) ==
+ CLIB_CACHE_LINE_BYTES,
+ "Data in cache line 0 is bigger than cache line size");
+ STATIC_ASSERT (offsetof (dpdk_worker_t, cacheline0) == 0,
+ "Cache line marker must be 1st element in dpdk_worker_t");
+ STATIC_ASSERT (offsetof (frame_queue_trace_t, cacheline0) == 0,
+ "Cache line marker must be 1st element in frame_queue_trace_t");
dm->vlib_main = vm;
dm->vnet_main = vnet_get_main ();
diff --git a/vnet/vnet/ip/lookup.c b/vnet/vnet/ip/lookup.c
index 4ddbb54279e..511a5cc83ec 100644
--- a/vnet/vnet/ip/lookup.c
+++ b/vnet/vnet/ip/lookup.c
@@ -165,8 +165,10 @@ ip_interface_address_add_del (ip_lookup_main_t * lm,
void ip_lookup_init (ip_lookup_main_t * lm, u32 is_ip6)
{
/* ensure that adjacency is cacheline aligned and sized */
- ASSERT(STRUCT_OFFSET_OF(ip_adjacency_t, cacheline0) == 0);
- ASSERT(STRUCT_OFFSET_OF(ip_adjacency_t, cacheline1) == CLIB_CACHE_LINE_BYTES);
+ STATIC_ASSERT(STRUCT_OFFSET_OF(ip_adjacency_t, cacheline0) == 0,
+ "Cache line marker must be 1st element in struct");
+ STATIC_ASSERT(STRUCT_OFFSET_OF(ip_adjacency_t, cacheline1) == CLIB_CACHE_LINE_BYTES,
+ "Data in cache line 0 is bigger than cache line size");
/* Preallocate three "special" adjacencies */
lm->adjacency_heap = adj_pool;
diff --git a/vppinfra/vppinfra/error_bootstrap.h b/vppinfra/vppinfra/error_bootstrap.h
index 3fa0a18ec9f..ad600621eae 100644
--- a/vppinfra/vppinfra/error_bootstrap.h
+++ b/vppinfra/vppinfra/error_bootstrap.h
@@ -79,6 +79,8 @@ do { \
} \
} while (0)
+#define STATIC_ASSERT(truth,...) _Static_assert(truth, __VA_ARGS__)
+
/* Assert without allocating memory. */
#define ASSERT_AND_PANIC(truth) \
do { \