Skip to content

0037 kyua: Add requirement resolver concept #40

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
76 changes: 76 additions & 0 deletions contrib/kyua/cli/cmd_prepare.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2024 The Kyua Authors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Google Inc. nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "cli/cmd_prepare.hpp"

#include "cli/common.ipp"
#include "engine/rr/rr.hpp"
#include "utils/cmdline/options.hpp"

namespace cmdline = utils::cmdline;
namespace config = utils::config;
namespace rr = engine::rr;

using cli::cmd_prepare;


/// Default constructor for cmd_prepare.
cmd_prepare::cmd_prepare(void) : cli_command(
"prepare", "[resolver-name ...]", 0, -1,
"Prepare env and resolve requirements before testing")
{
add_option(kyuafile_option);
add_option(build_root_option);
add_option(cmdline::bool_option('n', "dry-run", "Do not alter the system"));
}


/// Entry point for the "prepare" subcommand.
///
/// \param ui Object to interact with the I/O of the program.
/// \param cmdline Representation of the command line to the subcommand.
/// \param user_config The runtime configuration of the program.
///
/// \return 0 if successful, 1 otherwise.
int
cmd_prepare::run(cmdline::ui* ui, const cmdline::parsed_cmdline& cmdline,

Check failure on line 61 in contrib/kyua/cli/cmd_prepare.cpp

View workflow job for this annotation

GitHub Actions / Style Checker

spaces required around that '&' (ctx:VxW)

Check failure on line 61 in contrib/kyua/cli/cmd_prepare.cpp

View workflow job for this annotation

GitHub Actions / Style Checker

spaces required around that '*' (ctx:VxW)
const config::tree& user_config)

Check failure on line 62 in contrib/kyua/cli/cmd_prepare.cpp

View workflow job for this annotation

GitHub Actions / Style Checker

spaces required around that '&' (ctx:VxW)
{
// List available resolvers
if (cmdline.arguments().empty()) {
for (auto r : rr::resolvers()) {
ui->out(r->name(), false);
ui->out("\t\t\t", false);
ui->out(r->description());
}
return EXIT_SUCCESS;

Check failure on line 71 in contrib/kyua/cli/cmd_prepare.cpp

View workflow job for this annotation

GitHub Actions / Style Checker

parentheses required on return
}

// Or run specified ones
return rr::run(cmdline.arguments(), ui, cmdline, user_config);

Check failure on line 75 in contrib/kyua/cli/cmd_prepare.cpp

View workflow job for this annotation

GitHub Actions / Style Checker

parentheses required on return
}
53 changes: 53 additions & 0 deletions contrib/kyua/cli/cmd_prepare.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2024 The Kyua Authors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Google Inc. nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

/// \file cli/cmd_prepare.hpp
/// Provides the cmd_prepare class.

#if !defined(CLI_CMD_PREPARE_HPP)
#define CLI_CMD_PREPARE_HPP

#include "cli/common.hpp"

namespace cli {


/// Implementation of the "prepare" subcommand.
class cmd_prepare : public cli_command
{
public:
cmd_prepare(void);

int run(utils::cmdline::ui*, const utils::cmdline::parsed_cmdline&,

Check failure on line 46 in contrib/kyua/cli/cmd_prepare.hpp

View workflow job for this annotation

GitHub Actions / Style Checker

spaces required around that '&' (ctx:VxO)

Check failure on line 46 in contrib/kyua/cli/cmd_prepare.hpp

View workflow job for this annotation

GitHub Actions / Style Checker

spaces required around that '*' (ctx:VxO)
const utils::config::tree&);

Check failure on line 47 in contrib/kyua/cli/cmd_prepare.hpp

View workflow job for this annotation

GitHub Actions / Style Checker

spaces required around that '&' (ctx:VxB)
};


} // namespace cli

