-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor/Fix framework tests (config) (#124)
* Use absolute paths -> tests binary doesn't depend on working directory * Add test_directory_setups: Creates for each test setup another directory to allow well-defined environments * Updates usage of Everest::Config constructor * Add setting options in config.yaml files to allow 'custom directories' * Add logging config Signed-off-by: Andreas Heinrich <andreas.heinrich@rwth-aachen.de>
- Loading branch information
Showing
35 changed files
with
367 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Pionix GmbH and Contributors to EVerest | ||
|
||
#include <tests/helpers.hpp> | ||
|
||
#include <boost/uuid/uuid.hpp> | ||
#include <boost/uuid/uuid_generators.hpp> | ||
#include <boost/uuid/uuid_io.hpp> | ||
|
||
namespace Everest { | ||
namespace tests { | ||
|
||
fs::path get_bin_dir() { | ||
return fs::canonical("/proc/self/exe").parent_path(); | ||
} | ||
|
||
} // namespace tests | ||
} // namespace Everest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Pionix GmbH and Contributors to EVerest | ||
#ifndef TESTS_HELPERS_HPP | ||
|
||
#include <filesystem> | ||
|
||
namespace fs = std::filesystem; | ||
|
||
namespace Everest { | ||
namespace tests { | ||
|
||
fs::path get_bin_dir(); | ||
|
||
} // namespace tests | ||
} // namespace Everest | ||
|
||
#endif // TESTS_HELPERS_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,106 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest | ||
// Copyright Pionix GmbH and Contributors to EVerest | ||
#include <catch2/catch_all.hpp> | ||
|
||
#include <framework/everest.hpp> | ||
#include <framework/runtime.hpp> | ||
#include <tests/helpers.hpp> | ||
#include <utils/config.hpp> | ||
|
||
// FIXME: convert the configs, interfaces, etc. used in these tests to yaml | ||
namespace fs = std::filesystem; | ||
|
||
SCENARIO("Check config parser", "[!throws]") { | ||
GIVEN("An empty config") { | ||
Everest::Config config = Everest::Config("../../schemas", "valid/config.yaml", "test_modules", | ||
"test_interfaces", "dummy_types", "", ""); | ||
THEN("It should not contain some module") { | ||
CHECK(!config.contains("some_module")); | ||
SCENARIO("Check RuntimeSetting Constructor", "[!throws]") { | ||
std::string bin_dir = Everest::tests::get_bin_dir().string() + "/"; | ||
GIVEN("An invalid prefix, but a valid config file") { | ||
THEN("It should throw BootException") { | ||
CHECK_THROWS_AS( | ||
Everest::RuntimeSettings(bin_dir + "non-valid-prefix/", bin_dir + "valid_config/config.yaml"), | ||
Everest::BootException); | ||
} | ||
} | ||
|
||
// FIXME (aw): all the exception checks can't distinguish, what the | ||
// real reason was, this needs to be improved (probably | ||
// by proper ExceptionTypes) | ||
GIVEN("An invalid main dir") { | ||
THEN("It should throw Everest::EverestConfigError") { | ||
CHECK_THROWS_AS(Everest::Config("../../schemas", "wrong_maindir", "test_modules", "test_interfaces", | ||
"dummy_types", "", ""), | ||
Everest::EverestConfigError); | ||
GIVEN("A valid prefix, but a non existing config file") { | ||
THEN("It should throw BootException") { | ||
CHECK_THROWS_AS(Everest::RuntimeSettings(bin_dir + "valid_config/", bin_dir + "non-existing-config.yaml"), | ||
Everest::BootException); | ||
} | ||
} | ||
|
||
GIVEN("A non existing config file") { | ||
THEN("It should throw Everest::EverestConfigError") { | ||
CHECK_THROWS_AS(Everest::Config("../../schemas", "missing_config", "test_modules", "test_interfaces", | ||
"dummy_types", "", ""), | ||
Everest::EverestConfigError); | ||
GIVEN("A valid prefix and a valid config file") { | ||
THEN("It should not throw") { | ||
CHECK_NOTHROW(Everest::RuntimeSettings(bin_dir + "valid_config/", bin_dir + "valid_config/config.yaml")); | ||
} | ||
} | ||
|
||
GIVEN("A broken config file") { | ||
GIVEN("A broken yaml file") { | ||
THEN("It should throw") { | ||
CHECK_THROWS(Everest::RuntimeSettings(bin_dir + "broken_yaml/", bin_dir + "broken_yaml/config.yaml")); | ||
} | ||
} | ||
GIVEN("A empty yaml file") { | ||
THEN("It shouldn't throw") { | ||
CHECK_NOTHROW(Everest::RuntimeSettings(bin_dir + "empty_yaml/", bin_dir + "empty_yaml/config.yaml")); | ||
} | ||
} | ||
GIVEN("A empty yaml object file") { | ||
THEN("It shouldn't throw") { | ||
CHECK_NOTHROW( | ||
Everest::RuntimeSettings(bin_dir + "empty_yaml_object/", bin_dir + "empty_yaml_object/config.yaml")); | ||
} | ||
} | ||
GIVEN("A null yaml file") { | ||
THEN("It shouldn't throw") { | ||
CHECK_NOTHROW(Everest::RuntimeSettings(bin_dir + "null_yaml/", bin_dir + "null_yaml/config.yaml")); | ||
} | ||
} | ||
GIVEN("A string yaml file") { | ||
THEN("It should throw Everest::EverestConfigError") { | ||
CHECK_THROWS_AS(Everest::Config("../../schemas", "broken_config/config.yaml", "test_modules", | ||
"test_interfaces", "dummy_types", "", ""), | ||
Everest::EverestConfigError); | ||
CHECK_THROWS_AS(Everest::RuntimeSettings(bin_dir + "string_yaml/", bin_dir + "string_yaml/config.yaml"), | ||
Everest::BootException); | ||
} | ||
} | ||
} | ||
SCENARIO("Check Config Constructor", "[!throws]") { | ||
std::string bin_dir = Everest::tests::get_bin_dir().string() + "/"; | ||
GIVEN("A config without modules") { | ||
std::shared_ptr<Everest::RuntimeSettings> rs = std::make_shared<Everest::RuntimeSettings>( | ||
Everest::RuntimeSettings(bin_dir + "empty_config/", bin_dir + "empty_config/config.yaml")); | ||
Everest::Config config = Everest::Config(rs); | ||
THEN("It should not contain the module some_module") { | ||
CHECK(!config.contains("some_module")); | ||
} | ||
} | ||
|
||
GIVEN("A config file referencing a non existent module") { | ||
std::shared_ptr<Everest::RuntimeSettings> rs = std::make_shared<Everest::RuntimeSettings>( | ||
Everest::RuntimeSettings(bin_dir + "missing_module/", bin_dir + "missing_module/config.yaml")); | ||
THEN("It should throw Everest::EverestConfigError") { | ||
CHECK_THROWS_AS(Everest::Config("../../schemas", "missing_module_config/config.yaml", "test_modules", | ||
"test_interfaces", "dummy_types", "", ""), | ||
Everest::EverestConfigError); | ||
CHECK_THROWS_AS(Everest::Config(rs), Everest::EverestConfigError); | ||
} | ||
} | ||
|
||
// FIXME | ||
GIVEN("A config file using a module with broken manifest") { | ||
GIVEN("A config file using a module with broken manifest (missing meta data)") { | ||
std::shared_ptr<Everest::RuntimeSettings> rs = std::make_shared<Everest::RuntimeSettings>( | ||
Everest::RuntimeSettings(bin_dir + "broken_manifest_1/", bin_dir + "broken_manifest_1/config.yaml")); | ||
THEN("It should throw Everest::EverestConfigError") { | ||
CHECK_THROWS_AS(Everest::Config(rs), Everest::EverestConfigError); | ||
} | ||
} | ||
GIVEN("A config file using a module with broken manifest (empty file)") { | ||
std::shared_ptr<Everest::RuntimeSettings> rs = std::make_shared<Everest::RuntimeSettings>( | ||
Everest::RuntimeSettings(bin_dir + "broken_manifest_2/", bin_dir + "broken_manifest_2/config.yaml")); | ||
THEN("It should throw Everest::EverestConfigError") { | ||
CHECK_THROWS_AS(Everest::Config("../../schemas", "broken_manifest/config.yaml", "broken_manifest/modules", | ||
"test_interfaces", "dummy_types", "", ""), | ||
Everest::EverestConfigError); | ||
// FIXME: an empty manifest breaks the test? | ||
CHECK_THROWS_AS(Everest::Config("../../schemas", "broken_manifest2/config.yaml", "broken_manifest2/modules", | ||
"test_interfaces", "dummy_types", "", ""), | ||
Everest::EverestConfigError); | ||
CHECK_THROWS_AS(Everest::Config(rs), Everest::EverestConfigError); | ||
} | ||
} | ||
|
||
GIVEN("A config file using a module with a valid manifest referencing an invalid interface") { | ||
GIVEN("A config file using a module with an invalid interface (missing " | ||
"interface)") { | ||
std::shared_ptr<Everest::RuntimeSettings> rs = std::make_shared<Everest::RuntimeSettings>( | ||
Everest::RuntimeSettings(bin_dir + "missing_interface/", bin_dir + "missing_interface/config.yaml")); | ||
THEN("It should throw Everest::EverestConfigError") { | ||
CHECK_THROWS_AS(Everest::Config("../../schemas", "valid_manifest_missing_interface/config.yaml", | ||
"valid_manifest_missing_interface/modules", "test_interfaces", | ||
"dummy_types", "", ""), | ||
Everest::EverestConfigError); | ||
CHECK_THROWS_AS(Everest::Config(rs), Everest::EverestConfigError); | ||
} | ||
} | ||
|
||
GIVEN("A valid config") { | ||
std::shared_ptr<Everest::RuntimeSettings> rs = std::make_shared<Everest::RuntimeSettings>( | ||
Everest::RuntimeSettings(bin_dir + "valid_config/", bin_dir + "valid_config/config.yaml")); | ||
THEN("It should not throw at all") { | ||
CHECK_NOTHROW(Everest::Config("../../schemas", "valid_manifest_valid_interface/config.yaml", | ||
"valid_manifest_valid_interface/modules", | ||
"valid_manifest_valid_interface/interfaces", "dummy_types", "", "")); | ||
CHECK_NOTHROW(Everest::Config(rs)); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
active_modules: | ||
test_missing: | ||
module: "TESTBrokenManifest" | ||
settings: | ||
interfaces_dir: "interfaces" | ||
modules_dir: "modules" | ||
types_dir: "types" | ||
errors_dir: "errors" | ||
schemas_dir: "schemas" | ||
www_dir: "www" | ||
logging_config_file: "logging.ini" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
active_modules: | ||
test_missing: | ||
module: "TESTBrokenManifest2" | ||
settings: | ||
interfaces_dir: "interfaces" | ||
modules_dir: "modules" | ||
types_dir: "types" | ||
errors_dir: "errors" | ||
schemas_dir: "schemas" | ||
www_dir: "www" | ||
logging_config_file: "logging.ini" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
active_modules: {} | ||
settings:::: | ||
interfaces_dir: "interfaces" | ||
modules_dir: "modules" | ||
types_dir: "types" | ||
errors_dir: "errors" | ||
schemas_dir: "schemas" | ||
www_dir: "www" | ||
logging_config_file: "logging.ini" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
active_modules: {} | ||
settings: | ||
interfaces_dir: "interfaces" | ||
modules_dir: "modules" | ||
types_dir: "types" | ||
errors_dir: "errors" | ||
schemas_dir: "schemas" | ||
www_dir: "www" | ||
logging_config_file: "logging.ini" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
active_modules: | ||
missing_interface: | ||
module: "TESTMissingInterface" | ||
settings: | ||
interfaces_dir: "interfaces" | ||
modules_dir: "modules" | ||
types_dir: "types" | ||
errors_dir: "errors" | ||
schemas_dir: "schemas" | ||
www_dir: "www" | ||
logging_config_file: "logging.ini" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
active_modules: | ||
test_missing: | ||
module: "TESTMissingModule" | ||
settings: | ||
interfaces_dir: "interfaces" | ||
modules_dir: "modules" | ||
types_dir: "types" | ||
errors_dir: "errors" | ||
schemas_dir: "schemas" | ||
www_dir: "www" | ||
logging_config_file: "logging.ini" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"This is a string!" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
active_modules: {} | ||
settings: | ||
interfaces_dir: "interfaces" | ||
modules_dir: "modules" | ||
types_dir: "types" | ||
errors_dir: "errors" | ||
schemas_dir: "schemas" | ||
www_dir: "www" | ||
logging_config_file: "logging.ini" |
3 changes: 0 additions & 3 deletions
3
tests/test_configs/valid_manifest_missing_interface_config.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
set(SETUP_NAME "broken_manifest_1") | ||
set(PREFIX_DIR ${CMAKE_CURRENT_BINARY_DIR}/${SETUP_NAME}) | ||
|
||
configure_file(test_configs/${SETUP_NAME}_config.yaml ${SETUP_NAME}/config.yaml COPYONLY) | ||
configure_file(test_logging.ini ${SETUP_NAME}/logging.ini COPYONLY) | ||
file(COPY ../schemas/ DESTINATION ${SETUP_NAME}/schemas) | ||
file(COPY test_modules/TESTBrokenManifest1 DESTINATION ${SETUP_NAME}/modules) | ||
file(COPY test_interfaces/test_interface.yaml DESTINATION ${SETUP_NAME}/interfaces) | ||
file(MAKE_DIRECTORY "${PREFIX_DIR}/types") | ||
file(MAKE_DIRECTORY "${PREFIX_DIR}/errors") | ||
file(MAKE_DIRECTORY "${PREFIX_DIR}/www") | ||
file(MAKE_DIRECTORY "${PREFIX_DIR}/etc/everest") | ||
file(MAKE_DIRECTORY "${PREFIX_DIR}/share/everest") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
set(SETUP_NAME "broken_manifest_2") | ||
set(PREFIX_DIR ${CMAKE_CURRENT_BINARY_DIR}/${SETUP_NAME}) | ||
|
||
configure_file(test_configs/${SETUP_NAME}_config.yaml ${SETUP_NAME}/config.yaml COPYONLY) | ||
configure_file(test_logging.ini ${SETUP_NAME}/logging.ini COPYONLY) | ||
file(COPY ../schemas/ DESTINATION ${SETUP_NAME}/schemas) | ||
file(COPY test_modules/TESTBrokenManifest2 DESTINATION ${SETUP_NAME}/modules) | ||
file(COPY test_interfaces/test_interface.yaml DESTINATION ${SETUP_NAME}/interfaces) | ||
file(MAKE_DIRECTORY "${PREFIX_DIR}/types") | ||
file(MAKE_DIRECTORY "${PREFIX_DIR}/errors") | ||
file(MAKE_DIRECTORY "${PREFIX_DIR}/interfaces") | ||
file(MAKE_DIRECTORY "${PREFIX_DIR}/www") | ||
file(MAKE_DIRECTORY "${PREFIX_DIR}/etc/everest") | ||
file(MAKE_DIRECTORY "${PREFIX_DIR}/share/everest") |
Oops, something went wrong.