From: Lucas De Marchi Date: Wed, 25 Jan 2012 14:42:13 +0000 (-0200) Subject: testsuite: add trap to opendir() including tests X-Git-Tag: v5~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e36cb18e1a4b904a739980637c4a6165e206691;p=thirdparty%2Fkmod.git testsuite: add trap to opendir() including tests --- diff --git a/testsuite/path.c b/testsuite/path.c index ad750f9b..2891ea3f 100644 --- a/testsuite/path.c +++ b/testsuite/path.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -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); +} diff --git a/testsuite/rootfs.tar.xz b/testsuite/rootfs.tar.xz index 233caeb4..e999c9a5 100644 Binary files a/testsuite/rootfs.tar.xz and b/testsuite/rootfs.tar.xz differ diff --git a/testsuite/test-testsuite.c b/testsuite/test-testsuite.c index 84f0e07a..73ff5b3d 100644 --- a/testsuite/test-testsuite.c +++ b/testsuite/test-testsuite.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -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, };