[Feature] Using libLogger in lxcpp in an example clone function.
Set up unit-tests
Changed exception names
[Cause] N/A
[Solution] N/A
[Verification] N/A
Change-Id: I039bf3e17d791ccf1a18f17a9b2a180ee2081722
## Link libraries ##############################################################
INCLUDE_DIRECTORIES(${LIBS_FOLDER})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} Logger)
## Generate the pc file ########################################################
CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_CURRENT_BINARY_DIR}/${PC_FILE} @ONLY)
* @brief ContainerImpl definition
*/
-#include <lxcpp/container-impl.hpp>
-#include <lxcpp/exception.hpp>
+#include "lxcpp/container-impl.hpp"
+#include "lxcpp/exception.hpp"
namespace lxcpp {
std::string ContainerImpl::getName()
{
- throw NotImplemented();
+ throw NotImplementedException();
}
void ContainerImpl::setName(const std::string& /* name */)
{
- throw NotImplemented();
+ throw NotImplementedException();
}
void ContainerImpl::start()
{
- throw NotImplemented();
+ throw NotImplementedException();
}
void ContainerImpl::stop()
{
- throw NotImplemented();
+ throw NotImplementedException();
}
void ContainerImpl::freeze()
{
- throw NotImplemented();
+ throw NotImplementedException();
}
void ContainerImpl::unfreeze()
{
- throw NotImplemented();
+ throw NotImplementedException();
}
void ContainerImpl::reboot()
{
- throw NotImplemented();
+ throw NotImplementedException();
}
int ContainerImpl::getInitPid()
{
- throw NotImplemented();
+ throw NotImplementedException();
}
void ContainerImpl::create()
{
- throw NotImplemented();
+ throw NotImplementedException();
}
void ContainerImpl::destroy()
{
- throw NotImplemented();
+ throw NotImplementedException();
}
void ContainerImpl::setRootPath(const std::string& /* path */)
{
- throw NotImplemented();
+ throw NotImplementedException();
}
-std::string getRootPath()
+std::string ContainerImpl::getRootPath()
{
- throw NotImplemented();
+ throw NotImplementedException();
}
} // namespace lxcpp
#ifndef LXCPP_CONTAINER_IMPL_HPP
#define LXCPP_CONTAINER_IMPL_HPP
-#include <lxcpp/container.hpp>
+#include "lxcpp/container.hpp"
namespace lxcpp {
class Container {
public:
- virtual ~Container();
+ virtual ~Container() {};
virtual std::string getName() = 0;
virtual void setName(const std::string& name) = 0;
namespace lxcpp {
-class ContainerException : std::runtime_error
-{
-public:
- ContainerException(const std::string& what) : std::runtime_error(what) {}
+/**
+ * Base class for exceptions in lxcpp
+ */
+struct Exception: public std::runtime_error {
+ Exception(const std::string& message)
+ : std::runtime_error(message) {}
};
-class NotImplemented : ContainerException
-{
-public:
- NotImplemented() : ContainerException(std::string()) {}
+struct NotImplementedException: public Exception {
+ NotImplementedException(const std::string& message = "Functionality not yet implemented")
+ : Exception(message) {}
};
+struct ProcessSetupException: public Exception {
+ ProcessSetupException(const std::string& message = "Error during setting up a process")
+ : Exception(message) {}
+};
} // namespace lxcpp
#endif // LXCPP_EXCEPTION_HPP
* @brief lxcpp container factory definition
*/
-#include <lxcpp/container-impl.hpp>
+#include "lxcpp/container-impl.hpp"
namespace lxcpp {
/**
* @file
* @author Mateusz Malicki (m.malicki2@samsung.com)
- * @brief LXCpp factory declaration
+ * @brief lxcpp container factory
*/
#ifndef LXCPP_LXCPP_HPP
#define LXCPP_LXCPP_HPP
-#include <lxcpp/container.hpp>
+#include "lxcpp/container.hpp"
namespace lxcpp {
--- /dev/null
+/*
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * @author Jan Olszak (j.olszak@samsung.com)
+ * @brief process handling routines
+ */
+
+#include "lxcpp/process.hpp"
+#include "lxcpp/exception.hpp"
+#include "logger/logger.hpp"
+
+#include <alloca.h>
+#include <sched.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+namespace lxcpp {
+
+pid_t clone(int (*function)(void *), int flags, void *args) {
+ // Won't fail, well known resource name
+ size_t stackSize = ::sysconf(_SC_PAGESIZE);
+
+ // PAGESIZE is enough, it'll exec after this
+ char *stack = static_cast<char*>(::alloca(stackSize));
+
+ pid_t ret;
+ ret = ::clone(function, stack + stackSize, flags | SIGCHLD, args);
+ if (ret < 0) {
+ LOGE("clone() failed");
+ throw ProcessSetupException("clone() failed");
+ }
+
+ return ret;
+}
+
+} // namespace lxcpp
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * @author Jan Olszak (j.olszak@samsung.com)
+ * @brief process handling routines
+ */
+
+#ifndef LXCPP_PROCESS_HPP
+#define LXCPP_PROCESS_HPP
+
+#include <sys/types.h>
+
+namespace lxcpp {
+
+pid_t clone(int (*function)(void *), int flags, void *args);
+
+} // namespace lxcpp
+
+#endif // LXCPP_PROCESS_HPP
\ No newline at end of file
)
TARGET_LINK_LIBRARIES(${UT_SERVER_CODENAME} ${UT_SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES}
- Logger Config Ipc)
+ Logger Config Ipc lxcpp)
IF(NOT WITHOUT_DBUS)
TARGET_LINK_LIBRARIES(${UT_SERVER_CODENAME} SimpleDbus)
ENDIF(NOT WITHOUT_DBUS)
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Piotr Bartosiewicz <p.bartosiewi@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 Jan Olszak(j.olszak@samsung.com)
+ * @brief Unit tests of lxcpp Container class
+ */
+
+#include "config.hpp"
+#include "ut.hpp"
+
+#include "lxcpp/lxcpp.hpp"
+#include "lxcpp/exception.hpp"
+
+#include <memory>
+
+namespace {
+
+struct Fixture {
+ Fixture() {}
+ ~Fixture() {}
+};
+
+} // namespace
+
+BOOST_FIXTURE_TEST_SUITE(LxcppContainerSuite, Fixture)
+
+using namespace lxcpp;
+
+BOOST_AUTO_TEST_CASE(ConstructorDestructor)
+{
+ auto c = createContainer();
+ delete c;
+}
+
+BOOST_AUTO_TEST_SUITE_END()