many low memory boards don't have 1G memory,so add get_free_mem
function for low memory target, limit 3000M for 64bit kernel with
n32 file system.

Signed-off-by: Shang Yanfeng <[email protected]>
---
 testcases/kernel/mem/mtest06/mmap2.c |   50 ++++++++++++++++++++++++++-------
 1 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/testcases/kernel/mem/mtest06/mmap2.c 
b/testcases/kernel/mem/mtest06/mmap2.c
index 6d56a54..18c2b07 100644
--- a/testcases/kernel/mem/mtest06/mmap2.c
+++ b/testcases/kernel/mem/mtest06/mmap2.c
@@ -68,13 +68,14 @@
 #include <signal.h>
 #include <sys/time.h>
 #include <sys/wait.h>
+#include <sys/sysinfo.h>
 #include <signal.h>
 #include <string.h>
 #include <getopt.h>
 #include "test.h"
 #include "usctest.h"
 
-#define GB 1000000000
+#define MB 1048576
 #ifndef TRUE
 #define TRUE 1
 #endif
@@ -100,7 +101,7 @@ static int mkfile(int size)
                fprintf(stdout, "creating tmp file and writing 'a' to it ");
        }
 
-       while (index < (size * GB)) {
+       while (index < (size * MB)) {
                index += 4096;
                if (write(fd, buff, 4096) == -1) {
                        perror("mkfile(): write()");
@@ -128,6 +129,17 @@ static void sig_handler(int signal)
        exit(0);
 }
 
+
+static unsigned long get_free_mem()
+{
+       struct sysinfo board_sysinfo;
+       unsigned long avail_mem;
+       if (sysinfo(&board_sysinfo))
+               perror("sysinfo failed\n");
+       avail_mem = board_sysinfo.freeram/MB;
+       return avail_mem;
+}
+
 static void usage(char *progname)
 {
        fprintf(stderr,
@@ -137,7 +149,7 @@ static void usage(char *progname)
                        "\t -p set map_flag to MAP_PRIVATE.\tdefault:"
                        "MAP_SHARED\n"
                        "\t -s size of the file/memory to be mmaped.\tdefault:"
-                       "1GB\n"
+                       "1000MB\n"
                        "\t -x time for which test is to be run.\tdefault:"
                        "24 Hrs\n",
                        progname);
@@ -147,7 +159,7 @@ static void usage(char *progname)
 int main(int argc, char **argv)
 {
        int   fd;
-       int   fsize = 1;
+       unsigned long fsize = 1000;
        float exec_time = 24;
        int   c;
        int   sig_ndx;
@@ -174,6 +186,14 @@ int main(int argc, char **argv)
                {-1,     "ENDSIG"}
        };
 
+       fsize = get_free_mem()/2;
+
+/* threshold for 64bit kernel with n32 file system */
+
+#if __WORDSIZE == 32
+       if (fsize > 3000)
+               fprintf(stderr, "Using default fsize %ld MB\n", fsize = 3000);
+#endif
        while ((c =  getopt(argc, argv, "ahps:x:")) != -1) {
                        switch (c) {
                        case 'a':
@@ -188,9 +208,17 @@ int main(int argc, char **argv)
                                break;
                        case 's':
                                fsize = atoi(optarg);
+#if __WORDSIZE == 32
+                               if (fsize == 0 || fsize > 3000)
+                                       fprintf(stderr,
+                                       "Using default size %ld MB\n",
+                                       fsize = 1000);
+#else
                                if (fsize == 0)
-                                       fprintf(stderr, "Using default "
-                                               "fsize %d GB\n", fsize = 1);
+                                       fprintf(stderr,
+                                       "Using default fsize %ld MB\n",
+                                       fsize = 1000);
+#endif
                                break;
                        case 'x':
                                exec_time = atof(optarg);
@@ -208,7 +236,7 @@ int main(int argc, char **argv)
 
        fprintf(stdout, "MM Stress test, map/write/unmap large file\n"
                        "\tTest scheduled to run for:       %f\n"
-                       "\tSize of temp file in GB:         %d\n",
+                       "\tSize of temp file in MB:         %ld\n",
                        exec_time, fsize);
 
        alarm(exec_time * 3600.00);
@@ -239,7 +267,7 @@ int main(int argc, char **argv)
                        fd = -1;
                        map_flags = map_flags|MAP_ANONYMOUS;
                }
-               memptr = mmap(0, (fsize * GB), PROT_READ|PROT_WRITE,
+               memptr = mmap(0, (fsize * MB), PROT_READ|PROT_WRITE,
                                        map_flags, fd, 0);
                if (memptr  == MAP_FAILED) {
                        perror("main(): mmap()");
@@ -248,15 +276,15 @@ int main(int argc, char **argv)
                        fprintf(stdout, "file mapped at %p\n"
                                "changing file content to 'A'\n", memptr);
 
-               memset(memptr, 'A', ((fsize * GB)/sizeof(char)));
+               memset(memptr, 'A', ((fsize * MB)/sizeof(char)));
 
-               if (msync(memptr, ((fsize * GB)/sizeof(char)),
+               if (msync(memptr, ((fsize * MB)/sizeof(char)),
                                        MS_SYNC|MS_INVALIDATE) == -1) {
                        perror("main(): msync()");
                        exit(-1);
                }
 
-               if (munmap(memptr, (fsize * GB)/sizeof(char)) == -1) {
+               if (munmap(memptr, (fsize * MB)/sizeof(char)) == -1) {
                        perror("main(): munmap()");
                        exit(-1);
                } else
-- 
1.6.3.1


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to