diff --git a/Makefile.am b/Makefile.am index 1dc7f5f..eb35adf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -58,7 +58,7 @@ test_test_loaded_SOURCES = test/test-loaded.c test_test_loaded_LDADD = libkmod/libkmod.la noinst_PROGRAMS = test/test-insmod test/test-rmmod test/test-rmmod2 \ - $(check_PROGRAMS) + test/test-lookup $(check_PROGRAMS) test_test_rmmod_SOURCES = test/test-rmmod.c test_test_rmmod_LDADD = libkmod/libkmod.la @@ -67,3 +67,6 @@ test_test_rmmod2_LDADD = libkmod/libkmod.la test_test_insmod_SOURCES = test/test-insmod.c test_test_insmod_LDADD = libkmod/libkmod.la + +test_test_lookup_SOURCES = test/test-lookup.c +test_test_lookup_LDADD = libkmod/libkmod.la diff --git a/test/.gitignore b/test/.gitignore index bc9eb6e..d7f6681 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -4,3 +4,4 @@ test-loaded test-rmmod test-rmmod2 test-insmod +test-lookup diff --git a/test/test-lookup.c b/test/test-lookup.c new file mode 100644 index 0000000..42656ec --- /dev/null +++ b/test/test-lookup.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + const char *alias; + struct kmod_ctx *ctx; + struct kmod_list *list = NULL, *l; + struct kmod_module *mod; + int err; + + printf("libkmod version %s\n", VERSION); + + if (argc < 2) { + fprintf(stderr, "ERR: Provide an alias name\n"); + return EXIT_FAILURE; + } + + alias = argv[1]; + + ctx = kmod_new(NULL); + if (ctx == NULL) + exit(EXIT_FAILURE); + + err = kmod_module_new_from_lookup(ctx, alias, &list); + if (err < 0) + exit(EXIT_FAILURE); + + if (list == NULL) + printf("No module matches '%s'\n", alias); + else + printf("Alias: '%s'\nModules matching:\n", alias); + + kmod_list_foreach(l, list) { + struct kmod_module *mod = kmod_module_get_module(l); + printf("\t%s\n", kmod_module_get_name(mod)); + } + + kmod_module_unref_list(list); + kmod_unref(ctx); + + return EXIT_SUCCESS; +}