mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-13 19:38:42 +01:00
fixed multi receiver and frames sync help throw of bad variant access (#1266)
This commit is contained in:
@@ -34,13 +34,16 @@ ParsedOptions CommandLineOptions::parse(int argc, char *argv[]) {
|
|||||||
optind = 0; // reset getopt
|
optind = 0; // reset getopt
|
||||||
int opt, option_index = 0;
|
int opt, option_index = 0;
|
||||||
|
|
||||||
|
bool help_or_version_requested = false;
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, optString_.c_str(),
|
while ((opt = getopt_long(argc, argv, optString_.c_str(),
|
||||||
longOptions_.data(), &option_index)) != -1) {
|
longOptions_.data(), &option_index)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'v':
|
case 'v':
|
||||||
case 'h':
|
case 'h':
|
||||||
handleCommonOption(opt, optarg, base);
|
handleCommonOption(opt, optarg, base);
|
||||||
return base; // exit after version/help
|
help_or_version_requested = true;
|
||||||
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
case 'u':
|
case 'u':
|
||||||
handleCommonOption(opt, optarg, base);
|
handleCommonOption(opt, optarg, base);
|
||||||
@@ -56,7 +59,7 @@ ParsedOptions CommandLineOptions::parse(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remaining arguments
|
// remaining arguments
|
||||||
if (optind < argc) {
|
if (!help_or_version_requested && optind < argc) {
|
||||||
|
|
||||||
// deprecated and current options => invalid
|
// deprecated and current options => invalid
|
||||||
if (base.port != DEFAULT_TCP_RX_PORTNO || multi.numReceivers != 1 ||
|
if (base.port != DEFAULT_TCP_RX_PORTNO || multi.numReceivers != 1 ||
|
||||||
@@ -87,6 +90,7 @@ ParsedOptions CommandLineOptions::parse(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
|
if (!help_or_version_requested) {
|
||||||
LOG(sls::logINFO) << "TCP Port: " << base.port;
|
LOG(sls::logINFO) << "TCP Port: " << base.port;
|
||||||
if (appType_ == AppType::MultiReceiver) {
|
if (appType_ == AppType::MultiReceiver) {
|
||||||
LOG(sls::logINFO) << "Number of receivers: " << multi.numReceivers;
|
LOG(sls::logINFO) << "Number of receivers: " << multi.numReceivers;
|
||||||
@@ -95,6 +99,7 @@ ParsedOptions CommandLineOptions::parse(int argc, char *argv[]) {
|
|||||||
LOG(sls::logINFO) << "Number of receivers: " << frame.numReceivers;
|
LOG(sls::logINFO) << "Number of receivers: " << frame.numReceivers;
|
||||||
LOG(sls::logINFO) << "Print headers: " << frame.printHeaders;
|
LOG(sls::logINFO) << "Print headers: " << frame.printHeaders;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (appType_) {
|
switch (appType_) {
|
||||||
case AppType::SingleReceiver:
|
case AppType::SingleReceiver:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
#include "CommandLineOptions.h"
|
#include "CommandLineOptions.h"
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
#include "sls/logger.h"
|
||||||
#include "sls/versionAPI.h"
|
#include "sls/versionAPI.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -12,7 +13,7 @@ template <typename T, typename U> constexpr bool is_type() {
|
|||||||
return std::is_same_v<std::decay_t<U>, T>;
|
return std::is_same_v<std::decay_t<U>, T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("CommandLineOption construction", "[.rxcmdcall]") {
|
TEST_CASE("CommandLineOption construction", "[detector]") {
|
||||||
CommandLineOptions s(AppType::SingleReceiver);
|
CommandLineOptions s(AppType::SingleReceiver);
|
||||||
REQUIRE(s.getTypeString() == "slsReceiver");
|
REQUIRE(s.getTypeString() == "slsReceiver");
|
||||||
REQUIRE(s.getVersion() ==
|
REQUIRE(s.getVersion() ==
|
||||||
@@ -32,7 +33,22 @@ TEST_CASE("CommandLineOption construction", "[.rxcmdcall]") {
|
|||||||
REQUIRE_NOTHROW(f.getHelpMessage());
|
REQUIRE_NOTHROW(f.getHelpMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Validate common options", "[.rxcmdcall]") {
|
TEST_CASE("Parse Help", "[detector]") {
|
||||||
|
for (auto app : {AppType::SingleReceiver, AppType::MultiReceiver,
|
||||||
|
AppType::FrameSynchronizer}) {
|
||||||
|
CommandLineOptions s(app);
|
||||||
|
ParsedOptions opts = s.parse({"", "-h"});
|
||||||
|
if (app == AppType::SingleReceiver) {
|
||||||
|
REQUIRE_NOTHROW(std::get<CommonOptions>(opts).helpRequested);
|
||||||
|
} else if (app == AppType::MultiReceiver) {
|
||||||
|
REQUIRE_NOTHROW(std::get<MultiReceiverOptions>(opts).helpRequested);
|
||||||
|
} else if (app == AppType::FrameSynchronizer) {
|
||||||
|
REQUIRE_NOTHROW(std::get<FrameSyncOptions>(opts).helpRequested);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate common options", "[detector]") {
|
||||||
std::string uidStr = std::to_string(getuid());
|
std::string uidStr = std::to_string(getuid());
|
||||||
|
|
||||||
for (auto app : {AppType::SingleReceiver, AppType::MultiReceiver,
|
for (auto app : {AppType::SingleReceiver, AppType::MultiReceiver,
|
||||||
@@ -48,7 +64,7 @@ TEST_CASE("Validate common options", "[.rxcmdcall]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Validate specific options", "[.rxcmdcall]") {
|
TEST_CASE("Validate specific options", "[detector]") {
|
||||||
std::string uidStr = std::to_string(getuid());
|
std::string uidStr = std::to_string(getuid());
|
||||||
|
|
||||||
CommandLineOptions s(AppType::SingleReceiver);
|
CommandLineOptions s(AppType::SingleReceiver);
|
||||||
@@ -68,7 +84,7 @@ TEST_CASE("Validate specific options", "[.rxcmdcall]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse version and help", "[.rxcmdcall]") {
|
TEST_CASE("Parse version and help", "[detector]") {
|
||||||
for (auto app : {AppType::SingleReceiver, AppType::MultiReceiver,
|
for (auto app : {AppType::SingleReceiver, AppType::MultiReceiver,
|
||||||
AppType::FrameSynchronizer}) {
|
AppType::FrameSynchronizer}) {
|
||||||
CommandLineOptions s(app);
|
CommandLineOptions s(app);
|
||||||
@@ -99,7 +115,7 @@ TEST_CASE("Parse version and help", "[.rxcmdcall]") {
|
|||||||
opts = s.parse({"", "-h", "-v"});
|
opts = s.parse({"", "-h", "-v"});
|
||||||
std::visit(
|
std::visit(
|
||||||
[](const auto &o) {
|
[](const auto &o) {
|
||||||
REQUIRE(o.versionRequested == false); // exits after help
|
REQUIRE(o.versionRequested == true);
|
||||||
REQUIRE(o.helpRequested == true);
|
REQUIRE(o.helpRequested == true);
|
||||||
},
|
},
|
||||||
opts);
|
opts);
|
||||||
@@ -107,7 +123,7 @@ TEST_CASE("Parse version and help", "[.rxcmdcall]") {
|
|||||||
opts = s.parse({"", "-v", "-h"});
|
opts = s.parse({"", "-v", "-h"});
|
||||||
std::visit(
|
std::visit(
|
||||||
[](const auto &o) {
|
[](const auto &o) {
|
||||||
REQUIRE(o.helpRequested == false); // exits after version
|
REQUIRE(o.helpRequested == true);
|
||||||
REQUIRE(o.versionRequested == true);
|
REQUIRE(o.versionRequested == true);
|
||||||
},
|
},
|
||||||
opts);
|
opts);
|
||||||
@@ -115,14 +131,14 @@ TEST_CASE("Parse version and help", "[.rxcmdcall]") {
|
|||||||
opts = s.parse({"", "-v", "-h", "sdfsf"}); // ignores extra args
|
opts = s.parse({"", "-v", "-h", "sdfsf"}); // ignores extra args
|
||||||
std::visit(
|
std::visit(
|
||||||
[](const auto &o) {
|
[](const auto &o) {
|
||||||
REQUIRE(o.helpRequested == false); // exits after version
|
REQUIRE(o.helpRequested == true);
|
||||||
REQUIRE(o.versionRequested == true);
|
REQUIRE(o.versionRequested == true);
|
||||||
},
|
},
|
||||||
opts);
|
opts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse port and uid", "[.rxcmdcall]") {
|
TEST_CASE("Parse port and uid", "[detector]") {
|
||||||
uid_t uid = getuid();
|
uid_t uid = getuid();
|
||||||
std::string uidStr = std::to_string(uid);
|
std::string uidStr = std::to_string(uid);
|
||||||
uid_t invalidUid = uid + 1000;
|
uid_t invalidUid = uid + 1000;
|
||||||
@@ -161,7 +177,7 @@ TEST_CASE("Parse port and uid", "[.rxcmdcall]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse num receivers and opt arg (Specific opt)", "[.rxcmdcall]") {
|
TEST_CASE("Parse num receivers and opt arg (Specific opt)", "[detector]") {
|
||||||
for (auto app : {AppType::MultiReceiver, AppType::FrameSynchronizer}) {
|
for (auto app : {AppType::MultiReceiver, AppType::FrameSynchronizer}) {
|
||||||
CommandLineOptions s(app);
|
CommandLineOptions s(app);
|
||||||
|
|
||||||
@@ -216,7 +232,7 @@ TEST_CASE("Parse num receivers and opt arg (Specific opt)", "[.rxcmdcall]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse deprecated options", "[.rxcmdcall]") {
|
TEST_CASE("Parse deprecated options", "[detector]") {
|
||||||
for (auto app : {AppType::SingleReceiver, AppType::MultiReceiver,
|
for (auto app : {AppType::SingleReceiver, AppType::MultiReceiver,
|
||||||
AppType::FrameSynchronizer}) {
|
AppType::FrameSynchronizer}) {
|
||||||
CommandLineOptions s(app);
|
CommandLineOptions s(app);
|
||||||
|
|||||||
Reference in New Issue
Block a user