Skip to content

Commit

Permalink
wip(tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
bouda1 committed Oct 18, 2023
1 parent ca41797 commit de903c8
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/package-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
sudo $CMAKE \
-G "Ninja" \
-DDEBUG_ROBOT \
-DWITH_TESTING=OFF \
-DWITH_BENCH=ON \
-DWITH_MODULE_SIMU=OFF \
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ endif()
add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1")

option(NG "C++17 build." OFF)
option(DEBUG_ROBOT OFF)

if(NG)
set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -128,6 +129,10 @@ set(COLLECT_PATCH 0)
set(COLLECT_VERSION "${COLLECT_MAJOR}.${COLLECT_MINOR}.${COLLECT_PATCH}")
add_definitions(-DCENTREON_CONNECTOR_VERSION=\"${COLLECT_VERSION}\")

if (DEBUG_ROBOT)
add_definitions(-DDEBUG_ROBOT)
endif()

# ########### CONSTANTS ###########
set(USER_BROKER centreon-broker)
set(USER_ENGINE centreon-engine)
Expand Down
6 changes: 6 additions & 0 deletions broker/core/inc/com/centreon/broker/misc/misc.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ std::string dump_filters(const multiplexing::muxer_filter& filters);
std::list<perfdata> parse_perfdata(uint32_t host_id,
uint32_t service_id,
const char* str);
void debug(const std::string& content);
} // namespace misc

#if DEBUG_ROBOT
#define DEBUG(content) misc::debug(content)
#else
#define DEBUG(content)
#endif
CCB_END()

#endif // !CCB_MISC_MISC_HH
3 changes: 3 additions & 0 deletions broker/core/multiplexing/src/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "com/centreon/broker/config/applier/state.hh"
#include "com/centreon/broker/io/events.hh"
#include "com/centreon/broker/log_v2.hh"
#include "com/centreon/broker/misc/misc.hh"
#include "com/centreon/broker/multiplexing/muxer.hh"
#include "com/centreon/broker/pool.hh"

Expand Down Expand Up @@ -281,11 +282,13 @@ engine::engine()
_stats{stats::center::instance().register_engine()},
_unprocessed_events{0u},
_sending_to_subscribers{false} {
DEBUG(fmt::format("CONSTRUCTOR engine {:p}", static_cast<void*>(this)));
stats::center::instance().update(&EngineStats::set_mode, _stats,
EngineStats::NOT_STARTED);
}

engine::~engine() noexcept {
DEBUG(fmt::format("DESTRUCTOR engine {:p}", static_cast<void*>(this)));
log_v2::core()->debug("core: cbd engine destroyed.");
}

Expand Down
4 changes: 4 additions & 0 deletions broker/core/multiplexing/src/muxer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ muxer::muxer(std::string name,
_events_size{0u},
_last_stats{std::time(nullptr)} {
// Load head queue file back in memory.
DEBUG(fmt::format("CONSTRUCTOR muxer {:p} {}", static_cast<void*>(this),
_name));
std::lock_guard<std::mutex> lck(_mutex);
if (_persistent) {
try {
Expand Down Expand Up @@ -197,6 +199,8 @@ muxer::~muxer() noexcept {
"Destroying muxer {}: number of events in the queue: {}",
_name, _events_size);
_clean();
DEBUG(fmt::format("DESTRUCTOR muxer {:p} {}", static_cast<void*>(this),
_name));
}

/**
Expand Down
3 changes: 3 additions & 0 deletions broker/core/src/log_v2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <grpc/impl/codegen/log.h>

#include "com/centreon/exceptions/msg_fmt.hh"
#include "com/centreon/broker/misc/misc.hh"

using namespace com::centreon::broker;
using namespace com::centreon::exceptions;
Expand Down Expand Up @@ -90,6 +91,7 @@ log_v2::log_v2(const std::shared_ptr<asio::io_context>& io_context)
_flush_timer(*io_context),
_flush_timer_active(true),
_io_context(io_context) {
DEBUG(fmt::format("CONSTRUCTOR log_v2 {:p}", static_cast<void*>(this)));
auto stdout_sink = std::make_shared<sinks::stdout_color_sink_mt>();
auto create_logger = [&](const std::string& name) {
std::shared_ptr<spdlog::logger> log =
Expand Down Expand Up @@ -128,6 +130,7 @@ log_v2::~log_v2() noexcept {
_running = false;
for (auto& l : _log)
l.reset();
DEBUG(fmt::format("DESTRUCTOR log_v2 {:p}", static_cast<void*>(this)));
}

void log_v2::apply(const config::state& conf) {
Expand Down
1 change: 1 addition & 0 deletions broker/core/src/misc/filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "com/centreon/broker/misc/filesystem.hh"
#include <dirent.h>
#include <filesystem>
#include <fnmatch.h>
#include <sys/stat.h>
#include <sys/types.h>
Expand Down
16 changes: 16 additions & 0 deletions broker/core/src/misc/misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "com/centreon/broker/misc/misc.hh"

#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>

Expand Down Expand Up @@ -187,3 +188,18 @@ std::string misc::dump_filters(const multiplexing::muxer_filter& filters) {
ret.append(", ").append(it->second);
return ret;
}

void misc::debug(const std::string& content) {
int p = getpid();
std::string filename{fmt::format("failed/{}.log", p)};
FILE* f = fopen(filename.c_str(), "a");
if (!f) {
if (mkdir("failed", 0755) != 0)
return;
f = fopen(filename.c_str(), "a");
}
if (f) {
fprintf(f, "%s\n", content.c_str());
fclose(f);
}
}
3 changes: 3 additions & 0 deletions broker/core/src/processing/failover.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "com/centreon/broker/exceptions/shutdown.hh"
#include "com/centreon/broker/log_v2.hh"
#include "com/centreon/exceptions/msg_fmt.hh"
#include "com/centreon/broker/misc/misc.hh"

using namespace com::centreon::exceptions;
using namespace com::centreon::broker;
Expand All @@ -49,6 +50,7 @@ failover::failover(std::shared_ptr<io::endpoint> endp,
_next_timeout(0),
_muxer(mux),
_update(false) {
DEBUG(fmt::format("CONSTRUCTOR failover {:p} {} - muxer: {:p}", static_cast<void*>(this), name, static_cast<void*>(mux.get())));
SPDLOG_LOGGER_TRACE(log_v2::core(), "failover '{}' construction.", _name);
}

Expand All @@ -57,6 +59,7 @@ failover::failover(std::shared_ptr<io::endpoint> endp,
*/
failover::~failover() {
exit();
DEBUG(fmt::format("DESTRUCTOR failover {:p}", static_cast<void*>(this)));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions broker/core/src/processing/feeder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ feeder::feeder(const std::string& name,
_stat_timer(pool::io_context()),
_read_from_stream_timer(pool::io_context()),
_io_context(pool::io_context_ptr()) {
DEBUG(fmt::format("CONSTRUCTOR feeder {:p} {} - muxer: {:p}", static_cast<void*>(this), name, static_cast<void*>(_muxer.get())));
if (!_client)
throw msg_fmt("could not process '{}' with no client stream", _name);

Expand All @@ -100,6 +101,7 @@ feeder::~feeder() {
static_cast<const void*>(this));

multiplexing::engine::instance_ptr()->unsubscribe(_muxer.get());
DEBUG(fmt::format("DESTRUCTOR feeder {:p}", static_cast<void*>(this)));
}

bool feeder::is_finished() const noexcept {
Expand Down
2 changes: 1 addition & 1 deletion cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,5 @@ if [[ "$maj" == "Raspbian" ]] ; then
elif [[ "$maj" == "Debian" ]] ; then
CC=$CC CXX=$CXX CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF -DWITH_CONF=OFF $NG $* ..
else
CC=$CC CXX=$CXX CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF -DWITH_CONF=OFF $NG $* ..
CC=$CC CXX=$CXX CXXFLAGS="-Wall -Wextra" $cmake -DDEBUG_ROBOT=On -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF -DWITH_CONF=OFF $NG $* ..
fi

0 comments on commit de903c8

Please sign in to comment.