Merge #4 CI: Add libkmod to tests.
This commit is contained in:
commit
7acaebe897
46
tests/libkmod/Makefile
Normal file
46
tests/libkmod/Makefile
Normal file
@ -0,0 +1,46 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1+
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
#
|
||||
# Makefile of /CoreOS/libkmod
|
||||
# Description: Test if libkmod working ok
|
||||
# Author: Susant Sahani<susant@redhat.com>
|
||||
#
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
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<susant@redhat.com>" > $(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)
|
36
tests/libkmod/runtest.sh
Executable file
36
tests/libkmod/runtest.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
# SPDX-License-Identifier: LGPL-2.1+
|
||||
# ~~~
|
||||
# runtest.sh of libkmod
|
||||
# Description: Tests for libkmod.
|
||||
#
|
||||
# Author: Susant Sahani <susant@redhat.com>
|
||||
# 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
|
79
tests/libkmod/test-libkmod.c
Normal file
79
tests/libkmod/test-libkmod.c
Normal file
@ -0,0 +1,79 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+
|
||||
# ~~~
|
||||
# Description: Tests libkmod
|
||||
#
|
||||
# Author: Susant Sahani <susant@redhat.com>
|
||||
# Copyright (c) 2018 Red Hat, Inc.
|
||||
# ~~~
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libkmod.h>
|
||||
#include <setjmp.h>
|
||||
#include <inttypes.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
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);
|
||||
}
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user