From: Bian Naimeng <biannm@cn.fujitsu.com>
To: Garrett Cooper <yanegomi@gmail.com>
Cc: ltp-list@lists.sourceforge.net
Subject: [LTP] [PATCH]Fix bug of hugemmap
Date: Tue, 28 Dec 2010 17:34:44 +0800 [thread overview]
Message-ID: <4D19AF34.9030907@cn.fujitsu.com> (raw)
Man pages of mmap said:
Use of a mapped region can result in these signals:
SIGSEGV
Attempted write into a region mapped as read-only.
SIGBUS
Attempted access to a portion of the buffer that does not correspond to the
file (for example, beyond the end of the file, including the case where
another process has truncated the file).
So we should make sure the size of file is not zero, otherwise test will fail
when write to the mapped region.
Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com>
---
testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c | 11 +++++++++--
testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c | 11 +++++++++--
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
index 3676f1b..33b3ade 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
@@ -73,7 +73,8 @@
#include "test.h"
#include "usctest.h"
-#define BUFFER_SIZE 256
+#define BUFFER_SIZE 256
+#define FILE_SIZE 1024
char* TEMPFILE="mmapfile";
@@ -129,12 +130,18 @@ main(int ac, char **av)
/* Check looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* Creat a temporary file used for mapping */
+ /* Creat a temporary file used for mapping,and truncate it */
if ((fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0) {
tst_brkm(TFAIL, cleanup,
"open() on %s Failed, errno=%d : %s",
TEMPFILE, errno, strerror(errno));
}
+ if (ftruncate(fildes, FILE_SIZE) < 0) {
+ close(fildes);
+ tst_brkm(TFAIL, cleanup,
+ "ftruncate() on %s Failed, errno=%d : %s",
+ TEMPFILE, errno, strerror(errno));
+ }
/* Reset Tst_count in case we are looping. */
Tst_count=0;
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
index c3b7af2..02d7e9f 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
@@ -74,7 +74,8 @@
#include "usctest.h"
#include "system_specific_hugepages_info.h"
-#define BUFFER_SIZE 256
+#define BUFFER_SIZE 256
+#define FILE_SIZE 1024
char* TEMPFILE="mmapfile";
@@ -135,12 +136,18 @@ main(int ac, char **av)
/* Check looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* Creat a temporary file used for mapping */
+ /* Creat a temporary file used for mapping, and truncate it */
if ((fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0) {
tst_brkm(TFAIL, cleanup,
"open() on %s Failed, errno=%d : %s",
TEMPFILE, errno, strerror(errno));
}
+ if (ftruncate(fildes, FILE_SIZE) < 0) {
+ close(fildes);
+ tst_brkm(TFAIL, cleanup,
+ "ftruncate() on %s Failed, errno=%d : %s",
+ TEMPFILE, errno, strerror(errno));
+ }
/* Reset Tst_count in case we are looping. */
Tst_count=0;
--
1.7.0.4
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
reply other threads:[~2010-12-28 9:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D19AF34.9030907@cn.fujitsu.com \
--to=biannm@cn.fujitsu.com \
--cc=ltp-list@lists.sourceforge.net \
--cc=yanegomi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox