Skip to content

Commit

Permalink
iox-eclipse-iceoryx#91 Address review findings: handle default cases …
Browse files Browse the repository at this point in the history
…in switch, rename test cases and carve out constexpr

Signed-off-by: Simon Hoinkis <simon.hoinkis@apex.ai>
  • Loading branch information
mossmaurice committed Dec 14, 2020
1 parent bd1641d commit e12c827
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 12 deletions.
3 changes: 3 additions & 0 deletions iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.inl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ inline iox::log::LogStream& operator<<(iox::log::LogStream& logstream, const Mon
case MonitoringMode::ON:
logstream << "MonitoringMode::ON";
break;
default:
logstream << "MonitoringMode::UNDEFINED";
break;
}
return logstream;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
#include "iceoryx_posh/internal/roudi/roudi_lock.hpp"
#include "iceoryx_posh/internal/runtime/message_queue_interface.hpp"
#include "iceoryx_posh/roudi/memory/iceoryx_roudi_memory_manager.hpp"
#include "iceoryx_utils/cxx/expected.hpp"
#include "iceoryx_utils/cxx/generic_raii.hpp"

namespace iox
{
namespace roudi
{
enum class IceOryxRouDiComponentsError
{
SHARED_MEMORY_UNAVAILABLE
};
struct IceOryxRouDiComponents
{
public:
Expand All @@ -40,11 +45,11 @@ struct IceOryxRouDiComponents
IceOryxRouDiMemoryManager m_rouDiMemoryManager;

/// @brief Handles the ports in shared memory
PortManager m_portManager{initRouDiMemoryManager()};
PortManager m_portManager{initRouDiMemoryManager().value()};

private:
/// @brief Prepare the memory and clean up old ressources
IceOryxRouDiMemoryManager* initRouDiMemoryManager() noexcept;
cxx::expected<IceOryxRouDiMemoryManager*, IceOryxRouDiComponentsError> initRouDiMemoryManager() noexcept;
};
} // namespace roudi
} // namespace iox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ inline iox::log::LogStream& operator<<(iox::log::LogStream& logstream, const ver
case CompatibilityCheckLevel::BUILD_DATE:
logstream << "CompatibilityCheckLevel::BUILD_DATE";
break;
default:
logstream << "CompatibilityCheckLevel::UNDEFINED";
break;
}
return logstream;
}
Expand Down
5 changes: 3 additions & 2 deletions iceoryx_posh/source/roudi/iceoryx_roudi_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace iox
{
namespace roudi
{
IceOryxRouDiMemoryManager* IceOryxRouDiComponents::initRouDiMemoryManager() noexcept
cxx::expected<IceOryxRouDiMemoryManager*, IceOryxRouDiComponentsError>
IceOryxRouDiComponents::initRouDiMemoryManager() noexcept
{
// this temporary object will create a roudi mqueue and close it immediatelly
// if there was an outdated roudi message queue, it will be cleaned up
Expand All @@ -29,7 +30,7 @@ IceOryxRouDiMemoryManager* IceOryxRouDiComponents::initRouDiMemoryManager() noex
LogFatal() << "Could not create SharedMemory! Error: " << error;
errorHandler(Error::kROUDI_COMPONENTS__SHARED_MEMORY_UNAVAILABLE, nullptr, iox::ErrorLevel::FATAL);
});
return &m_rouDiMemoryManager;
return cxx::success<IceOryxRouDiMemoryManager*>(&m_rouDiMemoryManager);
}

} // namespace roudi
Expand Down
3 changes: 3 additions & 0 deletions iceoryx_posh/source/roudi/memory/roudi_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ iox::log::LogStream& operator<<(iox::log::LogStream& logstream, const RouDiMemor
case RouDiMemoryManagerError::MEMORY_DESTRUCTION_FAILED:
logstream << "MEMORY_DESTRUCTION_FAILED";
break;
default:
logstream << "ROUDI_MEMEMORY_ERROR_UNDEFINED";
break;
}
return logstream;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RouDiEnvironment::RouDiEnvironment(BaseCTor, const uint16_t uniqueRouDiId)
}

RouDiEnvironment::RouDiEnvironment(const RouDiConfig_t& roudiConfig,
roudi::MonitoringMode monitoringMode,
const roudi::MonitoringMode monitoringMode,
const uint16_t uniqueRouDiId)
: RouDiEnvironment(BaseCTor::BASE, uniqueRouDiId)
{
Expand Down
4 changes: 3 additions & 1 deletion iceoryx_utils/include/iceoryx_utils/posix_wrapper/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ enum class ThreadErrorType : int32_t
EXCEEDED_RANGE_LIMIT = 0
};

using ThreadName_t = cxx::string<15>;
constexpr uint8_t MAX_THREAD_NAME_LENGTH = 16;

using ThreadName_t = cxx::string<MAX_THREAD_NAME_LENGTH - 1>;

cxx::expected<ThreadErrorType> setThreadName(pthread_t thread, const ThreadName_t& name);
cxx::expected<ThreadName_t, ThreadErrorType> getThreadName(pthread_t thread);
Expand Down
5 changes: 2 additions & 3 deletions iceoryx_utils/source/posix_wrapper/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ cxx::expected<ThreadErrorType> setThreadName(pthread_t thread, const ThreadName_

cxx::expected<ThreadName_t, ThreadErrorType> getThreadName(pthread_t thread)
{
constexpr uint8_t maxCharCountThreadName = 16;
char tempName[maxCharCountThreadName];
char tempName[MAX_THREAD_NAME_LENGTH];
if (cxx::makeSmartC(pthread_getname_np,
cxx::ReturnMode::PRE_DEFINED_SUCCESS_CODE,
{0},
{},
thread,
tempName,
maxCharCountThreadName)
MAX_THREAD_NAME_LENGTH)
.hasErrors())
{
return cxx::error<ThreadErrorType>(ThreadErrorType::EXCEEDED_RANGE_LIMIT);
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_utils/test/moduletests/test_posix_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Thread_test : public Test
std::thread* m_thread;
};

TEST_F(Thread_test, DISABLED_LargeStringIsTruncated)
TEST_F(Thread_test, DISABLED_SetWithLargeStringDoesNotCompile)
{
/// @todo Renable this test, once "does not compile" tests are possible
#if 0
Expand All @@ -71,7 +71,7 @@ TEST_F(Thread_test, DISABLED_LargeStringIsTruncated)
#endif
}

TEST_F(Thread_test, ThreadNameCapacityIsNotTruncated)
TEST_F(Thread_test, SetAndGetWithThreadNameCapacityIsWorking)
{
ThreadName_t stringEqualToThreadNameCapacitiy = "123456789ABCDEF";

Expand All @@ -83,7 +83,7 @@ TEST_F(Thread_test, ThreadNameCapacityIsNotTruncated)
EXPECT_THAT(getResult.value(), StrEq(stringEqualToThreadNameCapacitiy));
}

TEST_F(Thread_test, SmallStringIsNotTruncated)
TEST_F(Thread_test, SetAndGetSmallStringIsWorking)
{
char stringShorterThanThreadNameCapacitiy[] = "I'm short";

Expand Down

0 comments on commit e12c827

Please sign in to comment.