namespace kernel {
namespace actor {
+void SimcallObserver::serialize(std::stringstream& stream) const
+{
+ stream << (short)mc::Transition::Type::UNKNOWN;
+}
bool SimcallObserver::depends(SimcallObserver* other)
{
THROW_UNIMPLEMENTED;
{
return get_issuer() == other->get_issuer();
}
-void RandomSimcall::serialize(mc::Transition::Type& type, std::stringstream& stream)
+void RandomSimcall::serialize(std::stringstream& stream) const
{
- type = mc::Transition::Type::RANDOM;
+ stream << (short)mc::Transition::Type::RANDOM << ' ';
stream << min_ << ' ' << max_;
}
return res;
}*/
-void ActivityWaitSimcall::serialize(mc::Transition::Type& type, std::stringstream& stream)
+void ActivityWaitSimcall::serialize(std::stringstream& stream) const
{
if (auto* comm = dynamic_cast<activity::CommImpl*>(activity_)) {
- type = mc::Transition::Type::COMM_WAIT;
+ stream << (short)mc::Transition::Type::COMM_WAIT << ' ';
stream << (timeout_ > 0) << ' ' << comm;
stream << ' ' << (comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1);
stream << ' ' << (comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1);
stream << ' ' << comm->get_mailbox_id();
stream << ' ' << (void*)comm->src_buff_ << ' ' << (void*)comm->dst_buff_ << ' ' << comm->src_buff_size_;
} else {
- type = mc::Transition::Type::UNKNOWN;
+ stream << (short)mc::Transition::Type::UNKNOWN;
}
}
-void ActivityTestSimcall::serialize(mc::Transition::Type& type, std::stringstream& stream)
+void ActivityTestSimcall::serialize(std::stringstream& stream) const
{
if (auto* comm = dynamic_cast<activity::CommImpl*>(activity_)) {
- type = mc::Transition::Type::COMM_TEST;
+ stream << (short)mc::Transition::Type::COMM_TEST << ' ';
stream << ' ' << (comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1);
stream << ' ' << (comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1);
stream << ' ' << comm->get_mailbox_id();
stream << ' ' << (void*)comm->src_buff_ << ' ' << (void*)comm->dst_buff_ << ' ' << comm->src_buff_size_;
} else {
- type = mc::Transition::Type::UNKNOWN;
+ stream << (short)mc::Transition::Type::UNKNOWN;
}
}
next_value_ = times_considered;
}
-void CommIsendSimcall::serialize(mc::Transition::Type& type, std::stringstream& stream)
+void CommIsendSimcall::serialize(std::stringstream& stream) const
{
- type = mc::Transition::Type::COMM_SEND;
+ stream << (short)mc::Transition::Type::COMM_SEND << ' ';
stream << mbox_->get_id() << ' ' << (void*)src_buff_ << ' ' << src_buff_size_;
XBT_DEBUG("SendObserver mbox:%u buff:%p size:%zu", mbox_->get_id(), src_buff_, src_buff_size_);
}
-void CommIrecvSimcall::serialize(mc::Transition::Type& type, std::stringstream& stream)
+void CommIrecvSimcall::serialize(std::stringstream& stream) const
{
- type = mc::Transition::Type::COMM_RECV;
- stream << mbox_->get_id() << dst_buff_;
+ stream << (short)mc::Transition::Type::COMM_RECV << ' ';
+ stream << mbox_->get_id() << ' ' << dst_buff_;
}
} // namespace actor
virtual bool depends(SimcallObserver* other);
/** Serialize to the given string buffer */
- virtual void serialize(mc::Transition::Type& type, std::stringstream& stream)
- {
- type = mc::Transition::Type::UNKNOWN;
- }
+ virtual void serialize(std::stringstream& stream) const;
/** Some simcalls may only be observable under some conditions.
* Most simcalls are not visible from the MC because they don't have an observer at all. */
{
xbt_assert(min < max);
}
- void serialize(mc::Transition::Type& type, std::stringstream& stream) override;
+ void serialize(std::stringstream& stream) const override;
int get_max_consider() const override;
void prepare(int times_considered) override;
int get_value() const { return next_value_; }
}
bool is_visible() const override { return true; }
activity::ActivityImpl* get_activity() const { return activity_; }
- void serialize(mc::Transition::Type& type, std::stringstream& stream) override;
+ void serialize(std::stringstream& stream) const override;
};
class ActivityTestanySimcall : public ResultingSimcall<ssize_t> {
: ResultingSimcall(actor, false), activity_(activity), timeout_(timeout)
{
}
- void serialize(mc::Transition::Type& type, std::stringstream& stream) override;
+ void serialize(std::stringstream& stream) const override;
bool is_visible() const override { return true; }
bool is_enabled() const override;
activity::ActivityImpl* get_activity() const { return activity_; }
, copy_data_fun_(copy_data_fun)
{
}
- void serialize(mc::Transition::Type& type, std::stringstream& stream) override;
+ void serialize(std::stringstream& stream) const override;
bool is_visible() const override { return true; }
activity::MailboxImpl* get_mailbox() const { return mbox_; }
double get_payload_size() const { return payload_size_; }
, copy_data_fun_(copy_data_fun)
{
}
- void serialize(mc::Transition::Type& type, std::stringstream& stream) override;
+ void serialize(std::stringstream& stream) const override;
bool is_visible() const override { return true; }
activity::MailboxImpl* get_mailbox() const { return mbox_; }
double get_rate() const { return rate_; }
checker_side_.dispatch(); // The app may send messages while processing the transition
if (new_transition)
- return recv_transition(aid, times_considered, answer.simcall, answer.buffer);
+ return recv_transition(aid, times_considered, answer.buffer);
else
return nullptr;
}
return xbt::string_printf("Random([%d;%d] ~> %d)", min_, max_, times_considered_);
}
-RandomTransition::RandomTransition(aid_t issuer, int times_considered, char* buffer)
+RandomTransition::RandomTransition(aid_t issuer, int times_considered, std::stringstream& stream)
: Transition(Type::RANDOM, issuer, times_considered)
{
- std::stringstream stream(buffer);
stream >> min_ >> max_;
}
std::string RandomTransition::dot_label() const
#include "simgrid/forward.h" // aid_t
#include "xbt/utility.hpp" // XBT_DECLARE_ENUM_CLASS
+#include <sstream>
#include <string>
namespace simgrid {
public:
std::string to_string(bool verbose) const override;
std::string dot_label() const override;
- RandomTransition(aid_t issuer, int times_considered, char* buffer);
+ RandomTransition(aid_t issuer, int times_considered, std::stringstream& stream);
bool depends(const Transition* other) const override { return false; } // Independent with any other transition
};
namespace simgrid {
namespace mc {
-CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, char* buffer)
+CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream)
: Transition(Type::COMM_WAIT, issuer, times_considered)
{
- std::stringstream stream(buffer);
stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_;
XBT_DEBUG("CommWaitTransition %s comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu",
(timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, src_buff_, dst_buff_, size_);
return true;
}
-CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, char* buffer)
+CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
: Transition(Type::COMM_TEST, issuer, times_considered)
{
- std::stringstream stream(buffer);
stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_;
XBT_DEBUG("CommTestTransition comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu", comm_, sender_,
receiver_, mbox_, src_buff_, dst_buff_, size_);
return true;
}
-CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, char* buffer)
+CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
: Transition(Type::COMM_RECV, issuer, times_considered)
{
- std::stringstream stream(buffer);
stream >> mbox_ >> dst_buff_;
}
std::string CommRecvTransition::to_string(bool verbose) const
return true;
}
-CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, char* buffer)
+CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
: Transition(Type::COMM_SEND, issuer, times_considered)
{
- std::stringstream stream(buffer);
stream >> mbox_ >> src_buff_ >> size_;
XBT_DEBUG("SendTransition mbox:%u buff:%p size:%zu", mbox_, src_buff_, size_);
}
return true;
}
-Transition* recv_transition(aid_t issuer, int times_considered, Transition::Type simcall, char* buffer)
+Transition* recv_transition(aid_t issuer, int times_considered, char* buffer)
{
+ std::stringstream stream(buffer);
+ short type;
+ stream >> type;
+ Transition::Type simcall = static_cast<Transition::Type>(type);
+
switch (simcall) {
case Transition::Type::COMM_RECV:
- return new CommRecvTransition(issuer, times_considered, buffer);
+ return new CommRecvTransition(issuer, times_considered, stream);
case Transition::Type::COMM_SEND:
- return new CommSendTransition(issuer, times_considered, buffer);
+ return new CommSendTransition(issuer, times_considered, stream);
case Transition::Type::COMM_TEST:
- return new CommTestTransition(issuer, times_considered, buffer);
+ return new CommTestTransition(issuer, times_considered, stream);
case Transition::Type::COMM_WAIT:
- return new CommWaitTransition(issuer, times_considered, buffer);
+ return new CommWaitTransition(issuer, times_considered, stream);
case Transition::Type::RANDOM:
- return new RandomTransition(issuer, times_considered, buffer);
+ return new RandomTransition(issuer, times_considered, stream);
case Transition::Type::UNKNOWN:
return new Transition(Transition::Type::UNKNOWN, issuer, times_considered);
#include "src/kernel/actor/SimcallObserver.hpp"
#include "src/mc/api/Transition.hpp"
+#include <sstream>
#include <string>
namespace simgrid {
friend CommTestTransition;
public:
- CommWaitTransition(aid_t issuer, int times_considered, char* buffer);
+ CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream);
std::string to_string(bool verbose) const override;
bool depends(const Transition* other) const override;
};
friend CommRecvTransition;
public:
- CommTestTransition(aid_t issuer, int times_considered, char* buffer);
+ CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream);
std::string to_string(bool verbose) const override;
bool depends(const Transition* other) const override;
};
void* dst_buff_;
public:
- CommRecvTransition(aid_t issuer, int times_considered, char* buffer);
+ CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream);
std::string to_string(bool verbose) const override;
bool depends(const Transition* other) const override;
};
size_t size_;
public:
- CommSendTransition(aid_t issuer, int times_considered, char* buffer);
+ CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream);
std::string to_string(bool verbose) const override;
bool depends(const Transition* other) const override;
};
/** Make a new transition from serialized description */
-Transition* recv_transition(aid_t issuer, int times_considered, Transition::Type simcall, char* buffer);
+Transition* recv_transition(aid_t issuer, int times_considered, char* buffer);
} // namespace mc
} // namespace simgrid
s_mc_message_simcall_execute_answer_t answer;
memset(&answer, 0, sizeof(answer));
answer.type = MessageType::SIMCALL_EXECUTE_ANSWER;
+ std::stringstream stream;
if (actor->simcall_.observer_ != nullptr) {
- std::stringstream stream;
- actor->simcall_.observer_->serialize(answer.simcall, stream);
- xbt_assert(stream.str().size() < sizeof(answer.buffer) - 1,
- "The serialized simcall is too large for the buffer. Please fix the code.");
- strncpy(answer.buffer, stream.str().c_str(), sizeof(answer.buffer) - 1);
+ actor->simcall_.observer_->serialize(stream);
} else {
- answer.simcall = mc::Transition::Type::UNKNOWN;
+ stream << (short)mc::Transition::Type::UNKNOWN;
}
+ xbt_assert(stream.str().size() < sizeof(answer.buffer) - 1,
+ "The serialized simcall is too large for the buffer. Please fix the code.");
+ strncpy(answer.buffer, stream.str().c_str(), sizeof(answer.buffer) - 1);
- XBT_DEBUG("send SIMCALL_EXECUTE_ANSWER(%s) ~> %s '%s'", actor->get_cname(), mc::Transition::to_c_str(answer.simcall),
- answer.buffer);
+ XBT_DEBUG("send SIMCALL_EXECUTE_ANSWER(%s) ~> '%s'", actor->get_cname(), answer.buffer);
xbt_assert(channel_.send(answer) == 0, "Could not send response");
// The client may send some messages to the server while processing the transition
};
struct s_mc_message_simcall_execute_answer_t {
simgrid::mc::MessageType type;
- simgrid::mc::Transition::Type simcall;
char buffer[SIMCALL_SERIALIZATION_BUFFER_SIZE];
};