Skip to content

Commit

Permalink
iox-558 Added noexcept to every method. Changed the commandline Parse…
Browse files Browse the repository at this point in the history
…r output such that it is easier readable. Changed the include guards to the Iceoryx Format.

Signed-off-by: Mueller Julian (CC-AD/EYF1) <[email protected]>
  • Loading branch information
JMueIIer committed Apr 21, 2021
1 parent 31d376e commit b8f0476
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 116 deletions.
69 changes: 28 additions & 41 deletions iceoryx_posh/test/fuzztests/cmdlineparserfuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <string>

iox::log::LogLevel m_logLevel{iox::log::LogLevel::kOff};
CmdLineParserFuzzing::CmdLineParserFuzzing()
CmdLineParserFuzzing::CmdLineParserFuzzing() noexcept
{
m_fuzzingAPI = FuzzingApi::NONE;
m_inputMode = InputMode::NONE;
Expand All @@ -35,37 +35,37 @@ CmdLineParserFuzzing::CmdLineParserFuzzing()
m_tomlFile = "";
}

bool CmdLineParserFuzzing::getHelpFlag()
bool CmdLineParserFuzzing::getHelpFlag() noexcept
{
return m_helpFlag;
}

InputMode CmdLineParserFuzzing::getInputMode()
InputMode CmdLineParserFuzzing::getInputMode() noexcept
{
return m_inputMode;
}

bool CmdLineParserFuzzing::getErrorFlag()
bool CmdLineParserFuzzing::getErrorFlag() noexcept
{
return m_errorFlag;
}

bool CmdLineParserFuzzing::getCmdLineFlag()
bool CmdLineParserFuzzing::getCmdLineFlag() noexcept
{
return m_cmdLineFlag;
}

FuzzingApi CmdLineParserFuzzing::getFuzzingAPI()
FuzzingApi CmdLineParserFuzzing::getFuzzingAPI() noexcept
{
return m_fuzzingAPI;
}

bool CmdLineParserFuzzing::getTomlFileFlag()
bool CmdLineParserFuzzing::getTomlFileFlag() noexcept
{
return m_tomlFileFlag;
}

std::string CmdLineParserFuzzing::getTomlFile()
std::string CmdLineParserFuzzing::getTomlFile() noexcept
{
return m_tomlFile;
}
Expand All @@ -91,37 +91,23 @@ std::vector<std::string> CmdLineParserFuzzing::parseCmd(int argc, char* argv[])
case 'h':
{
std::cout << "Usage: " << argv[0] << " [options]" << std::endl;
std::cout << "Options:" << std::endl;
std::cout << "-h, --help" << std::endl;
std::cout << "\tDisplay help." << std::endl;
std::cout << "-f, --fuzzing-api <API>" << std::endl;
std::cout << "\tSpecify API which will be fuzzed." << std::endl;
std::cout << "\t<API> {uds, com, toml}" << std::endl;
std::cout << "\t\tuds: Starts RouDi and sends messages via Unix Domain Sockets. Multiple messages can be "
"sent. (e.g.: register message first and then offer service)."
<< std::endl;
std::cout << "\t\tcom: Invokes the processMessage method in RouDi directly. This abstracts the IPC and is "
"faster but multiple messages are not supported."
<< std::endl;
std::cout << "\t\ttoml: Send inputs to test the TOML config file parser. A file is created in your current "
"working directory and the path is sent to the parser."
<< std::endl;
std::cout << "-m, --input-mode <MODE>" << std::endl;
std::cout << "\t<MODE> {stdin, cl}" << std::endl;
std::cout << "\t\tstdin: Send input via stdin." << std::endl;
std::cout << "\t\tcl: Send input via command line. Needs parameter i to send the input." << std::endl;
std::cout << "-c, --command-line-file <PATH_TO_FILE>" << std::endl;
std::cout << "\t<PATH_TO_FILE> Read the specified file and send the input to the interface." << std::endl;
std::cout << "-i, --command-line-input <INPUT>" << std::endl;
std::cout << "\t<INPUT> Send the input via this command line, requires to use input-mode cl. It's possible "
"to send several commands with several -i commands."
<< std::endl;
std::cout << "-t, --toml-file <PATH_TO_FILE>" << std::endl;
std::cout << "\t<PATH_TO_FILE> Needs to be used when TOML is parsed. The file is used to write messages "
"which will be parsed by the TOML configuration parser."
<< std::endl;
std::cout << "-l, --log-level" << std::endl;
std::cout << "\t<LogLevel> {off, fatal, debug} : Set the log level. Off is default;" << std::endl;
std::cout << R"(
Options:
-h, --help Display this help message.
-f, --fuzzing-api <API> Specify API which will be fuzzed.
<API> {uds, com, toml}
uds: Starts RouDi and sends messages via Unix Domain Sockets. Multiple messages can be sent. (e.g.: register message first and then offer service).
com: Invokes the processMessage method in RouDi directly. This abstracts the IPC and is faster but multiple messages are not supported.
toml: Send inputs to test the TOML config file parser. A file is created in your current working directory and the path is sent to the parser.
-m, --input-mode <MODE> <MODE> {stdin, cl}
stdin: Send input via stdin.
cl: Send input via command line. Needs parameter i to send the input.
-c, --command-line-file <PATH_TO_FILE> <PATH_TO_FILE> Read the specified file and send the input to the interface.
-i, --command-line-input <INPUT> <INPUT> Send the input via this command line, requires to use input-mode cl. It's possible to send several commands with several -i commands.
-t, --toml-file <PATH_TO_FILE> <PATH_TO_FILE> Needs to be used when TOML is parsed. The file is used to write messages which will be parsed by the TOML configuration parser.
-l, --log-level <LogLevel> {off, fatal, debug} : Set the log level. Off is default
)";

