Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/librumphijack more test cases:
details: https://anonhg.NetBSD.org/src/rev/b7ac2b6997a4
branches: trunk
changeset: 762341:b7ac2b6997a4
user: pooka <pooka%NetBSD.org@localhost>
date: Sat Feb 19 19:57:28 2011 +0000
description:
more test cases:
* // prefix
* fchdir
* cd-via-symlink
diffstat:
tests/lib/librumphijack/h_cwd.c | 119 ++++++++++++++++++++++++++++++++------
tests/lib/librumphijack/t_cwd.sh | 47 ++++++++++----
2 files changed, 131 insertions(+), 35 deletions(-)
diffs (234 lines):
diff -r ae0adc67d113 -r b7ac2b6997a4 tests/lib/librumphijack/h_cwd.c
--- a/tests/lib/librumphijack/h_cwd.c Sat Feb 19 19:42:07 2011 +0000
+++ b/tests/lib/librumphijack/h_cwd.c Sat Feb 19 19:57:28 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: h_cwd.c,v 1.1 2011/02/19 13:19:52 pooka Exp $ */
+/* $NetBSD: h_cwd.c,v 1.2 2011/02/19 19:57:28 pooka Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -32,59 +32,136 @@
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <string.h>
#include <unistd.h>
-int
-main(void)
+static const char *prefix;
+static size_t prefixlen;
+static char buf[1024];
+static char pwd[1024];
+
+static const char *
+makepath(const char *tail)
+{
+
+ strcpy(buf, prefix);
+ if (prefix[prefixlen-1] != '/')
+ strcat(buf, "/");
+ strcat(buf, tail);
+
+ return buf;
+}
+
+static void
+dochdir(const char *path, const char *errmsg)
{
- char pwd[1024];
+
+ if (chdir(path) == -1)
+ err(1, "%s", errmsg);
+}
+
+static void
+dofchdir(const char *path, const char *errmsg)
+{
+ int fd;
- if (chdir("/rump") == -1)
- err(1, "chdir1");
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ err(1, "open %s", errmsg);
+ if (fchdir(fd) == -1)
+ err(1, "fchdir %s", errmsg);
+ close(fd);
+}
+static void (*thechdir)(const char *, const char *);
+
+static void
+simple(void)
+{
+
+ thechdir(prefix, "chdir1");
if (getcwd(pwd, sizeof(pwd)) == NULL)
err(1, "getcwd1");
- if (strcmp(pwd, "/rump") != 0)
+ if (strcmp(pwd, prefix) != 0)
errx(1, "strcmp1");
if (mkdir("dir", 0777) == -1)
err(1, "mkdir2");
- if (chdir("dir") == -1)
- err(1, "chdir2");
+ thechdir("dir", "chdir2");
if (getcwd(pwd, sizeof(pwd)) == NULL)
err(1, "getcwd2");
- if (strcmp(pwd, "/rump/dir") != 0)
+ if (strcmp(pwd, makepath("dir")) != 0)
errx(1, "strcmp2");
if (mkdir("dir", 0777) == -1)
err(1, "mkdir3");
- if (chdir("dir") == -1)
- err(1, "chdir3");
+ thechdir("dir", "chdir3");
if (getcwd(pwd, sizeof(pwd)) == NULL)
err(1, "getcwd3");
- if (strcmp(pwd, "/rump/dir/dir") != 0)
+ if (strcmp(pwd, makepath("dir/dir")) != 0)
errx(1, "strcmp3");
- if (chdir("..") == -1)
- err(1, "chdir4");
+ thechdir("..", "chdir4");
if (getcwd(pwd, sizeof(pwd)) == NULL)
err(1, "getcwd4");
- if (strcmp(pwd, "/rump/dir") != 0)
+ if (strcmp(pwd, makepath("dir")) != 0)
errx(1, "strcmp4");
- if (chdir("../../../../../../..") == -1)
- err(1, "chdir5");
+
+ thechdir("../../../../../../..", "chdir5");
if (getcwd(pwd, sizeof(pwd)) == NULL)
err(1, "getcwd5");
- if (strcmp(pwd, "/rump") != 0)
+ if (strcmp(pwd, prefix) != 0)
errx(1, "strcmp5");
- if (chdir("/") == -1)
- err(1, "chdir6");
+ thechdir("/", "chdir6");
if (getcwd(pwd, sizeof(pwd)) == NULL)
err(1, "getcwd6");
if (strcmp(pwd, "/") != 0)
errx(1, "strcmp6");
+}
+
+static void
+symlinktest(void)
+{
+
+ thechdir(prefix, "chdir1");
+ if (mkdir("adir", 0777) == -1)
+ err(1, "mkdir1");
+ if (mkdir("anotherdir", 0777) == -1)
+ err(1, "mkdir2");
+
+ if (symlink("/adir", "anotherdir/lincthesink") == -1)
+ err(1, "symlink");
+
+ thechdir("anotherdir/lincthesink", "chdir2");
+ if (getcwd(pwd, sizeof(pwd)) == NULL)
+ err(1, "getcwd");
+ if (strcmp(pwd, makepath("adir")) != 0)
+ errx(1, "strcmp");
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ if (argc != 4)
+ errx(1, "usage");
+
+ prefix = argv[1];
+ prefixlen = strlen(argv[1]);
+
+ if (strcmp(argv[3], "chdir") == 0)
+ thechdir = dochdir;
+ else if (strcmp(argv[3], "fchdir") == 0)
+ thechdir = dofchdir;
+ else
+ errx(1, "invalid chdir type");
+
+ if (strcmp(argv[2], "simple") == 0)
+ simple();
+ if (strcmp(argv[2], "symlink") == 0)
+ symlinktest();
return 0;
}
diff -r ae0adc67d113 -r b7ac2b6997a4 tests/lib/librumphijack/t_cwd.sh
--- a/tests/lib/librumphijack/t_cwd.sh Sat Feb 19 19:42:07 2011 +0000
+++ b/tests/lib/librumphijack/t_cwd.sh Sat Feb 19 19:57:28 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_cwd.sh,v 1.1 2011/02/19 13:19:52 pooka Exp $
+# $NetBSD: t_cwd.sh,v 1.2 2011/02/19 19:57:28 pooka Exp $
#
# Copyright (c) 2011 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -28,26 +28,45 @@
rumpsrv='rump_server -lrumpvfs'
export RUMP_SERVER=unix://csock
-atf_test_case basic cleanup
-basic_head()
+test_case()
{
- atf_set "descr" "basic cwd test"
+ local name="${1}"; shift
+
+ atf_test_case "${name}" cleanup
+ eval "${name}_head() { }"
+ eval "${name}_body() { \
+ export RUMPHIJACK="path=${1}" ; \
+ atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER} ; \
+ testbody " "${@}" "; \
+ }"
+ eval "${name}_cleanup() { \
+ rump.halt
+ }"
}
-basic_body()
+test_case basic_chdir /rump simple chdir
+test_case basic_fchdir /rump simple fchdir
+test_case slash_chdir // simple chdir
+test_case slash_fchdir // simple fchdir
+test_case symlink_chdir /rump symlink chdir
+test_case symlink_fchdir /rump symlink fchdir
+test_case symlink_slash_chdir // symlink chdir
+test_case symlink_slash_fchdir // symlink fchdir
+
+testbody()
{
-
- atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
- $(atf_get_srcdir)/h_cwd
-}
-
-basic_cleanup()
-{
- rump.halt
+ $(atf_get_srcdir)/h_cwd $*
}
atf_init_test_cases()
{
- atf_add_test_case basic
+ atf_add_test_case basic_chdir
+ atf_add_test_case basic_fchdir
+ atf_add_test_case slash_chdir
+ atf_add_test_case slash_fchdir
+ atf_add_test_case symlink_chdir
+ atf_add_test_case symlink_fchdir
+ atf_add_test_case symlink_slash_chdir
+ atf_add_test_case symlink_slash_fchdir
}
Home |
Main Index |
Thread Index |
Old Index