From 81059eb5df274efe48ad3914039ddb657c3285ab Mon Sep 17 00:00:00 2001 From: imarom Date: Tue, 23 Feb 2016 08:04:11 -0500 Subject: global srand messed up stuff moved to local rand_r --- src/sim/trex_sim.h | 5 +++-- src/stateless/cp/trex_stateless_port.cpp | 4 ++-- src/stateless/cp/trex_stateless_port.h | 8 +++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/sim/trex_sim.h b/src/sim/trex_sim.h index 99bfb28e..21498978 100644 --- a/src/sim/trex_sim.h +++ b/src/sim/trex_sim.h @@ -111,14 +111,15 @@ public: int run(int argc, char **argv) { TrexStatelessCfg cfg; - cfg.m_port_count = 1; + cfg.m_port_count = 2; cfg.m_rpc_req_resp_cfg = NULL; cfg.m_rpc_async_cfg = NULL; cfg.m_rpc_server_verbose = false; - cfg.m_platform_api = new SimPlatformApi(1);; + cfg.m_platform_api = new SimPlatformApi(1); cfg.m_publisher = NULL; set_stateless_obj(new TrexStateless(cfg)); + assert( CMsgIns::Ins()->Create(4) ); int rc = gtest_main(argc, argv); diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 75f77cf7..99b6565c 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -657,7 +657,7 @@ TrexPortOwner::TrexPortOwner() { m_is_free = true; /* for handlers random generation */ - srand(time(NULL)); + m_seed = time(NULL); } /** @@ -675,7 +675,7 @@ TrexPortOwner::generate_handler() { /* generate 8 bytes of random handler */ for (int i = 0; i < 8; ++i) { - ss << alphanum[rand() % (sizeof(alphanum) - 1)]; + ss << alphanum[rand_r(&m_seed) % (sizeof(alphanum) - 1)]; } return (ss.str()); diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index a101cef0..49e69757 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -93,6 +93,8 @@ private: /* handler genereated internally */ std::string m_handler; + /* seed for generating random values */ + unsigned int m_seed; /* just references defaults... */ static const std::string g_unowned_name; @@ -442,9 +444,9 @@ public: static const std::initializer_list g_types; static const std::initializer_list g_ops; - mul_type_e m_type; - mul_op_e m_op; - double m_value; + mul_type_e m_type; + mul_op_e m_op; + double m_value; }; #endif /* __TREX_STATELESS_PORT_H__ */ -- cgit 1.2.3-korg