* [LTP] [PATCH v2 0/2] Fix getcwd0[12] tests for Android devices @ 2017-08-28 16:40 Sandeep Patil 2017-08-28 16:40 ` [LTP] [PATCH v2 1/2] getcwd01: Remove unnecessary usage of temporary directory Sandeep Patil 2017-08-28 16:40 ` [LTP] [PATCH v2 2/2] android: getcwd02: use temp dir from $TMPDIR if present Sandeep Patil 0 siblings, 2 replies; 5+ messages in thread From: Sandeep Patil @ 2017-08-28 16:40 UTC (permalink / raw) To: ltp Removes the unnecessary usage of temporary directory from getcwd01 and falls back to the directory pointed to by $TMPDIR if "/tmp" doesn't exist in getcwd02 test. v1->v2 ------ - Split the patch into separate patches for getcwd01 and getcwd02 - Remove the unnecessary header added in v1 (getcwd_helper.h) - Change the fallback order for tmpdir in getcwd02 as pointed in v1 review Sandeep Patil (2): getcwd01: Remove unnecessary usage of temporary directory android: getcwd02: use temp dir from $TMPDIR if present testcases/kernel/syscalls/getcwd/getcwd01.c | 6 ---- testcases/kernel/syscalls/getcwd/getcwd02.c | 43 +++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 9 deletions(-) -- 2.14.1.342.g6490525c54-goog ^ permalink raw reply [flat|nested] 5+ messages in thread
* [LTP] [PATCH v2 1/2] getcwd01: Remove unnecessary usage of temporary directory 2017-08-28 16:40 [LTP] [PATCH v2 0/2] Fix getcwd0[12] tests for Android devices Sandeep Patil @ 2017-08-28 16:40 ` Sandeep Patil 2017-08-29 11:21 ` Cyril Hrubis 2017-08-28 16:40 ` [LTP] [PATCH v2 2/2] android: getcwd02: use temp dir from $TMPDIR if present Sandeep Patil 1 sibling, 1 reply; 5+ messages in thread From: Sandeep Patil @ 2017-08-28 16:40 UTC (permalink / raw) To: ltp The test checks for errors returned from the system call and doesn't really need a temporary directory in order to do that. Signed-off-by: Sandeep Patil <sspatil@google.com> --- testcases/kernel/syscalls/getcwd/getcwd01.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/testcases/kernel/syscalls/getcwd/getcwd01.c b/testcases/kernel/syscalls/getcwd/getcwd01.c index fdf306103..1199e9f2e 100644 --- a/testcases/kernel/syscalls/getcwd/getcwd01.c +++ b/testcases/kernel/syscalls/getcwd/getcwd01.c @@ -74,13 +74,7 @@ static void verify_getcwd(unsigned int n) tst_res(TPASS | TTERRNO, "getcwd() failed as expected"); } -static void setup(void) -{ - SAFE_CHDIR("/tmp"); -} - static struct tst_test test = { - .setup = setup, .tcnt = ARRAY_SIZE(tcases), .test = verify_getcwd }; -- 2.14.1.342.g6490525c54-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH v2 1/2] getcwd01: Remove unnecessary usage of temporary directory 2017-08-28 16:40 ` [LTP] [PATCH v2 1/2] getcwd01: Remove unnecessary usage of temporary directory Sandeep Patil @ 2017-08-29 11:21 ` Cyril Hrubis 0 siblings, 0 replies; 5+ messages in thread From: Cyril Hrubis @ 2017-08-29 11:21 UTC (permalink / raw) To: ltp Hi! Pushed, thanks. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 5+ messages in thread
* [LTP] [PATCH v2 2/2] android: getcwd02: use temp dir from $TMPDIR if present 2017-08-28 16:40 [LTP] [PATCH v2 0/2] Fix getcwd0[12] tests for Android devices Sandeep Patil 2017-08-28 16:40 ` [LTP] [PATCH v2 1/2] getcwd01: Remove unnecessary usage of temporary directory Sandeep Patil @ 2017-08-28 16:40 ` Sandeep Patil 2017-08-29 11:22 ` Cyril Hrubis 1 sibling, 1 reply; 5+ messages in thread From: Sandeep Patil @ 2017-08-28 16:40 UTC (permalink / raw) To: ltp getcwd02 test are broken on an Android system as the device doesn't have "/tmp", so make sure the test checks if a directory exists before using it as a temporary directory. Look for an altternative path in 'TMPDIR' environment variable and fallback to using that as the temporary directory for the test if /tmp is not found. Signed-off-by: Sandeep Patil <sspatil@google.com> --- testcases/kernel/syscalls/getcwd/getcwd02.c | 43 +++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/testcases/kernel/syscalls/getcwd/getcwd02.c b/testcases/kernel/syscalls/getcwd/getcwd02.c index 384157d42..cff2124b7 100644 --- a/testcases/kernel/syscalls/getcwd/getcwd02.c +++ b/testcases/kernel/syscalls/getcwd/getcwd02.c @@ -27,9 +27,12 @@ #include <unistd.h> #include <stdlib.h> #include <string.h> +#include <sys/types.h> +#include <sys/stat.h> + #include "tst_test.h" -#define TMPDIR "/tmp" +#define GETCWD_TMPDIR_PATH "/tmp" static char exp_buf[PATH_MAX]; static char buffer[PATH_MAX]; @@ -43,6 +46,38 @@ static struct t_case { {NULL, PATH_MAX} }; +static int dir_exists(const char *dirpath) +{ + struct stat sb; + + if (!stat(dirpath, &sb) && S_ISDIR(sb.st_mode)) + return 1; + + return 0; +} + +static const char *get_tmpdir_path(void) +{ + char *tmpdir = GETCWD_TMPDIR_PATH; + + if (dir_exists(tmpdir)) + goto done; + + /* fallback to $TMPDIR */ + tmpdir = getenv("TMPDIR"); + if (!tmpdir) + tst_brk(TBROK | TERRNO, "Failed to get $TMPDIR"); + + if (tmpdir[0] != '/') + tst_brk(TBROK, "$TMPDIR must be an absolute path"); + + if (!dir_exists(tmpdir)) + tst_brk(TBROK | TERRNO, "TMPDIR '%s' doesn't exist", tmpdir); + +done: + return tmpdir; +} + static void verify_getcwd(unsigned int n) { struct t_case *tc = &tcases[n]; @@ -71,9 +106,11 @@ end: static void setup(void) { - SAFE_CHDIR(TMPDIR); + const char *tmpdir = get_tmpdir_path(); + + SAFE_CHDIR(tmpdir); - if (!realpath(TMPDIR, exp_buf)) + if (!realpath(tmpdir, exp_buf)) tst_brk(TBROK | TERRNO, "realpath() failed"); tst_res(TINFO, "Expected path '%s'", exp_buf); -- 2.14.1.342.g6490525c54-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH v2 2/2] android: getcwd02: use temp dir from $TMPDIR if present 2017-08-28 16:40 ` [LTP] [PATCH v2 2/2] android: getcwd02: use temp dir from $TMPDIR if present Sandeep Patil @ 2017-08-29 11:22 ` Cyril Hrubis 0 siblings, 0 replies; 5+ messages in thread From: Cyril Hrubis @ 2017-08-29 11:22 UTC (permalink / raw) To: ltp Hi! Pushed with a minor change, thanks. I got rid of the GETCWD_TMPDIR_PATH macro, we use the string only in a single place so there is no need to define it. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-08-29 11:22 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-08-28 16:40 [LTP] [PATCH v2 0/2] Fix getcwd0[12] tests for Android devices Sandeep Patil 2017-08-28 16:40 ` [LTP] [PATCH v2 1/2] getcwd01: Remove unnecessary usage of temporary directory Sandeep Patil 2017-08-29 11:21 ` Cyril Hrubis 2017-08-28 16:40 ` [LTP] [PATCH v2 2/2] android: getcwd02: use temp dir from $TMPDIR if present Sandeep Patil 2017-08-29 11:22 ` Cyril Hrubis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox