]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: fake kernel 4.0.20-kmod is out
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 25 Jan 2012 01:35:18 +0000 (23:35 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 26 Jan 2012 18:05:04 +0000 (16:05 -0200)
Go get it while it's fresh :-). Test fake results of "uname -r" by
LD_PRELOAD'ing uname.so.

Makefile.am
testsuite/test-testsuite.c [new file with mode: 0644]

index 42bf0b3db013043cdd9638f90443f52a89686169..4766424027b1a45cd580cd88e7807379ac9eafca 100644 (file)
@@ -145,11 +145,12 @@ testsuite_libtestsuite_la_SOURCES = testsuite/testsuite.c \
                                    testsuite/testsuite.h
 testsuite_libtestsuite_la_DEPENDENCIES = testsuite/uname.so
 
-TESTSUITE = testsuite/test-init
+TESTSUITE = testsuite/test-init testsuite/test-testsuite
 check_PROGRAMS = $(TESTSUITE)
 TESTS = $(TESTSUITE)
 
 testsuite_test_init_LDADD = testsuite/libtestsuite.la libkmod/libkmod-private.la
+testsuite_test_testsuite_LDADD = testsuite/libtestsuite.la
 
 DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc
 
diff --git a/testsuite/test-testsuite.c b/testsuite/test-testsuite.c
new file mode 100644 (file)
index 0000000..edbfe45
--- /dev/null
@@ -0,0 +1,72 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/utsname.h>
+#include <libkmod.h>
+
+#include "testsuite.h"
+
+
+#define TEST_UNAME "4.0.20-kmod"
+static int testsuite_uname(const struct test *t)
+{
+       struct utsname u;
+       int err = uname(&u);
+
+       if (err < 0)
+               exit(EXIT_FAILURE);
+
+       if (strcmp(u.release, TEST_UNAME) != 0) {
+               char *ldpreload = getenv("LD_PRELOAD");
+               ERR("u.release=%s should be %s\n", u.release, TEST_UNAME);
+               ERR("LD_PRELOAD=%s\n", ldpreload);
+               exit(EXIT_FAILURE);
+       }
+
+       exit(EXIT_SUCCESS);
+}
+static const struct test stestsuite_uname = {
+       .name = "testsuite_uname",
+       .description = "test if trap to uname() works",
+       .func = testsuite_uname,
+       .config = {
+               [TC_UNAME_R] = TEST_UNAME,
+       },
+       .need_spawn = true,
+};
+
+static const struct test *tests[] = {
+       &stestsuite_uname,
+       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);
+}