syscalls/mmap: Cleanups.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
diff --git a/testcases/kernel/syscalls/mmap/mmap001.c b/testcases/kernel/syscalls/mmap/mmap001.c
index 6be11e3..cc857ed 100644
--- a/testcases/kernel/syscalls/mmap/mmap001.c
+++ b/testcases/kernel/syscalls/mmap/mmap001.c
@@ -1,6 +1,4 @@
/*
- * mmap001.c - Tests mmapping a big file and writing it once
- *
* Copyright (C) 2000 Juan Quintela <quintela@fi.udc.es>
* Aaron Laffin <alaffin@sgi.com>
*
@@ -17,6 +15,8 @@
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * mmap001.c - Tests mmapping a big file and writing it once
*/
#include <sys/types.h>
#include <sys/stat.h>
@@ -37,21 +37,16 @@
static int m_opt = 0;
static char *m_copt;
-void cleanup()
+static void cleanup(void)
{
- /*
- * remove the tmp directory and exit
- */
-
- if (filename)
- free(filename);
+ free(filename);
TEST_CLEANUP;
tst_rmdir();
}
-void setup()
+static void setup(void)
{
char buf[1024];
/*
@@ -72,7 +67,7 @@
}
-void help()
+static void help(void)
{
printf(" -m x size of mmap in pages (default 1000)\n");
}
@@ -141,7 +136,7 @@
}
array = mmap(0, memsize, PROT_WRITE, MAP_SHARED, fd, 0);
- if (array == (char *)MAP_FAILED) {
+ if (array == MAP_FAILED) {
TEST_ERRNO = errno;
close(fd);
tst_brkm(TBROK | TTERRNO, cleanup,
diff --git a/testcases/kernel/syscalls/mmap/mmap01.c b/testcases/kernel/syscalls/mmap/mmap01.c
index 06a8ef6..8648384 100644
--- a/testcases/kernel/syscalls/mmap/mmap01.c
+++ b/testcases/kernel/syscalls/mmap/mmap01.c
@@ -1,25 +1,22 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * 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
*/
/*
- * Test Name: mmap01
- *
* Test Description:
* Verify that, mmap() succeeds when used to map a file where size of the
* file is not a multiple of the page size, the memory area beyond the end
@@ -33,43 +30,9 @@
* filled with zero.
* The changes beyond the end of file should not get written to the file.
*
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- * Create temporary directory.
- *
- * 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 timing stats if options given
- * Delete the temporary directory created.
- *
- * Usage: <for command-line>
- * mmap01 [-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 <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -90,15 +53,16 @@
char *TCID = "mmap01";
int TST_TOTAL = 1;
-char *addr; /* addr of memory mapped region */
-char *dummy; /* dummy string */
-size_t page_sz; /* system page size */
-size_t file_sz; /* mapped file size */
-int fildes; /* file descriptor for tempfile */
-char cmd_buffer[BUFSIZ]; /* command buffer to hold test command */
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
+static char *addr;
+static char *dummy;
+static size_t page_sz;
+static size_t file_sz;
+static int fildes;
+static char cmd_buffer[BUFSIZ];
+
+static void setup(void);
+static void cleanup(void);
int main(int ac, char **av)
{
@@ -127,10 +91,7 @@
tst_resm(TFAIL | TERRNO, "mmap of %s failed", TEMPFILE);
continue;
}
- /*
- * Perform functional verification if test
- * executed without (-f) option.
- */
+
if (STD_FUNCTIONAL_TEST) {
/*
* Check if mapped memory area beyond EOF are
@@ -187,20 +148,10 @@
}
-/*
- * setup() - performs all ONE TIME setup for this test.
- *
- * Get system page size, allocate and initialize the string dummy.
- * Initialize addr such that it is more than one page below the break
- * address of the process, and initialize one page region from addr
- * with char 'A'.
- * Creat a temporary directory and a file under it.
- * Write some known data into file and get the size of the file.
- */
-void setup()
+static void setup(void)
{
struct stat stat_buf;
- char Path_name[PATH_MAX]; /* pathname of temporary file */
+ char Path_name[PATH_MAX];
char write_buf[] = "hello world\n";
tst_sig(FORK, DEF_HANDLER, cleanup);
@@ -239,7 +190,7 @@
}
/* Allocate and initialize dummy string of system page size bytes */
- if ((dummy = (char *)calloc(page_sz, sizeof(char))) == NULL) {
+ if ((dummy = calloc(page_sz, sizeof(char))) == NULL) {
tst_brkm(TFAIL, cleanup, "calloc failed (dummy)");
}
@@ -264,25 +215,10 @@
sprintf(cmd_buffer, "grep XYZ %s/%s > /dev/null", Path_name, TEMPFILE);
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- * Free the memory allocated to dummy variable.
- * Remove the temporary directory created.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- */
close(fildes);
-
TEST_CLEANUP;
-
- /* Free the memory allocated for dummy string */
- if (dummy) {
- free(dummy);
- }
-
+ free(dummy);
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/mmap/mmap02.c b/testcases/kernel/syscalls/mmap/mmap02.c
index 5bdb589..7075809 100644
--- a/testcases/kernel/syscalls/mmap/mmap02.c
+++ b/testcases/kernel/syscalls/mmap/mmap02.c
@@ -1,25 +1,22 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * 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
*/
/*
- * Test Name: mmap02
- *
* Test Description:
* Call mmap() with prot parameter set to PROT_READ and with the file
* descriptor being open for read, to map a file creating mapped memory
@@ -32,43 +29,9 @@
* mmap() should succeed returning the address of the mapped region,
* the mapped region should contain the contents of the mapped file.
*
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- * Create temporary directory.
- *
- * 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 timing stats if options given
- * Delete the temporary directory created.
- *
- * Usage: <for command-line>
- * mmap02 [-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 <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -87,13 +50,14 @@
char *TCID = "mmap02";
int TST_TOTAL = 1;
-char *addr; /* addr of memory mapped region */
-char *dummy; /* dummy string */
-size_t page_sz; /* system page size */
-int fildes; /* file descriptor for temporary file */
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
+static char *addr;
+static char *dummy;
+static size_t page_sz;
+static int fildes;
+
+static void setup(void);
+static void cleanup(void);
int main(int ac, char **av)
{
@@ -122,10 +86,7 @@
tst_resm(TFAIL | TERRNO, "mmap of %s failed", TEMPFILE);
continue;
}
- /*
- * Perform functional verification if test
- * executed without (-f) option.
- */
+
if (STD_FUNCTIONAL_TEST) {
/*
* Read the file contents into the dummy
@@ -161,23 +122,11 @@
cleanup();
tst_exit();
-
}
-/*
- * setup() - performs all ONE TIME setup for this test.
- *
- * Get system page size, allocate and initialize the string dummy.
- * Initialize addr such that it is more than one page below the break
- * address of the process, and initialize one page region from addr
- * with char 'A'.
- * Create a temporary directory a file under it.
- * Write some known data into file and close it.
- * Change mode permissions on file to 0444.
- */
-void setup()
+static void setup(void)
{
- char *tst_buff; /* test buffer to hold known data */
+ char *tst_buff;
tst_sig(FORK, DEF_HANDLER, cleanup);
@@ -190,7 +139,7 @@
}
/* Allocate space for the test buffer */
- if ((tst_buff = (char *)calloc(page_sz, sizeof(char))) == NULL) {
+ if ((tst_buff = calloc(page_sz, sizeof(char))) == NULL) {
tst_brkm(TFAIL, NULL, "calloc failed (tst_buff)");
}
@@ -236,31 +185,16 @@
}
/* Allocate and initialize dummy string of system page size bytes */
- if ((dummy = (char *)calloc(page_sz, sizeof(char))) == NULL) {
+ if ((dummy = calloc(page_sz, sizeof(char))) == NULL) {
tst_brkm(TFAIL, cleanup, "calloc failed (dummy)");
}
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- * Free the memory allocated to dummy variable.
- * Remove the temporary directory created.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- */
close(fildes);
-
TEST_CLEANUP;
-
- /* Free the memory allocated for dummy string */
- if (dummy) {
- free(dummy);
- }
-
+ free(dummy);
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/mmap/mmap03.c b/testcases/kernel/syscalls/mmap/mmap03.c
index 8743142..78a5d4d 100644
--- a/testcases/kernel/syscalls/mmap/mmap03.c
+++ b/testcases/kernel/syscalls/mmap/mmap03.c
@@ -1,25 +1,22 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * 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
*/
/*
- * Test Name: mmap03
- *
* Test Description:
* Call mmap() to map a file creating a mapped region with execute access
* under the following conditions -
@@ -38,43 +35,9 @@
* an attempt to access the contents of the mapped region should give
* rise to the signal SIGSEGV.
*
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- * Create temporary directory.
- *
- * 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 timing stats if options given
- * Delete the temporary directory created.
- *
- * Usage: <for command-line>
- * mmap03 [-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 <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -94,16 +57,17 @@
char *TCID = "mmap03";
int TST_TOTAL = 1;
-size_t page_sz; /* system page size */
-char *addr; /* addr of memory mapped region */
-char *dummy; /* dummy variable to hold temp file contents */
-int fildes; /* file descriptor for temporary file */
-volatile int pass = 0; /* pass flag perhaps set to 1 in sig_handler */
-sigjmp_buf env; /* environment for sigsetjmp/siglongjmp */
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
-void sig_handler(); /* signal handler to catch SIGSEGV */
+static size_t page_sz;
+static char *addr;
+static char *dummy;
+static int fildes;
+static volatile int pass = 0;
+static sigjmp_buf env;
+
+static void setup(void);
+static void cleanup(void);
+static void sig_handler(int sig);
int main(int ac, char **av)
{
@@ -133,10 +97,7 @@
TEMPFILE);
continue;
}
- /*
- * Perform functional verification if test
- * executed without (-f) option.
- */
+
if (STD_FUNCTIONAL_TEST) {
/*
* Read the file contents into the dummy
@@ -195,17 +156,9 @@
}
-/*
- * setup() - performs all ONE TIME setup for this test.
- * Get the system page size.
- * Create a temporary directory and a file under it.
- * Write some known data into file and close it.
- * Change the mode permissions on file to 0555.
- * Re-open the file for reading.
- */
-void setup()
+static void setup(void)
{
- char *tst_buff; /* test buffer to hold known data */
+ char *tst_buff;
tst_sig(NOFORK, sig_handler, cleanup);
@@ -218,7 +171,7 @@
}
/* Allocate space for the test buffer */
- if ((tst_buff = (char *)calloc(page_sz, sizeof(char))) == NULL) {
+ if ((tst_buff = calloc(page_sz, sizeof(char))) == NULL) {
tst_brkm(TFAIL, NULL, "calloc failed (tst_buff)");
}
@@ -256,7 +209,7 @@
}
/* Allocate and initialize dummy string of system page size bytes */
- if ((dummy = (char *)calloc(page_sz, sizeof(char))) == NULL) {
+ if ((dummy = calloc(page_sz, sizeof(char))) == NULL) {
tst_brkm(TFAIL, cleanup, "calloc failed (dummy)");
}
@@ -268,12 +221,11 @@
}
/*
- * sig_handler() - Signal Cathing function.
* This function gets executed when the test process receives
* the signal SIGSEGV while trying to access the contents of memory which
* is not accessible.
*/
-void sig_handler(sig)
+static void sig_handler(int sig)
{
if (sig == SIGSEGV) {
/* set the global variable and jump back */
@@ -283,25 +235,10 @@
tst_brkm(TBROK, cleanup, "received an unexpected signal");
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- * Free the memory allocated to dummy variable.
- * Remove the temporary directory created.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- */
close(fildes);
-
TEST_CLEANUP;
-
- /* Free the memory space allocated for dummy variable */
- if (dummy) {
- free(dummy);
- }
-
+ free(dummy);
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/mmap/mmap04.c b/testcases/kernel/syscalls/mmap/mmap04.c
index 6f5d8ee..da71926 100644
--- a/testcases/kernel/syscalls/mmap/mmap04.c
+++ b/testcases/kernel/syscalls/mmap/mmap04.c
@@ -1,25 +1,22 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * 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
*/
/*
- * Test Name: mmap04
- *
* Test Description:
* Call mmap() to map a file creating a mapped region with read/exec access
* under the following conditions -
@@ -35,41 +32,8 @@
* mmap() should succeed returning the address of the mapped region,
* and the mapped region should contain the contents of the mapped file.
*
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- * Create temporary directory.
- *
- * 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 timing stats if options given
- * Delete the temporary directory created.
- *
- * Usage: <for command-line>
- * mmap04 [-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 <stdio.h>
@@ -90,13 +54,14 @@
char *TCID = "mmap04";
int TST_TOTAL = 1;
-size_t page_sz; /* system page size */
-char *addr; /* addr of memory mapped region */
-char *dummy; /* dummy variable to hold temp file contents */
-int fildes; /* file descriptor for temporary file */
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
+static size_t page_sz;
+static char *addr;
+static char *dummy;
+static int fildes;
+
+static void setup(void);
+static void cleanup(void);
int main(int ac, char **av)
{
@@ -126,10 +91,6 @@
continue;
}
- /*
- * Perform functional verification if test
- * executed without (-f) option.
- */
if (STD_FUNCTIONAL_TEST) {
/*
* Read the file contents into the dummy
@@ -164,32 +125,22 @@
}
cleanup();
tst_exit();
-
}
-/*
- * setup() - performs all ONE TIME setup for this test.
- * Get the system page size.
- * Create a temporary directory and a file under it.
- * Write some known data into file and close it.
- * Change the mode permissions on file to 0555.
- * Re-open the file for reading.
- */
-void setup()
+static void setup(void)
{
- char *tst_buff; /* test buffer to hold known data */
+ char *tst_buff;
tst_sig(NOFORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
- /* Get the system page size */
if ((page_sz = getpagesize()) < 0) {
tst_brkm(TFAIL, NULL,
"getpagesize() fails to get system page size");
}
- if ((tst_buff = (char *)calloc(page_sz, sizeof(char))) == NULL) {
+ if ((tst_buff = calloc(page_sz, sizeof(char))) == NULL) {
tst_brkm(TFAIL, NULL, "calloc failed (tst_buff)");
}
@@ -224,7 +175,7 @@
}
/* Allocate and initialize dummy string of system page size bytes */
- if ((dummy = (char *)calloc(page_sz, sizeof(char))) == NULL) {
+ if ((dummy = calloc(page_sz, sizeof(char))) == NULL) {
tst_brkm(TFAIL, cleanup, "calloc failed (dummy)");
}
@@ -235,26 +186,10 @@
}
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- * Free the memeory allocated to dummy variable.
- * Remove the temporary directory created.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
close(fildes);
-
TEST_CLEANUP;
-
- /* Free the memory space allocated for dummy variable */
- if (dummy) {
- free(dummy);
- }
-
+ free(dummy);
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/mmap/mmap05.c b/testcases/kernel/syscalls/mmap/mmap05.c
index 63d165e..378160a 100644
--- a/testcases/kernel/syscalls/mmap/mmap05.c
+++ b/testcases/kernel/syscalls/mmap/mmap05.c
@@ -1,25 +1,22 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * 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
*/
/*
- * Test Name: mmap05
- *
* Test Description:
* Call mmap() to map a file creating mapped memory with no access under
* the following conditions -
@@ -35,43 +32,9 @@
* and an attempt to access the contents of the mapped region should give
* rise to the signal SIGSEGV.
*
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- * Create temporary directory.
- *
- * 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>
- * mmap05 [-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 <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -91,21 +54,22 @@
char *TCID = "mmap05";
int TST_TOTAL = 1;
-size_t page_sz; /* system page size */
-volatile char *addr; /* addr of memory mapped region */
-int fildes; /* file descriptor for temporary file */
-volatile int pass = 0;
-sigjmp_buf env; /* environment for sigsetjmp/siglongjmp */
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
-void sig_handler(); /* signal handler to catch SIGSEGV */
+static size_t page_sz;
+static volatile char *addr;
+static int fildes;
+static volatile int pass = 0;
+static sigjmp_buf env;
+
+static void setup(void);
+static void cleanup(void);
+static void sig_handler(int sig);
int main(int ac, char **av)
{
int lc;
char *msg;
- char file_content; /* tempfile content */
+ char file_content;
if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
@@ -132,10 +96,6 @@
continue;
}
- /*
- * Perform functional verification if test
- * executed without (-f) option.
- */
if (STD_FUNCTIONAL_TEST) {
/*
@@ -170,20 +130,11 @@
}
cleanup();
tst_exit();
-
}
-/*
- * setup() - performs all ONE TIME setup for this test.
- * Get the system page size.
- * Create a temporary directory and a file under it.
- * Write some known data into file and close it.
- * Change the mode permissions on file to 0444
- * Re-open the file for reading.
- */
-void setup(void)
+static void setup(void)
{
- char *tst_buff; /* test buffer to hold known data */
+ char *tst_buff;
tst_sig(NOFORK, sig_handler, cleanup);
@@ -246,31 +197,21 @@
* the signal SIGSEGV while trying to access the contents of memory which
* is not accessible.
*/
-void sig_handler(sig)
+static void sig_handler(int sig)
{
if (sig == SIGSEGV) {
/* set the global variable and jump back */
pass = 1;
siglongjmp(env, 1);
- } else
+ } else {
tst_brkm(TBROK, cleanup, "received an unexpected signal: %d",
sig);
+ }
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- * Remove the temporary directory created.
- */
-void cleanup(void)
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
close(fildes);
-
TEST_CLEANUP;
-
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/mmap/mmap06.c b/testcases/kernel/syscalls/mmap/mmap06.c
index 8626e3b..c119c5c 100644
--- a/testcases/kernel/syscalls/mmap/mmap06.c
+++ b/testcases/kernel/syscalls/mmap/mmap06.c
@@ -1,25 +1,22 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * 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
*/
/*
- * Test Name: mmap06
- *
* Test Description:
* Call mmap() to map a file creating a mapped region with read access
* under the following conditions -
@@ -31,43 +28,9 @@
* Expected Result:
* mmap() should fail returning -1 and errno should get set to EACCES.
*
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- * Create temporary directory.
- *
- * 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>
- * mmap06 [-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:
- * None.
*/
-
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -86,14 +49,15 @@
char *TCID = "mmap06";
int TST_TOTAL = 1;
-int exp_enos[] = { EACCES, 0 };
-size_t page_sz; /* system page size */
-char *addr; /* addr of memory mapped region */
-int fildes; /* file descriptor for temporary file */
+static int exp_enos[] = { EACCES, 0 };
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
+static size_t page_sz;
+static char *addr;
+static int fildes;
+
+static void setup(void);
+static void cleanup(void);
int main(int ac, char **av)
{
@@ -105,7 +69,6 @@
setup();
- /* set the expected errnos... */
TEST_EXP_ENOS(exp_enos);
for (lc = 0; TEST_LOOPING(lc); lc++) {
@@ -146,15 +109,9 @@
}
-/*
- * setup() - performs all ONE TIME setup for this test.
- * Get the system page size.
- * Create a temporary directory and a file under it.
- * Write some known data into file.
- */
-void setup()
+static void setup(void)
{
- char *tst_buff; /* test buffer to hold known data */
+ char *tst_buff;
tst_sig(NOFORK, DEF_HANDLER, cleanup);
@@ -167,7 +124,7 @@
}
/* Allocate space for the test buffer */
- if ((tst_buff = (char *)calloc(page_sz, sizeof(char))) == NULL) {
+ if ((tst_buff = calloc(page_sz, sizeof(char))) == NULL) {
tst_brkm(TFAIL, NULL, "calloc() failed (tst_buff)");
}
@@ -188,24 +145,12 @@
tst_brkm(TFAIL, cleanup, "writing to %s failed", TEMPFILE);
}
- /* Free the memory allocated for test buffer */
free(tst_buff);
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- * Remove the temporary directory created.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
close(fildes);
-
TEST_CLEANUP;
-
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/mmap/mmap07.c b/testcases/kernel/syscalls/mmap/mmap07.c
index 1c24e06..ffb124d 100644
--- a/testcases/kernel/syscalls/mmap/mmap07.c
+++ b/testcases/kernel/syscalls/mmap/mmap07.c
@@ -1,25 +1,22 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * 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
*/
/*
- * Test Name: mmap07
- *
* Test Description:
* Call mmap() to map a file creating a mapped region with read access
* under the following conditions -
@@ -32,43 +29,9 @@
* Expected Result:
* mmap() should fail returning -1 and errno should get set to EACCES.
*
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- * Create temporary directory.
- *
- * 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>
- * mmap07 [-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:
- * None.
*/
-
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -87,14 +50,15 @@
char *TCID = "mmap07";
int TST_TOTAL = 1;
-int exp_enos[] = { EACCES, 0 };
-size_t page_sz; /* system page size */
-char *addr; /* addr of memory mapped region */
-int fildes; /* file descriptor for temporary file */
+static int exp_enos[] = { EACCES, 0 };
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
+static size_t page_sz;
+static char *addr;
+static int fildes;
+
+static void setup(void);
+static void cleanup(void);
int main(int ac, char **av)
{
@@ -106,7 +70,6 @@
setup();
- /* set the expected errnos... */
TEST_EXP_ENOS(exp_enos);
for (lc = 0; TEST_LOOPING(lc); lc++) {
@@ -148,15 +111,9 @@
}
-/*
- * setup() - performs all ONE TIME setup for this test.
- * Get the system page size.
- * Create a temporary directory and a file under it.
- * Write some known data into file.
- */
-void setup()
+static void setup(void)
{
- char *tst_buff; /* test buffer to hold known data */
+ char *tst_buff;
tst_sig(NOFORK, DEF_HANDLER, cleanup);
@@ -169,7 +126,7 @@
}
/* Allocate space for the test buffer */
- if ((tst_buff = (char *)calloc(page_sz, sizeof(char))) == NULL) {
+ if ((tst_buff = calloc(page_sz, sizeof(char))) == NULL) {
tst_brkm(TFAIL, NULL,
"calloc() failed to allocate space for tst_buff");
}
@@ -191,23 +148,12 @@
tst_brkm(TFAIL, cleanup, "writing to %s failed", TEMPFILE);
}
- /* Free the memory allocated for test buffer */
free(tst_buff);
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- * Remove the temporary directory created.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print errno log if that option was specified.
- */
close(fildes);
-
TEST_CLEANUP;
-
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/mmap/mmap08.c b/testcases/kernel/syscalls/mmap/mmap08.c
index 3f97c31..9403a7d 100644
--- a/testcases/kernel/syscalls/mmap/mmap08.c
+++ b/testcases/kernel/syscalls/mmap/mmap08.c
@@ -1,25 +1,22 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * 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
*/
/*
- * Test Name: mmap08
- *
* Test Description:
* Verify that mmap() fails to map a file creating a mapped region
* when the file specified by file descriptor is not valid.
@@ -27,43 +24,9 @@
* Expected Result:
* mmap() should fail returning -1 and errno should get set to EBADF.
*
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- * Create temporary directory.
- *
- * 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>
- * mmap08 [-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:
- * None.
*/
-
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -82,14 +45,15 @@
char *TCID = "mmap08";
int TST_TOTAL = 1;
-int exp_enos[] = { EBADF, 0 };
-size_t page_sz; /* system page size */
-char *addr; /* addr of memory mapped region */
-int fildes; /* file descriptor for temporary file */
+static int exp_enos[] = { EBADF, 0 };
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
+static size_t page_sz;
+static char *addr;
+static int fildes;
+
+static void setup(void);
+static void cleanup(void);
int main(int ac, char **av)
{
@@ -101,7 +65,6 @@
setup();
- /* set the expected errnos... */
TEST_EXP_ENOS(exp_enos);
for (lc = 0; TEST_LOOPING(lc); lc++) {
@@ -138,18 +101,11 @@
cleanup();
tst_exit();
-
}
-/*
- * setup() - performs all ONE TIME setup for this test.
- * Get the system page size.
- * Create a temporary directory and a file under it.
- * Write some known data into file and close it.
- */
-void setup()
+static void setup(void)
{
- char *tst_buff; /* test buffer to hold known data */
+ char *tst_buff;
tst_sig(NOFORK, DEF_HANDLER, cleanup);
@@ -161,7 +117,7 @@
"getpagesize() fails to get system page size");
}
- if ((tst_buff = (char *)calloc(page_sz, sizeof(char))) == NULL) {
+ if ((tst_buff = calloc(page_sz, sizeof(char))) == NULL) {
tst_brkm(TFAIL, NULL,
"calloc() failed to allocate space for tst_buff");
}
@@ -192,18 +148,8 @@
}
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- * Remove the temporary directory created.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
TEST_CLEANUP;
-
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/mmap/mmap09.c b/testcases/kernel/syscalls/mmap/mmap09.c
index 03e3141..b5b2f38 100644
--- a/testcases/kernel/syscalls/mmap/mmap09.c
+++ b/testcases/kernel/syscalls/mmap/mmap09.c
@@ -1,25 +1,22 @@
/*
+ * Copyright (c) International Business Machines Corp., 2003
*
- * Copyright (c) International Business Machines Corp., 2003
+ * 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
*/
/*
- * Test Name: mmap09
- *
* Test Description:
* Verify that truncating a mmaped file works correctly.
*
@@ -27,31 +24,13 @@
* ftruncate should be allowed to increase, decrease, or zero the
* size of a file that has been mmaped
*
- * Algorithm:
- * Setup:
- * Create file
- * mmap the file
- * fill it with data
- *
* Test:
* Use ftruncate to shrink the file while it is mapped
* Use ftruncate to grow the file while it is mapped
* Use ftruncate to zero the size of the file while it is mapped
*
- * Usage: <for command-line>
- * mmap09 [-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
* 04/2003 Written by Paul Larson
- *
- * RESTRICTIONS:
- * None.
*/
#include <stdio.h>
#include <unistd.h>
@@ -62,30 +41,31 @@
#include "test.h"
#include "usctest.h"
-void setup();
-void cleanup();
-
#define mapsize (1 << 14)
char *TCID = "mmap09";
int TST_TOTAL = 3;
-int fd;
-char *maddr;
-struct test_case_t {
+static int fd;
+static char *maddr;
+
+static struct test_case_t {
off_t newsize;
char *desc;
} TC[] = {
- {
- mapsize - 8192, "ftruncate mmaped file to a smaller size"}, {
- mapsize + 1024, "ftruncate mmaped file to a larger size"}, {
-0, "ftruncate mmaped file to 0 size"},};
+ {mapsize - 8192, "ftruncate mmaped file to a smaller size"},
+ {mapsize + 1024, "ftruncate mmaped file to a larger size"},
+ {0, "ftruncate mmaped file to 0 size"},
+};
+
+static void setup(void);
+static void cleanup(void);
int main(int argc, char **argv)
{
int lc;
int i;
- char *msg; /* for parse_opts */
+ char *msg;
if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
@@ -111,11 +91,10 @@
tst_exit();
}
-void setup()
+static void setup(void)
{
tst_sig(NOFORK, DEF_HANDLER, cleanup);
- /* Pause if option was specified */
TEST_PAUSE;
tst_tmpdir();
@@ -127,20 +106,19 @@
if (ftruncate(fd, mapsize) < 0)
tst_brkm(TFAIL | TERRNO, cleanup, "ftruncate file failed");
- maddr = mmap(0, (size_t) mapsize, PROT_READ | PROT_WRITE,
- MAP_FILE | MAP_SHARED, fd, (off_t) 0);
+ maddr = mmap(0, mapsize, PROT_READ | PROT_WRITE,
+ MAP_FILE | MAP_SHARED, fd, 0);
if (maddr == MAP_FAILED)
tst_brkm(TFAIL | TERRNO, cleanup, "mmapping mmaptest failed");
/* fill up the file with A's */
memset(maddr, 'A', mapsize);
-
}
-void cleanup()
+static void cleanup(void)
{
TEST_CLEANUP;
- munmap(maddr, (size_t) mapsize);
+ munmap(maddr, mapsize);
close(fd);
tst_rmdir();
}
diff --git a/testcases/kernel/syscalls/mmap/mmap10.c b/testcases/kernel/syscalls/mmap/mmap10.c
index 16ad299..4be367d 100644
--- a/testcases/kernel/syscalls/mmap/mmap10.c
+++ b/testcases/kernel/syscalls/mmap/mmap10.c
@@ -1,4 +1,27 @@
/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like. Any license provided herein, whether
+ * implied or otherwise, applies only to this software file. Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
* mmap/munmap /dev/zero: a common way of malloc()/free() anonymous
* memory on Solaris.
*
@@ -28,27 +51,6 @@
* is terrible. The mapping ZERO_PAGE in every pte within that virtual
* address range was an optimization to make the subsequent pagefault
* times faster on RHEL5 that has been removed/changed upstream.
- *
- * Copyright (C) 2010 Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like. Any license provided herein, whether
- * implied or otherwise, applies only to this software file. Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
*/
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/testcases/kernel/syscalls/mmap/mmap11.c b/testcases/kernel/syscalls/mmap/mmap11.c
index ffa0a01..6eaa154 100644
--- a/testcases/kernel/syscalls/mmap/mmap11.c
+++ b/testcases/kernel/syscalls/mmap/mmap11.c
@@ -1,4 +1,26 @@
/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program
+ * with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+/*
* munmap() don't check sysctl_max_mapcount
*
* From http://lkml.org/lkml/2009/10/2/85:
@@ -24,27 +46,6 @@
* free() shouldn't failed.
*
* Thus, munmap() shoudn't check max-mapcount.
- *
- * Copyright (C) 2010 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like. Any license provided herein, whether implied or
- * otherwise, applies only to this software file. Patent licenses, if
- * any, provided herein do not apply to combinations of this program
- * with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include<stdio.h>
#include<stdlib.h>