diff --git a/tests/libkmod/Makefile b/tests/libkmod/Makefile new file mode 100644 index 0000000..cc53a81 --- /dev/null +++ b/tests/libkmod/Makefile @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/libkmod +# Description: Test if libkmod working ok +# Author: Susant Sahani +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export TEST=/CoreOS/libkmod +export TESTVERSION=1.0 + +OBJS = test-libkmod.c +CFLAG = -Wall -g3 +CC = gcc +LIBS = -lkmod -lcmocka + +test-libkmod:${OBJ} + ${CC} ${CFLAGS} ${INCLUDES} -o $@ ${OBJS} ${LIBS} + +run: test-libkmod + ./runtest.sh +clean: + -rm -f test-libkmod + +.c.o: + ${CC} ${CFLAGS} ${INCLUDES} -c $< + +CC = gcc + +include /usr/share/rhts/lib/rhts-make.include +$(METADATA): Makefile + @echo "Owner: Susant Sahani" > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test libkmod works ok" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: libkmod" >> $(METADATA) + @echo "Requires: libkmod libkmod-devel" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + @echo "Releases: -Fedora 29" >> $(METADATA) + rhts-lint $(METADATA) diff --git a/tests/libkmod/runtest.sh b/tests/libkmod/runtest.sh new file mode 100755 index 0000000..1ef013c --- /dev/null +++ b/tests/libkmod/runtest.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of libkmod +# Description: Tests for libkmod. +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +# ~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="kmod-devel" +IPIP="/usr/lib/modules/$(uname -r)/kernel/net/ipv4/ipip.ko.xz" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlAssertExists "$IPIP" + rlRun "cp test-libkmod /usr/bin/" + rlPhaseEnd + + rlPhaseStartTest + rlLog "Starting libkmod tests ..." + rlRun "/usr/bin/test-libkmod" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "rm /usr/bin/test-libkmod" + rlLog "libkmod tests done" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + +rlGetTestState diff --git a/tests/libkmod/test-libkmod.c b/tests/libkmod/test-libkmod.c new file mode 100644 index 0000000..507e581 --- /dev/null +++ b/tests/libkmod/test-libkmod.c @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# Description: Tests libkmod +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +# ~~~ +*/ + +#include +#include +#include +#include +#include +#include +#include + +static int load_module(void **state) { + struct kmod_list *list = NULL; + struct kmod_ctx *ctx = NULL; + struct kmod_list *l; + int r; + + assert_non_null((ctx = kmod_new(NULL, NULL))); + assert_return_code(kmod_module_new_from_lookup(ctx, "ipip", &list), 0); + + kmod_list_foreach(l, list) { + struct kmod_module *mod = NULL; + + mod = kmod_module_get_module(l); + assert_non_null(mod); + + assert_return_code(kmod_module_probe_insert_module(mod, 0, NULL, NULL, NULL, NULL), 0); + } + + free(ctx); + + return 0; +} + +static int remove_module(void **state) { + struct kmod_list *list = NULL; + struct kmod_ctx *ctx = NULL; + struct kmod_list *l; + int r; + + assert_non_null((ctx = kmod_new(NULL, NULL))); + assert_return_code(kmod_module_new_from_lookup(ctx, "ipip", &list), 0); + + kmod_list_foreach(l, list) { + struct kmod_module *mod = NULL; + + mod = kmod_module_get_module(l); + assert_non_null(mod); + + assert_return_code(kmod_module_remove_module(mod, 0), 0); + } + + free(ctx); + + return 0; +} + +void test_load_module(void **state) { + load_module(NULL); +} + +void test_remove_module(void **state) { + remove_module(NULL); +} + +int main(int argc, char *argv[]) { + const struct CMUnitTest libmod_tests[] = { + cmocka_unit_test_teardown(test_load_module, remove_module), + cmocka_unit_test_setup(test_remove_module, load_module), + }; + + return cmocka_run_group_tests(libmod_tests, NULL, NULL); +} diff --git a/tests/sanity/Makefile b/tests/sanity/Makefile index 9ea4f00..e422f7f 100644 --- a/tests/sanity/Makefile +++ b/tests/sanity/Makefile @@ -76,6 +76,4 @@ $(METADATA): Makefile @echo "License: GPLv2" >> $(METADATA) @echo "Confidential: no" >> $(METADATA) @echo "Destructive: no" >> $(METADATA) - @echo "RhtsRequires: kernel-kernel-general-include" >> $(METADATA) rhts-lint $(METADATA) - diff --git a/tests/sanity/runtest.sh b/tests/sanity/runtest.sh index a0888d4..815972f 100755 --- a/tests/sanity/runtest.sh +++ b/tests/sanity/runtest.sh @@ -28,7 +28,6 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Include Beaker environment -. /usr/bin/rhts-environment.sh || exit 1 . /usr/share/beakerlib/beakerlib.sh || exit 1 . lib.sh @@ -133,4 +132,3 @@ rlJournalStart rlJournalPrintText rlJournalEnd - diff --git a/tests/tests.yml b/tests/tests.yml index d362e9f..828a27a 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -5,9 +5,14 @@ - role: standard-test-beakerlib tests: - sanity + - libkmod required_packages: - kernel - perf - sysstat - trace-cmd - + - kmod + - kmod-devel + - gcc + - libcmocka + - libcmocka-devel