[Bug/Feature] Make the code compatible with more compilers.
[Cause] N/A
[Solution] Redefine some C++11 keywords.
Remove some specific C++11 constructs not found in C++0x.
Specific defines for various compilers and their versions.
[Verification] Built with GCC 4.6, GCC 4.8 and CLANG 3.4 and run tests.
Change-Id: I5ce7c2c3ca4372ec79b41facb1793c7df5b1f6b0
Signed-off-by: Lukasz Pawelczyk <l.pawelczyk@partner.samsung.com>
ENDIF(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
+# special case for a GCC < 4.7, assume rest is fine
+IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+ SET(CXX_11_STD "c++0x")
+else()
+ SET(CXX_11_STD "c++11")
+endif()
+
SET(CMAKE_C_FLAGS_PROFILING "-g -O0 -pg")
-SET(CMAKE_CXX_FLAGS_PROFILING "-g -std=c++11 -O0 -pg")
+SET(CMAKE_CXX_FLAGS_PROFILING "-g -std=${CXX_11_STD} -O0 -pg")
SET(CMAKE_C_FLAGS_DEBUG "-g -O0 -ggdb")
-SET(CMAKE_CXX_FLAGS_DEBUG "-g -std=c++11 -O0 -ggdb")
+SET(CMAKE_CXX_FLAGS_DEBUG "-g -std=${CXX_11_STD} -O0 -ggdb")
SET(CMAKE_C_FLAGS_RELEASE "-g -O2 -DNDEBUG")
-SET(CMAKE_CXX_FLAGS_RELEASE "-g -std=c++11 -O2 -DNDEBUG")
+SET(CMAKE_CXX_FLAGS_RELEASE "-g -std=${CXX_11_STD} -O2 -DNDEBUG")
SET(CMAKE_C_FLAGS_CCOV "-g -O2 --coverage")
-SET(CMAKE_CXX_FLAGS_CCOV "-g -std=c++11 -O2 --coverage")
+SET(CMAKE_CXX_FLAGS_CCOV "-g -std=${CXX_11_STD} -O2 --coverage")
ADD_DEFINITIONS("-fPIC") # Position Independent Code
ADD_DEFINITIONS("-Werror") # Make all warnings into errors
* @brief Base class for exceptions in Security Containers Client
*/
struct ClientException: public SecurityContainersException {
- using SecurityContainersException::SecurityContainersException;
+
+ ClientException(const std::string& error = "") : SecurityContainersException(error) {}
};
* limitations under the License
*/
-
/**
* @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Main file for the Security Containers Client
*/
+#include "config.hpp"
+
#include "exception.hpp"
#define COMMON_BASE_EXCEPTION_HPP
#include <stdexcept>
+#include <string>
namespace security_containers {
* Base class security containers exceptions
*/
struct SecurityContainersException: public std::runtime_error {
- using std::runtime_error::runtime_error;
- SecurityContainersException() : std::runtime_error(std::string()) {}
+ SecurityContainersException(const std::string& error = "") : std::runtime_error(error) {}
};
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+/**
+ * @file
+ * @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
+ * @brief Configuration file for the code
+ */
+
+
+#ifndef COMMON_CONFIG_HPP
+#define COMMON_CONFIG_HPP
+
+
+#ifdef __clang__
+#define CLANG_VERSION (__clang__major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
+#endif // __clang__
+
+#if defined __GNUC__ && !defined __clang__ // clang also defines GCC versions
+#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+#endif // __GNUC__
+
+
+#ifdef GCC_VERSION
+
+#if GCC_VERSION < 40800
+// GCC 4.8 is the first where those defines are not required for
+// std::this_thread::sleep_for() and ::yield(). They might exist though
+// in previous versions depending on the build configuration of the GCC.
+#ifndef _GLIBCXX_USE_NANOSLEEP
+#define _GLIBCXX_USE_NANOSLEEP
+#endif // _GLIBCXX_USE_NANOSLEEP
+#ifndef _GLIBCXX_USE_SCHED_YIELD
+#define _GLIBCXX_USE_SCHED_YIELD
+#endif // _GLIBCXX_USE_SCHED_YIELD
+#endif // GCC_VERSION < 40800
+
+#if GCC_VERSION < 40700
+// Those appeared in 4.7 with full c++11 support
+#define final
+#define override
+#define thread_local __thread // use GCC extension instead of C++11
+#endif // GCC_VERSION < 40700
+
+#endif // GCC_VERSION
+
+
+#endif // COMMON_CONFIG_HPP
* @brief Helper class for parsing and storing configurations in JSON format.
*/
+#include "config.hpp"
#include "log/logger.hpp"
#include "config/configuration.hpp"
#include "config/exception.hpp"
* e.g. syntax error
*/
struct ConfigException: public SecurityContainersException {
- using SecurityContainersException::SecurityContainersException;
+
+ ConfigException(const std::string& error = "") : SecurityContainersException(error) {}
};
* @brief Dbus connection class
*/
+#include "config.hpp"
#include "dbus/connection.hpp"
#include "dbus/exception.hpp"
#include "utils/callback-wrapper.hpp"
const GDBusConnectionFlags flags =
static_cast<GDBusConnectionFlags>(G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION);
+ // TODO: this is possible deadlock if the dbus
+ // socket exists but there is no dbus-daemon
mConnection = g_dbus_connection_new_for_address_sync(address.c_str(),
flags,
NULL,
* Base class for dbus exceptions
*/
struct DbusException: public SecurityContainersException {
- using SecurityContainersException::SecurityContainersException;
+
+ DbusException(const std::string& error = "") : SecurityContainersException(error) {}
};
/**
* Dbus IO exception (connection failed, connection lost, etc)
*/
struct DbusIOException: public DbusException {
- using DbusException::DbusException;
+
+ DbusIOException(const std::string& error = "") : DbusException(error) {}
};
/**
* Dbus operation failed exception
*/
struct DbusOperationException: public DbusException {
- using DbusException::DbusException;
+
+ DbusOperationException(const std::string& error = "") : DbusException(error) {}
};
/**
* Dbus custom exception triggered by user logic
*/
struct DbusCustomException: public DbusException {
- using DbusException::DbusException;
+
+ DbusCustomException(const std::string& error = "") : DbusException(error) {}
};
/**
* Dbus invalid argument exception
*/
struct DbusInvalidArgumentException: public DbusException {
- using DbusException::DbusException;
+
+ DbusInvalidArgumentException(const std::string& error = "") : DbusException(error) {}
};
* @brief Implementation of the class wrapping connection to libvirtd
*/
+#include "config.hpp"
#include "log/logger.hpp"
#include "libvirt/helpers.hpp"
#include "libvirt/connection.hpp"
LibvirtConnection::LibvirtConnection(const std::string& uri)
+ : mCon(NULL)
{
libvirtInitialize();
operator bool() const;
private:
- virConnectPtr mCon = NULL;
+ virConnectPtr mCon;
};
* @brief Implementation of the class wrapping libvirt domain
*/
+#include "config.hpp"
#include "log/logger.hpp"
#include "libvirt/domain.hpp"
#include "libvirt/helpers.hpp"
LibvirtDomain::LibvirtDomain(const std::string& configXML)
- : mCon(LIBVIRT_LXC_ADDRESS)
+ : mCon(LIBVIRT_LXC_ADDRESS), mDom(NULL)
{
mDom = virDomainDefineXML(mCon.get(), configXML.c_str());
private:
LibvirtConnection mCon;
- virDomainPtr mDom = NULL;
+ virDomainPtr mDom;
};
* Base class for exceptions in libvirt
*/
struct LibvirtOperationException: public SecurityContainersException {
- using SecurityContainersException::SecurityContainersException;
+
+ LibvirtOperationException(const std::string& error = "") : SecurityContainersException(error) {}
};
* @brief A function helpers for the libvirt library
*/
+#include "config.hpp"
#include "libvirt/helpers.hpp"
#include "log/logger.hpp"
* @brief Implementation of the class wrapping libvirt network
*/
+#include "config.hpp"
+
#include "log/logger.hpp"
#include "libvirt/network.hpp"
#include "libvirt/helpers.hpp"
LibvirtNetwork::LibvirtNetwork(const std::string& configXML)
- : mCon(LIBVIRT_LXC_ADDRESS)
+ : mCon(LIBVIRT_LXC_ADDRESS), mNet(NULL)
{
mNet = virNetworkDefineXML(mCon.get(), configXML.c_str());
private:
LibvirtConnection mCon;
- virNetworkPtr mNet = NULL;
+ virNetworkPtr mNet;
};
* @brief Systemd journal backend for logger
*/
+#include "config.hpp"
#include "log/backend-journal.hpp"
#define SD_JOURNAL_SUPPRESS_LOCATION
* @brief Stderr backend for logger
*/
+#include "config.hpp"
#include "log/backend-stderr.hpp"
#include "log/formatter.hpp"
* @brief Console color for StderrBackend logger
*/
+#include "config.hpp"
#include "log/ccolor.hpp"
#include <stdio.h>
BLUE = 94,
MAGENTA = 95,
CYAN = 96,
- WHITE = 97,
+ WHITE = 97
};
enum class Attributes : unsigned int {
DEFAULT = 0,
- BOLD = 1,
+ BOLD = 1
};
std::string getConsoleEscapeSequence(Attributes attr, Color color);
* @brief Helper formatter for logger
*/
+#include "config.hpp"
#include "log/formatter.hpp"
#include "log/ccolor.hpp"
* @brief Functions to handle LogLevel
*/
+#include "config.hpp"
#include "log/level.hpp"
* @brief Logger
*/
+#include "config.hpp"
#include "log/logger.hpp"
#include "log/formatter.hpp"
#include "log/backend-null.hpp"
* @brief Callback guard
*/
-#include "callback-guard.hpp"
+#include "config.hpp"
+#include "utils/callback-guard.hpp"
#include "log/logger.hpp"
#include <mutex>
// Reference counting class like shared_ptr but with the ability to wait for it.
class CallbackGuard::SharedState {
public:
+ SharedState() : mCounter(0) {}
+
void inc()
{
std::unique_lock<std::mutex> lock(mMutex);
private:
std::mutex mMutex;
std::condition_variable mEmptyCondition;
- long mCounter = 0;
+ long mCounter;
};
namespace {
* Base class for exceptions in utils
*/
struct UtilsException: public SecurityContainersException {
- using SecurityContainersException::SecurityContainersException;
+
+ UtilsException(const std::string& error = "") : SecurityContainersException(error) {}
};
* @brief Wait for file utility function
*/
+#include "config.hpp"
#include "utils/exception.hpp"
#include "utils/file-wait.hpp"
* @brief File utility functions
*/
+#include "config.hpp"
#include "log/logger.hpp"
#include "utils/fs.hpp"
#include "utils/paths.hpp"
* @brief C++ wrapper of glib main loop
*/
+#include "config.hpp"
#include "utils/glib-loop.hpp"
#include "utils/callback-wrapper.hpp"
* @brief Synchronization latch
*/
+#include "config.hpp"
#include "utils/latch.hpp"
#include <cassert>
inline void removeTrailingSlash(std::string& path)
{
- if (path.size() > 1 && *(path.end() - 1) == '/') {
- path.pop_back();
+ size_t size = path.size();
+
+ if (size > 1 && path[size - 1] == '/') {
+ path.resize(size - 1);
}
}
* @brief Synchronization latch
*/
-#include "typeinfo.hpp"
+#include "config.hpp"
+#include "utils/typeinfo.hpp"
#include <string>
#include <cxxabi.h>
* @brief Dbus API for the Container Daemon
*/
+#include "config.hpp"
+
#include "daemon-connection.hpp"
#include "daemon-dbus-definitions.hpp"
#include "exception.hpp"
* @brief Definition of the Daemon, implementation of the logic of the daemon.
*/
+#include "config.hpp"
+
#include "daemon.hpp"
#include "log/logger.hpp"
* Base class for exceptions in Security Containers Container Daemon
*/
struct ContainerDaemonException: public SecurityContainersException {
- using SecurityContainersException::SecurityContainersException;
+
+ ContainerDaemonException(const std::string& error = "") : SecurityContainersException(error) {}
};
#define LOG_TO_CONSOLE
#endif
+#include "config.hpp"
+
+#include "exception.hpp"
+#include "runner.hpp"
+
#include "log/logger.hpp"
#include "log/backend-stderr.hpp"
#include "log/backend-journal.hpp"
#include "utils/typeinfo.hpp"
-#include "exception.hpp"
-#include "runner.hpp"
-
#include <boost/program_options.hpp>
#include <iostream>
* @brief Definition of the Runner class, that manages daemon's lifetime
*/
+#include "config.hpp"
+
#include "runner.hpp"
#include "daemon.hpp"
* @brief Implementation of class for administrating one container
*/
+#include "config.hpp"
+
#include "container-admin.hpp"
#include "exception.hpp"
mDetachOnExit(false),
mLifecycleCallbackId(-1),
mRebootCallbackId(-1),
- mNextIdForListener(0)
+ mNextIdForListener(1)
{
LOGD(mId << ": Instantiating ContainerAdmin object");
}
};
- ListenerId id = registerListener(setStopped, nullptr);
+ ListenerId id = registerLifecycleListener(setStopped, nullptr);
shutdown();
bool stopped = stoppedOccured.wait(SHUTDOWN_WAIT);
- removeListener<LifecycleListener>(id);
+ removeListener(id);
if (!stopped) {
LOGW(mId << ": Gracefull shutdown timed out, the container is still running, destroying");
return quota;
}
+ContainerAdmin::ListenerId ContainerAdmin::registerLifecycleListener(const ContainerAdmin::LifecycleListener& listener,
+ const utils::CallbackGuard::Tracker& tracker)
+{
+
+ utils::CallbackWrapper<LifecycleListener> wrap(listener, tracker);
+
+ std::unique_lock<std::mutex> lock(mListenerMutex);
+ unsigned int id = mNextIdForListener++;
+ mLifecycleListeners.insert(LifecycleListenerMap::value_type(id, std::move(wrap)));
+
+ return id;
+}
+
+ContainerAdmin::ListenerId ContainerAdmin::registerRebootListener(const ContainerAdmin::RebootListener& listener,
+ const utils::CallbackGuard::Tracker& tracker)
+{
+
+ utils::CallbackWrapper<RebootListener> wrap(listener, tracker);
+
+ std::unique_lock<std::mutex> lock(mListenerMutex);
+ unsigned int id = mNextIdForListener++;
+ mRebootListeners.insert(RebootListenerMap::value_type(id, std::move(wrap)));
+
+ return id;
+}
+
+void ContainerAdmin::removeListener(const ContainerAdmin::ListenerId id)
+{
+ std::unique_lock<std::mutex> lock(mListenerMutex);
+ mLifecycleListeners.erase(id);
+ mRebootListeners.erase(id);
+}
+
int ContainerAdmin::libvirtLifecycleCallback(virConnectPtr /*con*/,
virDomainPtr /*dom*/,
int event,
}
}
-template<>
-ContainerAdmin::ListenerMap<ContainerAdmin::LifecycleListener>&
-ContainerAdmin::getListenerMap<ContainerAdmin::LifecycleListener>()
-{
- return mLifecycleListeners;
-}
-
-template<>
-ContainerAdmin::ListenerMap<ContainerAdmin::RebootListener>&
-ContainerAdmin::getListenerMap<ContainerAdmin::RebootListener>()
-{
- return mRebootListeners;
-}
-
} // namespace security_containers
typedef unsigned int ListenerId;
/**
+ * An invalid ListenerId value.
+ */
+ static const ListenerId LISTENER_ID_INVALID = 0;
+
+ /**
* A function type used for the lifecycle listener
*/
typedef std::function<void(const int eventId, const int detailId)> LifecycleListener;
std::int64_t getSchedulerQuota();
/**
- * Sets a listener for a specific event.
+ * Sets a listener for a lifecycle event.
* It's a caller's responsibility to remove the listener
* prior to destroying the object.
*
* @return listener ID that can be used to remove.
*/
- template <typename Listener>
- ListenerId registerListener(const Listener& listener,
- const utils::CallbackGuard::Tracker& tracker);
+ ListenerId registerLifecycleListener(const LifecycleListener& listener,
+ const utils::CallbackGuard::Tracker& tracker);
+
+ /**
+ * Sets a listener for a reboot event.
+ * It's a caller's responsibility to remove the listener
+ * prior to destroying the object.
+ *
+ * @return listener ID that can be used to remove.
+ */
+ ListenerId registerRebootListener(const RebootListener& listener,
+ const utils::CallbackGuard::Tracker& tracker);
/**
* Remove a previously registered listener.
*/
- template <typename Listener>
void removeListener(const ListenerId id);
private:
// for handling external listeners triggered from libvirt callbacks
// TODO, the Listener type might not be unique, reimplement using proper listeners
- template <typename Listener>
- using ListenerMap = std::map<ListenerId, utils::CallbackWrapper<Listener>>;
+ typedef std::map<ListenerId, utils::CallbackWrapper<LifecycleListener>> LifecycleListenerMap;
+ typedef std::map<ListenerId, utils::CallbackWrapper<RebootListener>> RebootListenerMap;
std::mutex mListenerMutex;
- std::atomic<unsigned int> mNextIdForListener;
- ListenerMap<LifecycleListener> mLifecycleListeners;
- ListenerMap<RebootListener> mRebootListeners;
-
- template <typename Listener>
- ListenerMap<Listener>& getListenerMap();
+ unsigned int mNextIdForListener;
+ LifecycleListenerMap mLifecycleListeners;
+ RebootListenerMap mRebootListeners;
};
-template <typename Listener>
-unsigned int ContainerAdmin::registerListener(const Listener& listener,
- const utils::CallbackGuard::Tracker& tracker)
-{
-
- ListenerMap<Listener>& map = getListenerMap<Listener>();
- unsigned int id = mNextIdForListener++;
- utils::CallbackWrapper<Listener> wrap(listener, tracker);
-
- std::unique_lock<std::mutex> lock(mListenerMutex);
- map.emplace(id, std::move(wrap));
-
- return id;
-}
-
-template <typename Listener>
-void ContainerAdmin::removeListener(const ContainerAdmin::ListenerId id)
-{
- ListenerMap<Listener>& map = getListenerMap<Listener>();
-
- std::unique_lock<std::mutex> lock(mListenerMutex);
- map.erase(id);
-}
-
} // namespace security_containers
* @brief Implementation of a class for communication transport between container and server
*/
+#include "config.hpp"
+
#include "container-connection-transport.hpp"
#include "exception.hpp"
* @brief Implementation of a class for communication between container and server
*/
+#include "config.hpp"
+
#include "container-connection.hpp"
#include "container-dbus-definitions.hpp"
#include "exception.hpp"
* @brief Implementation of class for managing one container
*/
+#include "config.hpp"
+
#include "container.hpp"
#include "log/logger.hpp"
* @brief Definition of the class for managing containers
*/
+#include "config.hpp"
+
#include "containers-manager.hpp"
#include "container-admin.hpp"
#include "exception.hpp"
+
#include "utils/paths.hpp"
#include "log/logger.hpp"
LOGD("Creating Container " << containerConfigPath);
std::unique_ptr<Container> c(new Container(containerConfigPath));
std::string id = c->getId();
- mContainers.emplace(id, std::move(c));
+ mContainers.insert(ContainerMap::value_type(id, std::move(c)));
}
LOGD("ContainersManager object instantiated");
* Base class for exceptions in Security Containers Server
*/
struct ServerException: public SecurityContainersException {
- using SecurityContainersException::SecurityContainersException;
+
+ ServerException(const std::string& error = "") : SecurityContainersException(error) {}
};
/**
* e.g. start, stop a container
*/
struct ContainerOperationException: public ServerException {
- using ServerException::ServerException;
+
+ ContainerOperationException(const std::string& error = "") : ServerException(error) {}
};
/**
* Exception during performing an operation on a container connection
*/
struct ContainerConnectionException: public ServerException {
- using ServerException::ServerException;
+
+ ContainerConnectionException(const std::string& error = "") : ServerException(error) {}
};
/**
* e.g. create channel, register callback etc.
*/
struct InputMonitorException: public ServerException {
- using ServerException::ServerException;
+
+ InputMonitorException(const std::string& error = "") : ServerException(error) {}
};
#define LOG_TO_CONSOLE
#endif
+#include "config.hpp"
+
+#include "exception.hpp"
+#include "server.hpp"
+
#include "log/logger.hpp"
#include "log/backend-stderr.hpp"
#include "log/backend-journal.hpp"
#include "utils/typeinfo.hpp"
-#include "exception.hpp"
-#include "server.hpp"
#include <boost/program_options.hpp>
#include <iostream>
* @brief Server class definition
*/
+#include "config.hpp"
+
#include "server.hpp"
#include "containers-manager.hpp"
#include "exception.hpp"
* @brief Unit test of ConfigurationBase
*/
+#include "config.hpp"
#include "ut.hpp"
#include "config/configuration.hpp"
* @brief Example dbus api client
*/
+#include "config.hpp"
+
#include "dbus/test-client.hpp"
#include "dbus/test-common.hpp"
* @brief Example dbus api server
*/
+#include "config.hpp"
+
#include "dbus/test-server.hpp"
#include "dbus/test-common.hpp"
* @brief Dbus connection unit tests
*/
+#include "config.hpp"
#include "ut.hpp"
#include "dbus/test-server.hpp"
#include "dbus/test-client.hpp"
* @brief Unit tests of the LibvirtConnection class
*/
+#include "config.hpp"
#include "ut.hpp"
#include "libvirt/connection.hpp"
* @brief Unit tests of the LibvirtDomain class
*/
+#include "config.hpp"
#include "ut.hpp"
#include "libvirt/domain.hpp"
* @brief Unit tests of the LibvirtNetwork class
*/
+#include "config.hpp"
#include "ut.hpp"
#include "libvirt/network.hpp"
* @brief Unit tests of the log utility
*/
+#include "config.hpp"
#include "ut.hpp"
#include "log/logger.hpp"
#include "log/formatter.hpp"
* @brief Unit tests of the ContainerAdmin class
*/
+#include "config.hpp"
#include "ut.hpp"
#include "container-admin.hpp"
BOOST_AUTO_TEST_CASE(StartTest)
{
utils::Latch booted;
- ContainerAdmin::ListenerId id;
+ ContainerAdmin::ListenerId id = ContainerAdmin::LISTENER_ID_INVALID;
ContainerConfig config; config.parseFile(TEST_CONFIG_PATH);
ContainerAdmin ca(config);
booted.set();
}
};
- BOOST_REQUIRE_NO_THROW(id = ca.registerListener(bootedListener, mGuard.spawn()));
+ BOOST_REQUIRE_NO_THROW(id = ca.registerLifecycleListener(bootedListener, mGuard.spawn()));
BOOST_REQUIRE_NO_THROW(ca.start());
ensureStarted();
BOOST_CHECK(booted.wait(WAIT_TIMEOUT));
BOOST_CHECK(ca.isRunning());
- BOOST_REQUIRE_NO_THROW(ca.removeListener<ContainerAdmin::LifecycleListener>(id));
+ BOOST_REQUIRE_NO_THROW(ca.removeListener(id));
}
BOOST_AUTO_TEST_CASE(ShutdownTest)
{
utils::Latch shutdown;
- ContainerAdmin::ListenerId id;
+ ContainerAdmin::ListenerId id = ContainerAdmin::LISTENER_ID_INVALID;
ContainerConfig config; config.parseFile(TEST_CONFIG_PATH);
ContainerAdmin ca(config);
BOOST_REQUIRE_NO_THROW(ca.start());
ensureStarted();
BOOST_REQUIRE(ca.isRunning());
- BOOST_REQUIRE_NO_THROW(id = ca.registerListener(shutdownListener, mGuard.spawn()));
+ BOOST_REQUIRE_NO_THROW(id = ca.registerLifecycleListener(shutdownListener, mGuard.spawn()));
BOOST_REQUIRE_NO_THROW(ca.shutdown());
BOOST_CHECK(shutdown.wait(WAIT_TIMEOUT));
BOOST_CHECK(!ca.isRunning());
BOOST_CHECK(ca.isStopped());
- BOOST_REQUIRE_NO_THROW(ca.removeListener<ContainerAdmin::LifecycleListener>(id));
+ BOOST_REQUIRE_NO_THROW(ca.removeListener(id));
}
BOOST_AUTO_TEST_CASE(DestroyTest)
{
utils::Latch destroyed;
- ContainerAdmin::ListenerId id;
+ ContainerAdmin::ListenerId id = ContainerAdmin::LISTENER_ID_INVALID;
ContainerConfig config; config.parseFile(TEST_CONFIG_PATH);
ContainerAdmin ca(config);
BOOST_REQUIRE_NO_THROW(ca.start());
ensureStarted();
BOOST_REQUIRE(ca.isRunning());
- BOOST_REQUIRE_NO_THROW(id = ca.registerListener(destroyedListener, mGuard.spawn()));
+ BOOST_REQUIRE_NO_THROW(id = ca.registerLifecycleListener(destroyedListener, mGuard.spawn()));
BOOST_REQUIRE_NO_THROW(ca.destroy());
BOOST_CHECK(destroyed.wait(WAIT_TIMEOUT));
BOOST_CHECK(!ca.isRunning());
BOOST_CHECK(ca.isStopped());
- BOOST_REQUIRE_NO_THROW(ca.removeListener<ContainerAdmin::LifecycleListener>(id));
+ BOOST_REQUIRE_NO_THROW(ca.removeListener(id));
}
BOOST_AUTO_TEST_CASE(StopShutdownTest)
{
utils::Latch shutdown;
- ContainerAdmin::ListenerId id;
+ ContainerAdmin::ListenerId id = ContainerAdmin::LISTENER_ID_INVALID;
ContainerConfig config; config.parseFile(TEST_CONFIG_PATH);
ContainerAdmin ca(config);
BOOST_REQUIRE_NO_THROW(ca.start());
ensureStarted();
BOOST_REQUIRE(ca.isRunning());
- BOOST_REQUIRE_NO_THROW(id = ca.registerListener(shutdownListener, mGuard.spawn()));
+ BOOST_REQUIRE_NO_THROW(id = ca.registerLifecycleListener(shutdownListener, mGuard.spawn()));
BOOST_REQUIRE_NO_THROW(ca.stop());
BOOST_CHECK(shutdown.wait(WAIT_TIMEOUT));
BOOST_CHECK(!ca.isRunning());
BOOST_CHECK(ca.isStopped());
- BOOST_REQUIRE_NO_THROW(ca.removeListener<ContainerAdmin::LifecycleListener>(id));
+ BOOST_REQUIRE_NO_THROW(ca.removeListener(id));
}
// This test needs to wait for a shutdown timer in stop() method. This takes 10s+.
BOOST_AUTO_TEST_CASE(StopDestroyTest)
{
utils::Latch destroyed;
- ContainerAdmin::ListenerId id;
+ ContainerAdmin::ListenerId id = ContainerAdmin::LISTENER_ID_INVALID;
ContainerConfig config; config.parseFile(TEST_NO_SHUTDOWN_CONFIG_PATH);
ContainerAdmin ca(config);
BOOST_REQUIRE_NO_THROW(ca.start());
ensureStarted();
BOOST_REQUIRE(ca.isRunning());
- BOOST_REQUIRE_NO_THROW(id = ca.registerListener(destroyedListener, mGuard.spawn()));
+ BOOST_REQUIRE_NO_THROW(id = ca.registerLifecycleListener(destroyedListener, mGuard.spawn()));
BOOST_REQUIRE_NO_THROW(ca.stop());
BOOST_CHECK(destroyed.wait(WAIT_STOP_TIMEOUT));
BOOST_CHECK(!ca.isRunning());
BOOST_CHECK(ca.isStopped());
- BOOST_REQUIRE_NO_THROW(ca.removeListener<ContainerAdmin::LifecycleListener>(id));
+ BOOST_REQUIRE_NO_THROW(ca.removeListener(id));
}
BOOST_AUTO_TEST_CASE(SuspendTest)
{
utils::Latch paused;
- ContainerAdmin::ListenerId id;
+ ContainerAdmin::ListenerId id = ContainerAdmin::LISTENER_ID_INVALID;
ContainerConfig config; config.parseFile(TEST_CONFIG_PATH);
ContainerAdmin ca(config);
BOOST_REQUIRE_NO_THROW(ca.start())
ensureStarted();
BOOST_REQUIRE(ca.isRunning());
- BOOST_REQUIRE_NO_THROW(id = ca.registerListener(pausedListener, mGuard.spawn()));
+ BOOST_REQUIRE_NO_THROW(id = ca.registerLifecycleListener(pausedListener, mGuard.spawn()));
BOOST_REQUIRE_NO_THROW(ca.suspend());
BOOST_CHECK(paused.wait(WAIT_TIMEOUT));
BOOST_CHECK(!ca.isRunning());
BOOST_CHECK(ca.isPaused());
- BOOST_REQUIRE_NO_THROW(ca.removeListener<ContainerAdmin::LifecycleListener>(id));
+ BOOST_REQUIRE_NO_THROW(ca.removeListener(id));
}
BOOST_AUTO_TEST_CASE(ResumeTest)
{
utils::Latch unpaused;
- ContainerAdmin::ListenerId id;
+ ContainerAdmin::ListenerId id = ContainerAdmin::LISTENER_ID_INVALID;
ContainerConfig config; config.parseFile(TEST_CONFIG_PATH);
ContainerAdmin ca(config);
BOOST_REQUIRE(ca.isRunning());
BOOST_REQUIRE_NO_THROW(ca.suspend())
BOOST_REQUIRE(ca.isPaused());
- BOOST_REQUIRE_NO_THROW(id = ca.registerListener(unpausedListener, mGuard.spawn()));
+ BOOST_REQUIRE_NO_THROW(id = ca.registerLifecycleListener(unpausedListener, mGuard.spawn()));
BOOST_REQUIRE_NO_THROW(ca.resume());
BOOST_CHECK(unpaused.wait(WAIT_TIMEOUT));
BOOST_CHECK(!ca.isPaused());
BOOST_CHECK(ca.isRunning());
- BOOST_REQUIRE_NO_THROW(ca.removeListener<ContainerAdmin::LifecycleListener>(id));
+ BOOST_REQUIRE_NO_THROW(ca.removeListener(id));
}
BOOST_AUTO_TEST_CASE(SchedulerLevelTest)
* @brief Unit tests of the ContainerConnection class
*/
+#include "config.hpp"
#include "ut.hpp"
#include "container-connection.hpp"
* @brief Unit tests of the Container class
*/
+#include "config.hpp"
#include "ut.hpp"
#include "container.hpp"
* @brief Unit tests of the ContainersManager class
*/
+#include "config.hpp"
#include "ut.hpp"
#include "containers-manager.hpp"
* @brief Unit tests of the InputMonitor class
*/
+#include "config.hpp"
#include "ut.hpp"
#include "input-monitor.hpp"
* @brief Unit tests of the Server class
*/
+#include "config.hpp"
#include "ut.hpp"
#include "server.hpp"
#include <string>
#include <future>
+
BOOST_AUTO_TEST_SUITE(ServerSuite)
using namespace security_containers;
* @brief Main file for the Security Containers Daemon unit tests
*/
+#include "config.hpp"
+
#include "log/logger.hpp"
#include "log/backend-stderr.hpp"
* @brief Starts external daemon in constructor, stops it in destructor
*/
+#include "config.hpp"
+
#include "utils/scoped-daemon.hpp"
#include "log/logger.hpp"
* @brief Unit tests of callback guard
*/
+#include "config.hpp"
#include "ut.hpp"
#include "utils/callback-guard.hpp"
Latch trackerCreated;
Latch trackerCanBeDestroyed;
- std::future<bool> future = std::async(std::launch::async, [&] {
+ std::future<bool> future = std::async(std::launch::async, [&]() -> bool {
CallbackGuard::Tracker tracker = guard.spawn();
trackerCreated.set();
if (!trackerCanBeDestroyed.wait(TIMEOUT)) {
* @brief Unit tests of utils
*/
+#include "config.hpp"
#include "ut.hpp"
#include "utils/fs.hpp"
* @brief Unit tests of glib-loop
*/
+#include "config.hpp"
#include "ut.hpp"
#include "utils/latch.hpp"
CallbackGuard guard;
Latch latch;
- Glib::OnTimerEventCallback callback = [&] {
+ Glib::OnTimerEventCallback callback = [&]()->bool {
static unsigned int counter = 0;
latch.set();
if (++counter >= TIMER_NUMBER) {
* @brief Unit tests of utils
*/
+#include "config.hpp"
#include "ut.hpp"
#include "utils/paths.hpp"