From: Gustavo Sverzut Barbieri Date: Mon, 19 Dec 2011 23:23:45 +0000 (-0200) Subject: add test/test-elf X-Git-Tag: v3~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f85ae0d5989ff7be01606963ddb4fa093c381a7f;p=thirdparty%2Fkmod.git add test/test-elf will be focused on testing ELF operations and takes a filename to load instead of looking for it in the system. --- diff --git a/Makefile.am b/Makefile.am index 9523d71b..56d2f29d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -106,7 +106,7 @@ test_test_loaded_LDADD = libkmod/libkmod.la noinst_PROGRAMS = test/test-insmod test/test-rmmod test/test-rmmod2 \ test/test-lookup test/test-path-from-name \ test/test-get-dependencies test/test-mod-double-ref \ - test/test-blacklist \ + test/test-blacklist test/test-elf \ $(check_PROGRAMS) test_test_rmmod_LDADD = libkmod/libkmod.la @@ -117,3 +117,6 @@ test_test_path_from_name_LDADD = libkmod/libkmod.la test_test_get_dependencies_LDADD = libkmod/libkmod.la test_test_mod_double_ref_LDADD = libkmod/libkmod.la test_test_blacklist_LDADD = libkmod/libkmod.la + +test_test_elf_SOURCES = test/test-elf.c +test_test_elf_LDADD = libkmod/libkmod.la diff --git a/test/.gitignore b/test/.gitignore index 0722c91e..3118b918 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -9,3 +9,4 @@ test-path-from-name test-get-dependencies test-mod-double-ref test-blacklist +test-elf diff --git a/test/test-elf.c b/test/test-elf.c new file mode 100644 index 00000000..773ca6ba --- /dev/null +++ b/test/test-elf.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + struct kmod_ctx *ctx; + struct kmod_module *mod; + struct kmod_list *list, *l; + int err; + + printf("libkmod version %s\n", VERSION); + + if (argc != 2) { + fprintf(stderr, "Usage:\n\t%s \n", argv[0]); + return EXIT_FAILURE; + } + + ctx = kmod_new(NULL, NULL); + if (ctx == NULL) + return EXIT_FAILURE; + + err = kmod_module_new_from_path(ctx, argv[1], &mod); + if (err < 0) { + fprintf(stderr, "ERROR: could not load %s: %s\n", + argv[1], strerror(-errno)); + goto module_error; + } + + list = NULL; + err = kmod_module_get_info(mod, &list); + if (err <= 0) + printf("no information! (%s)\n", strerror(-err)); + else { + puts("info:"); + kmod_list_foreach(l, list) { + const char *key, *val; + key = kmod_module_info_get_key(l); + val = kmod_module_info_get_value(l); + printf("\t%s: %s\n", key, val ? val : ""); + } + kmod_module_info_free_list(list); + } + + list = NULL; + err = kmod_module_get_versions(mod, &list); + if (err <= 0) + printf("no modversions! (%s)\n", strerror(-err)); + else { + puts("modversions:"); + kmod_list_foreach(l, list) { + const char *symbol; + uint64_t crc; + symbol = kmod_module_version_get_symbol(l); + crc = kmod_module_version_get_crc(l); + printf("\t%s: %#"PRIx64"\n", symbol, crc); + } + kmod_module_versions_free_list(list); + } + + list = NULL; + err = kmod_module_get_symbols(mod, &list); + if (err <= 0) + printf("no symbols! (%s)\n", strerror(-err)); + else { + puts("symbols:"); + kmod_list_foreach(l, list) { + const char *symbol; + uint64_t crc; + symbol = kmod_module_symbol_get_symbol(l); + crc = kmod_module_symbol_get_crc(l); + printf("\t%s: %#"PRIx64"\n", symbol, crc); + } + kmod_module_symbols_free_list(list); + } + + kmod_module_unref(mod); +module_error: + kmod_unref(ctx); + + return (err < 0) ? EXIT_FAILURE : EXIT_SUCCESS; +}