m_helpFlag = true;
break;
}
Expand Down Expand Up @@ -187,7 +173,8 @@ std::vector<std::string> CmdLineParserFuzzing::parseCmd(int argc, char* argv[])
else
{
std::cout
<< "Error cannot open file. Either file does not exist or I don't have the permissions to open it.";
<< "Error cannot open file. Either file does not exist or I don't have the permissions to open it."
<< std::endl;
m_errorFlag = true;
return m_allMessages;
}
Expand Down Expand Up @@ -222,7 +209,7 @@ std::vector<std::string> CmdLineParserFuzzing::parseCmd(int argc, char* argv[])
}
default:
{
std::cout << "Unknown command.\n" << std::endl;
std::cout << "Unknown command." << std::endl;
m_errorFlag = true;
return m_allMessages;
}
Expand Down
22 changes: 11 additions & 11 deletions iceoryx_posh/test/fuzztests/cmdlineparserfuzzing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef CMDLINEPARSERFUZZING_HPP
#define CMDLINEPARSERFUZZING_HPP
#ifndef IOX_POSH_FUZZTESTS_CMDLINEPARSERFUZZING_HPP
#define IOX_POSH_FUZZTESTS_CMDLINEPARSERFUZZING_HPP

#include <string>
#include <vector>
Expand All @@ -40,7 +40,7 @@ enum class InputMode
class CmdLineParserFuzzing
{
public:
CmdLineParserFuzzing();
CmdLineParserFuzzing() noexcept;

/// @brief Parses the command line parameters which are entered by starting the fuzz wrappers
/// @param[in] amount of arguments given to the method
Expand All @@ -50,32 +50,32 @@ class CmdLineParserFuzzing

/// @brief Getter to return m_helpFlag
/// @param[out] Containing a flag showing if the help menu was displayed.
bool getHelpFlag();
bool getHelpFlag() noexcept;

/// @brief Getter to return m inputMode
/// @param[out] Containing enum InputMode to show if messages are sent to the API via stdin or command line (cl).
InputMode getInputMode();
InputMode getInputMode() noexcept;

/// @brief Getter to return m_errorFlag
/// @param[out] Containing a flag showing if an error happened and fuzzing cannot be started
bool getErrorFlag();
bool getErrorFlag() noexcept;

/// @brief Getter to return m_cmdLineFlag
/// @param[out] Containing a flag showing if a command line parameter was given after InputMode::CL was set
bool getCmdLineFlag();
bool getCmdLineFlag() noexcept;

/// @brief Getter to return m_fuzzingAPI
/// @param[out] Containing enum FuzzingFlag indicating which API wants to be fuzzed.
FuzzingApi getFuzzingAPI();
FuzzingApi getFuzzingAPI() noexcept;

/// @brief Getter to return m_tomlFileFlag
/// @param[out] Containing a flag showing if TOML API wants to be fuzzed.
bool getTomlFileFlag();
bool getTomlFileFlag() noexcept;

/// @brief Getter to return m_tomlFile
/// @param[out] Containing an std::string to a file which can be used to temporarily write a TOML configuration to
/// the file.
std::string getTomlFile();
std::string getTomlFile() noexcept;

private:
bool m_errorFlag;
Expand All @@ -87,4 +87,4 @@ class CmdLineParserFuzzing
std::string m_tomlFile;
std::vector<std::string> m_allMessages;
};
#endif // CMDLINEPARSERFUZZING_HPP
#endif // IOX_POSH_FUZZTESTS_CMDLINEPARSERFUZZING_HPP
8 changes: 4 additions & 4 deletions iceoryx_posh/test/fuzztests/fuzz_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "iceoryx_posh/roudi/iceoryx_roudi_components.hpp"


