diff options
author | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2011-11-30 19:10:48 -0200 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2011-11-30 19:10:48 -0200 |
commit | aed94cd72a2fdf9b43359c217beb1cc8ef9f52e2 (patch) | |
tree | 461e7ffa3bc66d0458059c9d4fd9cf460ee2d86f /test | |
parent | 7f3eb0cced7fc97b8ff1313e046b00e9e62c57bf (diff) | |
download | kmod-aed94cd72a2fdf9b43359c217beb1cc8ef9f52e2.tar.gz |
Add test for lookup function
Diffstat (limited to 'test')
-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/test-lookup.c | 50 |
2 files changed, 51 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> +#include <stddef.h> +#include <errno.h> +#include <unistd.h> +#include <inttypes.h> +#include <string.h> +#include <libkmod.h> + + +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; +} |