aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/Makefile2
-rw-r--r--Documentation/vm/Makefile8
-rw-r--r--tools/testing/selftests/Makefile2
-rw-r--r--tools/testing/selftests/vm/Makefile14
-rw-r--r--tools/testing/selftests/vm/hugepage-mmap.c (renamed from Documentation/vm/hugepage-mmap.c)13
-rw-r--r--tools/testing/selftests/vm/hugepage-shm.c (renamed from Documentation/vm/hugepage-shm.c)10
-rw-r--r--tools/testing/selftests/vm/map_hugetlb.c (renamed from Documentation/vm/map_hugetlb.c)10
-rw-r--r--tools/testing/selftests/vm/run_vmtests77
8 files changed, 112 insertions, 24 deletions
diff --git a/Documentation/Makefile b/Documentation/Makefile
index 9b4bc5c76f33..30b656ece7aa 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -1,3 +1,3 @@
1obj-m := DocBook/ accounting/ auxdisplay/ connector/ \ 1obj-m := DocBook/ accounting/ auxdisplay/ connector/ \
2 filesystems/ filesystems/configfs/ ia64/ laptops/ networking/ \ 2 filesystems/ filesystems/configfs/ ia64/ laptops/ networking/ \
3 pcmcia/ spi/ timers/ vm/ watchdog/src/ 3 pcmcia/ spi/ timers/ watchdog/src/
diff --git a/Documentation/vm/Makefile b/Documentation/vm/Makefile
deleted file mode 100644
index e538864bfc63..000000000000
--- a/Documentation/vm/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
1# kbuild trick to avoid linker error. Can be omitted if a module is built.
2obj- := dummy.o
3
4# List of programs to build
5hostprogs-y := hugepage-mmap hugepage-shm map_hugetlb
6
7# Tell kbuild to always build the programs
8always := $(hostprogs-y)
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 9203cd77fc33..28bc57ee757c 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -1,4 +1,4 @@
1TARGETS = breakpoints 1TARGETS = breakpoints vm
2 2
3all: 3all:
4 for TARGET in $(TARGETS); do \ 4 for TARGET in $(TARGETS); do \
diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
new file mode 100644
index 000000000000..b336b24aa6c0
--- /dev/null
+++ b/tools/testing/selftests/vm/Makefile
@@ -0,0 +1,14 @@
1# Makefile for vm selftests
2
3CC = $(CROSS_COMPILE)gcc
4CFLAGS = -Wall -Wextra
5
6all: hugepage-mmap hugepage-shm map_hugetlb
7%: %.c
8 $(CC) $(CFLAGS) -o $@ $^
9
10run_tests: all
11 /bin/sh ./run_vmtests
12
13clean:
14 $(RM) hugepage-mmap hugepage-shm map_hugetlb
diff --git a/Documentation/vm/hugepage-mmap.c b/tools/testing/selftests/vm/hugepage-mmap.c
index db0dd9a33d54..a10f310d2362 100644
--- a/Documentation/vm/hugepage-mmap.c
+++ b/tools/testing/selftests/vm/hugepage-mmap.c
@@ -22,7 +22,7 @@
22#include <sys/mman.h> 22#include <sys/mman.h>
23#include <fcntl.h> 23#include <fcntl.h>
24 24
25#define FILE_NAME "/mnt/hugepagefile" 25#define FILE_NAME "huge/hugepagefile"
26#define LENGTH (256UL*1024*1024) 26#define LENGTH (256UL*1024*1024)
27#define PROTECTION (PROT_READ | PROT_WRITE) 27#define PROTECTION (PROT_READ | PROT_WRITE)
28 28
@@ -48,7 +48,7 @@ static void write_bytes(char *addr)
48 *(addr + i) = (char)i; 48 *(addr + i) = (char)i;
49} 49}
50 50
51static void read_bytes(char *addr) 51static int read_bytes(char *addr)
52{ 52{
53 unsigned long i; 53 unsigned long i;
54 54
@@ -56,14 +56,15 @@ static void read_bytes(char *addr)
56 for (i = 0; i < LENGTH; i++) 56 for (i = 0; i < LENGTH; i++)
57 if (*(addr + i) != (char)i) { 57 if (*(addr + i) != (char)i) {
58 printf("Mismatch at %lu\n", i); 58 printf("Mismatch at %lu\n", i);
59 break; 59 return 1;
60 } 60 }
61 return 0;
61} 62}
62 63
63int main(void) 64int main(void)
64{ 65{
65 void *addr; 66 void *addr;
66 int fd; 67 int fd, ret;
67 68
68 fd = open(FILE_NAME, O_CREAT | O_RDWR, 0755); 69 fd = open(FILE_NAME, O_CREAT | O_RDWR, 0755);
69 if (fd < 0) { 70 if (fd < 0) {
@@ -81,11 +82,11 @@ int main(void)
81 printf("Returned address is %p\n", addr); 82 printf("Returned address is %p\n", addr);
82 check_bytes(addr); 83 check_bytes(addr);
83 write_bytes(addr); 84 write_bytes(addr);
84 read_bytes(addr); 85 ret = read_bytes(addr);
85 86
86 munmap(addr, LENGTH); 87 munmap(addr, LENGTH);
87 close(fd); 88 close(fd);
88 unlink(FILE_NAME); 89 unlink(FILE_NAME);
89 90
90 return 0; 91 return ret;
91} 92}
diff --git a/Documentation/vm/hugepage-shm.c b/tools/testing/selftests/vm/hugepage-shm.c
index 07956d8592c9..0d0ef4fc0c04 100644
--- a/Documentation/vm/hugepage-shm.c
+++ b/tools/testing/selftests/vm/hugepage-shm.c
@@ -57,8 +57,8 @@ int main(void)
57 unsigned long i; 57 unsigned long i;
58 char *shmaddr; 58 char *shmaddr;
59 59
60 if ((shmid = shmget(2, LENGTH, 60 shmid = shmget(2, LENGTH, SHM_HUGETLB | IPC_CREAT | SHM_R | SHM_W);
61 SHM_HUGETLB | IPC_CREAT | SHM_R | SHM_W)) < 0) { 61 if (shmid < 0) {
62 perror("shmget"); 62 perror("shmget");
63 exit(1); 63 exit(1);
64 } 64 }
@@ -82,14 +82,16 @@ int main(void)
82 82
83 dprintf("Starting the Check..."); 83 dprintf("Starting the Check...");
84 for (i = 0; i < LENGTH; i++) 84 for (i = 0; i < LENGTH; i++)
85 if (shmaddr[i] != (char)i) 85 if (shmaddr[i] != (char)i) {
86 printf("\nIndex %lu mismatched\n", i); 86 printf("\nIndex %lu mismatched\n", i);
87 exit(3);
88 }
87 dprintf("Done.\n"); 89 dprintf("Done.\n");
88 90
89 if (shmdt((const void *)shmaddr) != 0) { 91 if (shmdt((const void *)shmaddr) != 0) {
90 perror("Detach failure"); 92 perror("Detach failure");
91 shmctl(shmid, IPC_RMID, NULL); 93 shmctl(shmid, IPC_RMID, NULL);
92 exit(3); 94 exit(4);
93 } 95 }
94 96
95 shmctl(shmid, IPC_RMID, NULL); 97 shmctl(shmid, IPC_RMID, NULL);
diff --git a/Documentation/vm/map_hugetlb.c b/tools/testing/selftests/vm/map_hugetlb.c
index eda1a6d3578a..ac56639dd4a9 100644
--- a/Documentation/vm/map_hugetlb.c
+++ b/tools/testing/selftests/vm/map_hugetlb.c
@@ -44,7 +44,7 @@ static void write_bytes(char *addr)
44 *(addr + i) = (char)i; 44 *(addr + i) = (char)i;
45} 45}
46 46
47static void read_bytes(char *addr) 47static int read_bytes(char *addr)
48{ 48{
49 unsigned long i; 49 unsigned long i;
50 50
@@ -52,13 +52,15 @@ static void read_bytes(char *addr)
52 for (i = 0; i < LENGTH; i++) 52 for (i = 0; i < LENGTH; i++)
53 if (*(addr + i) != (char)i) { 53 if (*(addr + i) != (char)i) {
54 printf("Mismatch at %lu\n", i); 54 printf("Mismatch at %lu\n", i);
55 break; 55 return 1;
56 } 56 }
57 return 0;
57} 58}
58 59
59int main(void) 60int main(void)
60{ 61{
61 void *addr; 62 void *addr;
63 int ret;
62 64
63 addr = mmap(ADDR, LENGTH, PROTECTION, FLAGS, 0, 0); 65 addr = mmap(ADDR, LENGTH, PROTECTION, FLAGS, 0, 0);
64 if (addr == MAP_FAILED) { 66 if (addr == MAP_FAILED) {
@@ -69,9 +71,9 @@ int main(void)
69 printf("Returned address is %p\n", addr); 71 printf("Returned address is %p\n", addr);
70 check_bytes(addr); 72 check_bytes(addr);
71 write_bytes(addr); 73 write_bytes(addr);
72 read_bytes(addr); 74 ret = read_bytes(addr);
73 75
74 munmap(addr, LENGTH); 76 munmap(addr, LENGTH);
75 77
76 return 0; 78 return ret;
77} 79}
diff --git a/tools/testing/selftests/vm/run_vmtests b/tools/testing/selftests/vm/run_vmtests
new file mode 100644
index 000000000000..8b40bd5e5cc2
--- /dev/null
+++ b/tools/testing/selftests/vm/run_vmtests
@@ -0,0 +1,77 @@
1#!/bin/bash
2#please run as root
3
4#we need 256M, below is the size in kB
5needmem=262144
6mnt=./huge
7
8#get pagesize and freepages from /proc/meminfo
9while read name size unit; do
10 if [ "$name" = "HugePages_Free:" ]; then
11 freepgs=$size
12 fi
13 if [ "$name" = "Hugepagesize:" ]; then
14 pgsize=$size
15 fi
16done < /proc/meminfo
17
18#set proper nr_hugepages
19if [ -n "$freepgs" ] && [ -n "$pgsize" ]; then
20 nr_hugepgs=`cat /proc/sys/vm/nr_hugepages`
21 needpgs=`expr $needmem / $pgsize`
22 if [ $freepgs -lt $needpgs ]; then
23 lackpgs=$(( $needpgs - $freepgs ))
24 echo $(( $lackpgs + $nr_hugepgs )) > /proc/sys/vm/nr_hugepages
25 if [ $? -ne 0 ]; then
26 echo "Please run this test as root"
27 exit 1
28 fi
29 fi
30else
31 echo "no hugetlbfs support in kernel?"
32 exit 1
33fi
34
35mkdir $mnt
36mount -t hugetlbfs none $mnt
37
38echo "--------------------"
39echo "runing hugepage-mmap"
40echo "--------------------"
41./hugepage-mmap
42if [ $? -ne 0 ]; then
43 echo "[FAIL]"
44else
45 echo "[PASS]"
46fi
47
48shmmax=`cat /proc/sys/kernel/shmmax`
49shmall=`cat /proc/sys/kernel/shmall`
50echo 268435456 > /proc/sys/kernel/shmmax
51echo 4194304 > /proc/sys/kernel/shmall
52echo "--------------------"
53echo "runing hugepage-shm"
54echo "--------------------"
55./hugepage-shm
56if [ $? -ne 0 ]; then
57 echo "[FAIL]"
58else
59 echo "[PASS]"
60fi
61echo $shmmax > /proc/sys/kernel/shmmax
62echo $shmall > /proc/sys/kernel/shmall
63
64echo "--------------------"
65echo "runing map_hugetlb"
66echo "--------------------"
67./map_hugetlb
68if [ $? -ne 0 ]; then
69 echo "[FAIL]"
70else
71 echo "[PASS]"
72fi
73
74#cleanup
75umount $mnt
76rm -rf $mnt
77echo $nr_hugepgs > /proc/sys/vm/nr_hugepages