From: Arnaud Giersch Date: Thu, 2 Jul 2020 15:30:56 +0000 (+0200) Subject: [sonar] Declare functions "const" in src/mc/. X-Git-Tag: v3.26~512 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/6ebe4cd9a47fdc974ebe8ec1310777c433411715 [sonar] Declare functions "const" in src/mc/. --- diff --git a/src/mc/Session.cpp b/src/mc/Session.cpp index 2ace38ce87..71b28fc38f 100644 --- a/src/mc/Session.cpp +++ b/src/mc/Session.cpp @@ -105,18 +105,18 @@ void Session::initialize() initial_snapshot_ = std::make_shared(0); } -void Session::execute(Transition const& transition) +void Session::execute(Transition const& transition) const { model_checker_->handle_simcall(transition); model_checker_->wait_for_requests(); } -void Session::restore_initial_state() +void Session::restore_initial_state() const { this->initial_snapshot_->restore(&model_checker_->get_remote_simulation()); } -void Session::log_state() +void Session::log_state() const { model_checker_->getChecker()->log_state(); @@ -141,7 +141,7 @@ void Session::close() } } -bool Session::actor_is_enabled(aid_t pid) +bool Session::actor_is_enabled(aid_t pid) const { s_mc_message_actor_enabled_t msg{MC_MESSAGE_ACTOR_ENABLED, pid}; model_checker_->channel().send(msg); diff --git a/src/mc/Session.hpp b/src/mc/Session.hpp index 9f07badd7e..7934ec0e58 100644 --- a/src/mc/Session.hpp +++ b/src/mc/Session.hpp @@ -45,11 +45,11 @@ public: void close(); void initialize(); - void execute(Transition const& transition); - void log_state(); + void execute(Transition const& transition) const; + void log_state() const; - void restore_initial_state(); - bool actor_is_enabled(aid_t pid); + void restore_initial_state() const; + bool actor_is_enabled(aid_t pid) const; }; // Temporary :) diff --git a/src/mc/checker/LivenessChecker.cpp b/src/mc/checker/LivenessChecker.cpp index 3598ae060a..e22741d715 100644 --- a/src/mc/checker/LivenessChecker.cpp +++ b/src/mc/checker/LivenessChecker.cpp @@ -70,7 +70,7 @@ static bool evaluate_label(const xbt_automaton_exp_label* l, std::vector co Pair::Pair(unsigned long expanded_pairs) : num(expanded_pairs) {} -std::shared_ptr> LivenessChecker::get_proposition_values() +std::shared_ptr> LivenessChecker::get_proposition_values() const { std::vector values; unsigned int cursor = 0; diff --git a/src/mc/checker/LivenessChecker.hpp b/src/mc/checker/LivenessChecker.hpp index 3ce6200e80..d471da91bb 100644 --- a/src/mc/checker/LivenessChecker.hpp +++ b/src/mc/checker/LivenessChecker.hpp @@ -61,7 +61,7 @@ public: void log_state() override; private: - std::shared_ptr> get_proposition_values(); + std::shared_ptr> get_proposition_values() const; std::shared_ptr insert_acceptance_pair(Pair* pair); int insert_visited_pair(std::shared_ptr visited_pair, Pair* pair); void show_acceptance_cycle(std::size_t depth); diff --git a/src/mc/mc_hash.cpp b/src/mc/mc_hash.cpp index 7ae53cbba3..7b86d7f724 100644 --- a/src/mc/mc_hash.cpp +++ b/src/mc/mc_hash.cpp @@ -30,10 +30,7 @@ public: { state_ = (state_ << 5) + state_ + x; } - hash_type value() - { - return state_; - } + hash_type value() const { return state_; } }; } diff --git a/src/mc/mc_private.hpp b/src/mc/mc_private.hpp index 3feeed90bf..c89997cb0a 100644 --- a/src/mc/mc_private.hpp +++ b/src/mc/mc_private.hpp @@ -16,7 +16,7 @@ namespace simgrid { namespace mc { struct DerefAndCompareByActorsCountAndUsedHeap { - template bool operator()(X const& a, Y const& b) + template bool operator()(X const& a, Y const& b) const { return std::make_pair(a->actors_count, a->heap_bytes_used) < std::make_pair(b->actors_count, b->heap_bytes_used); } diff --git a/src/mc/remote/AppSide.cpp b/src/mc/remote/AppSide.cpp index af8d7c0d29..0c7ff0d0b2 100644 --- a/src/mc/remote/AppSide.cpp +++ b/src/mc/remote/AppSide.cpp @@ -66,7 +66,7 @@ AppSide* AppSide::initialize() return instance_.get(); } -void AppSide::handle_deadlock_check(const s_mc_message_t*) +void AppSide::handle_deadlock_check(const s_mc_message_t*) const { bool deadlock = false; if (not simix_global->process_list.empty()) { @@ -82,11 +82,11 @@ void AppSide::handle_deadlock_check(const s_mc_message_t*) s_mc_message_int_t answer{MC_MESSAGE_DEADLOCK_CHECK_REPLY, deadlock}; xbt_assert(channel_.send(answer) == 0, "Could not send response"); } -void AppSide::handle_continue(const s_mc_message_t*) +void AppSide::handle_continue(const s_mc_message_t*) const { /* Nothing to do */ } -void AppSide::handle_simcall(const s_mc_message_simcall_handle_t* message) +void AppSide::handle_simcall(const s_mc_message_simcall_handle_t* message) const { smx_actor_t process = SIMIX_process_from_PID(message->pid); xbt_assert(process != nullptr, "Invalid pid %lu", message->pid); @@ -95,7 +95,7 @@ void AppSide::handle_simcall(const s_mc_message_simcall_handle_t* message) xbt_die("Could not send MESSAGE_WAITING to model-checker"); } -void AppSide::handle_actor_enabled(const s_mc_message_actor_enabled_t* msg) +void AppSide::handle_actor_enabled(const s_mc_message_actor_enabled_t* msg) const { bool res = simgrid::mc::actor_is_enabled(SIMIX_process_from_PID(msg->aid)); s_mc_message_int_t answer{MC_MESSAGE_ACTOR_ENABLED_REPLY, res}; @@ -161,7 +161,7 @@ void AppSide::report_assertion_failure() this->handle_messages(); } -void AppSide::ignore_memory(void* addr, std::size_t size) +void AppSide::ignore_memory(void* addr, std::size_t size) const { s_mc_message_ignore_memory_t message; message.type = MC_MESSAGE_IGNORE_MEMORY; @@ -171,7 +171,7 @@ void AppSide::ignore_memory(void* addr, std::size_t size) xbt_die("Could not send IGNORE_MEMORY message to model-checker"); } -void AppSide::ignore_heap(void* address, std::size_t size) +void AppSide::ignore_heap(void* address, std::size_t size) const { const s_xbt_mheap_t* heap = mmalloc_get_current_heap(); @@ -192,7 +192,7 @@ void AppSide::ignore_heap(void* address, std::size_t size) xbt_die("Could not send ignored region to MCer"); } -void AppSide::unignore_heap(void* address, std::size_t size) +void AppSide::unignore_heap(void* address, std::size_t size) const { s_mc_message_ignore_memory_t message; message.type = MC_MESSAGE_UNIGNORE_HEAP; @@ -202,7 +202,7 @@ void AppSide::unignore_heap(void* address, std::size_t size) xbt_die("Could not send IGNORE_HEAP message to model-checker"); } -void AppSide::declare_symbol(const char* name, int* value) +void AppSide::declare_symbol(const char* name, int* value) const { s_mc_message_register_symbol_t message; message.type = MC_MESSAGE_REGISTER_SYMBOL; @@ -215,7 +215,7 @@ void AppSide::declare_symbol(const char* name, int* value) xbt_die("Could send REGISTER_SYMBOL message to model-checker"); } -void AppSide::declare_stack(void* stack, size_t size, ucontext_t* context) +void AppSide::declare_stack(void* stack, size_t size, ucontext_t* context) const { const s_xbt_mheap_t* heap = mmalloc_get_current_heap(); diff --git a/src/mc/remote/AppSide.hpp b/src/mc/remote/AppSide.hpp index b1cd172dfe..0c96f35db6 100644 --- a/src/mc/remote/AppSide.hpp +++ b/src/mc/remote/AppSide.hpp @@ -30,22 +30,22 @@ public: void handle_messages(); private: - void handle_deadlock_check(const s_mc_message_t* msg); - void handle_continue(const s_mc_message_t* msg); - void handle_simcall(const s_mc_message_simcall_handle_t* message); - void handle_actor_enabled(const s_mc_message_actor_enabled_t* msg); + void handle_deadlock_check(const s_mc_message_t* msg) const; + void handle_continue(const s_mc_message_t* msg) const; + void handle_simcall(const s_mc_message_simcall_handle_t* message) const; + void handle_actor_enabled(const s_mc_message_actor_enabled_t* msg) const; public: Channel const& get_channel() const { return channel_; } Channel& get_channel() { return channel_; } XBT_ATTRIB_NORETURN void main_loop(); void report_assertion_failure(); - void ignore_memory(void* addr, std::size_t size); - void ignore_heap(void* addr, std::size_t size); - void unignore_heap(void* addr, std::size_t size); - void declare_symbol(const char* name, int* value); + void ignore_memory(void* addr, std::size_t size) const; + void ignore_heap(void* addr, std::size_t size) const; + void unignore_heap(void* addr, std::size_t size) const; + void declare_symbol(const char* name, int* value) const; #if HAVE_UCONTEXT_H - void declare_stack(void* stack, size_t size, ucontext_t* context); + void declare_stack(void* stack, size_t size, ucontext_t* context) const; #endif // Singleton :/ diff --git a/src/mc/remote/RemoteSimulation.cpp b/src/mc/remote/RemoteSimulation.cpp index 290c765ba5..34d1f27f80 100644 --- a/src/mc/remote/RemoteSimulation.cpp +++ b/src/mc/remote/RemoteSimulation.cpp @@ -454,13 +454,13 @@ void* RemoteSimulation::read_bytes(void* buffer, std::size_t size, RemotePtr address) +void RemoteSimulation::write_bytes(const void* buffer, size_t len, RemotePtr address) const { if (pwrite_whole(this->memory_file, buffer, len, (size_t)address.address()) < 0) xbt_die("Write to process %lli failed", (long long)this->pid_); } -void RemoteSimulation::clear_bytes(RemotePtr address, size_t len) +void RemoteSimulation::clear_bytes(RemotePtr address, size_t len) const { pthread_once(&zero_buffer_flag, zero_buffer_init); while (len) { @@ -575,7 +575,7 @@ void RemoteSimulation::unignore_heap(void* address, size_t size) } } -void RemoteSimulation::ignore_local_variable(const char* var_name, const char* frame_name) +void RemoteSimulation::ignore_local_variable(const char* var_name, const char* frame_name) const { if (frame_name != nullptr && strcmp(frame_name, "*") == 0) frame_name = nullptr; @@ -595,7 +595,7 @@ std::vector& RemoteSimulation::dead_actors() return smx_dead_actors_infos; } -void RemoteSimulation::dump_stack() +void RemoteSimulation::dump_stack() const { unw_addr_space_t as = unw_create_addr_space(&_UPT_accessors, BYTE_ORDER); if (as == nullptr) { diff --git a/src/mc/remote/RemoteSimulation.hpp b/src/mc/remote/RemoteSimulation.hpp index 55f3f97b6a..3bd73c2a29 100644 --- a/src/mc/remote/RemoteSimulation.hpp +++ b/src/mc/remote/RemoteSimulation.hpp @@ -102,8 +102,8 @@ public: using AddressSpace::read_string; // Write memory: - void write_bytes(const void* buffer, size_t len, RemotePtr address); - void clear_bytes(RemotePtr address, size_t len); + void write_bytes(const void* buffer, size_t len, RemotePtr address) const; + void clear_bytes(RemotePtr address, size_t len) const; // Debug information: std::shared_ptr find_object_info(RemotePtr addr) const; @@ -142,7 +142,7 @@ public: void terminate() { running_ = false; } - void ignore_global_variable(const char* name) + void ignore_global_variable(const char* name) const { for (std::shared_ptr const& info : this->object_infos) info->remove_global_variable(name); @@ -155,7 +155,7 @@ public: void ignore_heap(IgnoredHeapRegion const& region); void unignore_heap(void* address, size_t size); - void ignore_local_variable(const char* var_name, const char* frame_name); + void ignore_local_variable(const char* var_name, const char* frame_name) const; std::vector& actors(); std::vector& dead_actors(); @@ -185,7 +185,7 @@ public: return nullptr; } - void dump_stack(); + void dump_stack() const; private: void init_memory_map_info(); diff --git a/src/mc/sosp/PageStore.hpp b/src/mc/sosp/PageStore.hpp index 934a32515e..702fc15d39 100644 --- a/src/mc/sosp/PageStore.hpp +++ b/src/mc/sosp/PageStore.hpp @@ -146,16 +146,16 @@ public: // Debug/test methods /** @brief Get the number of references for a page */ - std::size_t get_ref(std::size_t pageno); + std::size_t get_ref(std::size_t pageno) const; /** @brief Get the number of used pages */ - std::size_t size(); + std::size_t size() const; /** @brief Get the capacity of the page store * * The capacity is expanded by a system call (mremap). * */ - std::size_t capacity(); + std::size_t capacity() const; }; XBT_ALWAYS_INLINE void PageStore::unref_page(std::size_t pageno) @@ -174,17 +174,17 @@ XBT_ALWAYS_INLINE void* PageStore::get_page(std::size_t pageno) const return (void*)simgrid::mc::mmu::join(pageno, (std::uintptr_t)this->memory_); } -XBT_ALWAYS_INLINE std::size_t PageStore::get_ref(std::size_t pageno) +XBT_ALWAYS_INLINE std::size_t PageStore::get_ref(std::size_t pageno) const { return this->page_counts_[pageno]; } -XBT_ALWAYS_INLINE std::size_t PageStore::size() +XBT_ALWAYS_INLINE std::size_t PageStore::size() const { return this->top_index_ - this->free_pages_.size(); } -XBT_ALWAYS_INLINE std::size_t PageStore::capacity() +XBT_ALWAYS_INLINE std::size_t PageStore::capacity() const { return this->capacity_; } diff --git a/src/mc/sosp/Region.cpp b/src/mc/sosp/Region.cpp index a770cd374f..653586c047 100644 --- a/src/mc/sosp/Region.cpp +++ b/src/mc/sosp/Region.cpp @@ -32,7 +32,7 @@ Region::Region(RegionType region_type, void* start_addr, size_t size) * * @param region Target region */ -void Region::restore() +void Region::restore() const { xbt_assert(((start().address()) & (xbt_pagesize - 1)) == 0, "Not at the beginning of a page"); xbt_assert(simgrid::mc::mmu::chunk_count(size()) == get_chunks().page_count()); diff --git a/src/mc/sosp/Region.hpp b/src/mc/sosp/Region.hpp index 0131713643..62d13c3f1a 100644 --- a/src/mc/sosp/Region.hpp +++ b/src/mc/sosp/Region.hpp @@ -60,7 +60,7 @@ public: bool contain(RemotePtr p) const { return p >= start() && p < end(); } /** @brief Restore a region from a snapshot */ - void restore(); + void restore() const; /** @brief Read memory that was snapshotted in this region * diff --git a/src/mc/sosp/Snapshot.cpp b/src/mc/sosp/Snapshot.cpp index 6646082f44..7e799892f4 100644 --- a/src/mc/sosp/Snapshot.cpp +++ b/src/mc/sosp/Snapshot.cpp @@ -273,7 +273,7 @@ Region* Snapshot::get_region(const void* addr, Region* hinted_region) const return get_region(addr); } -void Snapshot::restore(RemoteSimulation* process) +void Snapshot::restore(RemoteSimulation* process) const { XBT_DEBUG("Restore snapshot %i", num_state_); diff --git a/src/mc/sosp/Snapshot.hpp b/src/mc/sosp/Snapshot.hpp index d232d0b64a..ac6b434a26 100644 --- a/src/mc/sosp/Snapshot.hpp +++ b/src/mc/sosp/Snapshot.hpp @@ -74,7 +74,7 @@ public: ReadOptions options = ReadOptions::none()) const override; Region* get_region(const void* addr) const; Region* get_region(const void* addr, Region* hinted_region) const; - void restore(RemoteSimulation* get_remote_simulation); + void restore(RemoteSimulation* get_remote_simulation) const; // To be private int num_state_;