Page MenuHomeFreeBSD

D47470.diff
No OneTemporary

D47470.diff

diff --git a/contrib/atf/atf-c/tc.h b/contrib/atf/atf-c/tc.h
--- a/contrib/atf/atf-c/tc.h
+++ b/contrib/atf/atf-c/tc.h
@@ -106,6 +106,7 @@
ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2);
void atf_tc_pass(void)
ATF_DEFS_ATTRIBUTE_NORETURN;
+void atf_tc_require_kld(const char *);
void atf_tc_require_prog(const char *);
void atf_tc_skip(const char *, ...)
ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2)
diff --git a/contrib/atf/atf-c/tc.c b/contrib/atf/atf-c/tc.c
--- a/contrib/atf/atf-c/tc.c
+++ b/contrib/atf/atf-c/tc.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <libutil.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
@@ -103,6 +104,7 @@
static void errno_test(struct context *, const char *, const size_t,
const int, const char *, const bool,
void (*)(struct context *, atf_dynstr_t *));
+static atf_error_t check_kld(struct context *, const char *);
static atf_error_t check_prog_in_dir(const char *, void *);
static atf_error_t check_prog(struct context *, const char *);
@@ -460,6 +462,19 @@
}
}
+static atf_error_t
+check_kld(struct context *ctx, const char *kld)
+{
+ if (!kld_isloaded(kld)) {
+ atf_dynstr_t reason;
+
+ format_reason_fmt(&reason, NULL, 0, "The required kld %s "
+ "is not loaded", kld);
+ fail_requirement(ctx, &reason);
+ }
+ return atf_no_error();
+}
+
struct prog_found_pair {
const char *prog;
bool found;
@@ -829,6 +844,7 @@
static void _atf_tc_fail_requirement(struct context *, const char *,
const size_t, const char *, va_list) ATF_DEFS_ATTRIBUTE_NORETURN;
static void _atf_tc_pass(struct context *) ATF_DEFS_ATTRIBUTE_NORETURN;
+static void _atf_tc_require_kld(struct context *, const char *);
static void _atf_tc_require_prog(struct context *, const char *);
static void _atf_tc_skip(struct context *, const char *, va_list)
ATF_DEFS_ATTRIBUTE_NORETURN;
@@ -908,6 +924,12 @@
UNREACHABLE;
}
+static void
+_atf_tc_require_kld(struct context *ctx, const char *kld)
+{
+ check_fatal_error(check_kld(ctx, kld));
+}
+
static void
_atf_tc_require_prog(struct context *ctx, const char *prog)
{
diff --git a/contrib/kyua/engine/atf_list.cpp b/contrib/kyua/engine/atf_list.cpp
--- a/contrib/kyua/engine/atf_list.cpp
+++ b/contrib/kyua/engine/atf_list.cpp
@@ -129,6 +129,8 @@
mdbuilder.set_string("required_configs", value);
} else if (name == "require.files") {
mdbuilder.set_string("required_files", value);
+ } else if (name == "require.klds") {
+ mdbuilder.set_string("required_modules", value);
} else if (name == "require.machine") {
mdbuilder.set_string("allowed_platforms", value);
} else if (name == "require.memory") {
diff --git a/contrib/kyua/engine/requirements.cpp b/contrib/kyua/engine/requirements.cpp
--- a/contrib/kyua/engine/requirements.cpp
+++ b/contrib/kyua/engine/requirements.cpp
@@ -41,6 +41,8 @@
#include "utils/sanity.hpp"
#include "utils/units.hpp"
+#include <libutil.h>
+
namespace config = utils::config;
namespace fs = utils::fs;
namespace passwd = utils::passwd;
@@ -220,6 +222,24 @@
}
+/// Checks if all required modules are loaded.
+///
+/// \param required_programs Set of modules.
+///
+/// \return Empty if the required modules are all loaded or an error
+/// message otherwise.
+static std::string
+check_required_modules(const model::strings_set& required_modules)
+{
+ for (model::strings_set::const_iterator iter = required_modules.begin();
+ iter != required_modules.end(); iter++) {
+ if (!kld_isloaded((*iter).c_str()))
+ return F("Required module '%s' not loaded") % *iter;
+ }
+ return "";
+}
+
+
/// Checks if the current system has the specified amount of memory.
///
/// \param required_memory Amount of required physical memory, or zero if not
@@ -312,6 +332,10 @@
if (!reason.empty())
return reason;
+ reason = check_required_modules(md.required_modules());
+ if (!reason.empty())
+ return reason;
+
reason = check_required_memory(md.required_memory());
if (!reason.empty())
return reason;
diff --git a/contrib/kyua/model/metadata.hpp b/contrib/kyua/model/metadata.hpp
--- a/contrib/kyua/model/metadata.hpp
+++ b/contrib/kyua/model/metadata.hpp
@@ -76,6 +76,7 @@
const utils::units::bytes& required_disk_space(void) const;
const paths_set& required_files(void) const;
const utils::units::bytes& required_memory(void) const;
+ const strings_set& required_modules(void) const;
const paths_set& required_programs(void) const;
const std::string& required_user(void) const;
const utils::datetime::delta& timeout(void) const;
@@ -121,6 +122,7 @@
metadata_builder& set_required_disk_space(const utils::units::bytes&);
metadata_builder& set_required_files(const paths_set&);
metadata_builder& set_required_memory(const utils::units::bytes&);
+ metadata_builder& set_required_modules(const strings_set&);
metadata_builder& set_required_programs(const paths_set&);
metadata_builder& set_required_user(const std::string&);
metadata_builder& set_string(const std::string&, const std::string&);
diff --git a/contrib/kyua/model/metadata.cpp b/contrib/kyua/model/metadata.cpp
--- a/contrib/kyua/model/metadata.cpp
+++ b/contrib/kyua/model/metadata.cpp
@@ -256,6 +256,7 @@
tree.define< bytes_node >("required_disk_space");
tree.define< paths_set_node >("required_files");
tree.define< bytes_node >("required_memory");
+ tree.define< config::strings_set_node >("required_modules");
tree.define< paths_set_node >("required_programs");
tree.define< user_node >("required_user");
tree.define< delta_node >("timeout");
@@ -282,6 +283,7 @@
tree.set< bytes_node >("required_disk_space", units::bytes(0));
tree.set< paths_set_node >("required_files", model::paths_set());
tree.set< bytes_node >("required_memory", units::bytes(0));
+ tree.set< config::strings_set_node >("required_modules", model::strings_set());
tree.set< paths_set_node >("required_programs", model::paths_set());
tree.set< user_node >("required_user", "");
// TODO(jmmv): We shouldn't be setting a default timeout like this. See
@@ -597,6 +599,20 @@
}
+/// Returns the list of modules needed by the test.
+///
+/// \return Set of strings.
+const model::strings_set&
+model::metadata::required_modules(void) const
+{
+ if (_pimpl->props.is_set("required_modules")) {
+ return _pimpl->props.lookup< config::strings_set_node >("required_modules");
+ } else {
+ return get_defaults().lookup< config::strings_set_node >("required_modules");
+ }
+}
+
+
/// Returns the list of programs needed by the test.
///
/// \return Set of paths.
diff --git a/lib/atf/libatf-c/Makefile b/lib/atf/libatf-c/Makefile
--- a/lib/atf/libatf-c/Makefile
+++ b/lib/atf/libatf-c/Makefile
@@ -31,6 +31,7 @@
LIB= atf-c
PRIVATELIB= true
SHLIB_MAJOR= 1
+LIBADD= util
ATF= ${SRCTOP}/contrib/atf
.PATH: ${ATF}
diff --git a/tests/sys/fs/tarfs/tarfs_test.sh b/tests/sys/fs/tarfs/tarfs_test.sh
--- a/tests/sys/fs/tarfs/tarfs_test.sh
+++ b/tests/sys/fs/tarfs/tarfs_test.sh
@@ -48,7 +48,7 @@
}
tarfs_setup() {
- kldload -n tarfs || atf_skip "This test requires tarfs and could not load it"
+ atf_require_kld tarfs
mkdir "${mnt}"
}
diff --git a/usr.bin/kyua/Makefile b/usr.bin/kyua/Makefile
--- a/usr.bin/kyua/Makefile
+++ b/usr.bin/kyua/Makefile
@@ -13,7 +13,7 @@
PACKAGE= tests
PROG_CXX= kyua
SRCS= main.cpp
-LIBADD= lutok sqlite3
+LIBADD= lutok sqlite3 util
MAN= kyua-about.1 \
kyua-config.1 \

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 7, 11:59 PM (8 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14523523
Default Alt Text
D47470.diff (7 KB)

Event Timeline