#endif // !defined(CLI_CMD_PREPARE_HPP)
2 changes: 2 additions & 0 deletions contrib/kyua/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extern "C" {
#include "cli/cmd_debug.hpp"
#include "cli/cmd_help.hpp"
#include "cli/cmd_list.hpp"
#include "cli/cmd_prepare.hpp"
#include "cli/cmd_report.hpp"
#include "cli/cmd_report_html.hpp"
#include "cli/cmd_report_junit.hpp"
Expand Down Expand Up @@ -191,6 +192,7 @@ safe_main(cmdline::ui* ui, int argc, const char* const argv[],

commands.insert(new cli::cmd_debug(), "Workspace");
commands.insert(new cli::cmd_list(), "Workspace");
commands.insert(new cli::cmd_prepare(), "Workspace");
commands.insert(new cli::cmd_test(), "Workspace");

commands.insert(new cli::cmd_report(), "Reporting");
Expand Down
2 changes: 2 additions & 0 deletions contrib/kyua/engine/atf_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ engine::parse_atf_metadata(const model::properties_map& props)
mdbuilder.set_string("required_disk_space", value);
} else if (name == "require.files") {
mdbuilder.set_string("required_files", value);
} else if (name == "require.kmods") {
mdbuilder.set_string("required_kmods", value);
} else if (name == "require.machine") {
mdbuilder.set_string("allowed_platforms", value);
} else if (name == "require.memory") {
Expand Down
83 changes: 83 additions & 0 deletions contrib/kyua/engine/rr/rr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2024 The Kyua Authors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Google Inc. nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "engine/rr/rr.hpp"

#include "engine/rr/rr_all.hpp"

namespace rr = engine::rr;


/// List of registered execution environments, except default host one.
///
/// Use register_execenv() to add an entry to this global list.
static std::vector< std::shared_ptr< rr::interface > > _resolvers = {
std::shared_ptr< rr::interface >(new rr::rr_all())
};


void
rr::register_resolver(const std::shared_ptr< interface > resolver)
{
_resolvers.push_back(resolver);
}


const std::vector< std::shared_ptr< rr::interface > >
rr::resolvers()
{
return _resolvers;

Check failure on line 54 in contrib/kyua/engine/rr/rr.cpp

View workflow job for this annotation

GitHub Actions / Style Checker

parentheses required on return
}


int
rr::run(const std::vector< std::string >& resolver_names,

Check failure on line 59 in contrib/kyua/engine/rr/rr.cpp

View workflow job for this annotation

GitHub Actions / Style Checker

space required before that '&' (ctx:OxW)
cmdline::ui* ui,
const cmdline::parsed_cmdline& cmdline,
const config::tree& user_config)
{
for (auto rname : resolver_names) {
std::shared_ptr< rr::interface > resolver = nullptr;
for (auto r : rr::resolvers())
if (r->name() == rname) {
resolver = r;
break;
}

if (resolver == nullptr) {
ui->out(F("Unknown requirement resolver: %s") % rname);
return EXIT_FAILURE;
}

if (resolver->exec(ui, cmdline, user_config) != EXIT_SUCCESS)
// suppress the actual code -- main limits possible exit codes
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}
107 changes: 107 additions & 0 deletions contrib/kyua/engine/rr/rr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright 2024 The Kyua Authors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Google Inc. nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

/// \file engine/rr/rr.hpp
/// Requirement resolver subsystem interface.

#if !defined(ENGINE_RR_RR_HPP)
#define ENGINE_RR_RR_HPP

#include <string>
#include <vector>

#include "utils/cmdline/parser.ipp"
#include "utils/cmdline/ui.hpp"
#include "utils/config/tree.ipp"

namespace cmdline = utils::cmdline;
namespace config = utils::config;


namespace engine {
namespace rr {


/// Abstract interface of a requirement resolver.
class interface {
public:
/// Constructor.
interface() {}

/// Destructor.
virtual ~interface() {}

/// Returns name of the resolver.
virtual const std::string& name() const = 0;

/// Returns short description of the resolver.
virtual const std::string& description() const = 0;

/// Runs the requirement resolver.
///
/// \param ui Object to interact with the I/O of the program.
/// \param cmdline Representation of the command line to the subcommand.
/// \param user_config The runtime configuration of the program.
///
/// \return 0 to indicate success.
virtual int exec(cmdline::ui* ui,
const cmdline::parsed_cmdline& cmdline,
const config::tree& user_config) const = 0;
};


/// Registers a requirement resolver.
///
/// \param resolver A requirement resolver.
void register_resolver(const std::shared_ptr< interface > resolver);


/// Returns the list of registered requirement resolvers.
///
/// \return A vector of pointers to requirement resolvers.
const std::vector< std::shared_ptr< interface > > resolvers();


/// Run named resolvers.
///
/// \param resolver_names Names of resolvers to run.
/// \param ui Object to interact with the I/O of the program.
/// \param cmdline Representation of the command line to the subcommand.
/// \param user_config The runtime configuration of the program.
///
/// \return 0 to indicate success.
int run(const std::vector< std::string >& resolver_names,
cmdline::ui* ui,
const cmdline::parsed_cmdline& cmdline,
const config::tree& user_config);


} // namespace rr
} // namespace engine

#endif // !defined(ENGINE_RR_RR_HPP)
Loading