zte's code,first commit
Change-Id: I9a04da59e459a9bc0d67f101f700d9d7dc8d681b
diff --git a/ap/build/uClibc/test/mmap/Makefile b/ap/build/uClibc/test/mmap/Makefile
new file mode 100644
index 0000000..64b652d
--- /dev/null
+++ b/ap/build/uClibc/test/mmap/Makefile
@@ -0,0 +1,7 @@
+# uClibc mmap tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+top_builddir=../../
+include ../Rules.mak
+-include Makefile.in
+include ../Test.mak
diff --git a/ap/build/uClibc/test/mmap/mmap.c b/ap/build/uClibc/test/mmap/mmap.c
new file mode 100644
index 0000000..8b29737
--- /dev/null
+++ b/ap/build/uClibc/test/mmap/mmap.c
@@ -0,0 +1,73 @@
+
+/* The mmap test is useful, since syscalls with 6 arguments
+ * (as mmap) are done differently on various architectures.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#define SIZEOF_ARRAY(type) (sizeof(type)/sizeof(*type))
+
+struct mmap_test {
+ void *ret;
+ int err;
+ struct {
+ void *start;
+ size_t length;
+ int prot;
+ int flags;
+ int fd;
+ off_t offset;
+ } args;
+};
+
+struct mmap_test tests[] = {
+ [0] {
+ .err = 0,
+ .args.start = NULL,
+ .args.length = 4096,
+ .args.prot = PROT_READ|PROT_WRITE,
+ .args.flags = MAP_PRIVATE|MAP_ANONYMOUS,
+ .args.fd = 0,
+ .args.offset = 0
+ },
+};
+
+#define err(fmt, args...) \
+ do { \
+ fprintf(stderr, fmt "\n" , ## args); \
+ exit(1); \
+ } while (0)
+#define errp(fmt, args...) err(fmt ": %s" , ## args , strerror(errno))
+
+int main(int argc, char **argv)
+{
+ int i;
+ struct mmap_test *t;
+
+ for (i=0; i<SIZEOF_ARRAY(tests); ++i) {
+ t = tests + i;
+
+ errno = 0;
+ t->ret = mmap(t->args.start, t->args.length, t->args.prot,
+ t->args.flags, t->args.fd, t->args.offset);
+
+ if (t->err) {
+ if (t->ret != MAP_FAILED)
+ err("mmap test %i should have failed, but gave us %p", i, t->ret);
+ else if (t->err != errno)
+ errp("mmap test %i failed, but gave us wrong errno (got %i instead of %i)", i, errno, t->err);
+ } else {
+ if (t->ret == MAP_FAILED)
+ errp("mmap test %i failed", i);
+ else if (munmap(t->ret, t->args.length) != 0)
+ errp("munmap test %i failed", i);
+ }
+ }
+
+ exit(0);
+}
diff --git a/ap/build/uClibc/test/mmap/mmap2.c b/ap/build/uClibc/test/mmap/mmap2.c
new file mode 100644
index 0000000..8b94c61
--- /dev/null
+++ b/ap/build/uClibc/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 <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#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/ap/build/uClibc/test/mmap/mmap64.c b/ap/build/uClibc/test/mmap/mmap64.c
new file mode 100644
index 0000000..87165fe
--- /dev/null
+++ b/ap/build/uClibc/test/mmap/mmap64.c
@@ -0,0 +1,29 @@
+
+/* The mmap test is useful, since syscalls with 6 arguments
+ * (as mmap) are done differently on various architectures.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <features.h>
+
+int main(int argc, char **argv)
+{
+#ifdef __UCLIBC_HAS_LFS__
+ void *ptr;
+
+ ptr = mmap64(NULL, 4096, PROT_READ|PROT_WRITE,
+ MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+
+ if (ptr == MAP_FAILED) {
+ perror("mmap");
+ exit(1);
+ }
+ printf("mmap returned %p\n", ptr);
+ exit(0);
+#else
+ exit(0);
+#endif
+}