|
From: Cyril H. <su...@li...> - 2013-04-24 13:21:57
|
The branch, master, has been updated
via 3dfde4d6860c43a5f9e35381d2af3d58272adc8d (commit)
via 8e9b997658241bac4d56f63f2725a1a9965383a7 (commit)
via 8e3afe9b89515df7d4d869853a93826675bfdcde (commit)
via 123895c0761d4b20260b367437bdfcb144fc2fe8 (commit)
from db02e96d6424303e36b1fba58f35f636e7f7830b (commit)
- Log -----------------------------------------------------------------
commit 3dfde4d6860c43a5f9e35381d2af3d58272adc8d
Author: Cyril Hrubis <ch...@su...>
Date: Wed Apr 24 14:46:03 2013 +0200
openposix/.../mmap/14-1: Fix cleanup.
The test wasn't unlinking the temporary file on exit.
Signed-off-by: Cyril Hrubis <ch...@su...>
commit 8e9b997658241bac4d56f63f2725a1a9965383a7
Author: Cyril Hrubis <ch...@su...>
Date: Wed Apr 24 14:22:24 2013 +0200
syscalls/mincore*: Fixes.
* Make use of tst_tmpdir() to create temporary files
* Add option parsing and looping to mincore02
* Changed mmap() first parameter from 0 to NULL
* etc.
Signed-off-by: Cyril Hrubis <ch...@su...>
commit 8e3afe9b89515df7d4d869853a93826675bfdcde
Author: Cyril Hrubis <ch...@su...>
Date: Wed Apr 24 13:58:29 2013 +0200
syscalls/micore*: Fix.
Remove the UCLINUX ifdefs, add mincore directory
into UCLINUX FILTER_OUT_DIRS in syscalls Makefile.
Signed-off-by: Cyril Hrubis <ch...@su...>
commit 123895c0761d4b20260b367437bdfcb144fc2fe8
Author: Cyril Hrubis <ch...@su...>
Date: Wed Apr 24 13:34:46 2013 +0200
syscalls/mincore*: Cleanup.
Signed-off-by: Cyril Hrubis <ch...@su...>
-----------------------------------------------------------------------
Summary of changes:
testcases/kernel/syscalls/Makefile | 2 +-
testcases/kernel/syscalls/mincore/mincore01.c | 203 ++++++-----------
testcases/kernel/syscalls/mincore/mincore02.c | 245 +++++++-------------
.../conformance/interfaces/mmap/14-1.c | 1 +
4 files changed, 153 insertions(+), 298 deletions(-)
diff --git a/testcases/kernel/syscalls/Makefile b/testcases/kernel/syscalls/Makefile
index cee99e9..da7c7fa 100644
--- a/testcases/kernel/syscalls/Makefile
+++ b/testcases/kernel/syscalls/Makefile
@@ -26,7 +26,7 @@ include $(top_srcdir)/include/mk/env_pre.mk
ifeq ($(UCLINUX),1)
FILTER_OUT_DIRS += capget capset chmod chown clone fork getcontext llseek \
- nftw profil remap_file_pages
+ nftw profil remap_file_pages mincore
endif
include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/kernel/syscalls/mincore/mincore01.c b/testcases/kernel/syscalls/mincore/mincore01.c
index 779c52f..d3519f2 100644
--- a/testcases/kernel/syscalls/mincore/mincore01.c
+++ b/testcases/kernel/syscalls/mincore/mincore01.c
@@ -1,58 +1,33 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
+ * Author: Rajeev Tiwari: raj...@in...
+ * Copyright (c) 2004 Gernot Payer <gp...@su...>
+ * Copyright (c) 2013 Cyril Hrubis <ch...@su...>
*
- * Copyright (c) International Business Machines Corp., 2001
- *
- * 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
*/
/*
- * NAME
- * mincore01.c
- *
- * DESCRIPTION
- * Testcase to check the error conditions for mincore
- *
- * ALGORITHM
- * test1:
- * Invoke mincore() when the start address is not multiple of page size.
- * EINVAL
- * test2:
- * Invoke mincore() when the vector points to an invalid address. EFAULT
- * test3:
- * Invoke mincore() when the starting address + length contained unmapped
- * memory. ENOMEM
- *
- * USAGE: <for command-line>
- * mincore01 [-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
- * Author: Rajeev Tiwari: raj...@in...
- * 08/2004 Rajeev Tiwari : does a basic sanity check for the various error
- * conditions possible with the mincore system call.
- *
- * 2004/09/10 Gernot Payer <gp...@su...>
- * code cleanup
- *$
- * RESTRICTIONS
- * None
+ * test1:
+ * Invoke mincore() when the start address is not multiple of page size.
+ * EINVAL
+ * test2:
+ * Invoke mincore() when the vector points to an invalid address. EFAULT
+ * test3:
+ * Invoke mincore() when the starting address + length contained unmapped
+ * memory. ENOMEM
*/
#include <fcntl.h>
@@ -78,25 +53,22 @@ static void setup3(void);
char *TCID = "mincore01";
int TST_TOTAL = 3;
-static char file_name[] = "fooXXXXXX";
static char *global_pointer = NULL;
static unsigned char *global_vec = NULL;
static int global_len = 0;
-static int file_desc = 0;
-
-#if !defined(UCLINUX)
+static int fd = 0;
static struct test_case_t {
char *addr;
int len;
unsigned char *vector;
int exp_errno;
- void (*setupfunc) ();
+ void (*setupfunc) (void);
} TC[] = {
- {
- NULL, 0, NULL, EINVAL, setup1}, {
- NULL, 0, NULL, EFAULT, setup2}, {
-NULL, 0, NULL, ENOMEM, setup3},};
+ {NULL, 0, NULL, EINVAL, setup1},
+ {NULL, 0, NULL, EFAULT, setup2},
+ {NULL, 0, NULL, ENOMEM, setup3},
+};
int main(int ac, char **av)
{
@@ -104,25 +76,20 @@ int main(int ac, char **av)
int i;
char *msg;
- if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+ msg = parse_opts(ac, av, NULL, NULL);
+ if (msg != NULL)
tst_brkm(TBROK, cleanup, "error parsing options: %s", msg);
- }
- setup(); /* global setup */
+ setup();
- /* The following loop checks looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
-
- /* reset tst_count in case we are looping */
tst_count = 0;
- /* loop through the test cases */
for (i = 0; i < TST_TOTAL; i++) {
- /* perform test specific setup */
- if (TC[i].setupfunc != NULL) {
+ if (TC[i].setupfunc != NULL)
TC[i].setupfunc();
- }
+
TEST(mincore(TC[i].addr, TC[i].len, TC[i].vector));
if (TEST_RETURN != -1) {
@@ -147,56 +114,42 @@ int main(int ac, char **av)
tst_exit();
}
-/*
- * setup1() - sets up conditions for the first test. the start address is not
- * multiple of page size
- */
-void setup1()
+static void setup1(void)
{
TC[0].addr = global_pointer + 1;
TC[0].len = global_len;
TC[0].vector = global_vec;
}
-/*
- * setup2() - sets up conditions for the test 2. the vector points to an
- * invalid address.
- */
-void setup2()
+void setup2(void)
{
unsigned char *t;
struct rlimit limit;
+
+ t = mmap(NULL, global_len, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
/* Create pointer to invalid address */
- if (MAP_FAILED ==
- (t =
- mmap(0, global_len, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, 0, 0))) {
- tst_brkm(TBROK, cleanup, "mmaping anonymous memory failed: %s",
- strerror(errno));
+ if (t == MAP_FAILED) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "mmaping anonymous memory failed");
}
+
munmap(t, global_len);
/* set stack limit so that the unmaped pointer is invalid for architectures like s390 */
limit.rlim_cur = STACK_LIMIT;
limit.rlim_max = STACK_LIMIT;
- if (setrlimit(RLIMIT_STACK, &limit) != 0) {
- tst_brkm(TBROK, cleanup, "setrlimit failed: %s",
- strerror(errno));
- }
+ if (setrlimit(RLIMIT_STACK, &limit) != 0)
+ tst_brkm(TBROK | TERRNO, cleanup, "setrlimit failed");
TC[1].addr = global_pointer;
TC[1].len = global_len;
TC[1].vector = t;
}
-/*
- * setup3() - performs the setup for test3(the starting address + length
- * contained unmapped memory). we give the length of mapped file equal to 5
- * times the mapped file size.
- */
-void setup3()
+static void setup3(void)
{
TC[2].addr = global_pointer;
TC[2].len = global_len * 2;
@@ -204,19 +157,18 @@ void setup3()
TC[2].vector = global_vec;
}
-/*
- * setup() - performs all ONE TIME setup for this test
- */
-void setup()
+static void setup(void)
{
char *buf;
PAGESIZE = getpagesize();
+ tst_tmpdir();
+
/* global_pointer will point to a mmapped area of global_len bytes */
global_len = PAGESIZE * 2;
- buf = (char *)malloc(global_len);
+ buf = malloc(global_len);
memset(buf, 42, global_len);
tst_sig(FORK, DEF_HANDLER, cleanup);
@@ -224,60 +176,39 @@ void setup()
TEST_PAUSE;
/* create a temporary file */
- if (-1 == (file_desc = mkstemp(file_name))) {
- tst_brkm(TBROK, cleanup,
- "Error while creating temporary file: %s",
- strerror(errno));
+ fd = open("mincore01", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+ if (fd == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "Error while creating temporary file");
}
/* fill the temporary file with two pages of data */
- if (-1 == write(file_desc, buf, global_len)) {
- tst_brkm(TBROK, cleanup,
- "Error while writing to temporary file: %s",
- strerror(errno));
+ if (write(fd, buf, global_len) == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "Error while writing to temporary file");
}
free(buf);
/* map the file in memory */
- if (MAP_FAILED ==
- (global_pointer =
- (char *)mmap(NULL, global_len * 2,
- PROT_READ | PROT_WRITE | PROT_EXEC, MAP_SHARED,
- file_desc, 0))) {
- tst_brkm(TBROK, cleanup,
- "Temporary file could not be mmapped: %s",
- strerror(errno));
+ global_pointer = mmap(NULL, global_len * 2,
+ PROT_READ | PROT_WRITE | PROT_EXEC, MAP_SHARED,
+ fd, 0);
+
+ if (global_pointer == MAP_FAILED) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "Temporary file could not be mmapped");
}
/* initialize the vector buffer to collect the page info */
global_vec = malloc((global_len + PAGESIZE - 1) / PAGESIZE);
}
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing status if that option was specified.
- * print errno log if that option was specified
- */
TEST_CLEANUP;
free(global_vec);
munmap(global_pointer, global_len);
- close(file_desc);
- remove(file_name);
-
-}
-
-#else
-
-int main()
-{
- tst_resm(TINFO, "test is not available on uClinux");
- tst_exit();
+ close(fd);
+ tst_rmdir();
}
-
-#endif /* if !defined(UCLINUX) */
diff --git a/testcases/kernel/syscalls/mincore/mincore02.c b/testcases/kernel/syscalls/mincore/mincore02.c
index 6b51b69..11eaec6 100644
--- a/testcases/kernel/syscalls/mincore/mincore02.c
+++ b/testcases/kernel/syscalls/mincore/mincore02.c
@@ -1,49 +1,29 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
+ * Author: Rajeev Tiwari: raj...@in...
+ * Copyright (c) 2004 Gernot Payer <gp...@su...>
+ * Copyright (c) 2013 Cyril Hrubis <ch...@su...>
*
- * Copyright (c) International Business Machines Corp., 2001
+ * 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
*/
/*
- * NAME
- * mincore02.c
- *
- * DESCRIPTION
- * Testcase to check the error conditions for mincore
- *
- * ALGORITHM
- * test1:
- * This test case provides a functional validation for mincore system call.
- * We mmap a file of known size (multiple of page size) and lock it in
- * memory. Then we obtain page location information via mincore and compare
- * the result with the expected value.
- *
- * USAGE: <for command-line>
- * ./mincore02
- *
- * HISTORY
- * Author: Rajeev Tiwari: raj...@in...
- * 08/2004 Rajeev Tiwari : Provides a functional validation of mincore system call.
- *
- * 2004/09/10 Gernot Payer <gp...@su...>
- * - Original testcase was based on wrong assumptions
- * - Major code cleanup
- *
- * RESTRICTIONS
- * None
+ * This test case provides a functional validation for mincore system call.
+ * We mmap a file of known size (multiple of page size) and lock it in
+ * memory. Then we obtain page location information via mincore and compare
+ * the result with the expected value.
*/
#include <sys/mman.h>
@@ -58,163 +38,106 @@
#include "test.h"
#include "usctest.h"
-/* comment out if you need to debug */
-/* #define DEBUG_MODE 1 */
-
char *TCID = "mincore02";
int TST_TOTAL = 1;
-static int file_desc = 0; /* this is for the file descriptor */
-static char *position = NULL;
-static int p_size; /* page size obtained via getpagesize() */
-static int num_pages = 4; /* four pages are used in this test */
+static int fd = 0;
+static void *addr = NULL;
+static int page_size;
+static int num_pages = 4;
static unsigned char *vec = NULL;
-#if !defined(UCLINUX)
-
-static char tmpfilename[] = "fooXXXXXX";
-
-/* Extern Global Functions */
-/******************************************************************************/
-/* */
-/* Function: cleanup */
-/* */
-/* Description: Performs all one time clean up for this test on successful */
-/* completion, premature exit or failure. Closes all temporary */
-/* files, removes all temporary directories exits the test with */
-/* appropriate return code by calling tst_exit() function. */
-/* */
-/* Input: None. */
-/* */
-/* Output: None. */
-/* */
-/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
-/* On success - Exits calling tst_exit(). With '0' return code. */
-/* */
-/******************************************************************************/
-void cleanup()
+static void cleanup(void)
{
-
- /* Close all open file descriptors. */
-
free(vec);
- munlock(position, p_size * num_pages);
- munmap(position, p_size * num_pages);
+ munlock(addr, page_size * num_pages);
+ munmap(addr, page_size * num_pages);
TEST_CLEANUP;
- close(file_desc);
- remove(tmpfilename);
-
+ close(fd);
+ tst_rmdir();
}
-/* Local Functions */
-/******************************************************************************/
-/* */
-/* Function: setup */
-/* */
-/* Description: Performs all one time setup for this test. This function is */
-/* typically used to capture signals, create temporary dirs */
-/* and temporary files that may be used in the course of this */
-/* test. */
-/* */
-/* Input: None. */
-/* */
-/* Output: None. */
-/* */
-/* Return: On failure - Exits by calling cleanup(). */
-/* */
-/* */
-/******************************************************************************/
-
-void setup()
+static void setup(void)
{
char *buf;
- int size;
- int status;
+ size_t size;
- if (-1 == (p_size = getpagesize())) {
- tst_brkm(TBROK, cleanup, "Unable to get page size: %s",
- strerror(errno));
- }
+ tst_tmpdir();
- size = p_size * num_pages;
- buf = (char *)malloc(p_size * num_pages);
+ page_size = getpagesize();
+ if (page_size == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "Unable to get page size");
- memset(buf, 42, size);
- vec = malloc((size + p_size - 1) / p_size);
-
- /* create a temporary file to be used */
+ size = page_size * num_pages;
+ buf = malloc(size);
- if (-1 == (file_desc = mkstemp(tmpfilename))) {
- tst_brkm(TBROK, cleanup, "Unable to create temporary file: %s",
- strerror(errno));
+ memset(buf, 42, size);
+ vec = malloc((size + page_size - 1) / page_size);
+
+ fd = open("mincore02", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+ if (fd == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "Unable to create temporary file");
}
/* fill the temporary file with two pages of data */
-
- if (-1 == write(file_desc, buf, size)) {
- tst_brkm(TBROK, cleanup, "Error in writing to the file: %s",
- strerror(errno));
+ if (write(fd, buf, size) < 0) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "Error in writing to the file");
}
free(buf);
- /* mmap the file in virtual address space in read , write and execute mode , the mapping should be shared */
+ addr = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_SHARED, fd, 0);
- if (MAP_FAILED ==
- (position =
- (char *)mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_SHARED, file_desc, 0))) {
- tst_brkm(TBROK, cleanup,
- "Unable to map file for read/write. Error: %d (%s)",
- errno, strerror(errno));
+ if (addr == MAP_FAILED) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "Unable to map file for read/write");
}
/* lock mmapped file, so mincore returns "in core" for all pages */
- if ((status = mlock(position, size)) == -1) {
- tst_brkm(TBROK, cleanup, "Unable to lock the file: %s",
- strerror(errno));
- }
- return;
+ if (mlock(addr, size) == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "Unable to lock the file");
}
int main(int argc, char **argv)
{
int lock_pages, counter;
+ char *msg;
+ int lc;
- setup();
-
- if (-1 == mincore((void *)position, num_pages * p_size, vec)) {
- tst_brkm(TBROK, cleanup,
- "Unable to execute mincore system call: %s",
- strerror(errno));
- }
-
- /* check status of pages */
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, cleanup, "error parsing options: %s", msg);
- lock_pages = 0;
-
- for (counter = 0; counter < num_pages; counter++) {
- if (vec[counter] & 1)
- lock_pages++;
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+
+ if (mincore(addr, num_pages * page_size, vec) == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "Unable to execute mincore system call");
+ }
+
+ /* check status of pages */
+ lock_pages = 0;
+
+ for (counter = 0; counter < num_pages; counter++) {
+ if (vec[counter] & 1)
+ lock_pages++;
+ }
+
+ if (lock_pages == num_pages) {
+ tst_resm(TPASS, "%d pages locked, %d pages in-core", num_pages,
+ lock_pages);
+ } else {
+ tst_resm(TFAIL,
+ "not all locked pages are in-core: no. locked: %d, no. in-core: %d",
+ num_pages, lock_pages);
+ }
}
- if (lock_pages == num_pages)
- tst_resm(TPASS, "%d pages locked, %d pages in-core", num_pages,
- lock_pages);
- else
- tst_resm(TFAIL,
- "not all locked pages are in-core: no. locked: %d, no. in-core: %d",
- num_pages, lock_pages);
-
cleanup();
tst_exit();
}
-
-#else
-
-int main()
-{
- tst_resm(TINFO, "test is not available on uClinux");
- tst_exit();
-}
-
-#endif /* if !defined(UCLINUX) */
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/14-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/14-1.c
index 8fc8e5d..9431b97 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/14-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/14-1.c
@@ -116,6 +116,7 @@ int main(void)
munmap(pa, size);
close(fd);
+ unlink(tmpfname);
printf("Test PASSED\n");
return PTS_PASS;
}
hooks/post-receive
--
ltp
|