std::vector<std::string> FuzzHelper::getStdInMessages()
std::vector<std::string> FuzzHelper::getStdInMessages() noexcept
{
std::vector<std::string> stdInMessages;
for (std::string line; std::getline(std::cin, line);)
Expand All @@ -29,7 +29,7 @@ std::vector<std::string> FuzzHelper::getStdInMessages()
return stdInMessages;
}

std::shared_ptr<RouDiFuzz> FuzzHelper::startRouDiThread()
std::shared_ptr<RouDiFuzz> FuzzHelper::startRouDiThread() noexcept
{
static iox::roudi::IceOryxRouDiComponents m_rouDiComponents(iox::RouDiConfig_t().setDefaults());
static iox::RouDiConfig_t m_config = iox::RouDiConfig_t().setDefaults();
Expand All @@ -38,7 +38,7 @@ std::shared_ptr<RouDiFuzz> FuzzHelper::startRouDiThread()
return aRouDi;
}

bool FuzzHelper::checkIsRouDiRunning()
bool FuzzHelper::checkIsRouDiRunning() noexcept
{
Fuzzing aFuzzer;
int udsStatus = aFuzzer.fuzzingRouDiUDS("Hello Roudi!");
Expand All @@ -52,7 +52,7 @@ bool FuzzHelper::checkIsRouDiRunning()
}
}

std::vector<std::string> FuzzHelper::combineString(std::vector<std::string> allMessages)
std::vector<std::string> FuzzHelper::combineString(std::vector<std::string> allMessages) noexcept
{
std::string tempString = "";
for (std::string aMessage : allMessages)
Expand Down
14 changes: 7 additions & 7 deletions iceoryx_posh/test/fuzztests/fuzz_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef FUZZHELPER_HPP
#define FUZZHELPER_HPP
#ifndef IOX_POSH_FUZZTESTS_FUZZHELPER_HPP
#define IOX_POSH_FUZZTESTS_FUZZHELPER_HPP

#include "roudi_fuzz.hpp"
#include <memory>
Expand All @@ -29,23 +29,23 @@ class FuzzHelper
/// @param[out] std::vector containing std::strings of the messages from stdin. Each std::string in the vector
/// is one line of stdin. This means that if there is one newline in stdin, there will be two std::strings, with two
/// newlines, there will be three messages,...
std::vector<std::string> getStdInMessages();
std::vector<std::string> getStdInMessages() noexcept;

/// @brief a shared Ptr to a RouDi thread which will be used to keep the thread alive until the message is
/// processed by RouDi
/// @param[out] a shated_ptr to RouDiFuzz which inherits from RouDi
std::shared_ptr<RouDiFuzz> startRouDiThread();
std::shared_ptr<RouDiFuzz> startRouDiThread() noexcept;

/// @brief Splitted messages in allMessages are put together as one String. This is used for TOML parser for
/// example because one message can contain newlines
/// @param[in] std::vector containing several std::string messages which shall be sent to an interface
/// @param[out] std::vector containing one std::string message
std::vector<std::string> combineString(std::vector<std::string> allMessages);
std::vector<std::string> combineString(std::vector<std::string> allMessages) noexcept;

/// @brief A method to check if RouDi is alive. It checks if the UDS is available and then sends a default message
/// to RouDi
/// @param[out] Boolean value indicating if RouDi is available
bool checkIsRouDiRunning();
bool checkIsRouDiRunning() noexcept;
};

#endif /*FUZZHELPER_HPP*/
#endif /*IOX_POSH_FUZZTESTS_FUZZHELPER_HPP*/
8 changes: 4 additions & 4 deletions iceoryx_posh/test/fuzztests/fuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

std::string const UDS_NAME = "/tmp/";

Fuzzing::Fuzzing()
Fuzzing::Fuzzing() noexcept
{
}

