From eebca81e945a0ba6a79931d4d6a62e022b93b828 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 24 Jan 2012 21:53:27 -0200 Subject: [PATCH] testsuite: test libkmod initialization --- Makefile.am | 6 +++++ testsuite/.gitignore | 1 + testsuite/test-init.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 testsuite/test-init.c diff --git a/Makefile.am b/Makefile.am index 857774ca..257575cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -133,6 +133,12 @@ testsuite_libtestsuite_la_SOURCES = testsuite/testsuite.c \ testsuite/testsuite.h testsuite_libtestsuite_la_DEPENDENCIES = testsuite/uname.so +TESTSUITE = testsuite/test-init +check_PROGRAMS = $(TESTSUITE) +TESTS = $(TESTSUITE) + +testsuite_test_init_LDADD = testsuite/libtestsuite.la libkmod/libkmod-private.la + DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc diff --git a/testsuite/.gitignore b/testsuite/.gitignore index f4fd00f3..4b5d6967 100644 --- a/testsuite/.gitignore +++ b/testsuite/.gitignore @@ -3,3 +3,4 @@ *.la *.so test-testsuite +test-init diff --git a/testsuite/test-init.c b/testsuite/test-init.c new file mode 100644 index 00000000..38011f81 --- /dev/null +++ b/testsuite/test-init.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "testsuite.h" + +static int testsuite_init(const struct test *t) +{ + struct kmod_ctx *ctx; + const char *null_config = NULL; + + ctx = kmod_new(NULL, &null_config); + if (ctx == NULL) + exit(EXIT_FAILURE); + + kmod_unref(ctx); + + exit(EXIT_SUCCESS); +} +static const struct test stestsuite_init = { + .name = "testsuite_init", + .description = "test if libkmod's init function work", + .func = testsuite_init, +}; + +static const struct test *tests[] = { + &stestsuite_init, + NULL, +}; + +int main(int argc, char *argv[]) +{ + const struct test *t; + int arg; + size_t i; + + arg = test_init(argc, argv, tests); + if (arg == 0) + return 0; + + if (arg < argc) { + t = test_find(tests, argv[arg]); + if (t == NULL) { + fprintf(stderr, "could not find test %s\n", argv[arg]); + exit(EXIT_FAILURE); + } + + return test_run(t); + } + + for (i = 0; tests[i] != NULL; i++) { + if (test_run(tests[i]) != 0) + exit(EXIT_FAILURE); + } + + exit(EXIT_SUCCESS); +} -- 2.47.2