diff options
author | imarom <imarom@cisco.com> | 2016-01-04 06:57:45 -0500 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-01-04 10:02:59 -0500 |
commit | e134270a3bcf3c9498a2926ffea1d7bb0d4960eb (patch) | |
tree | 5cbff2f3ae4c6b9a28de58c0c7d9b592ebfd9676 /src/sim | |
parent | 82e65a02d2f9bdab552521a4859795937821f1be (diff) |
a script to inject simulation stateless files
Diffstat (limited to 'src/sim')
-rw-r--r-- | src/sim/trex_sim.h | 3 | ||||
-rw-r--r-- | src/sim/trex_sim_stateless.cpp | 45 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/sim/trex_sim.h b/src/sim/trex_sim.h index d997e2f5..02f62d79 100644 --- a/src/sim/trex_sim.h +++ b/src/sim/trex_sim.h @@ -24,6 +24,7 @@ limitations under the License. #include <string> #include <os_time.h> #include <bp_sim.h> +#include <json/json.h> int gtest_main(int argc, char **argv); @@ -117,6 +118,8 @@ private: void run_dp(const std::string &out_filename); void flush_dp_to_cp_messages(); + void validate_response(const Json::Value &resp); + bool is_verbose() { return m_verbose; } diff --git a/src/sim/trex_sim_stateless.cpp b/src/sim/trex_sim_stateless.cpp index dd81a591..9803ccbc 100644 --- a/src/sim/trex_sim_stateless.cpp +++ b/src/sim/trex_sim_stateless.cpp @@ -24,6 +24,8 @@ limitations under the License. #include <trex_stateless_messaging.h> #include <trex_rpc_cmd_api.h> #include <json/json.h> +#include <stdexcept> +#include <sstream> using namespace std; @@ -32,6 +34,17 @@ TrexStateless * get_stateless_obj() { } +class SimRunException : public std::runtime_error +{ +public: + SimRunException() : std::runtime_error("") { + + } + SimRunException(const std::string &what) : std::runtime_error(what) { + } +}; + + /** * handler for DP to CP messages * @@ -88,7 +101,13 @@ SimStateless::run(const string &json_filename, const string &out_filename) { prepare_dataplane(); prepare_control_plane(); - execute_json(json_filename); + try { + execute_json(json_filename); + } catch (const SimRunException &e) { + std::cout << "*** test failed ***\n\n" << e.what() << "\n"; + exit(-1); + } + run_dp(out_filename); flush_dp_to_cp_messages(); @@ -172,9 +191,33 @@ SimStateless::execute_json(const std::string &json_filename) { if (is_verbose()) { std::cout << "server response: \n\n" << root << "\n\n"; } + + validate_response(root); + } void +SimStateless::validate_response(const Json::Value &resp) { + std::stringstream ss; + + if (resp.isArray()) { + for (const auto &single : resp) { + if (single["error"] != Json::nullValue) { + ss << "failed with:\n\n" << single["error"] << "\n\n"; + throw SimRunException(ss.str()); + } + } + } else { + if (resp["error"] != Json::nullValue) { + ss << "failed with:\n\n" << resp["error"] << "\n\n"; + throw SimRunException(ss.str()); + } + } + +} + + +void SimStateless::run_dp(const std::string &out_filename) { CFlowGenListPerThread *lpt = m_fl.m_threads_info[0]; |