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 <[email protected]>
---
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list