From 766da4190705a32fbddd5d0fe61175d76ad31090 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Wed, 15 Jun 2016 20:42:29 +0200 Subject: test: mmap2 is not ARM specific --- test/mmap/Makefile.in | 4 ---- test/mmap/mmap-arm.c | 46 ---------------------------------------------- test/mmap/mmap2.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 50 deletions(-) delete mode 100644 test/mmap/mmap-arm.c create mode 100644 test/mmap/mmap2.c (limited to 'test') diff --git a/test/mmap/Makefile.in b/test/mmap/Makefile.in index 7bb34acb6..581f3b062 100644 --- a/test/mmap/Makefile.in +++ b/test/mmap/Makefile.in @@ -1,6 +1,2 @@ # uClibc mmap tests # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - -ifneq ($(TARGET_ARCH),arm) -TESTS_DISABLED += mmap-arm -endif diff --git a/test/mmap/mmap-arm.c b/test/mmap/mmap-arm.c deleted file mode 100644 index 8b94c6199..000000000 --- a/test/mmap/mmap-arm.c +++ /dev/null @@ -1,46 +0,0 @@ -/* When trying to map /dev/mem with offset 0xFFFFF000 on the ARM platform, mmap - * returns -EOVERFLOW. - * - * Since off_t is defined as a long int and the sign bit is set in the address, - * the shift operation shifts in ones instead of zeroes - * from the left. This results the offset sent to the kernel function becomes - * 0xFFFFFFFF instead of 0x000FFFFF with MMAP2_PAGE_SHIFT set to 12. - */ - -#include -#include -#include -#include -#include -#include -#include - -#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \ - __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0) - -#define MAP_SIZE 4096UL -#define MAP_MASK (MAP_SIZE - 1) - -int main(int argc, char **argv) { - void* map_base = 0; - int fd; - off_t target = 0xfffff000; - if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) { - /* skip test for non-root users */ - if (errno == EACCES) - return 0; - FATAL; - } - printf("/dev/mem opened.\n"); - fflush(stdout); - - /* Map one page */ - map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, - fd, target & ~MAP_MASK); - if(map_base == (void *) -1) FATAL; - printf("Memory mapped at address %p.\n", map_base); - fflush(stdout); - if(munmap(map_base, MAP_SIZE) == -1) FATAL; - close(fd); - return 0; -} diff --git a/test/mmap/mmap2.c b/test/mmap/mmap2.c new file mode 100644 index 000000000..8b94c6199 --- /dev/null +++ b/test/mmap/mmap2.c @@ -0,0 +1,46 @@ +/* When trying to map /dev/mem with offset 0xFFFFF000 on the ARM platform, mmap + * returns -EOVERFLOW. + * + * Since off_t is defined as a long int and the sign bit is set in the address, + * the shift operation shifts in ones instead of zeroes + * from the left. This results the offset sent to the kernel function becomes + * 0xFFFFFFFF instead of 0x000FFFFF with MMAP2_PAGE_SHIFT set to 12. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \ + __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0) + +#define MAP_SIZE 4096UL +#define MAP_MASK (MAP_SIZE - 1) + +int main(int argc, char **argv) { + void* map_base = 0; + int fd; + off_t target = 0xfffff000; + if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) { + /* skip test for non-root users */ + if (errno == EACCES) + return 0; + FATAL; + } + printf("/dev/mem opened.\n"); + fflush(stdout); + + /* Map one page */ + map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, + fd, target & ~MAP_MASK); + if(map_base == (void *) -1) FATAL; + printf("Memory mapped at address %p.\n", map_base); + fflush(stdout); + if(munmap(map_base, MAP_SIZE) == -1) FATAL; + close(fd); + return 0; +} -- cgit v1.2.3