mirror of
https://github.com/AuxXxilium/kmod.git
synced 2025-02-17 15:06:37 +07:00
Add test for lookup function
This commit is contained in:
parent
7f3eb0cced
commit
aed94cd72a
@ -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
|
||||
|
1
test/.gitignore
vendored
1
test/.gitignore
vendored
@ -4,3 +4,4 @@ test-loaded
|
||||
test-rmmod
|
||||
test-rmmod2
|
||||
test-insmod
|
||||
test-lookup
|
||||
|
50
test/test-lookup.c
Normal file
50
test/test-lookup.c
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user