summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/bp_sim.cpp11
-rw-r--r--src/common/utl_gcc_diag.h39
-rw-r--r--src/gtest/bp_timer_gtest.cpp18
3 files changed, 50 insertions, 18 deletions
diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp
index 72eb91ba..68cc325d 100755
--- a/src/bp_sim.cpp
+++ b/src/bp_sim.cpp
@@ -26,6 +26,7 @@ limitations under the License.
#include "msg_manager.h"
#include "trex_watchdog.h"
#include "utl_ipg_bucket.h"
+#include <common/utl_gcc_diag.h>
#include <common/basic_utils.h>
@@ -3791,16 +3792,6 @@ inline void CFlowGenListPerThread::on_flow_tick(CGenNode *node){
}
}
-#define GCC_DIAG_STR(s) #s
-#define GCC_DIAG_JOINSTR(x,y) GCC_DIAG_STR(x ## y)
-# define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
-# define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
-#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
- GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
-#define GCC_DIAG_ON() GCC_DIAG_PRAGMA(pop)
-
-#define UNSAFE_CONTAINER_OF_PUSH GCC_DIAG_OFF(invalid-offsetof)
-#define UNSAFE_CONTAINER_OF_POP GCC_DIAG_ON()
static void tw_free_node(void *userdata,
diff --git a/src/common/utl_gcc_diag.h b/src/common/utl_gcc_diag.h
new file mode 100644
index 00000000..1bda919d
--- /dev/null
+++ b/src/common/utl_gcc_diag.h
@@ -0,0 +1,39 @@
+#ifndef UTL_GCC_DIAG_H
+#define UTL_GCC_DIAG_H
+
+/*
+ Hanoh Haim
+ Cisco Systems, Inc.
+*/
+
+/*
+Copyright (c) 2015-2015 Cisco Systems, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+
+#define GCC_DIAG_STR(s) #s
+#define GCC_DIAG_JOINSTR(x,y) GCC_DIAG_STR(x ## y)
+# define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
+# define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
+#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
+ GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
+#define GCC_DIAG_ON() GCC_DIAG_PRAGMA(pop)
+
+#define UNSAFE_CONTAINER_OF_PUSH GCC_DIAG_OFF(invalid-offsetof)
+#define UNSAFE_CONTAINER_OF_POP GCC_DIAG_ON()
+
+
+
+#endif
diff --git a/src/gtest/bp_timer_gtest.cpp b/src/gtest/bp_timer_gtest.cpp
index 5185da87..07f0e214 100644
--- a/src/gtest/bp_timer_gtest.cpp
+++ b/src/gtest/bp_timer_gtest.cpp
@@ -22,6 +22,8 @@ limitations under the License.
#include <common/gtest.h>
#include <common/basic_utils.h>
#include "h_timer.h"
+#include <common/utl_gcc_diag.h>
+
class gt_r_timer : public testing::Test {
@@ -150,9 +152,9 @@ void my_test_on_tick_cb(void *userdata,CHTimerObj *tmr){
CHTimerWheel * lp=(CHTimerWheel *)userdata;
- #pragma GCC diagnostic ignored "-Winvalid-offsetof"
+ UNSAFE_CONTAINER_OF_PUSH
CMyTestObject *lpobj=(CMyTestObject *)((uint8_t*)tmr-offsetof (CMyTestObject,m_timer));
- #pragma GCC diagnostic pop
+ UNSAFE_CONTAINER_OF_POP
printf(" [event %d ]",lpobj->m_id);
lp->timer_start(tmr,2);
}
@@ -182,9 +184,9 @@ void my_test_on_tick_cb7(void *userdata,CHTimerObj *tmr){
CHTimerWheel * lp=(CHTimerWheel *)userdata;
- #pragma GCC diagnostic ignored "-Winvalid-offsetof"
+ UNSAFE_CONTAINER_OF_PUSH
CMyTestObject *lpobj=(CMyTestObject *)((uint8_t*)tmr-offsetof (CMyTestObject,m_timer));
- #pragma GCC diagnostic pop
+ UNSAFE_CONTAINER_OF_POP
printf(" [event %d ]",lpobj->m_id);
lp->timer_start(tmr,9);
}
@@ -193,9 +195,9 @@ void my_test_on_tick_cb_free(void *userdata,CHTimerObj *tmr){
//CHTimerWheel * lp=(CHTimerWheel *)userdata;
- #pragma GCC diagnostic ignored "-Winvalid-offsetof"
+ UNSAFE_CONTAINER_OF_PUSH
CMyTestObject *lpobj=(CMyTestObject *)((uint8_t*)tmr-offsetof (CMyTestObject,m_timer));
- #pragma GCC diagnostic pop
+ UNSAFE_CONTAINER_OF_POP
printf(" [event %d ]",lpobj->m_id);
delete lpobj;
}
@@ -262,9 +264,9 @@ private:
void my_test_on_tick_cb8(void *userdata,CHTimerObj *tmr){
CHTimerWheelBase * lp=(CHTimerWheelBase *)userdata;
- #pragma GCC diagnostic ignored "-Winvalid-offsetof"
+ UNSAFE_CONTAINER_OF_PUSH
CMyTestObject *lpobj=(CMyTestObject *)((uint8_t*)tmr-offsetof (CMyTestObject,m_timer));
- #pragma GCC diagnostic pop
+ UNSAFE_CONTAINER_OF_POP
lp->on_tick(lpobj);
}