void Fuzzing::fuzzingRouDiCom(std::shared_ptr<RouDiFuzz> aRouDi, std::string aMessage)
void Fuzzing::fuzzingRouDiCom(std::shared_ptr<RouDiFuzz> aRouDi, std::string aMessage) noexcept
{
if (aRouDi != nullptr)
{
Expand All @@ -40,7 +40,7 @@ void Fuzzing::fuzzingRouDiCom(std::shared_ptr<RouDiFuzz> aRouDi, std::string aMe
}
}

int Fuzzing::fuzzingRouDiUDS(std::string aMessage)
int Fuzzing::fuzzingRouDiUDS(std::string aMessage) noexcept
{
int sockfd = socket(AF_LOCAL, SOCK_DGRAM, 0);
struct sockaddr aSockAddr;
Expand All @@ -63,7 +63,7 @@ int Fuzzing::fuzzingRouDiUDS(std::string aMessage)
}


void Fuzzing::fuzzingTOMLParser(std::string aMessage, std::string tempFile)
void Fuzzing::fuzzingTOMLParser(std::string aMessage, std::string tempFile) noexcept
{
std::ofstream aTomlFile;
aTomlFile.open(tempFile);
Expand Down
14 changes: 7 additions & 7 deletions iceoryx_posh/test/fuzztests/fuzzing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef FUZZING_HPP
#define FUZZING_HPP
#ifndef IOX_POSH_FUZZTESTS_FUZZING_HPP
#define IOX_POSH_FUZZTESTS_FUZZING_HPP

#include "roudi_fuzz.hpp"
#include <memory>
Expand All @@ -25,27 +25,27 @@
class Fuzzing
{
public:
Fuzzing();
Fuzzing() noexcept;

/// @brief fuzzingRouDiCom is a method to test the processMessage method of RouDi. It shall be independent from
/// the underlying protocol such as uds. It should also be slightly faster since some functions are not invoked
/// compared to uds fuzzing. However, a RouDi thread is also started with this approach because otherwise it was not
/// be possible to invoke the processMessage method within RouDi without directly modifying the code in RouDi.
/// @param[in] shared_ptr to RouDiFuzz such that processMessage can be invoked
/// @param[in] std::string containing a message which shall be sent to the interface
void fuzzingRouDiCom(std::shared_ptr<RouDiFuzz> aRouDi, std::string aMessage);
void fuzzingRouDiCom(std::shared_ptr<RouDiFuzz> aRouDi, std::string aMessage) noexcept;

/// @brief fuzzingRouDiUDS is a method to test the Unix Domain Socket interface of RouDi. It connects to
/// RouDi's uds and sends the message given as input to RouDi
/// @param[in] std::string containing a message which shall be sent to the interface
/// @param[out] int as result of connect(). If the int = -1 it means that it was not possible to connect to the
/// socket
int fuzzingRouDiUDS(std::string aMessage);
int fuzzingRouDiUDS(std::string aMessage) noexcept;

/// @brief fuzzingTOMLParser is a method to send a message to the TOML parser.
/// @param[in] std::string containing a message which shall be sent to the interface
/// @param[in] std::string containing a valid path to an empty file which will be used to write the tomlFile into.
/// This is necessary because the TOML parser expects a path to a file as input
void fuzzingTOMLParser(std::string tomlFile, std::string tempFile);
void fuzzingTOMLParser(std::string tomlFile, std::string tempFile) noexcept;
};
#endif /* FUZZING_HPP */
#endif /* IOX_POSH_FUZZTESTS_FUZZING_HPP */
3 changes: 1 addition & 2 deletions iceoryx_posh/test/fuzztests/fuzztests_roudi_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "fuzztests_roudi_wrapper.hpp"
#include "cmdlineparserfuzzing.hpp"
#include "fuzz_helper.hpp"
#include "fuzzing.hpp"
Expand All @@ -26,7 +25,7 @@
#include <iostream>
#include <thread>

int main(int argc, char* argv[])
int main(int argc, char* argv[]) noexcept
{
constexpr uint8_t MAX_RETRIES = 50;
constexpr uint64_t WAIT_RETRY_IN_MS = 100;
Expand Down
28 changes: 0 additions & 28 deletions iceoryx_posh/test/fuzztests/fuzztests_roudi_wrapper.hpp

This file was deleted.

Loading

0 comments on commit b8f0476

Please sign in to comment.