|
From: Cyril H. <su...@li...> - 2013-04-26 08:21:51
|
The branch, master, has been updated
via b3e9e5ee189c11cc36fff206896f03fdfbec63fc (commit)
via 330f4e37d8e46934fe9f86c844226926b8e60c1b (commit)
via 41dae8917c820defbc06fcaf61c807072ed13549 (commit)
via 332fe2d0634d9ed972169bdb8bbd080fd00817eb (commit)
via f85fea706a1fb8e1abcbb4bef74c28c593c8ea54 (commit)
from b662202c9b679e7c69560cd557f766f750325273 (commit)
- Log -----------------------------------------------------------------
commit b3e9e5ee189c11cc36fff206896f03fdfbec63fc
Author: Wanlong Gao <gao...@cn...>
Date: Fri Apr 26 14:55:25 2013 +0800
access05: code cleanups
Cleanup the code.
Signed-off-by: Wanlong Gao <gao...@cn...>
commit 330f4e37d8e46934fe9f86c844226926b8e60c1b
Author: Wanlong Gao <gao...@cn...>
Date: Fri Apr 26 14:55:25 2013 +0800
access04: code cleanups
Cleanup the code.
Signed-off-by: Wanlong Gao <gao...@cn...>
commit 41dae8917c820defbc06fcaf61c807072ed13549
Author: Wanlong Gao <gao...@cn...>
Date: Fri Apr 26 14:55:25 2013 +0800
access03: code cleanups
Cleanup the code.
Signed-off-by: Wanlong Gao <gao...@cn...>
commit 332fe2d0634d9ed972169bdb8bbd080fd00817eb
Author: Wanlong Gao <gao...@cn...>
Date: Fri Apr 26 14:55:25 2013 +0800
access02: code cleanups
Cleanup the code.
Signed-off-by: Wanlong Gao <gao...@cn...>
commit f85fea706a1fb8e1abcbb4bef74c28c593c8ea54
Author: Wanlong Gao <gao...@cn...>
Date: Fri Apr 26 14:55:25 2013 +0800
access01: code cleanups
Cleanup the code.
Signed-off-by: Wanlong Gao <gao...@cn...>
-----------------------------------------------------------------------
Summary of changes:
testcases/kernel/syscalls/access/access01.c | 199 ++++++--------------------
testcases/kernel/syscalls/access/access02.c | 210 ++++++++++-----------------
testcases/kernel/syscalls/access/access03.c | 105 ++------------
testcases/kernel/syscalls/access/access04.c | 75 ++--------
testcases/kernel/syscalls/access/access05.c | 141 +++++-------------
5 files changed, 188 insertions(+), 542 deletions(-)
diff --git a/testcases/kernel/syscalls/access/access01.c b/testcases/kernel/syscalls/access/access01.c
index f239f3f..2b85c1e 100644
--- a/testcases/kernel/syscalls/access/access01.c
+++ b/testcases/kernel/syscalls/access/access01.c
@@ -20,103 +20,13 @@
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA 94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
*/
-/* $Id: access01.c,v 1.8 2009/11/09 05:56:58 yaberauneya Exp $ */
-/**********************************************************
- *
- * OS Test - Silicon Graphics, Inc.
- *
- * TEST IDENTIFIER : access01
- *
- * EXECUTED BY : anyone
- *
- * TEST TITLE : Basic test for access(2) using F_OK,
- * R_OK, W_OK and X_OK arguments.
- *
- * PARENT DOCUMENT : usctpl01
- *
- * TEST CASE TOTAL : 6
- *
- * WALL CLOCK TIME : 1
- *
- * CPU TYPES : ALL
- *
- * AUTHOR : William Roske
- *
- * CO-PILOT : Dave Fenner
- *
- * DATE STARTED : 03/30/92
- *
- * INITIAL RELEASE : UNICOS 7.0
- *
- * TEST CASES
- *
- * 1.) access(2) returns 0 for F_OK...(See Description)
- * 2.) access(2) returns 0 for R_OK...(See Description)
- * 3.) access(2) returns 0 for W_OK...(See Description)
- * 4.) access(2) returns 0 for X_OK...(See Description)
- *
- * INPUT SPECIFICATIONS
- * The standard options for system call tests are accepted.
- * (See the parse_opts(3) man page).
- *
- * OUTPUT SPECIFICATIONS
- *
- * DURATION
- * Terminates - with frequency and infinite modes.
- *
- * SIGNALS
- * Uses SIGUSR1 to pause before test if option set.
- * (See the parse_opts(3) man page).
- *
- * RESOURCES
- * None
- *
- * ENVIRONMENTAL NEEDS
- * The libcuts.a and libsys.a libraries must be included in
- * the compilation of this test.
- *
- * SPECIAL PROCEDURAL REQUIREMENTS
- * None
- *
- * INTERCASE DEPENDENCIES
- * None
- *
- * DETAILED DESCRIPTION
- * This is a Phase I test for the access(2) system call. It is intended
- * to provide a limited exposure of the system call, for now. It
- * should/will be extended when full functional tests are written for
- * access(2).
- *
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- * Create a temp directory and cd to it.
- * Creat a temp file wil read, write and execute permissions.
- *
- * Test:
- * Loop if the proper options are given.
- * Execute system call with F_OK on tmp file
- * Check return code, if system call failed (return=-1)
- * Log the errno and Issue a FAIL message.
- * Otherwise, Issue a PASS message.
- * Execute system call with X_OK on tmp file...
- * Execute system call with W_OK on tmp file...
- * Execute system call with R_OK on tmp file...
- *
- * Cleanup:
- * Print errno log
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
+
+/*
+ * Description:
+ * Basic test for access(2) using F_OK, R_OK, W_OK and X_OK on tmp file
+ * AUTHOR : William Roske
+ */
#include <string.h>
#include <unistd.h>
@@ -127,77 +37,66 @@
#include <sys/stat.h>
#include "test.h"
#include "usctest.h"
-void setup();
-void cleanup();
+
char *TCID = "access01";
-int TST_TOTAL = 4;
-char Fname[255];
+char fname[255];
static struct test_case_t {
char *file;
int mode;
char *string;
int experrno;
-} Test_cases[] = {
- {
- Fname, F_OK, "F_OK", 0}, {
- Fname, X_OK, "X_OK", 0}, {
- Fname, W_OK, "W_OK", 0}, {
-Fname, R_OK, "R_OK", 0},};
+} test_cases[] = {
+ {fname, F_OK, "F_OK", 0},
+ {fname, X_OK, "X_OK", 0},
+ {fname, W_OK, "W_OK", 0},
+ {fname, R_OK, "R_OK", 0},
+};
-int Ntc = sizeof(Test_cases) / sizeof(struct test_case_t);
+int TST_TOTAL = sizeof(test_cases) / sizeof(struct test_case_t);
+
+static void setup(void);
+static void cleanup(void);
-/***********************************************************************
- * Main
- ***********************************************************************/
int main(int ac, char **av)
{
int lc;
char *msg;
int tc;
- TST_TOTAL = Ntc;
-
- if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
+ msg = parse_opts(ac, av, NULL, NULL);
+ if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
-
tst_count = 0;
+ for (tc = 0; tc < TST_TOTAL; tc++) {
+ TEST(access(test_cases[tc].file, test_cases[tc].mode));
- for (tc = 0; tc < Ntc; tc++) {
- /*
- * Call access(2)
- */
- TEST(access(Test_cases[tc].file, Test_cases[tc].mode));
-
- /* check return code */
- if (TEST_RETURN == -1 && Test_cases[tc].experrno == 0) {
+ if (TEST_RETURN == -1 && test_cases[tc].experrno == 0) {
tst_resm(TFAIL | TTERRNO,
"access(%s, %s) failed",
- Test_cases[tc].file,
- Test_cases[tc].string);
+ test_cases[tc].file,
+ test_cases[tc].string);
} else if (TEST_RETURN != -1
- && Test_cases[tc].experrno != 0) {
+ && test_cases[tc].experrno != 0) {
tst_resm(TFAIL,
"access(%s, %s) returned %ld, "
"exp -1, errno:%d",
- Test_cases[tc].file,
- Test_cases[tc].string, TEST_RETURN,
- Test_cases[tc].experrno);
+ test_cases[tc].file,
+ test_cases[tc].string, TEST_RETURN,
+ test_cases[tc].experrno);
} else {
-
if (STD_FUNCTIONAL_TEST) {
- /* No Verification test, yet... */
tst_resm(TPASS,
"access(%s, %s) returned %ld",
- Test_cases[tc].file,
- Test_cases[tc].string,
+ test_cases[tc].file,
+ test_cases[tc].string,
TEST_RETURN);
}
}
@@ -209,17 +108,15 @@ int main(int ac, char **av)
tst_exit();
}
-void setup()
+static void setup(void)
{
int fd;
struct stat stbuf;
tst_sig(FORK, DEF_HANDLER, cleanup);
- umask(0); /* reset umask avoid it affects on modes */
-
+ umask(0);
TEST_PAUSE;
-
tst_tmpdir();
/*
@@ -231,42 +128,32 @@ void setup()
"chown(\".\", -1, %d) failed", getegid());
}
- sprintf(Fname, "accessfile");
+ snprintf(fname, sizeof(fname), "accessfile");
- fd = open(Fname, O_RDWR | O_CREAT, 06777);
+ fd = open(fname, O_RDWR | O_CREAT, 06777);
if (fd == -1)
tst_brkm(TBROK | TERRNO, cleanup,
- "open(%s, O_RDWR|O_CREAT, 06777) failed", Fname);
+ "open(%s, O_RDWR|O_CREAT, 06777) failed", fname);
else if (close(fd) == -1)
- tst_resm(TINFO | TERRNO, "close(%s) failed", Fname);
+ tst_resm(TINFO | TERRNO, "close(%s) failed", fname);
/*
* force the mode to be set to 6777
*/
- if (chmod(Fname, 06777) == -1)
+ if (chmod(fname, 06777) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "chmod(%s, 06777) failed",
- Fname);
+ fname);
- stat(Fname, &stbuf);
+ stat(fname, &stbuf);
if ((stbuf.st_mode & 06777) != 06777) {
- /*
- * file can not be properly setup
- */
+ tst_brkm(TBROK, cleanup, "'%s' can't be properly setup",
+ fname);
}
-
}
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- ***************************************************************/
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- */
TEST_CLEANUP;
-
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/access/access02.c b/testcases/kernel/syscalls/access/access02.c
index 55ad73a..57b5812 100644
--- a/testcases/kernel/syscalls/access/access02.c
+++ b/testcases/kernel/syscalls/access/access02.c
@@ -18,8 +18,6 @@
*/
/*
- * Test Name: access02
- *
* Test Description:
* Verify that access() succeeds to check the read/write/execute permissions
* on a file if the mode argument passed was R_OK/W_OK/X_OK.
@@ -27,46 +25,7 @@
* Also verify that, access() succeeds to test the accessibility of the file
* referred to by symbolic link if the pathname points to a symbolic link.
*
- * Expected Result:
- * access() should return 0 value and the specified file should have
- * respective permissions set on it.
- *
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Create temporary directory.
- * Pause for SIGUSR1 if option specified.
- *
- * Test:
- * Loop if the proper options are given.
- * Execute system call
- * Check return code, if system call failed (return=-1)
- * Log the errno and Issue a FAIL message.
- * Otherwise,
- * Verify the Functionality of system call
- * if successful,
- * Issue Functionality-Pass message.
- * Otherwise,
- * Issue Functionality-Fail message.
- * Cleanup:
- * Print errno log and/or timing stats if options given
- * Delete the temporary directory created.
- *
- * Usage: <for command-line>
- * access02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -f : Turn off functionality Testing.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
* 07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- * None.
- *
*/
#include <sys/types.h>
@@ -92,54 +51,47 @@
char *TCID = "access02";
int TST_TOTAL = 4;
-int fd1, fd2, fd4; /* file descriptor for testfile(s) */
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-int setup1(); /* setup() to test access() for R_OK */
-int setup2(); /* setup() to test access() for W_OK */
-int setup3(); /* setup() to test access() for X_OK */
-int setup4(); /* setup() to test access() on symlink file */
+static int fd1, fd2, fd4;
+static const char nobody_uid[] = "nobody";
+static struct passwd *ltpuser;
-struct test_case_t { /* test case structure */
+static int setup1(void);
+static int setup2(void);
+static int setup3(void);
+static int setup4(void);
+
+static struct test_case_t {
char *pathname;
mode_t a_mode;
- int (*setupfunc) ();
+ int (*setupfunc) (void);
} test_cases[] = {
- /* Read access */
- {
- TEST_FILE1, R_OK, setup1},
- /* Write access */
- {
- TEST_FILE2, W_OK, setup2},
- /* Execute access */
- {
- TEST_FILE3, X_OK, setup3},
- /* Symlink */
- {
-SYM_FILE, W_OK, setup4},};
-
-void setup();
-void cleanup();
-int access_verify(int);
+ {TEST_FILE1, R_OK, setup1},
+ {TEST_FILE2, W_OK, setup2},
+ {TEST_FILE3, X_OK, setup3},
+ {SYM_FILE, W_OK, setup4},
+};
+
+static void setup(void);
+static void cleanup(void);
+static int access_verify(int);
int main(int ac, char **av)
{
int lc;
int i;
char *msg;
- mode_t access_mode; /* specified access mode for testfile */
- char *file_name; /* name of the testfile */
+ mode_t access_mode;
+ char *file_name;
- if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
+ msg = parse_opts(ac, av, NULL, NULL);
+ if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
setup();
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;
@@ -157,24 +109,22 @@ int main(int ac, char **av)
continue;
}
- if (STD_FUNCTIONAL_TEST) {
+ if (STD_FUNCTIONAL_TEST)
access_verify(i);
- } else
+ else
tst_resm(TPASS, "call succeeded");
}
}
cleanup();
-
tst_exit();
}
-void setup()
+static void setup(void)
{
int i;
tst_require_root(NULL);
-
tst_sig(FORK, DEF_HANDLER, cleanup);
ltpuser = getpwnam(nobody_uid);
@@ -184,7 +134,6 @@ void setup()
tst_brkm(TINFO | TERRNO, NULL, "setuid failed");
TEST_PAUSE;
-
tst_tmpdir();
for (i = 0; i < TST_TOTAL; i++)
@@ -198,12 +147,12 @@ void setup()
* Creat/open a testfile and write some data into it.
* This function returns 0.
*/
-int setup1()
+static int setup1(void)
{
char write_buf[] = "abc";
- /* Creat a test file under above directory created */
- if ((fd1 = open(TEST_FILE1, O_RDWR | O_CREAT, FILE_MODE)) == -1) {
+ fd1 = open(TEST_FILE1, O_RDWR | O_CREAT, FILE_MODE);
+ if (fd1 == -1) {
tst_brkm(TBROK | TERRNO, cleanup,
"open(%s, O_RDWR|O_CREAT, %#o) failed",
TEST_FILE1, FILE_MODE);
@@ -225,10 +174,10 @@ int setup1()
* Creat/open a testfile for writing under temporary directory.
* This function returns 0.
*/
-int setup2()
+static int setup2(void)
{
- /* Creat a test file under temporary directory */
- if ((fd2 = open(TEST_FILE2, O_RDWR | O_CREAT, FILE_MODE)) == -1) {
+ fd2 = open(TEST_FILE2, O_RDWR | O_CREAT, FILE_MODE);
+ if (fd1 == -1) {
tst_brkm(TBROK | TERRNO, cleanup,
"open(%s, O_RDWR|O_CREAT, %#o) failed",
TEST_FILE2, FILE_MODE);
@@ -244,15 +193,15 @@ int setup2()
* Creat/open a testfile and provide execute permissions to it.
* This function returns 0.
*/
-int setup3()
+static int setup3(void)
{
- int fd3; /* File handle for test file */
+ int fd3;
#ifdef UCLINUX
char exechead[] = "#!/bin/sh\n";
#endif
- /* Creat a test file under temporary directory */
- if ((fd3 = open(TEST_FILE3, O_RDWR | O_CREAT, FILE_MODE)) == -1) {
+ fd3 = open(TEST_FILE3, O_RDWR | O_CREAT, FILE_MODE);
+ if (fd3 == -1) {
tst_brkm(TBROK | TERRNO, cleanup,
"open(%s, O_RDWR|O_CREAT, %#o) failed",
TEST_FILE3, FILE_MODE);
@@ -287,10 +236,10 @@ int setup3()
* Creat a symbolic link of temporary file.
* This function returns 0.
*/
-int setup4()
+static int setup4(void)
{
- /* Creat a temporary file under temporary directory */
- if ((fd4 = open(TEMP_FILE, O_RDWR | O_CREAT, FILE_MODE)) == -1) {
+ fd4 = open(TEMP_FILE, O_RDWR | O_CREAT, FILE_MODE);
+ if (fd4 == -1) {
tst_brkm(TBROK | TERRNO, cleanup,
"open(%s, O_RDWR|O_CREAT, %#o) failed",
TEMP_FILE, FILE_MODE);
@@ -311,7 +260,7 @@ int setup4()
* This function verify the accessibility of the
* the testfile with the one verified by access().
*/
-int access_verify(int i)
+static int access_verify(int i)
{
char write_buf[] = "abc";
char read_buf[BUFSIZ];
@@ -320,40 +269,48 @@ int access_verify(int i)
rval = 0;
switch (i) {
- case 0: /*
- * The specified file has read access.
- * Attempt to read some data from the testfile
- * and if successful, access() behaviour is
- * correct.
- */
- if ((rval = read(fd1, &read_buf, sizeof(read_buf))) == -1)
+ case 0:
+ /*
+ * The specified file has read access.
+ * Attempt to read some data from the testfile
+ * and if successful, access() behaviour is
+ * correct.
+ */
+ rval = read(fd1, &read_buf, sizeof(read_buf));
+ if (rval == -1)
tst_resm(TFAIL | TERRNO, "read(%s) failed", TEST_FILE1);
break;
- case 1: /*
- * The specified file has write access.
- * Attempt to write some data to the testfile
- * and if successful, access() behaviour is correct.
- */
- if ((rval = write(fd2, write_buf, strlen(write_buf))) == -1)
+ case 1:
+ /*
+ * The specified file has write access.
+ * Attempt to write some data to the testfile
+ * and if successful, access() behaviour is correct.
+ */
+ rval = write(fd2, write_buf, strlen(write_buf));
+ if (rval == -1)
tst_resm(TFAIL | TERRNO, "write(%s) failed",
TEST_FILE2);
break;
- case 2: /*
- * The specified file has execute access.
- * Attempt to execute the specified executable
- * file, if successful, access() behaviour is correct.
- */
- if ((rval = system("./" TEST_FILE3)) != 0)
+ case 2:
+ /*
+ * The specified file has execute access.
+ * Attempt to execute the specified executable
+ * file, if successful, access() behaviour is correct.
+ */
+ rval = system("./" TEST_FILE3);
+ if (rval != 0)
tst_resm(TFAIL, "Fail to execute the %s", TEST_FILE3);
break;
- case 3: /*
- * The file pointed to by symbolic link has
- * write access.
- * Attempt to write some data to this temporary file
- * pointed to by symlink. if successful, access() bahaviour
- * is correct.
- */
- if ((rval = write(fd4, write_buf, strlen(write_buf))) == -1)
+ case 3:
+ /*
+ * The file pointed to by symbolic link has
+ * write access.
+ * Attempt to write some data to this temporary file
+ * pointed to by symlink. if successful, access() bahaviour
+ * is correct.
+ */
+ rval = write(fd4, write_buf, strlen(write_buf));
+ if (rval == -1)
tst_resm(TFAIL | TERRNO, "write(%s) failed", TEMP_FILE);
break;
default:
@@ -363,18 +320,8 @@ int access_verify(int i)
return rval;
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- *
- * Remove the test directory and testfile created in the setup.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
TEST_CLEANUP;
/* Close the testfile(s) created in the setup()s */
@@ -385,10 +332,5 @@ void cleanup()
if (close(fd4) == -1)
tst_brkm(TFAIL | TERRNO, NULL, "close(%s) failed", TEMP_FILE);
- /*
- * Delete the test directory/file and temporary directory
- * created in the setup.
- */
tst_rmdir();
-
}
diff --git a/testcases/kernel/syscalls/access/access03.c b/testcases/kernel/syscalls/access/access03.c
index 145ec74..04d6ceb 100644
--- a/testcases/kernel/syscalls/access/access03.c
+++ b/testcases/kernel/syscalls/access/access03.c
@@ -20,82 +20,11 @@
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA 94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
*/
-/* $Id: access03.c,v 1.8 2009/03/23 13:35:39 subrata_modak Exp $ */
-/**********************************************************
- *
- * OS Test - Silicon Graphics, Inc.
- *
- * TEST IDENTIFIER : access03
- *
- * EXECUTED BY : anyone
- *
- * TEST TITLE : EFAULT error testing for access(2)
- *
- * PARENT DOCUMENT : acstds01
- *
- * TEST CASE TOTAL : 8
- *
- * WALL CLOCK TIME : 1
- *
- * CPU TYPES : ALL
- *
- * AUTHOR : Kathy Olmsted
- *
- * CO-PILOT : Tom Hampson
- *
- * DATE STARTED : 05/13/92
- *
- * INITIAL RELEASE : UNICOS 7.0
- *
- * TEST CASES
- *
- * access(2) test for errno(s) EFAULT.
- *
- * INPUT SPECIFICATIONS
- * The standard options for system call tests are accepted.
- * (See the parse_opts(3) man page).
- *
- * DURATION
- * Terminates - with frequency and infinite modes.
- *
- * SIGNALS
- * Uses SIGUSR1 to pause before test if option set.
- * (See the parse_opts(3) man page).
- *
- * ENVIRONMENTAL NEEDS
- * No run-time environmental needs.
- *
- * DETAILED DESCRIPTION
- *
- * Setup:
- * Setup signal handling.
- * Make and change to a temporary directory.
- * Pause for SIGUSR1 if option specified.
- *
- * Test:
- * Loop if the proper options are given.
- * Execute system call
- * Check return code, if system call failed (return=-1)
- * Log the errno.
- * If doing functional test
- * check the errno returned and print result message
- *
- * Cleanup:
- * Print errno log and/or timing stats if options given
- * Remove the temporary directory and exit.
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
+
+/*
+ * access(2) test for errno(s) EFAULT.
+ */
#include <errno.h>
#include <string.h>
@@ -115,8 +44,8 @@ int TST_TOTAL = 8;
int exp_enos[] = { EFAULT, 0 }; /* List must end with 0 */
/* XXX (garrcoop): uh, this isn't a bad address yo. */
-void *low_addr;
-void *high_addr;
+static void *low_addr;
+static void *high_addr;
#if !defined(UCLINUX)
@@ -125,7 +54,8 @@ int main(int ac, char **av)
int lc;
char *msg;
- if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
+ msg = parse_opts(ac, av, NULL, NULL);
+ if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
setup();
@@ -134,6 +64,7 @@ int main(int ac, char **av)
TEST_EXP_ENOS(exp_enos);
#define TEST_ACCESS(addr, mode) \
+{ \
if (access(low_addr, mode) == -1) { \
if (errno == EFAULT) { \
tst_resm(TPASS, \
@@ -147,10 +78,10 @@ int main(int ac, char **av)
} else { \
tst_resm(TFAIL, \
"access(%p, %s) succeeded unexpectedly", addr, #mode); \
- }
+ } \
+}
for (lc = 0; TEST_LOOPING(lc); lc++) {
-
tst_count = 0;
TEST_ACCESS(low_addr, R_OK);
@@ -162,25 +93,22 @@ int main(int ac, char **av)
TEST_ACCESS(high_addr, W_OK);
TEST_ACCESS(high_addr, X_OK);
TEST_ACCESS(high_addr, F_OK);
-
}
cleanup();
tst_exit();
-
}
-void setup()
+static void setup(void)
{
-
tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
TEST_PAUSE;
low_addr = mmap(0, 1, PROT_NONE,
MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
if (low_addr == MAP_FAILED)
tst_brkm(TBROK | TERRNO, NULL, "mmap failed");
+
high_addr = get_high_address();
if (high_addr == NULL)
tst_brkm(TBROK | TERRNO, NULL, "get_high_address failed");
@@ -189,14 +117,9 @@ void setup()
tst_tmpdir();
}
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- ***************************************************************/
-void cleanup()
+static void cleanup(void)
{
TEST_CLEANUP;
-
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/access/access04.c b/testcases/kernel/syscalls/access/access04.c
index 6da846d..09adecf 100644
--- a/testcases/kernel/syscalls/access/access04.c
+++ b/testcases/kernel/syscalls/access/access04.c
@@ -18,52 +18,11 @@
*/
/*
- * Test Name: access04
- *
* Test Description:
* Verify that access() succeeds to check the existance of a file if
* search access is permitted on the pathname of the specified file.
*
- * Expected Result:
- * access() should return 0 value and the specified file should exist
- * on the file system.
- *
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Create temporary directory.
- * Pause for SIGUSR1 if option specified.
- *
- * Test:
- * Loop if the proper options are given.
- * Execute system call
- * Check return code, if system call failed (return=-1)
- * Log the errno and Issue a FAIL message.
- * Otherwise,
- * Verify the Functionality of system call
- * if successful,
- * Issue Functionality-Pass message.
- * Otherwise,
- * Issue Functionality-Fail message.
- * Cleanup:
- * Print errno log and/or timing stats if options given
- * Delete the temporary directory created.
- *
- * Usage: <for command-line>
- * access04 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -f : Turn off functionality Testing.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- * None.
- *
+ * 07/2001 Ported by Wayne Boyer
*/
#include <stdio.h>
@@ -81,30 +40,31 @@
#define TESTDIR "testdir"
#define TESTFILE "testdir/testfile"
-#define DIR_MODE S_IRWXU | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP
-#define FILE_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
+#define DIR_MODE (S_IRWXU | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP)
+#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
char *TCID = "access04";
int TST_TOTAL = 1;
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
+static const char nobody_uid[] = "nobody";
+static struct passwd *ltpuser;
+
+static void setup(void);
+static void cleanup(void);
int main(int ac, char **av)
{
- struct stat stat_buf; /* struct buffer for stat(2) */
+ struct stat stat_buf;
int lc;
char *msg;
- if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
+ msg = parse_opts(ac, av, NULL, NULL);
+ if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
-
tst_count = 0;
TEST(access(TESTFILE, F_OK));
@@ -123,22 +83,20 @@ int main(int ac, char **av)
tst_resm(TPASS, "functionality of "
"access(%s, F_OK) ok", TESTFILE);
}
- } else
+ } else {
tst_resm(TPASS, "call succeeded");
+ }
}
cleanup();
-
tst_exit();
-
}
-void setup()
+static void setup(void)
{
int fd;
tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
tst_require_root(NULL);
ltpuser = getpwnam(nobody_uid);
@@ -149,7 +107,6 @@ void setup()
tst_brkm(TINFO | TERRNO, NULL, "setuid failed");
TEST_PAUSE;
-
tst_tmpdir();
if (mkdir(TESTDIR, DIR_MODE) < 0)
@@ -174,10 +131,8 @@ void setup()
"chmod(%s, 0) failed", TESTFILE);
}
-void cleanup()
+static void cleanup(void)
{
TEST_CLEANUP;
-
tst_rmdir();
-
}
diff --git a/testcases/kernel/syscalls/access/access05.c b/testcases/kernel/syscalls/access/access05.c
index 20b71d8..be86225 100644
--- a/testcases/kernel/syscalls/access/access05.c
+++ b/testcases/kernel/syscalls/access/access05.c
@@ -18,8 +18,6 @@
*/
/*
- * Test Name: access05
- *
* Test Description:
* Verify that,
* 1. access() fails with -1 return value and sets errno to EACCES
@@ -35,45 +33,7 @@
* 5. access() fails with -1 return value and sets errno to ENAMETOOLONG
* if the pathname size is > PATH_MAX characters.
*
- * Expected Result:
- * access() should fail with return value -1 and set expected errno.
- *
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Create temporary directory.
- * Pause for SIGUSR1 if option specified.
- *
- * Test:
- * Loop if the proper options are given.
- * Execute system call
- * Check return code, if system call failed (return=-1)
- * if errno set == expected errno
- * Issue sys call fails with expected return value and errno.
- * Otherwise,
- * Issue sys call fails with unexpected errno.
- * Otherwise,
- * Issue sys call returns unexpected value.
- *
- * Cleanup:
- * Print errno log and/or timing stats if options given
- * Delete the temporary directory(s)/file(s) created.
- *
- * Usage: <for command-line>
- * access05 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -e : Turn on errno logging.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- * This test should be run by 'non-super-user' only.
- *
+ * 07/2001 Ported by Wayne Boyer
*/
#include <stdio.h>
@@ -98,59 +58,59 @@
#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
-void setup1(); /* setup() to test access() for EACCES */
-void setup2(); /* setup() to test access() for EACCES */
-void setup3(); /* setup() to test access() for EACCES */
-void setup4(); /* setup() to test access() for EINVAL */
-void longpath_setup(); /* setup function to test access() for ENAMETOOLONG */
+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)
-char high_address_node[64];
+static char high_address_node[64];
#endif
-char Longpathname[PATH_MAX + 2];
+static char longpathname[PATH_MAX + 2];
-struct test_case_t { /* test case structure */
+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, setup1},
+ {TEST_FILE2, W_OK, EACCES, setup2},
+ {TEST_FILE3, X_OK, EACCES, setup3},
+ {TEST_FILE4, INV_OK, EINVAL, setup4},
#if !defined(UCLINUX)
- {
- (char *)-1, R_OK, EFAULT, NULL}, {
- high_address_node, R_OK, EFAULT, NULL},
+ {(char *)-1, R_OK, EFAULT, NULL},
+ {high_address_node, R_OK, EFAULT, NULL},
#endif
- {
- "", W_OK, ENOENT, NULL}, {
-Longpathname, R_OK, ENAMETOOLONG, longpath_setup},};
+ {"", W_OK, ENOENT, NULL},
+ {longpathname, R_OK, ENAMETOOLONG, longpath_setup},
+};
char *TCID = "access05";
int TST_TOTAL = sizeof(test_cases) / sizeof(*test_cases);
-int exp_enos[] = { EACCES, EFAULT, EINVAL, ENOENT, ENAMETOOLONG, 0 };
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
+static int exp_enos[] = { EACCES, EFAULT, EINVAL, ENOENT, ENAMETOOLONG, 0 };
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
+static const char nobody_uid[] = "nobody";
+static struct passwd *ltpuser;
-char *bad_addr = 0;
+static void setup(void);
+static void cleanup(void);
+
+static char *bad_addr;
int main(int ac, char **av)
{
int lc;
char *msg;
- char *file_name; /* name of the testfile */
- int access_mode; /* specified access mode for testfile */
+ char *file_name;
+ int access_mode;
int i;
- if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
+ msg = parse_opts(ac, av, NULL, NULL);
+ if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
setup();
@@ -158,7 +118,6 @@ int main(int ac, char **av)
TEST_EXP_ENOS(exp_enos);
for (lc = 0; TEST_LOOPING(lc); lc++) {
-
tst_count = 0;
for (i = 0; i < TST_TOTAL; i++) {
@@ -197,17 +156,14 @@ int main(int ac, char **av)
}
cleanup();
-
tst_exit();
-
}
-void setup()
+static void setup(void)
{
int i;
tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
tst_require_root(NULL);
ltpuser = getpwnam(nobody_uid);
@@ -233,11 +189,10 @@ void setup()
test_cases[i].setupfunc();
}
-void setup_file(const char *file, mode_t perms)
+static void setup_file(const char *file, mode_t perms)
{
- int fd; /* file handle for testfile */
-
- if ((fd = open(file, O_RDWR | O_CREAT, FILE_MODE)) == -1)
+ 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);
@@ -258,7 +213,7 @@ void setup_file(const char *file, mode_t perms)
* Deny read access permissions on testfile.
* This function returns 0.
*/
-void setup1()
+static void setup1(void)
{
setup_file(TEST_FILE1, 0333);
}
@@ -271,7 +226,7 @@ void setup1()
* Deny write access permissions on testfile.
* This function returns 0.
*/
-void setup2()
+static void setup2(void)
{
setup_file(TEST_FILE2, 0555);
}
@@ -284,7 +239,7 @@ void setup2()
* Deny search access permissions on testfile.
* This function returns 0.
*/
-void setup3()
+static void setup3(void)
{
setup_file(TEST_FILE3, 0666);
}
@@ -297,7 +252,7 @@ void setup3()
* Creat/open a testfile and close it.
* This function returns 0.
*/
-void setup4()
+static void setup4(void)
{
setup_file(TEST_FILE4, FILE_MODE);
}
@@ -306,32 +261,16 @@ void setup4()
* longpath_setup() - setup to create a node with a name length exceeding
* the MAX. length of PATH_MAX.
*/
-void longpath_setup()
+static void longpath_setup(void)
{
int i;
for (i = 0; i <= (PATH_MAX + 1); i++)
- Longpathname[i] = 'a';
+ longpathname[i] = 'a';
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- *
- * Remove the test directory and testfile created in the setup.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
TEST_CLEANUP;
-
- /*
- * Delete the test directory/file and temporary directory
- * created in the setup.
- */
tst_rmdir();
-
}
hooks/post-receive
--
ltp
|