From e4ebfcbdb11eb5f0237ac456237c9aa63c0f8749 Mon Sep 17 00:00:00 2001 From: jyelon Date: Fri, 11 Mar 2022 19:11:09 -0500 Subject: [PATCH] Added vreplay with stdout --- luprex/core/cpp/driver-common.cpp | 41 +++++++++++++++++++------------ luprex/core/cpp/driver-util.cpp | 5 ++++ luprex/core/cpp/driver-util.hpp | 10 ++++++++ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/luprex/core/cpp/driver-common.cpp b/luprex/core/cpp/driver-common.cpp index 02a4505b..49629a33 100644 --- a/luprex/core/cpp/driver-common.cpp +++ b/luprex/core/cpp/driver-common.cpp @@ -470,9 +470,12 @@ public: cleanup_channels(); } - int replay_logfile(const char *fn) { + int replay_logfile(const char *fn, bool verbose) { drv::ReplayPlayer player; player.open_logfile(fn); + if (verbose) { + player.enable_stdout(); + } while (true) { drv::ReplayPlayer::Status st = player.step(); if (st != drv::ReplayPlayer::ST_REPLAYING) { @@ -493,27 +496,33 @@ public: // If argv contains "replay ", do a replay, // and then skip everything else. - if ((argc >= 1) && (strcmp(argv[0], "replay") == 0)) { - if (argc != 2) { - std::cerr << "usage: " << program << " replay " << std::endl; - exit(1); + if (argc >= 1) { + std::string cmd(argv[0]); + if ((cmd == "replay") || (cmd == "vreplay")) { + if (argc != 2) { + std::cerr << "usage: " << program << " replay " << std::endl; + return 1; + } + return replay_logfile(argv[1], cmd == "vreplay"); } - return replay_logfile(argv[1]); } // If argv contains "record ", start recording, // and remove the "record " from argv. - if ((argc >= 1) && (strcmp(argv[0], "record") == 0)) { - if (argc < 2) { - DrivenEngine::print_usage(std::cerr, program); - return 1; + if (argc >= 1) { + std::string cmd = argv[0]; + if (cmd == "record") { + if (argc < 2) { + DrivenEngine::print_usage(std::cerr, program); + return 1; + } + bool ok = recorder_.open_logfile(argv[1]); + if (!ok) { + std::cerr << "Could not open logfile: " << argv[1] << std::endl; + return 1; + } + argc -= 2; argv += 2; } - bool ok = recorder_.open_logfile(argv[1]); - if (!ok) { - std::cerr << "Could not open logfile: " << argv[1] << std::endl; - return 1; - } - argc -= 2; argv += 2; } // Create the engine. diff --git a/luprex/core/cpp/driver-util.cpp b/luprex/core/cpp/driver-util.cpp index 096f6bfc..bfcaf30d 100644 --- a/luprex/core/cpp/driver-util.cpp +++ b/luprex/core/cpp/driver-util.cpp @@ -160,6 +160,7 @@ std::string_view rlog_string(std::ifstream &s, char *rlog_buf) { ReplayPlayer::ReplayPlayer() { status_ = ST_REPLAYING; + enable_stdout_ = false; buf_.reset(new char[RLOG_BUFSIZE]); } @@ -344,6 +345,10 @@ void ReplayPlayer::drv_sent_outgoing() { set_status(ST_NONDERMINISTIC); return; } + if ((chid == 0) && (enable_stdout_)) { + std::string_view sub = data.substr(0, nbytes); + std::cout << sub; + } e_->drv_sent_outgoing(chid, nbytes); } diff --git a/luprex/core/cpp/driver-util.hpp b/luprex/core/cpp/driver-util.hpp index 2d3f0af2..a70814ef 100644 --- a/luprex/core/cpp/driver-util.hpp +++ b/luprex/core/cpp/driver-util.hpp @@ -96,6 +96,7 @@ private: Status status_; std::string logfn_; std::string engine_; + bool enable_stdout_; void set_status(Status e); @@ -119,6 +120,15 @@ public: // bool open_logfile(const char *fn); + // Enable stdout. + // + // Normally, stdout is suppressed during replay. + // If you enable stdout, then the engine will print + // all the same messages it did when running in the + // first place. + // + void enable_stdout() { enable_stdout_ = true; } + // Execute a single step from the replay log. // // Returns a status code, which is usually ST_REPLAYING.