From: Dan McGee Date: Thu, 23 Feb 2012 05:56:59 +0000 (-0600) Subject: test-conversion: convert test-get-dependencies to new infrastructure X-Git-Tag: v9~41 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c88aec70d1b74ea71cd3ec538b3f43ad8c6783b3;p=thirdparty%2Fkmod.git test-conversion: convert test-get-dependencies to new infrastructure The test uses the ext4 module dependencies as the testcase, checking both the number and the names of the returned modules. --- diff --git a/Makefile.am b/Makefile.am index 416672e9..e04e7f73 100644 --- a/Makefile.am +++ b/Makefile.am @@ -161,7 +161,7 @@ testsuite_libtestsuite_la_CPPFLAGS = $(TESTSUITE_CPPFLAGS) TESTSUITE = testsuite/test-init testsuite/test-testsuite testsuite/test-loaded \ testsuite/test-modinfo testsuite/test-alias testsuite/test-new-module \ - testsuite/test-modprobe testsuite/test-blacklist + testsuite/test-modprobe testsuite/test-blacklist testsuite/test-dependencies check_PROGRAMS = $(TESTSUITE) TESTS = $(TESTSUITE) @@ -181,6 +181,8 @@ testsuite_test_modprobe_LDADD = $(TESTSUITE_LDADD) testsuite_test_modprobe_CPPFLAGS = $(TESTSUITE_CPPFLAGS) testsuite_test_blacklist_LDADD = $(TESTSUITE_LDADD) testsuite_test_blacklist_CPPFLAGS = $(TESTSUITE_CPPFLAGS) +testsuite_test_dependencies_LDADD = $(TESTSUITE_LDADD) +testsuite_test_dependencies_CPPFLAGS = $(TESTSUITE_CPPFLAGS) testsuite-distclean: -find testsuite/rootfs-dirty -type d -exec chmod +w {} \; diff --git a/test/test-get-dependencies.c b/test/test-get-dependencies.c deleted file mode 100644 index 3a7bbf2e..00000000 --- a/test/test-get-dependencies.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - - -int main(int argc, char *argv[]) -{ - const char *name; - 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, "ERR: Provide a module name\n"); - return EXIT_FAILURE; - } - - name = argv[1]; - - ctx = kmod_new(NULL, NULL); - if (ctx == NULL) - exit(EXIT_FAILURE); - - err = kmod_module_new_from_name(ctx, name, &mod); - if (err < 0) { - kmod_unref(ctx); - exit(EXIT_FAILURE); - } - - list = kmod_module_get_dependencies(mod); - printf("Module: %s\nDependency list:\n", name); - - kmod_list_foreach(l, list) { - struct kmod_module *m = kmod_module_get_module(l); - printf("\t%s\n", kmod_module_get_name(m)); - kmod_module_unref(m); - } - - kmod_module_unref_list(list); - kmod_module_unref(mod); - kmod_unref(ctx); - - return EXIT_SUCCESS; -} diff --git a/testsuite/.gitignore b/testsuite/.gitignore index 0c620aa9..21fe5182 100644 --- a/testsuite/.gitignore +++ b/testsuite/.gitignore @@ -4,6 +4,7 @@ /.dirstamp /test-alias /test-blacklist +/test-dependencies /test-init /test-loaded /test-modinfo diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/jbd2/jbd2.ko b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/jbd2/jbd2.ko new file mode 100644 index 00000000..521c214f Binary files /dev/null and b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/jbd2/jbd2.ko differ diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/mbcache.ko b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/mbcache.ko new file mode 100644 index 00000000..5849fa75 Binary files /dev/null and b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/mbcache.ko differ diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/kernel/lib/crc16.ko b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/kernel/lib/crc16.ko new file mode 100644 index 00000000..2fffdb72 Binary files /dev/null and b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/kernel/lib/crc16.ko differ diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.alias b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.alias new file mode 100644 index 00000000..ba76e181 --- /dev/null +++ b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.alias @@ -0,0 +1 @@ +# Aliases extracted from modules themselves. diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.alias.bin b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.alias.bin new file mode 100644 index 00000000..7075435f Binary files /dev/null and b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.alias.bin differ diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin new file mode 100644 index 00000000..e69de29b diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin.bin b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin.bin new file mode 100644 index 00000000..7075435f Binary files /dev/null and b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.builtin.bin differ diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.dep b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.dep new file mode 100644 index 00000000..c4e25160 --- /dev/null +++ b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.dep @@ -0,0 +1,4 @@ +kernel/fs/mbcache.ko: +kernel/fs/ext4/ext4.ko: kernel/lib/crc16.ko kernel/fs/jbd2/jbd2.ko kernel/fs/mbcache.ko +kernel/fs/jbd2/jbd2.ko: +kernel/lib/crc16.ko: diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.dep.bin b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.dep.bin new file mode 100644 index 00000000..2e89d91f Binary files /dev/null and b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.dep.bin differ diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.devname b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.devname new file mode 100644 index 00000000..58f6d6d6 --- /dev/null +++ b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.devname @@ -0,0 +1 @@ +# Device nodes to trigger on-demand module loading. diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.order b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.order new file mode 100644 index 00000000..85f2778e --- /dev/null +++ b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.order @@ -0,0 +1,7 @@ +kernel/fs/mbcache.ko +kernel/fs/ext3/ext3.ko +kernel/fs/ext2/ext2.ko +kernel/fs/ext4/ext4.ko +kernel/fs/jbd/jbd.ko +kernel/fs/jbd2/jbd2.ko +kernel/lib/crc16.ko diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.softdep b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.softdep new file mode 100644 index 00000000..3cc05126 --- /dev/null +++ b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.softdep @@ -0,0 +1,2 @@ +# Soft dependencies extracted from modules themselves. +# Copy, with a .conf extension, to /etc/modprobe.d to use it with modprobe. diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols new file mode 100644 index 00000000..0f0d88cc --- /dev/null +++ b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols @@ -0,0 +1,58 @@ +# Aliases for symbols, used by symbol_request(). +alias symbol:jbd2_journal_invalidatepage jbd2 +alias symbol:jbd2_journal_release_buffer jbd2 +alias symbol:jbd2_journal_init_inode jbd2 +alias symbol:jbd2__journal_restart jbd2 +alias symbol:mb_cache_entry_find_next mbcache +alias symbol:crc16 crc16 +alias symbol:mb_cache_entry_insert mbcache +alias symbol:jbd2_journal_destroy jbd2 +alias symbol:jbd2_journal_lock_updates jbd2 +alias symbol:mb_cache_entry_free mbcache +alias symbol:jbd2_log_start_commit jbd2 +alias symbol:mb_cache_entry_find_first mbcache +alias symbol:mb_cache_destroy mbcache +alias symbol:jbd2_journal_extend jbd2 +alias symbol:jbd2_journal_begin_ordered_truncate jbd2 +alias symbol:jbd2_journal_revoke jbd2 +alias symbol:jbd2_journal_get_write_access jbd2 +alias symbol:jbd2_inode_cache jbd2 +alias symbol:jbd2_journal_ack_err jbd2 +alias symbol:mb_cache_create mbcache +alias symbol:jbd2_journal_flush jbd2 +alias symbol:jbd2_journal_init_jbd_inode jbd2 +alias symbol:mb_cache_entry_alloc mbcache +alias symbol:jbd2_journal_get_undo_access jbd2 +alias symbol:jbd2_journal_get_create_access jbd2 +alias symbol:jbd2_journal_update_format jbd2 +alias symbol:crc16_table crc16 +alias symbol:jbd2_journal_wipe jbd2 +alias symbol:jbd2_journal_check_used_features jbd2 +alias symbol:mb_cache_entry_get mbcache +alias symbol:jbd2_journal_force_commit_nested jbd2 +alias symbol:jbd2_log_wait_commit jbd2 +alias symbol:jbd2_journal_stop jbd2 +alias symbol:jbd2_journal_set_triggers jbd2 +alias symbol:jbd2_journal_release_jbd_inode jbd2 +alias symbol:jbd2_journal_unlock_updates jbd2 +alias symbol:jbd2_journal_start_commit jbd2 +alias symbol:jbd2_journal_dirty_metadata jbd2 +alias symbol:jbd2_journal_force_commit jbd2 +alias symbol:mb_cache_entry_release mbcache +alias symbol:jbd2_journal_init_dev jbd2 +alias symbol:jbd2_journal_forget jbd2 +alias symbol:jbd2_journal_set_features jbd2 +alias symbol:jbd2_journal_start jbd2 +alias symbol:jbd2_journal_clear_features jbd2 +alias symbol:jbd2__journal_start jbd2 +alias symbol:mb_cache_shrink mbcache +alias symbol:jbd2_journal_clear_err jbd2 +alias symbol:jbd2_journal_file_inode jbd2 +alias symbol:jbd2_journal_restart jbd2 +alias symbol:jbd2_journal_load jbd2 +alias symbol:jbd2_journal_check_available_features jbd2 +alias symbol:jbd2_journal_abort jbd2 +alias symbol:jbd2_journal_blocks_per_page jbd2 +alias symbol:jbd2_journal_try_to_free_buffers jbd2 +alias symbol:jbd2_trans_will_send_data_barrier jbd2 +alias symbol:jbd2_journal_errno jbd2 diff --git a/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols.bin b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols.bin new file mode 100644 index 00000000..aa8cfc85 Binary files /dev/null and b/testsuite/rootfs/test-dependencies/lib/modules/4.0.20-kmod/modules.symbols.bin differ diff --git a/testsuite/test-dependencies.c b/testsuite/test-dependencies.c new file mode 100644 index 00000000..a4a1d405 --- /dev/null +++ b/testsuite/test-dependencies.c @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2011-2012 ProFUSION embedded systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "testsuite.h" +#define TEST_UNAME "4.0.20-kmod" + +static int test_dependencies(const struct test *t) +{ + struct kmod_ctx *ctx; + struct kmod_module *mod; + struct kmod_list *list, *l; + int err; + size_t len = 0; + int crc16 = 0, mbcache = 0, jbd2 = 0; + + ctx = kmod_new(NULL, NULL); + if (ctx == NULL) + return EXIT_FAILURE; + + err = kmod_module_new_from_name(ctx, "ext4", &mod); + if (err < 0) { + kmod_unref(ctx); + return EXIT_FAILURE; + } + + list = kmod_module_get_dependencies(mod); + + kmod_list_foreach(l, list) { + struct kmod_module *m = kmod_module_get_module(l); + const char *name = kmod_module_get_name(m); + + if (strcmp(name, "crc16") == 0) + crc16 = 1; + if (strcmp(name, "mbcache") == 0) + mbcache = 1; + else if (strcmp(name, "jbd2") == 0) + jbd2 = 1; + + kmod_module_unref(m); + len++; + } + + /* crc16, mbcache, jbd2 */ + if (len != 3 || !crc16 || !mbcache || !jbd2) + return EXIT_FAILURE; + + kmod_module_unref_list(list); + kmod_module_unref(mod); + kmod_unref(ctx); + + return EXIT_SUCCESS; +} +static const struct test stest_dependencies = { + .name = "test_dependencies", + .description = "test if kmod_module_get_dependencies works", + .func = test_dependencies, + .config = { + [TC_ROOTFS] = TESTSUITE_ROOTFS "test-dependencies/", + [TC_UNAME_R] = TEST_UNAME, + }, + .need_spawn = true, +}; + +static const struct test *tests[] = { + &stest_dependencies, + NULL, +}; + +TESTSUITE_MAIN(tests);