|
From: Cyril H. <su...@li...> - 2013-10-23 12:51:44
|
The branch, master, has been updated
via ba293cb1bc6f2dc48be2eac55e2f4c4eb1a47d1e (commit)
via 226edbe58217837e076d94b2d0d882a13117da6c (commit)
via 49e58686340a5f5f939018b8f0520ad6c04c8445 (commit)
from b968712a8cce12862e24d0461b073eaabe9cd3aa (commit)
- Log -----------------------------------------------------------------
commit ba293cb1bc6f2dc48be2eac55e2f4c4eb1a47d1e
Author: Zeng Linggang <zen...@cn...>
Date: Wed Oct 23 14:51:35 2013 +0800
acct/acct01.c: clean up
Using loops to the test.
Signed-off-by: Zeng Linggang <zen...@cn...>
commit 226edbe58217837e076d94b2d0d882a13117da6c
Author: Wang, Xiaoguang <wan...@cn...>
Date: Tue Oct 22 16:27:16 2013 +0800
tst_res: add some common errno values
Signed-off-by: Xiaoguang Wang <wan...@cn...>
commit 49e58686340a5f5f939018b8f0520ad6c04c8445
Author: Wang, Xiaoguang <wan...@cn...>
Date: Mon Oct 21 16:30:16 2013 +0800
access/access05.c: clean up
Signed-off-by: Xiaoguang Wang <wan...@cn...>
-----------------------------------------------------------------------
Summary of changes:
lib/tst_res.c | 5 +
testcases/kernel/syscalls/access/access05.c | 204 +++++++++------------------
testcases/kernel/syscalls/acct/acct01.c | 196 ++++++++++++++------------
3 files changed, 179 insertions(+), 226 deletions(-)
diff --git a/lib/tst_res.c b/lib/tst_res.c
index 245bd5f..f73022b 100644
--- a/lib/tst_res.c
+++ b/lib/tst_res.c
@@ -249,7 +249,12 @@ static const char *strerrnodef(int err)
PAIR(EPIPE)
PAIR(EDOM)
PAIR(ERANGE)
+ PAIR(EDEADLK)
PAIR(ENAMETOOLONG)
+ PAIR(ENOLCK)
+ PAIR(ENOSYS)
+ PAIR(ENOTEMPTY)
+ PAIR(ELOOP)
};
return pair_lookup(errno_pairs, err);
}
diff --git a/testcases/kernel/syscalls/access/access05.c b/testcases/kernel/syscalls/access/access05.c
index be86225..739b4b2 100644
--- a/testcases/kernel/syscalls/access/access05.c
+++ b/testcases/kernel/syscalls/access/access05.c
@@ -49,6 +49,7 @@
#include "test.h"
#include "usctest.h"
+#include "safe_macros.h"
#define INV_OK -1
#define TEST_FILE1 "test_file1"
@@ -56,13 +57,6 @@
#define TEST_FILE3 "test_file3"
#define TEST_FILE4 "test_file4"
-#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
-
-static void setup1(void); /* setup() to test access() for EACCES */
-static void setup2(void); /* setup() to test access() for EACCES */
-static void setup3(void); /* setup() to test access() for EACCES */
-static void setup4(void); /* setup() to test access() for EINVAL */
-static void longpath_setup(); /* setup function to test access() for ENAMETOOLONG */
#if !defined(UCLINUX)
static char high_address_node[64];
@@ -74,22 +68,21 @@ static struct test_case_t {
char *pathname;
int a_mode;
int exp_errno;
- void (*setupfunc) (void);
} test_cases[] = {
- {TEST_FILE1, R_OK, EACCES, setup1},
- {TEST_FILE2, W_OK, EACCES, setup2},
- {TEST_FILE3, X_OK, EACCES, setup3},
- {TEST_FILE4, INV_OK, EINVAL, setup4},
+ {TEST_FILE1, R_OK, EACCES},
+ {TEST_FILE2, W_OK, EACCES},
+ {TEST_FILE3, X_OK, EACCES},
+ {TEST_FILE4, INV_OK, EINVAL},
#if !defined(UCLINUX)
- {(char *)-1, R_OK, EFAULT, NULL},
- {high_address_node, R_OK, EFAULT, NULL},
+ {(char *)-1, R_OK, EFAULT},
+ {high_address_node, R_OK, EFAULT},
#endif
- {"", W_OK, ENOENT, NULL},
- {longpathname, R_OK, ENAMETOOLONG, longpath_setup},
+ {"", W_OK, ENOENT},
+ {longpathname, R_OK, ENAMETOOLONG},
};
char *TCID = "access05";
-int TST_TOTAL = sizeof(test_cases) / sizeof(*test_cases);
+int TST_TOTAL = ARRAY_SIZE(test_cases);
static int exp_enos[] = { EACCES, EFAULT, EINVAL, ENOENT, ENAMETOOLONG, 0 };
@@ -97,6 +90,7 @@ static const char nobody_uid[] = "nobody";
static struct passwd *ltpuser;
static void setup(void);
+static void access_verify(int i);
static void cleanup(void);
static char *bad_addr;
@@ -105,8 +99,6 @@ int main(int ac, char **av)
{
int lc;
char *msg;
- char *file_name;
- int access_mode;
int i;
msg = parse_opts(ac, av, NULL, NULL);
@@ -120,39 +112,8 @@ int main(int ac, char **av)
for (lc = 0; TEST_LOOPING(lc); lc++) {
tst_count = 0;
- for (i = 0; i < TST_TOTAL; i++) {
- file_name = test_cases[i].pathname;
- access_mode = test_cases[i].a_mode;
-
-#if !defined(UCLINUX)
- if (file_name == high_address_node)
- file_name = get_high_address();
-#endif
-
- /*
- * Call access(2) to test different test conditions.
- * verify that it fails with -1 return value and
- * sets appropriate errno.
- */
- TEST(access(file_name, access_mode));
-
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL,
- "access(%s, %#o) succeeded unexpectedly",
- file_name, access_mode);
- continue;
- }
-
- if (TEST_ERRNO == test_cases[i].exp_errno)
- tst_resm(TPASS | TTERRNO,
- "access failed as expected");
- else
- tst_resm(TFAIL | TTERRNO,
- "access failed unexpectedly; expected: "
- "%d - %s",
- test_cases[i].exp_errno,
- strerror(test_cases[i].exp_errno));
- }
+ for (i = 0; i < TST_TOTAL; i++)
+ access_verify(i);
}
cleanup();
@@ -161,17 +122,13 @@ int main(int ac, char **av)
static void setup(void)
{
- int i;
+ int fd;
tst_sig(NOFORK, DEF_HANDLER, cleanup);
tst_require_root(NULL);
- ltpuser = getpwnam(nobody_uid);
- if (ltpuser == NULL)
- tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
- if (setuid(ltpuser->pw_uid) == -1)
- tst_brkm(TBROK | TERRNO, NULL, "setuid failed");
-
+ ltpuser = SAFE_GETPWNAM(cleanup, nobody_uid);
+ SAFE_SETUID(cleanup, ltpuser->pw_uid);
TEST_PAUSE;
#if !defined(UCLINUX)
@@ -179,98 +136,73 @@ static void setup(void)
MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
if (bad_addr == MAP_FAILED)
tst_brkm(TBROK | TERRNO, NULL, "mmap failed");
- test_cases[5].pathname = bad_addr;
+ test_cases[4].pathname = bad_addr;
+
+ test_cases[5].pathname = get_high_address();
#endif
tst_tmpdir();
- for (i = 0; i < TST_TOTAL; i++)
- if (test_cases[i].setupfunc != NULL)
- test_cases[i].setupfunc();
+ /*
+ * create TEST_FILE1 to test R_OK EACCESS
+ */
+ fd = SAFE_CREAT(cleanup, TEST_FILE1, 0333);
+ SAFE_CLOSE(cleanup, fd);
+
+ /*
+ * create TEST_FILE2 to test W_OK EACCESS
+ */
+ fd = SAFE_CREAT(cleanup, TEST_FILE2, 0555);
+ SAFE_CLOSE(cleanup, fd);
+
+ /*
+ * create TEST_FILE3 to test X_OK EACCESS
+ */
+ fd = SAFE_CREAT(cleanup, TEST_FILE3, 0666);
+ SAFE_CLOSE(cleanup, fd);
+
+ /*
+ * create TEST_FILE4 to test EINVAL
+ */
+ fd = SAFE_CREAT(cleanup, TEST_FILE4, 0333);
+ SAFE_CLOSE(cleanup, fd);
+
+ /*
+ *setup to create a node with a name length exceeding
+ *the MAX length of PATH_MAX.
+ */
+ memset(longpathname, 'a', sizeof(longpathname) - 1);
}
-static void setup_file(const char *file, mode_t perms)
-{
- int fd = open(file, O_RDWR | O_CREAT, FILE_MODE);
- if (fd == -1)
- tst_brkm(TBROK | TERRNO, cleanup,
- "open(%s, O_RDWR|O_CREAT, %#o) failed",
- file, FILE_MODE);
-
- if (fchmod(fd, perms) < 0)
- tst_brkm(TBROK | TERRNO, cleanup, "chmod(%s, %#o) failed",
- file, perms);
- if (close(fd) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed", file);
-}
-
-/*
- * setup1() - Setup function to test access() for return value -1
- * and errno EACCES when read access denied for specified
- * testfile.
- *
- * Creat/open a testfile and close it.
- * Deny read access permissions on testfile.
- * This function returns 0.
- */
-static void setup1(void)
-{
- setup_file(TEST_FILE1, 0333);
-}
-
-/*
- * setup2() - Setup function to test access() for return value -1 and
- * errno EACCES when write access denied on testfile.
- *
- * Creat/open a testfile and close it.
- * Deny write access permissions on testfile.
- * This function returns 0.
- */
-static void setup2(void)
+static void access_verify(int i)
{
- setup_file(TEST_FILE2, 0555);
-}
+ char *file_name;
+ int access_mode;
-/*
- * setup3() - Setup function to test access() for return value -1 and
- * errno EACCES when execute access denied on testfile.
- *
- * Creat/open a testfile and close it.
- * Deny search access permissions on testfile.
- * This function returns 0.
- */
-static void setup3(void)
-{
- setup_file(TEST_FILE3, 0666);
-}
+ file_name = test_cases[i].pathname;
+ access_mode = test_cases[i].a_mode;
-/*
- * setup4() - Setup function to test access() for return value -1
- * and errno EINVAL when specified access mode argument is
- * invalid.
- *
- * Creat/open a testfile and close it.
- * This function returns 0.
- */
-static void setup4(void)
-{
- setup_file(TEST_FILE4, FILE_MODE);
-}
+ TEST(access(file_name, access_mode));
-/*
- * longpath_setup() - setup to create a node with a name length exceeding
- * the MAX. length of PATH_MAX.
- */
-static void longpath_setup(void)
-{
- int i;
+ if (TEST_RETURN != -1) {
+ tst_resm(TFAIL, "access(%s, %#o) succeeded unexpectedly",
+ file_name, access_mode);
+ return;
+ }
- for (i = 0; i <= (PATH_MAX + 1); i++)
- longpathname[i] = 'a';
+ if (TEST_ERRNO == test_cases[i].exp_errno) {
+ tst_resm(TPASS | TTERRNO, "access failed as expected");
+ } else {
+ tst_resm(TFAIL | TTERRNO,
+ "access failed unexpectedly; expected: "
+ "%d - %s", test_cases[i].exp_errno,
+ strerror(test_cases[i].exp_errno));
+ }
}
static void cleanup(void)
{
TEST_CLEANUP;
+
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/acct/acct01.c b/testcases/kernel/syscalls/acct/acct01.c
index 462fd5a..ee794cc 100644
--- a/testcases/kernel/syscalls/acct/acct01.c
+++ b/testcases/kernel/syscalls/acct/acct01.c
@@ -1,39 +1,29 @@
/*
*
- * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (c) International Business Machines Corp., 2002
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/* 12/03/2002 Port to LTP ro...@us... */
+/* 12/03/2002 Port to LTP ro...@us... */
/* 06/30/2001 Port to Linux nsh...@us... */
/*
- * NAME
- * acct01.c -- test acct
- *
- * CALLS
- * acct
- *
* ALGORITHM
* issue calls to acct and test the returned values against
* expected results
- *
- * RESTRICTIONS
- * This must run root since the acct call may only be done
- * by root. Use the TERM flag, to clean up files.
*/
#include <sys/types.h>
@@ -41,7 +31,7 @@
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
-#include <stdio.h> /* needed by testhead.h */
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -49,100 +39,126 @@
#include "usctest.h"
#include "safe_macros.h"
-char *TCID = "acct01";
-int TST_TOTAL = 6;
+#define TEST_FILE1 "/"
+#define TEST_FILE2 "/dev/null"
+#define TEST_FILE3 "/tmp/does/not/exist"
+#define TEST_FILE4 "/etc/fstab/"
+#define TEST_FILE5 "./tmpfile"
+
+static void setup(void);
+static void cleanup(void);
+static void setup2(void);
+static void cleanup2(void);
+static void acct_verify(int);
+
+static struct test_case_t {
+ char *filename;
+ char *exp_errval;
+ int exp_errno;
+ void (*setupfunc) ();
+ void (*cleanfunc) ();
+} test_cases[] = {
+ {TEST_FILE1, "EISDIR", EISDIR, NULL, NULL},
+ {TEST_FILE2, "EACCES", EACCES, NULL, NULL},
+ {TEST_FILE3, "ENOENT", ENOENT, NULL, NULL},
+ {TEST_FILE4, "ENOTDIR", ENOTDIR, NULL, NULL},
+ {TEST_FILE5, "EPERM", EPERM, setup2, cleanup2},
+};
-char tmpbuf[80];
-int fd;
+char *TCID = "acct01";
+int TST_TOTAL = ARRAY_SIZE(test_cases);
+static struct passwd *ltpuser;
+static int exp_enos[] = { EISDIR, EACCES, ENOENT, ENOTDIR, EPERM, 0 };
-static void cleanup(void)
+int main(int argc, char *argv[])
{
+ int lc;
+ int i;
- if (acct(NULL) == -1)
- tst_resm(TBROK | TERRNO, "acct(NULL) failed");
+ setup();
- tst_rmdir();
+ TEST_EXP_ENOS(exp_enos);
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+ for (i = 0; i < TST_TOTAL; i++)
+ acct_verify(i);
+ }
+
+ cleanup();
+ tst_exit();
}
static void setup(void)
{
+ int fd;
- /*
- * XXX: FreeBSD says you must always be superuser, but Linux says you
- * need to have CAP_SYS_PACCT capability.
- *
- * Either way, it's better to do this to test out the EPERM
- * requirement.
- */
tst_require_root(NULL);
tst_tmpdir();
+ ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
+
+ fd = SAFE_CREAT(cleanup, TEST_FILE5, 0777);
+ SAFE_CLOSE(cleanup, fd);
+
+ if (acct(TEST_FILE5) == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "acct failed unexpectedly");
+
/* turn off acct, so we are in a known state */
if (acct(NULL) == -1) {
- if (errno == ENOSYS)
+ if (errno == ENOSYS) {
tst_brkm(TCONF, cleanup,
- "BSD process accounting is not configured in this "
- "kernel");
- else
+ "BSD process accounting is not configured in "
+ "this kernel");
+ } else {
tst_brkm(TBROK | TERRNO, cleanup, "acct(NULL) failed");
+ }
}
}
-int main(int argc, char *argv[])
+static void acct_verify(int i)
{
- struct passwd *pwent;
- setup();
+ if (test_cases[i].setupfunc)
+ test_cases[i].setupfunc();
- /* EISDIR */
- if (acct("/") == -1 && errno == EISDIR)
- tst_resm(TPASS, "Failed with EISDIR as expected");
- else
- tst_brkm(TFAIL | TERRNO, cleanup,
- "didn't fail as expected; expected EISDIR");
-
- /* EACCES */
- if (acct("/dev/null") == -1 && errno == EACCES)
- tst_resm(TPASS, "Failed with EACCES as expected");
- else
- tst_brkm(TFAIL | TERRNO, cleanup,
- "didn't fail as expected; expected EACCES");
-
- /* ENOENT */
- if (acct("/tmp/does/not/exist") == -1 && errno == ENOENT)
- tst_resm(TPASS, "Failed with ENOENT as expected");
- else
- tst_brkm(TBROK | TERRNO, cleanup,
- "didn't fail as expected; expected ENOENT");
-
- /* ENOTDIR */
- if (acct("/etc/fstab/") == -1 && errno == ENOTDIR)
- tst_resm(TPASS, "Failed with ENOTDIR as expected");
- else
- tst_brkm(TFAIL | TERRNO, cleanup,
- "didn't fail as expected; expected ENOTDIR");
-
- /* EPERM */
- sprintf(tmpbuf, "./%s.%d", TCID, getpid());
- fd = SAFE_CREAT(cleanup, tmpbuf, 0777);
- SAFE_CLOSE(cleanup, fd);
+ TEST(acct(test_cases[i].filename));
- if (acct(tmpbuf) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "acct failed unexpectedly");
+ if (test_cases[i].cleanfunc)
+ test_cases[i].cleanfunc();
- pwent = SAFE_GETPWNAM(cleanup, "nobody");
- SAFE_SETEUID(cleanup, pwent->pw_uid);
+ if (TEST_RETURN != -1) {
+ tst_resm(TFAIL, "acct(%s) succeeded unexpectedly",
+ test_cases[i].filename);
+ return;
+ }
+ if (TEST_ERRNO == test_cases[i].exp_errno) {
+ tst_resm(TPASS | TTERRNO, "acct failed as expected");
+ } else {
+ tst_resm(TFAIL | TTERRNO,
+ "acct failed unexpectedly; expected: %d - %s",
+ test_cases[i].exp_errno,
+ strerror(test_cases[i].exp_errno));
+ }
+}
- if (acct(tmpbuf) == -1 && errno == EPERM)
- tst_resm(TPASS, "Failed with EPERM as expected");
- else
- tst_brkm(TBROK | TERRNO, cleanup,
- "didn't fail as expected; expected EPERM");
+static void setup2(void)
+{
+ SAFE_SETEUID(cleanup, ltpuser->pw_uid);
+}
+static void cleanup2(void)
+{
SAFE_SETEUID(cleanup, 0);
- SAFE_UNLINK(cleanup, tmpbuf);
+}
- cleanup();
- tst_exit();
+static void cleanup(void)
+{
+ TEST_CLEANUP;
+
+ if (acct(NULL) == -1)
+ tst_resm(TBROK | TERRNO, "acct(NULL) failed");
+
+ tst_rmdir();
}
hooks/post-receive
--
ltp
|