From: Lucas De Marchi Date: Wed, 25 Jan 2012 14:22:50 +0000 (-0200) Subject: testsuite: add trap to stat() and friends including tests X-Git-Tag: v5~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1426a613fa172604a4a3321238fdc6e53017f610;p=thirdparty%2Fkmod.git testsuite: add trap to stat() and friends including tests Add trap to stat(): we need to trap other functions too, depending on stat.h, the function from glibc that is actually called may be stat64 or __xstat() too. --- diff --git a/testsuite/path.c b/testsuite/path.c index cd2a7d49..ad750f9b 100644 --- a/testsuite/path.c +++ b/testsuite/path.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "testsuite.h" @@ -119,3 +120,76 @@ TS_EXPORT int open(const char *path, int flags, ...) return _open(p, flags); } + +TS_EXPORT int stat(const char *path, struct stat *st) +{ + const char *p; + char buf[PATH_MAX * 2]; + static int (*_stat)(const char *path, struct stat *buf); + + if (!get_rootpath(__func__)) + return -1; + + _stat = get_libc_func("stat"); + + p = trap_path(path, buf); + if (p == NULL) + return -1; + + return _stat(p, st); +} + +TS_EXPORT int stat64(const char *path, struct stat64 *st) +{ + const char *p; + char buf[PATH_MAX * 2]; + static int (*_stat64)(const char *path, struct stat64 *buf); + + if (!get_rootpath(__func__)) + return -1; + + _stat64 = get_libc_func("stat64"); + + p = trap_path(path, buf); + if (p == NULL) + return -1; + + return _stat64(p, st); +} + +TS_EXPORT int __xstat(int ver, const char *path, struct stat *st) +{ + const char *p; + char buf[PATH_MAX * 2]; + static int (*_xstat)(int __ver, const char *__filename, + struct stat *__stat_buf); + + if (!get_rootpath(__func__)) + return -1; + + _xstat = get_libc_func("__xstat"); + + p = trap_path(path, buf); + if (p == NULL) + return -1; + + return _xstat(ver, p, st); +} + +TS_EXPORT int access(const char *path, int mode) +{ + const char *p; + char buf[PATH_MAX * 2]; + static int (*_access)(const char *path, int mode); + + if (!get_rootpath(__func__)) + return -1; + + _access = get_libc_func("access"); + + p = trap_path(path, buf); + if (p == NULL) + return -1; + + return _access(p, mode); +} diff --git a/testsuite/test-testsuite.c b/testsuite/test-testsuite.c index ec541524..84f0e07a 100644 --- a/testsuite/test-testsuite.c +++ b/testsuite/test-testsuite.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include @@ -103,10 +105,37 @@ static const struct test stestsuite_rootfs_open = { .need_spawn = true, }; +static int testsuite_rootfs_stat_access(const struct test *t) +{ + struct stat st; + + if (access("/lib/modules/a", F_OK) < 0) { + ERR("access failed: %m\n"); + return EXIT_FAILURE; + } + + if (stat("/lib/modules/a", &st) < 0) { + ERR("stat failed: %m\n"); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} +static const struct test stestsuite_rootfs_stat_access = { + .name = "testsuite_rootfs_stat_access", + .description = "test if rootfs works - stat() and access()", + .func = testsuite_rootfs_stat_access, + .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, NULL, };