]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: add trap to opendir() including tests
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 25 Jan 2012 14:42:13 +0000 (12:42 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 26 Jan 2012 18:05:04 +0000 (16:05 -0200)
testsuite/path.c
testsuite/rootfs.tar.xz
testsuite/test-testsuite.c

index ad750f9bba113d31a2ccbedfd23d0d32daa6b23c..2891ea3fcde6b9ced032f79406a9aa10eb588300 100644 (file)
@@ -1,5 +1,6 @@
 #include <assert.h>
 #include <errno.h>
+#include <dirent.h>
 #include <fcntl.h>
 #include <dlfcn.h>
 #include <limits.h>
@@ -193,3 +194,21 @@ TS_EXPORT int access(const char *path, int mode)
 
        return _access(p, mode);
 }
+
+TS_EXPORT DIR *opendir(const char *path)
+{
+       const char *p;
+       char buf[PATH_MAX * 2];
+       static int (*_opendir)(const char *path);
+
+       if (!get_rootpath(__func__))
+               return NULL;
+
+       _opendir = get_libc_func("opendir");
+
+       p = trap_path(path, buf);
+       if (p == NULL)
+               return NULL;
+
+       return (void *)(long)(*_opendir)(p);
+}
index 233caeb43e70bc1003b4da3093417def20280808..e999c9a508568b79ae480b68cf6ae5c1b6d52e26 100644 (file)
Binary files a/testsuite/rootfs.tar.xz and b/testsuite/rootfs.tar.xz differ
index 84f0e07af267d6b747035b3728ec0d7b246d8b90..73ff5b3db49c717d106cd3006299eb828bc1a45d 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
+#include <dirent.h>
 #include <errno.h>
 #include <unistd.h>
 #include <sys/stat.h>
@@ -131,11 +132,35 @@ static const struct test stestsuite_rootfs_stat_access = {
        .need_spawn = true,
 };
 
+static int testsuite_rootfs_opendir(const struct test *t)
+{
+       DIR *d;
+
+       d = opendir("/testdir");
+       if (d == NULL) {
+               ERR("opendir failed: %m\n");
+               return EXIT_FAILURE;
+       }
+
+       closedir(d);
+       return EXIT_SUCCESS;
+}
+static const struct test stestsuite_rootfs_opendir = {
+       .name = "testsuite_rootfs_opendir",
+       .description = "test if rootfs works - opendir()",
+       .func = testsuite_rootfs_opendir,
+       .config = {
+               [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/",
+       },
+       .need_spawn = true,
+};
+
 static const struct test *tests[] = {
        &stestsuite_uname,
        &stestsuite_rootfs_fopen,
        &stestsuite_rootfs_open,
        &stestsuite_rootfs_stat_access,
+       &stestsuite_rootfs_opendir,
        NULL,
 };