Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iox #454 create test file for iceoryx roudi and roudi app #587

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions iceoryx_posh/source/roudi/application/roudi_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// 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.
//
// SPDX-License-Identifier: Apache-2.0
marthtz marked this conversation as resolved.
Show resolved Hide resolved

#include "iceoryx_posh/roudi/roudi_app.hpp"

Expand Down
182 changes: 182 additions & 0 deletions iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// Copyright (c) 2021 by Robert Bosch GmbH. All rights reserved.
//
// 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.
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_posh/internal/log/posh_logging.hpp"
#include "iceoryx_posh/roudi/iceoryx_roudi_app.hpp"
#include "iceoryx_posh/roudi/roudi_cmd_line_parser_config_file_option.hpp"
#include "iceoryx_posh/roudi/roudi_config_toml_file_provider.hpp"

#include "test.hpp"

using namespace ::testing;
using ::testing::Return;

using iox::roudi::IceOryxRouDiApp;
using namespace iox::config;

namespace iox
{
namespace test
{
class IceoryxRoudiApp_Child : public IceOryxRouDiApp
{
public:
IceoryxRoudiApp_Child(const config::CmdLineArgs_t& cmdLineArgs, const RouDiConfig_t& roudiConfig)
: IceOryxRouDiApp(cmdLineArgs, roudiConfig)
{
}

bool getVariableRun()
{
return m_run;
}

iox::log::LogLevel getLogLevel()
{
return m_logLevel;
}

roudi::MonitoringMode getMonitoringMode()
{
return m_monitoringMode;
}

RouDiConfig_t getConfig()
{
return m_config;
}

void setVariableRun(bool condition)
{
m_run = condition;
}

uint8_t callRun() noexcept
{
return run();
}
};

/// @brief Test goal: This file tests class roudi app
class IceoryxRoudiApp_test : public Test
{
public:
CmdLineParserConfigFileOption cmdLineParser;

void TearDown()
{
// Reset optind to be able to parse again
optind = 0;
marthtz marked this conversation as resolved.
Show resolved Hide resolved
};
};

TEST_F(IceoryxRoudiApp_test, VerifyConstructorIsSuccessfull)
marthtz marked this conversation as resolved.
Show resolved Hide resolved
{
constexpr uint8_t numberOfArgs{1U};
marthtz marked this conversation as resolved.
Show resolved Hide resolved
char* args[numberOfArgs];
char appName[] = "./foo";
args[0] = &appName[0];

auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args);

IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults());
marthtz marked this conversation as resolved.
Show resolved Hide resolved

EXPECT_TRUE(roudi.getVariableRun());
EXPECT_THAT(roudi.getLogLevel(), Eq(iox::log::LogLevel::kWarn));
EXPECT_THAT(roudi.getMonitoringMode(), Eq(roudi::MonitoringMode::ON));
}

TEST_F(IceoryxRoudiApp_test, CreateTwoRoudiAppIsSuccessfull)
{
constexpr uint8_t numberOfArgs{1U};
char* args[numberOfArgs];
char appName[] = "./foo";
args[0] = &appName[0];

auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args);

IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults());
Copy link
Contributor

@elfenpiff elfenpiff Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do not want this kind of behavior or is there a use case that the RoudiApp should be instantiated twice in the same process?! @budrus

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this come from the current implementation. The RouDiLock is located in IceOryxRouDiComponents.
The Components are only instantiated when you call IceOryxRouDiApp::run(). Here in this case only the class is instantiated... Maybe the lock should be relocated to fire earlier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, nothing bad happens until run is called, so this is no problem. What's instantiated is just a small shell around some configuration data, the actual roudi is created in run

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the lock's description is Locks the socket for preventing multiple start of RouDi, so, is the intention just to prevent run or to instantiate it? In case of run-only another test for that is missing?!

Copy link
Member

@elBoberido elBoberido Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from my point of view it should only be run, else you cannot execute ./iox-roudi -v anymore when RouDi is running. All the stuff that can break if two instances are running happens in the run method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense and I'm fine with that. So, is the PR complete now or should a 2nd run be tested?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in the dev meeting, a test for a 2nd run will be done in #621.


IceoryxRoudiApp_Child roudiTest(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults());

EXPECT_TRUE(roudiTest.getVariableRun());
}

TEST_F(IceoryxRoudiApp_test, VerifyRunMethodWithFalseConditionReturnExitSuccess)
{
constexpr uint8_t numberOfArgs{1U};
char* args[numberOfArgs];
char appName[] = "./foo";
args[0] = &appName[0];

auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args);

IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults());

roudi.setVariableRun(false);

uint8_t result = roudi.callRun();

EXPECT_EQ(result, EXIT_SUCCESS);
}

TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgUniqueIdTwoTimesReturnError)
{
constexpr uint8_t numberOfArgs{3U};
char* args[numberOfArgs];
char appName[] = "./foo";
char option[] = "--unique-roudi-id";
char value[] = "4242";
args[0] = &appName[0];
args[1] = &option[0];
args[2] = &value[0];

auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args);

iox::cxx::optional<iox::Error> detectedError;
auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler(
[&detectedError](const iox::Error error, const std::function<void()>, const iox::ErrorLevel errorLevel) {
detectedError.emplace(error);
EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE));
});

IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults());

IceoryxRoudiApp_Child roudiTest(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults());

ASSERT_THAT(detectedError.has_value(), Eq(true));
EXPECT_THAT(detectedError.value(), Eq(iox::Error::kPOPO__TYPED_UNIQUE_ID_ROUDI_HAS_ALREADY_DEFINED_UNIQUE_ID));
}

TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgVersionSetRunVariableToFalse)
{
constexpr uint8_t numberOfArgs{2U};
char* args[numberOfArgs];
char appName[] = "./foo";
char option[] = "-v";
args[0] = &appName[0];
args[1] = &option[0];

auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args);

IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults());

EXPECT_FALSE(roudi.getVariableRun());
}

marthtz marked this conversation as resolved.
Show resolved Hide resolved

} // namespace test
} // namespace iox